Skip to content

Commit

Permalink
release: desktop shimmer 2.1.11 #7992 from iotaledger/release/desktop…
Browse files Browse the repository at this point in the history
…-shimmer-2.1.11

Merge pull request #7992 from iotaledger/release/desktop-shimmer-2.1.11
  • Loading branch information
begonaalvarezd authored Feb 6, 2024
2 parents 7cfce69 + 2545b70 commit 0d6e0ad
Show file tree
Hide file tree
Showing 29 changed files with 685 additions and 620 deletions.
8 changes: 8 additions & 0 deletions packages/desktop/components/modals/AccountActionsMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
modal?.close()
}
function onWithdrawFromL2Click(): void {
openPopup({ id: PopupId.WithdrawFromL2 })
modal?.close()
}
function onVerifyAddressClick(): void {
const ADDRESS_INDEX = 0
checkOrConnectLedger(() => {
Expand Down Expand Up @@ -79,6 +84,9 @@
onClick={onViewAddressHistoryClick}
/>
{/if}
{#if $activeProfile?.network?.id === NetworkId.Shimmer || $activeProfile?.network?.id === NetworkId.Testnet}
<MenuItem icon={Icon.Transfer} title={localize('actions.withdrawFromL2')} onClick={onWithdrawFromL2Click} />
{/if}
<MenuItem icon={Icon.Customize} title={localize('actions.customizeAcount')} onClick={onCustomiseAccountClick} />
{#if $isActiveLedgerProfile}
<MenuItem
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop/components/popups/Popup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import VestingCollectPopup from './VestingCollectPopup.svelte'
import PayoutDetailsPopup from './PayoutDetailsPopup.svelte'
import VestingRewardsFinderPopup from './VestingRewardsFinderPopup.svelte'
import WithdrawFromL2Popup from './WithdrawFromL2Popup.svelte'
export let id: PopupId
export let props: any
Expand Down Expand Up @@ -144,6 +145,7 @@
[PopupId.VestingCollect]: VestingCollectPopup,
[PopupId.PayoutDetails]: PayoutDetailsPopup,
[PopupId.VestingRewardsFinder]: VestingRewardsFinderPopup,
[PopupId.WithdrawFromL2]: WithdrawFromL2Popup,
}
function onKey(event: KeyboardEvent): void {
Expand Down
219 changes: 219 additions & 0 deletions packages/desktop/components/popups/WithdrawFromL2Popup.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
<script lang="ts">
import { PopupId, closePopup, openPopup } from '@auxiliary/popup'
import { getSelectedAccount } from '@core/account'
import { localize } from '@core/i18n'
import { getArchivedBaseTokens } from '@core/layer-2/helpers/getArchivedBaseTokens'
import { getBaseToken, getCoinType, activeProfile, isActiveLedgerProfile, isSoftwareProfile } from '@core/profile'
import { truncateString } from '@core/utils'
import { formatTokenAmountPrecise, getRequiredStorageDepositForMinimalBasicOutput } from '@core/wallet'
import { Button, FontWeight, KeyValueBox, Spinner, Text, TextType } from 'shared/components'
import { onMount } from 'svelte'
import { WithdrawRequest, getLayer2WithdrawRequest } from '@core/layer-2/utils'
import { withdrawL2Funds } from '@core/layer-2/helpers/widthdrawL2Funds'
import { getL2ReceiptByRequestId } from '@core/layer-2/helpers/getL2ReceiptByRequestId'
import { showAppNotification } from '@auxiliary/notification'
import { Bip44 } from '@iota/sdk/out/types'
import { displayNotificationForLedgerProfile, ledgerNanoStatus } from '@core/ledger'
import { getEstimatedGasForOffLedgerRequest, getNonceForWithdrawRequest } from '@core/layer-2/helpers'
export let withdrawOnLoad = false
export let withdrawableAmount: number
const WASP_ISC_OPTIMIZATION_AMOUNT = 1
const WASP_ISC_MOCK_GAS_AMOUNT = 1000
const bip44Chain: Bip44 = {
coinType: Number(getCoinType()),
account: getSelectedAccount().index,
change: 0,
addressIndex: 0,
}
let error = ''
let address: string | undefined = undefined
let isWithdrawing = false
const { isStrongholdLocked } = $activeProfile
$: withdrawOnLoad && address && !$isStrongholdLocked && withdrawFromL2()
function onCancelClick(): void {
closePopup()
}
async function onWithdrawFromL2Click(): Promise<void> {
if ($isSoftwareProfile && $isStrongholdLocked) {
openUnlockStrongholdPopup()
} else {
await handleAction(withdrawFromL2)
}
}
async function handleAction(callback: () => Promise<void>): Promise<void> {
try {
error = ''
if ($isActiveLedgerProfile && !$ledgerNanoStatus.connected) {
displayNotificationForLedgerProfile('warning')
return
}
await callback()
} catch (err) {
error = localize(err.error)
if ($isActiveLedgerProfile) {
displayNotificationForLedgerProfile('error', true, true, err)
} else {
showAppNotification({
type: 'error',
message: localize(err.error),
})
}
}
}
async function withdrawFromL2(): Promise<void> {
isWithdrawing = true
if ($isActiveLedgerProfile && !$ledgerNanoStatus.connected) {
isWithdrawing = false
displayNotificationForLedgerProfile('warning')
return
}
try {
const nonce = await getNonceForWithdrawRequest(address)
if (!nonce) {
isWithdrawing = false
displayNotificationForLedgerProfile('warning')
return
}
const minRequiredStorageDeposit: number = Number(await getRequiredStorageDepositForMinimalBasicOutput())
let withdrawAmount =
withdrawableAmount < minRequiredStorageDeposit + WASP_ISC_MOCK_GAS_AMOUNT
? withdrawableAmount
: withdrawableAmount - WASP_ISC_MOCK_GAS_AMOUNT
// create withdraw request for gas estimations with hardcoded gasBudget
let withdrawRequest: WithdrawRequest | undefined
withdrawRequest = await getLayer2WithdrawRequest(withdrawAmount, nonce, bip44Chain)
const gasEstimatePayload = await getEstimatedGasForOffLedgerRequest(withdrawRequest.request)
// adjust withdrawAmount to use estimated gas fee charged
withdrawAmount = withdrawableAmount - gasEstimatePayload.gasFeeCharged
// calculate gas
const gasBudget = gasEstimatePayload.gasBurned + WASP_ISC_OPTIMIZATION_AMOUNT
if (withdrawableAmount > Number(minRequiredStorageDeposit) + Number(gasBudget)) {
// Create new withdraw request with correct gas budget and withdraw amount
withdrawRequest = await getLayer2WithdrawRequest(withdrawAmount, nonce, bip44Chain, gasBudget)
} else {
isWithdrawing = false
showErrorNotification(localize('error.send.notEnoughBalance'))
return
}
await withdrawL2Funds(withdrawRequest.request)
const receipt = await getL2ReceiptByRequestId(withdrawRequest.requestId)
isWithdrawing = false
if (receipt?.errorMessage) {
// if withdawing fails refresh the withdrawable amount because gas was used for the withdraw attempt
withdrawableAmount = await getArchivedBaseTokens(address)
showErrorNotification(receipt?.errorMessage)
} else {
closePopup()
}
} catch (err) {
// if withdawing fails refresh the withdrawable amount because gas was used for the withdraw attempt (withdrawL2Funds())
withdrawableAmount = await getArchivedBaseTokens(address)
let error = err
// TODO: check error object in real ledger device when user cancels transaction. (In simulator the returned object is a string)
// parse the error because ledger simulator returns error as a string.
if (typeof err === 'string') {
try {
const parsedError = JSON.parse(err)
error = parsedError?.payload ? parsedError.payload : parsedError
} catch (e) {
console.error(e)
}
}
isWithdrawing = false
showErrorNotification(error)
}
}
function openUnlockStrongholdPopup(): void {
openPopup({
id: PopupId.UnlockStronghold,
props: {
onSuccess: () => {
openPopup({
id: PopupId.WithdrawFromL2,
props: {
withdrawOnLoad: true,
withdrawableAmount,
},
})
},
onCancelled: () => {
openPopup({
id: PopupId.WithdrawFromL2,
props: {
withdrawableAmount,
},
})
},
subtitle: localize('popups.password.backup'),
},
})
}
function showErrorNotification(error): void {
if ($isActiveLedgerProfile) {
displayNotificationForLedgerProfile('error', true, false, error)
} else {
showAppNotification({
type: 'error',
message: error,
alert: true,
})
}
}
onMount(async () => {
address = getSelectedAccount().depositAddress
if (!withdrawableAmount) {
withdrawableAmount = await getArchivedBaseTokens(address)
}
})
</script>

<div class="flex flex-col space-y-6">
<Text type={TextType.h3} fontWeight={FontWeight.semibold} lineHeight="6">
{localize('popups.withdrawFromL2.title')}
</Text>
<Text fontSize="15" color="gray-700" classes="text-left">{localize('popups.withdrawFromL2.body')}</Text>
{#if address}
<KeyValueBox
classes="flex items-center w-full py-4"
keyText={truncateString(address, 15, 15)}
valueText={formatTokenAmountPrecise(withdrawableAmount, getBaseToken())}
/>
{:else}
<div class="flex items-center justify-center">
<Spinner />
</div>
{/if}
<div class="flex flex-row flex-nowrap w-full space-x-4 mt-6">
<Button classes="w-full" outline onClick={onCancelClick} disabled={isWithdrawing}>
{localize('actions.cancel')}
</Button>
<Button
classes="w-full"
onClick={onWithdrawFromL2Click}
disabled={!withdrawableAmount || Number(withdrawableAmount) === 0 || isWithdrawing}
isBusy={isWithdrawing}
busyMessage={localize('popups.withdrawFromL2.withdrawing')}
>
{localize('popups.withdrawFromL2.withdraw')}
</Button>
</div>
</div>
12 changes: 2 additions & 10 deletions packages/desktop/electron-builder-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const notarize = require('./scripts/notarize.macos.js')
const getNotarizeOptions = require('./scripts/notarize.macos.js')
const merge = require('lodash.merge')
const { STAGE, getAppName, APP_ID, APP_PROTOCOL, CHANNEL_NAME, APP_ARTIFACT } = require('./product.js')

Expand All @@ -9,15 +9,6 @@ const prodConfig = () => ({
directories: { buildResources: './public', output: './out' },
files: ['public/', 'package.json', '!node_modules/@iota/sdk/target/*'],
appId: APP_ID,
afterSign: async () => {
// eslint-disable-next-line no-useless-catch
try {
await notarize(getAppName())
} catch (err) {
// This catch is necessary or the promise rejection is swallowed
throw err
}
},
asar: true,
protocols: [{ name: `${getAppName()} URL Scheme`, schemes: [APP_PROTOCOL] }],
dmg: {
Expand Down Expand Up @@ -63,6 +54,7 @@ const prodConfig = () => ({
hardenedRuntime: true,
gatekeeperAssess: false,
asarUnpack: ['**/*.node'],
notarize: getNotarizeOptions(),
},
publish: {
provider: 'generic',
Expand Down
19 changes: 10 additions & 9 deletions packages/desktop/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,19 @@ app.on('window-all-closed', () => {
}
})

powerMonitor.on('suspend', () => {
// MacOS, Windows and Linux
windows.main?.webContents?.send('power-monitor-suspend')
})
app.once('ready', () => {
powerMonitor.on('suspend', () => {
// MacOS, Windows and Linux
windows.main?.webContents?.send('power-monitor-suspend')
})

powerMonitor.on('lock-screen', () => {
// MacOS and Windows
windows.main?.webContents?.send('power-monitor-lock-screen')
})
powerMonitor.on('lock-screen', () => {
// MacOS and Windows
windows.main?.webContents?.send('power-monitor-lock-screen')
})

app.once('ready', () => {
ipcMain.handle('error-data', () => lastError)

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
Expand Down
7 changes: 7 additions & 0 deletions packages/desktop/electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ try {

return client
},
async getSecretManager(managerId) {
const manager = profileManagers[managerId]
const secretManager = await manager.getSecretManager()
bindMethodsAcrossContextBridge(IotaSdk.SecretManager.prototype, secretManager)

return secretManager
},
async migrateStrongholdSnapshotV2ToV3(currentPath, newPath, currentPassword, newPassword) {
const snapshotSaltV2 = 'wallet.rs'
const snapshotRoundsV2 = 100
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/features/electron.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const electronFeatures: IElectronFeatures = {
autoUpdate: {
enabled: true,
win32: {
enabled: false,
enabled: true,
},
linux: {
enabled: true,
Expand Down
13 changes: 6 additions & 7 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "desktop",
"productName": "Firefly Shimmer",
"version": "2.1.10",
"version": "2.1.11",
"description": "Official wallet application of Shimmer",
"main": "public/build/main.js",
"repository": "[email protected]:iotaledger/firefly.git",
Expand Down Expand Up @@ -32,9 +32,9 @@
"@sentry/electron": "^4.10.0",
"@types/webpack-dev-server": "^4.7.2",
"dotenv": "^16.0.3",
"electron-dl": "^3.5.0",
"electron-log": "^4.3.1",
"electron-updater": "5.3.0",
"electron-dl": "^3.5.1",
"electron-log": "^4.4.8",
"electron-updater": "6.1.4",
"https-browserify": "^1.0.0",
"keytar": "^7.9.0",
"node-machine-id": "^1.1.12",
Expand All @@ -43,14 +43,13 @@
},
"devDependencies": {
"@sentry/webpack-plugin": "^2.8.0",
"@electron/notarize": "^2.1.0",
"@tsconfig/svelte": "^4.0.1",
"@types/webpack": "^5.28.1",
"copy-webpack-plugin": "^11.0.0",
"cross-env": "^7.0.2",
"css-loader": "^6.7.3",
"electron": "22.3.27",
"electron-builder": "^24.0.0",
"electron": "27.0.2",
"electron-builder": "^24.6.4",
"esbuild-loader": "^4.0.2",
"lodash.merge": "^4.6.2",
"mini-css-extract-plugin": "^2.7.6",
Expand Down
Loading

0 comments on commit 0d6e0ad

Please sign in to comment.