From bc23fd8319eb8b92aa999fe1d6962d0a9f559681 Mon Sep 17 00:00:00 2001 From: Mark Nardi Date: Fri, 5 Apr 2024 17:01:09 +0200 Subject: [PATCH] chore: update profile auth for evm address generation (#2268) * update profile auth on networkcard * update profile auth on receive address popup * update profile auth on network summary * remove checkActiveProfileAuth * remove unused prop * chore: cosmetics * rename checkActiveProfileAuthAsync -> checkActiveProfileAuth --------- Co-authored-by: Tuditi Co-authored-by: Tuditi <45079109+Tuditi@users.noreply.github.com> --- .../desktop/components/NetworkCard.svelte | 65 +++++++++++-------- .../menus/AccountActionsMenu.svelte | 42 ++++++------ .../menus/CollectibleDetailsMenu.svelte | 6 +- .../popups/AliasConfirmationPopup.svelte | 4 +- .../popup/popups/BalanceBreakdownPopup.svelte | 4 +- .../BurnNativeTokensConfirmationPopup.svelte | 4 +- .../popup/popups/CreateAccountPopup.svelte | 4 +- .../popups/EvmTransactionFromDappPopup.svelte | 4 +- .../popups/ManageVotingPowerPopup.svelte | 4 +- .../MintNativeTokenConfirmationPopup.svelte | 4 +- .../MintNftCollectionConfirmationPopup.svelte | 4 +- .../popups/MintNftConfirmationPopup.svelte | 4 +- .../popup/popups/ReceiveAddressPopup.svelte | 56 ++++++++++------ .../popup/popups/RevotePopup.svelte | 4 +- .../popup/popups/SignMessagePopup.svelte | 4 +- .../popup/popups/SignTypedDataPopup.svelte | 4 +- .../components/popup/popups/SiwePopup.svelte | 4 +- .../StardustActivityDetailsPopup.svelte | 4 +- .../popup/popups/StopVotingPopup.svelte | 4 +- .../popup/popups/SyncAccountsPopup.svelte | 58 +++++++---------- .../popup/popups/VoteForProposalPopup.svelte | 4 +- .../popups/VotingPowerToZeroPopup.svelte | 4 +- .../views/CollectiblesGalleryView.svelte | 4 -- .../views/TransactionSummaryView.svelte | 4 +- .../components/AccountNetworkSummary.svelte | 46 +++++++------ .../components/buttons/ReceiveButton.svelte | 4 -- .../account/utils/sumBalanceForAccounts.ts | 6 +- .../interfaces/chain-status.interface.ts | 2 +- .../active-profile/checkActiveProfileAuth.ts | 17 ++--- .../checkActiveProfileAuthAsync.ts | 19 ------ .../profile/actions/active-profile/index.ts | 1 - 31 files changed, 196 insertions(+), 202 deletions(-) delete mode 100644 packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuthAsync.ts diff --git a/packages/desktop/components/NetworkCard.svelte b/packages/desktop/components/NetworkCard.svelte index 34078f0b54..49cc3ad8b9 100644 --- a/packages/desktop/components/NetworkCard.svelte +++ b/packages/desktop/components/NetworkCard.svelte @@ -3,6 +3,7 @@ import { IAccountState } from '@core/account' import { selectedAccount } from '@core/account/stores' import { openUrlInBrowser } from '@core/app' + import { handleError } from '@core/error/handlers' import { localize } from '@core/i18n' import { generateAndStoreEvmAddressForAccounts, pollL2BalanceForAccount } from '@core/layer-2/actions' import { LedgerAppName } from '@core/ledger' @@ -26,58 +27,68 @@ import { NetworkConfigRoute, networkConfigRouter } from '@views/dashboard/drawers' import { onMount } from 'svelte' - export let network: INetwork = undefined - export let chain: IChain = undefined + export let network: INetwork | undefined = undefined + export let chain: IChain | undefined = undefined export let onCardClick: UiEventFunction export let onQrCodeIconClick: UiEventFunction - let configuration: IIscpChainConfiguration = undefined + let configuration: IIscpChainConfiguration | undefined = undefined let networkId: NetworkId | undefined let name = '' - let address = '' + let address: string | undefined = undefined let status: NetworkHealth $: $networkStatus, $chainStatuses, $selectedAccount, setNetworkCardData() - $: explorer = getDefaultExplorerUrl(networkId, ExplorerEndpoint.Address) + $: explorer = networkId ? getDefaultExplorerUrl(networkId, ExplorerEndpoint.Address) : undefined - function onExplorerClick(address: string): void { + function onExplorerClick(): void { + if (!explorer || !address) { + return + } const url = buildUrl({ origin: explorer.baseUrl, pathname: `${explorer.endpoint}/${address}` }) openUrlInBrowser(url?.href) } function setNetworkCardData(): void { + const account = $selectedAccount as IAccountState if (network) { networkId = network.getMetadata().id name = network.getMetadata().name - address = $selectedAccount.depositAddress + address = account.depositAddress status = $networkStatus.health } else if (chain) { configuration = chain.getConfiguration() as IIscpChainConfiguration networkId = configuration.id name = configuration.name - address = $selectedAccount.evmAddresses[configuration.coinType] + address = account.evmAddresses[configuration.coinType] status = chain.getStatus().health } } - function onGenerateAddressClick(): void { - setSelectedChain(chain) - if (chain) { - checkActiveProfileAuth( - async () => { - await generateAndStoreEvmAddressForAccounts( - $activeProfile.type, - configuration.coinType, - $selectedAccount as IAccountState - ) - pollL2BalanceForAccount($activeProfile.id, $selectedAccount as IAccountState) - if ($activeProfile.type === ProfileType.Ledger) { - $networkConfigRouter.goTo(NetworkConfigRoute.ConfirmLedgerEvmAddress) - } - }, - {}, - LedgerAppName.Ethereum + async function onGenerateAddressClick(): Promise { + if (!chain) { + return + } + + try { + await checkActiveProfileAuth(LedgerAppName.Ethereum) + } catch { + return + } + + try { + setSelectedChain(chain) + await generateAndStoreEvmAddressForAccounts( + $activeProfile.type, + configuration.coinType, + $selectedAccount as IAccountState ) + pollL2BalanceForAccount($activeProfile.id, $selectedAccount as IAccountState) + if ($activeProfile.type === ProfileType.Ledger) { + $networkConfigRouter.goTo(NetworkConfigRoute.ConfirmLedgerEvmAddress) + } + } catch (error) { + handleError(error) } } @@ -118,12 +129,12 @@ {/if}
- {#if explorer.baseUrl && address} + {#if explorer?.baseUrl && address} onExplorerClick(address)} + on:click={onExplorerClick} /> {/if} {#if address} diff --git a/packages/desktop/components/menus/AccountActionsMenu.svelte b/packages/desktop/components/menus/AccountActionsMenu.svelte index 055097d1ea..5064227dd4 100644 --- a/packages/desktop/components/menus/AccountActionsMenu.svelte +++ b/packages/desktop/components/menus/AccountActionsMenu.svelte @@ -3,6 +3,7 @@ import { IAccountState } from '@core/account' import { setNextSelectedAccount } from '@core/account/actions' import { selectedAccount } from '@core/account/stores' + import { handleError } from '@core/error/handlers' import { localize } from '@core/i18n' import { deleteAccount } from '@core/profile-manager/actions' import { checkActiveProfileAuth, updateActiveAccountPersistedData } from '@core/profile/actions' @@ -11,6 +12,8 @@ let menu: Menu | undefined = undefined + $: account = $selectedAccount as IAccountState + function onSyncAccountsClick(): void { openPopup({ id: PopupId.SyncAccounts }) menu?.close() @@ -27,19 +30,15 @@ } function onShowAccountClick(): void { - if ($selectedAccount) { - updateActiveAccountPersistedData($selectedAccount.index, { hidden: false }) - menu?.close() - } + updateActiveAccountPersistedData(account.index, { hidden: false }) + menu?.close() } function onHideAccountClick(): void { if ($nonHiddenActiveAccounts.length > 1) { - if ($selectedAccount) { - updateActiveAccountPersistedData($selectedAccount.index, { hidden: true }) - if (!$activeProfile.showHiddenAccounts) { - setNextSelectedAccount() - } + updateActiveAccountPersistedData(account.index, { hidden: true }) + if (!$activeProfile.showHiddenAccounts) { + setNextSelectedAccount() } } else { console.error('Not enough accounts visible: ', $nonHiddenActiveAccounts.length) @@ -52,17 +51,22 @@ id: PopupId.Confirmation, props: { variant: 'danger', - title: localize('popups.deleteAccount.title', { values: { name: $selectedAccount?.name } }), + title: localize('popups.deleteAccount.title', { values: { name: account.name } }), alert: { variant: 'warning', text: localize('popups.deleteAccount.hint') }, confirmText: localize('actions.delete'), onConfirm: async () => { - await checkActiveProfileAuth( - async () => { - await deleteAccount($selectedAccount?.index) - closePopup() - }, - { stronghold: true } - ) + try { + await checkActiveProfileAuth() + } catch { + return + } + + try { + await deleteAccount(account.index) + closePopup() + } catch (error) { + handleError(error) + } }, }, }) @@ -112,9 +116,9 @@ } } $: setItems( - $selectedAccount, + account, $nonHiddenActiveAccounts, - $selectedAccount?.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1 + account.index === $activeAccounts?.length - 1 && $visibleActiveAccounts?.length > 1 ) diff --git a/packages/desktop/components/menus/CollectibleDetailsMenu.svelte b/packages/desktop/components/menus/CollectibleDetailsMenu.svelte index 60f8e7d0aa..dc8158a6d4 100644 --- a/packages/desktop/components/menus/CollectibleDetailsMenu.svelte +++ b/packages/desktop/components/menus/CollectibleDetailsMenu.svelte @@ -5,7 +5,7 @@ import { localize } from '@core/i18n' import { isEvmChain } from '@core/network' import { IIrc27Nft, Nft, isNftLocked } from '@core/nfts' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { activeProfile, updateActiveProfile } from '@core/profile/stores' import { CollectiblesRoute, collectiblesRouter } from '@core/router' import { burnNft } from '@core/wallet' @@ -46,8 +46,8 @@ confirmText: localize('actions.burn'), onConfirm: async () => { try { - await checkActiveProfileAuthAsync() - } catch (error) { + await checkActiveProfileAuth() + } catch { return } diff --git a/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte b/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte index 0d7320dfcb..3f6127eaae 100644 --- a/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/AliasConfirmationPopup.svelte @@ -4,7 +4,7 @@ import { processAndAddToActivities } from '@core/activity/actions' import { handleError } from '@core/error/handlers/handleError' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions' + import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions' import { EMPTY_HEX_ID, sendPreparedTransaction } from '@core/wallet' import { AliasOutputBuilderParams, @@ -46,7 +46,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (error) { return } diff --git a/packages/desktop/components/popup/popups/BalanceBreakdownPopup.svelte b/packages/desktop/components/popup/popups/BalanceBreakdownPopup.svelte index a92b01ed53..86fd32d461 100644 --- a/packages/desktop/components/popup/popups/BalanceBreakdownPopup.svelte +++ b/packages/desktop/components/popup/popups/BalanceBreakdownPopup.svelte @@ -2,7 +2,7 @@ import { selectedAccount } from '@core/account/stores' import { getStorageDepositFromOutput } from '@core/activity/utils/helper' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { consolidateOutputs } from '@core/wallet/actions/consolidateOutputs' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' import { CommonOutput, OutputType, UnlockCondition, UnlockConditionType } from '@iota/sdk/out/types' @@ -115,7 +115,7 @@ confirmText: localize('popups.minimizeStorageDeposit.confirmButton'), onConfirm: async () => { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (err) { return } diff --git a/packages/desktop/components/popup/popups/BurnNativeTokensConfirmationPopup.svelte b/packages/desktop/components/popup/popups/BurnNativeTokensConfirmationPopup.svelte index 34b9cde34f..a9020d41a7 100644 --- a/packages/desktop/components/popup/popups/BurnNativeTokensConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/BurnNativeTokensConfirmationPopup.svelte @@ -2,7 +2,7 @@ import { Alert, Table } from '@bloomwalletio/ui' import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { ITokenWithBalance, formatTokenAmountBestMatch } from '@core/token' import { burnToken } from '@core/wallet' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' @@ -22,7 +22,7 @@ async function onBurnTokenClick(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (err) { return } diff --git a/packages/desktop/components/popup/popups/CreateAccountPopup.svelte b/packages/desktop/components/popup/popups/CreateAccountPopup.svelte index 3e6d534e90..4c50a23156 100644 --- a/packages/desktop/components/popup/popups/CreateAccountPopup.svelte +++ b/packages/desktop/components/popup/popups/CreateAccountPopup.svelte @@ -4,7 +4,7 @@ import { tryCreateAdditionalAccount, validateAccountName } from '@core/account/actions' import { handleError } from '@core/error/handlers/handleError' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { getTrimmedLength } from '@core/utils' import { closePopup } from '@desktop/auxiliary/popup' import PopupTemplate from '../PopupTemplate.svelte' @@ -36,7 +36,7 @@ } try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (error) { return } diff --git a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte index 52afe9055c..fecd9d3580 100644 --- a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte @@ -27,7 +27,7 @@ import { openUrlInBrowser } from '@core/app' import { StardustActivityType } from '@core/activity' import { BASE_TOKEN_ID } from '@core/token/constants' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { LedgerAppName } from '@core/ledger' import { DappVerification, RpcMethod } from '@auxiliary/wallet-connect/enums' import { LegacyTransaction } from '@ethereumjs/tx' @@ -119,7 +119,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync(LedgerAppName.Ethereum) + await checkActiveProfileAuth(LedgerAppName.Ethereum) } catch (error) { return } diff --git a/packages/desktop/components/popup/popups/ManageVotingPowerPopup.svelte b/packages/desktop/components/popup/popups/ManageVotingPowerPopup.svelte index 569165f233..c28f2e1230 100644 --- a/packages/desktop/components/popup/popups/ManageVotingPowerPopup.svelte +++ b/packages/desktop/components/popup/popups/ManageVotingPowerPopup.svelte @@ -5,7 +5,7 @@ import { selectedAccount } from '@core/account/stores' import { handleError } from '@core/error/handlers' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { activeProfile } from '@core/profile/stores' import { visibleSelectedAccountTokens } from '@core/token/stores' import { PopupId, closePopup, openPopup, popupState } from '@desktop/auxiliary/popup' @@ -44,7 +44,7 @@ } try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch { return } diff --git a/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte b/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte index ee7781be71..1aa2c0984e 100644 --- a/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/MintNativeTokenConfirmationPopup.svelte @@ -4,7 +4,7 @@ import { selectedAccount } from '@core/account/stores' import { handleError } from '@core/error/handlers/handleError' import { localize } from '@core/i18n' - import { getBaseToken, checkActiveProfileAuthAsync } from '@core/profile/actions' + import { getBaseToken, checkActiveProfileAuth } from '@core/profile/actions' import { mintNativeToken, mintTokenDetails, buildFoundryOutputBuilderParams, IMintTokenDetails } from '@core/wallet' import { closePopup, openPopup, PopupId } from '@desktop/auxiliary/popup' import { IIrc30Metadata, TokenStandard, formatTokenAmountPrecise } from '@core/token' @@ -58,7 +58,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (error) { return } diff --git a/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte b/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte index 7dce548a56..b020a204b9 100644 --- a/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/MintNftCollectionConfirmationPopup.svelte @@ -5,7 +5,7 @@ import { localize } from '@core/i18n' import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts' import { getClient } from '@core/profile-manager' - import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions' + import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions' import { formatTokenAmountPrecise } from '@core/token' import { buildNftOutputBuilderParams, mintNftCollection, mintNftCollectionDetails } from '@core/wallet' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' @@ -55,7 +55,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (err) { return } diff --git a/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte b/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte index 9522a4a092..c1385fe69e 100644 --- a/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte +++ b/packages/desktop/components/popup/popups/MintNftConfirmationPopup.svelte @@ -5,7 +5,7 @@ import { localize } from '@core/i18n' import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts' import { getClient } from '@core/profile-manager' - import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions' + import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions' import { formatTokenAmountPrecise } from '@core/token' import { buildNftOutputBuilderParams, mintNft, mintNftDetails } from '@core/wallet' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' @@ -72,7 +72,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (err) { return } diff --git a/packages/desktop/components/popup/popups/ReceiveAddressPopup.svelte b/packages/desktop/components/popup/popups/ReceiveAddressPopup.svelte index 1fade87735..640eac027b 100644 --- a/packages/desktop/components/popup/popups/ReceiveAddressPopup.svelte +++ b/packages/desktop/components/popup/popups/ReceiveAddressPopup.svelte @@ -4,37 +4,35 @@ import { localize } from '@core/i18n' import { selectedAccount } from '@core/account/stores' import { setClipboard } from '@core/utils' - import { isEvmChain, isStardustNetwork, network, NetworkId } from '@core/network' + import { getActiveNetworkId, isEvmChain, isStardustNetwork, network, NetworkId } from '@core/network' import { generateAndStoreEvmAddressForAccounts, pollL2BalanceForAccount } from '@core/layer-2/actions' import { activeProfile, activeProfileId } from '@core/profile/stores' import { checkActiveProfileAuth } from '@core/profile/actions' import { LedgerAppName } from '@core/ledger' import PopupTemplate from '../PopupTemplate.svelte' + import { handleError } from '@core/error/handlers' + import { IAccountState } from '@core/account' - export let selectedNetworkId: NetworkId = $network.getMetadata().id + let selectedNetworkId: NetworkId | undefined = getActiveNetworkId() $: selectedNetworkId, updateNetworkNameAndAddress() - let networkName: string - let receiveAddress: string + let networkName: string | undefined + let receiveAddress: string | undefined function updateNetworkNameAndAddress(): void { - if (isStardustNetwork(selectedNetworkId)) { - networkName = $network.getMetadata().name - receiveAddress = $selectedAccount.depositAddress - } else if (isEvmChain(selectedNetworkId)) { - const { id, name, coinType } = $network.getChain(selectedNetworkId)?.getConfiguration() ?? {} + const account = $selectedAccount as IAccountState + + if (selectedNetworkId && isStardustNetwork(selectedNetworkId)) { + networkName = $network?.getMetadata().name + receiveAddress = account.depositAddress + } else if (selectedNetworkId && isEvmChain(selectedNetworkId)) { + const chainConfig = $network?.getChain(selectedNetworkId)?.getConfiguration() + if (!chainConfig) return + + const { name, coinType } = chainConfig networkName = name - receiveAddress = $selectedAccount.evmAddresses?.[coinType] + receiveAddress = account.evmAddresses?.[coinType] if (!receiveAddress) { - void checkActiveProfileAuth( - async () => { - await generateAndStoreEvmAddressForAccounts($activeProfile.type, coinType, $selectedAccount) - pollL2BalanceForAccount($activeProfileId as string, $selectedAccount) - networkName = name - receiveAddress = $selectedAccount.evmAddresses?.[coinType] - }, - { ledger: true, stronghold: true, props: { selectedNetworkId: id } }, - LedgerAppName.Ethereum - ) + generateAddress(account, coinType) } } else { networkName = undefined @@ -42,6 +40,22 @@ } } + async function generateAddress(account: IAccountState, coinType: number): Promise { + try { + await checkActiveProfileAuth(LedgerAppName.Ethereum) + } catch { + return + } + + try { + await generateAndStoreEvmAddressForAccounts($activeProfile.type, coinType, account) + pollL2BalanceForAccount($activeProfileId as string, account) + updateNetworkNameAndAddress() + } catch (error) { + handleError(error) + } + } + onMount(() => { updateNetworkNameAndAddress() }) @@ -52,7 +66,7 @@ description={localize('popups.receiveAddress.body')} continueButton={{ text: localize('actions.copyAddress'), - onClick: () => setClipboard(receiveAddress), + onClick: () => receiveAddress && setClipboard(receiveAddress), disabled: !receiveAddress, }} > diff --git a/packages/desktop/components/popup/popups/RevotePopup.svelte b/packages/desktop/components/popup/popups/RevotePopup.svelte index 6784966d1c..877a572f33 100644 --- a/packages/desktop/components/popup/popups/RevotePopup.svelte +++ b/packages/desktop/components/popup/popups/RevotePopup.svelte @@ -3,7 +3,7 @@ import { vote } from '@contexts/governance/actions' import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { closePopup } from '@desktop/auxiliary/popup' import { PopupTemplate } from '@components/popup' @@ -12,7 +12,7 @@ async function onSubmit(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (error) { return } diff --git a/packages/desktop/components/popup/popups/SignMessagePopup.svelte b/packages/desktop/components/popup/popups/SignMessagePopup.svelte index 3cf4fbcbe8..ecffc7f9b5 100644 --- a/packages/desktop/components/popup/popups/SignMessagePopup.svelte +++ b/packages/desktop/components/popup/popups/SignMessagePopup.svelte @@ -9,7 +9,7 @@ import { IAccountState } from '@core/account' import { IChain } from '@core/network' import { AccountLabel, DappInfo } from '@ui' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { LedgerAppName } from '@core/ledger' import PopupTemplate from '../PopupTemplate.svelte' import { DappVerification } from '@auxiliary/wallet-connect/enums' @@ -25,7 +25,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync(LedgerAppName.Ethereum) + await checkActiveProfileAuth(LedgerAppName.Ethereum) } catch { return } diff --git a/packages/desktop/components/popup/popups/SignTypedDataPopup.svelte b/packages/desktop/components/popup/popups/SignTypedDataPopup.svelte index 93975de7b8..c6d720ce36 100644 --- a/packages/desktop/components/popup/popups/SignTypedDataPopup.svelte +++ b/packages/desktop/components/popup/popups/SignTypedDataPopup.svelte @@ -7,7 +7,7 @@ import { IAccountState } from '@core/account' import { IChain } from '@core/network' import { AccountLabel, DappInfo } from '@ui' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { LedgerAppName } from '@core/ledger' import PopupTemplate from '../PopupTemplate.svelte' import { SignTypedDataVersion } from '@metamask/eth-sig-util' @@ -26,7 +26,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync(LedgerAppName.Ethereum) + await checkActiveProfileAuth(LedgerAppName.Ethereum) } catch { return } diff --git a/packages/desktop/components/popup/popups/SiwePopup.svelte b/packages/desktop/components/popup/popups/SiwePopup.svelte index 4c16ef3856..9f9d471a32 100644 --- a/packages/desktop/components/popup/popups/SiwePopup.svelte +++ b/packages/desktop/components/popup/popups/SiwePopup.svelte @@ -9,7 +9,7 @@ import { IAccountState } from '@core/account' import { IChain, NetworkId, getNameFromNetworkId } from '@core/network' import { AccountLabel, DappInfo, KeyValue, NetworkLabel } from '@ui' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { LedgerAppName } from '@core/ledger' import PopupTemplate from '../PopupTemplate.svelte' import { ParsedMessage } from '@spruceid/siwe-parser' @@ -43,7 +43,7 @@ async function onConfirmClick(): Promise { try { - await checkActiveProfileAuthAsync(LedgerAppName.Ethereum) + await checkActiveProfileAuth(LedgerAppName.Ethereum) } catch { return } diff --git a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte index aa87d8bd6d..9c9768dc4d 100644 --- a/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte +++ b/packages/desktop/components/popup/popups/StardustActivityDetailsPopup.svelte @@ -15,7 +15,7 @@ import { getDefaultExplorerUrl } from '@core/network/utils' import { getNftByIdFromAllAccountNfts } from '@core/nfts/actions' import { ownedNfts, selectedNftId } from '@core/nfts/stores' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { CollectiblesRoute, DashboardRoute, collectiblesRouter, dashboardRouter } from '@core/router' import { buildUrl, setClipboard, truncateString } from '@core/utils' import { claimActivity, rejectActivity } from '@core/wallet' @@ -72,7 +72,7 @@ async function onClaimClick(_activity: StardustActivity): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch { return } diff --git a/packages/desktop/components/popup/popups/StopVotingPopup.svelte b/packages/desktop/components/popup/popups/StopVotingPopup.svelte index 65e02da16d..2df1c97206 100644 --- a/packages/desktop/components/popup/popups/StopVotingPopup.svelte +++ b/packages/desktop/components/popup/popups/StopVotingPopup.svelte @@ -4,7 +4,7 @@ import { selectedProposal } from '@contexts/governance/stores' import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { closePopup } from '@desktop/auxiliary/popup' import PopupTemplate from '../PopupTemplate.svelte' @@ -17,7 +17,7 @@ async function onStopVotingClick(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch (error) { return } diff --git a/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte b/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte index d2b3dc892d..44d12d3fae 100644 --- a/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte +++ b/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte @@ -13,13 +13,11 @@ import { formatTokenAmountBestMatch } from '@core/token' import { refreshAccountTokensForActiveProfile } from '@core/token/actions' import { closePopup } from '@desktop/auxiliary/popup' - import { onDestroy, onMount } from 'svelte' + import { onDestroy } from 'svelte' import PopupTemplate from '../PopupTemplate.svelte' import { StardustNetworkId } from '@core/network/enums' import { ledgerRaceConditionProtectionWrapper } from '@core/ledger' - export let searchForBalancesOnLoad = false - const { network, type } = $activeProfile const DEFAULT_CONFIG = DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION[type] @@ -39,27 +37,6 @@ $: totalBalance = sumBalanceForAccounts($visibleActiveAccounts) - async function searchForBalance(): Promise { - try { - error = '' - isBusy = true - const _function = networkSearchMethod[network?.id] ?? singleAddressSearch - await ledgerRaceConditionProtectionWrapper(_function) - await loadAccounts() - previousAccountsLength = $visibleActiveAccounts.length - previousAccountGapLimit = accountGapLimit - hasUsedWalletFinder = true - } catch (err) { - error = localize(err.error) - showNotification({ - variant: 'error', - text: localize(err.error), - }) - } finally { - isBusy = false - } - } - const networkSearchMethod: { [key in StardustNetworkId]?: () => Promise } = { [StardustNetworkId.Iota]: multiAddressSearch, [StardustNetworkId.Shimmer]: singleAddressSearch, @@ -123,21 +100,36 @@ } async function onFindBalancesClick(): Promise { - await checkActiveProfileAuth(() => searchForBalance(), { - stronghold: true, - ledger: true, - props: { searchForBalancesOnLoad: true }, - }) + try { + await checkActiveProfileAuth() + } catch { + return + } + + try { + error = '' + isBusy = true + const _function = networkSearchMethod[network?.id] ?? singleAddressSearch + await ledgerRaceConditionProtectionWrapper(_function) + await loadAccounts() + previousAccountsLength = $visibleActiveAccounts.length + previousAccountGapLimit = accountGapLimit + hasUsedWalletFinder = true + } catch (err) { + error = localize(err.error) + showNotification({ + variant: 'error', + text: error, + }) + } finally { + isBusy = false + } } function onCancelClick(): void { closePopup() } - onMount(() => { - searchForBalancesOnLoad && void searchForBalance() - }) - onDestroy(async () => { if (hasUsedWalletFinder) { const profileId = getActiveProfileId() diff --git a/packages/desktop/components/popup/popups/VoteForProposalPopup.svelte b/packages/desktop/components/popup/popups/VoteForProposalPopup.svelte index b5e141ceb3..b91d9c7188 100644 --- a/packages/desktop/components/popup/popups/VoteForProposalPopup.svelte +++ b/packages/desktop/components/popup/popups/VoteForProposalPopup.svelte @@ -5,7 +5,7 @@ import { selectedProposal } from '@contexts/governance/stores' import { selectedAccount } from '@core/account/stores' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync, getBaseToken } from '@core/profile/actions' + import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions' import { formatTokenAmountBestMatch } from '@core/token' import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup' import PopupTemplate from '../PopupTemplate.svelte' @@ -24,7 +24,7 @@ async function onSubmit(): Promise { if (hasVotingPower) { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch { return } diff --git a/packages/desktop/components/popup/popups/VotingPowerToZeroPopup.svelte b/packages/desktop/components/popup/popups/VotingPowerToZeroPopup.svelte index ce48e9cdd6..4907596633 100644 --- a/packages/desktop/components/popup/popups/VotingPowerToZeroPopup.svelte +++ b/packages/desktop/components/popup/popups/VotingPowerToZeroPopup.svelte @@ -4,7 +4,7 @@ import { selectedAccount } from '@core/account/stores' import { handleError } from '@core/error/handlers' import { localize } from '@core/i18n' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { PopupId, closePopup, openPopup, popupState } from '@desktop/auxiliary/popup' import { PopupTemplate } from '@components/popup' @@ -19,7 +19,7 @@ async function onSubmit(): Promise { try { - await checkActiveProfileAuthAsync() + await checkActiveProfileAuth() } catch { return } diff --git a/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte b/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte index 1e0854ec56..0a981e2051 100644 --- a/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte +++ b/packages/desktop/views/dashboard/collectibles/views/CollectiblesGalleryView.svelte @@ -4,16 +4,12 @@ import { NftGallery, SearchInput } from '@ui' import { Button, IconName, Text, Pill } from '@bloomwalletio/ui' import { PopupId, openPopup } from '@desktop/auxiliary/popup' - import { getActiveNetworkId } from '@core/network' import features from '@features/features' import { CollectiblesListMenu, EmptyListPlaceholder } from '@components' function onReceiveClick(): void { openPopup({ id: PopupId.ReceiveAddress, - props: { - selectedNetworkId: getActiveNetworkId(), - }, }) } diff --git a/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte b/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte index 39e632f437..69a94ce874 100644 --- a/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte @@ -23,7 +23,7 @@ import { TransactionSummaryProps } from './types' import { setGasFee } from '@core/layer-2/actions' import { showNotification } from '@auxiliary/notification' - import { checkActiveProfileAuthAsync } from '@core/profile/actions' + import { checkActiveProfileAuth } from '@core/profile/actions' import { LedgerAppName, ledgerPreparedOutput } from '@core/ledger' import { getActiveProfileId, getIsActiveLedgerProfile } from '@core/profile/stores' @@ -96,7 +96,7 @@ } try { - await checkActiveProfileAuthAsync(isSourceNetworkLayer2 ? LedgerAppName.Ethereum : undefined) + await checkActiveProfileAuth(isSourceNetworkLayer2 ? LedgerAppName.Ethereum : undefined) } catch (error) { return } diff --git a/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte b/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte index b4bd834160..36664f2216 100644 --- a/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte +++ b/packages/desktop/views/dashboard/wallet/panes/account-summary/components/AccountNetworkSummary.svelte @@ -17,6 +17,8 @@ import { DashboardDrawerRoute, NetworkConfigRoute } from '@views/dashboard/drawers' import { ProfileType } from 'shared/src/lib/core/profile' import features from '@features/features' + import { handleError } from '@core/error/handlers' + import { IAccountState } from '@core/account' export let networkId: NetworkId export let name: string @@ -66,30 +68,32 @@ $dashboardRouter?.goTo(DashboardRoute.Collectibles) } - function onGenerateAddressClick(): void { - const chain = $network.getChain(networkId) + async function onGenerateAddressClick(): Promise { + const chain = $network?.getChain(networkId) if (!chain) { return } - checkActiveProfileAuth( - async () => { - await generateAndStoreEvmAddressForAccounts( - $activeProfile.type, - chain.getConfiguration().coinType, - $selectedAccount - ) - pollL2BalanceForAccount($activeProfile.id, $selectedAccount) - if ($activeProfile.type === ProfileType.Ledger) { - setSelectedChain(chain) - toggleDashboardDrawer({ - id: DashboardDrawerRoute.NetworkConfig, - initialSubroute: NetworkConfigRoute.ConfirmLedgerEvmAddress, - }) - } - }, - {}, - LedgerAppName.Ethereum - ) + + try { + await checkActiveProfileAuth(LedgerAppName.Ethereum) + } catch (error) { + return + } + + try { + const account = $selectedAccount as IAccountState + await generateAndStoreEvmAddressForAccounts($activeProfile.type, chain.getConfiguration().coinType, account) + pollL2BalanceForAccount($activeProfile.id, account) + if ($activeProfile.type === ProfileType.Ledger) { + setSelectedChain(chain) + toggleDashboardDrawer({ + id: DashboardDrawerRoute.NetworkConfig, + initialSubroute: NetworkConfigRoute.ConfirmLedgerEvmAddress, + }) + } + } catch (error) { + handleError(error) + } } diff --git a/packages/shared/src/components/buttons/ReceiveButton.svelte b/packages/shared/src/components/buttons/ReceiveButton.svelte index 40c63ffb26..1700d0bb53 100644 --- a/packages/shared/src/components/buttons/ReceiveButton.svelte +++ b/packages/shared/src/components/buttons/ReceiveButton.svelte @@ -1,6 +1,5 @@ diff --git a/packages/shared/src/lib/core/account/utils/sumBalanceForAccounts.ts b/packages/shared/src/lib/core/account/utils/sumBalanceForAccounts.ts index 12966e538a..e0132eddcc 100644 --- a/packages/shared/src/lib/core/account/utils/sumBalanceForAccounts.ts +++ b/packages/shared/src/lib/core/account/utils/sumBalanceForAccounts.ts @@ -1,8 +1,8 @@ import { IAccountState } from '@core/account' -export function sumBalanceForAccounts(accounts: IAccountState[]): number { +export function sumBalanceForAccounts(accounts: IAccountState[]): bigint { return accounts.reduce( - (total: number, account: IAccountState) => (total += Number(account.balances.baseCoin.total)), - 0 + (total: bigint, account: IAccountState) => (total += account.balances.baseCoin.total), + BigInt(0) ) } diff --git a/packages/shared/src/lib/core/network/interfaces/chain-status.interface.ts b/packages/shared/src/lib/core/network/interfaces/chain-status.interface.ts index 7c23af1cb9..400d811b90 100644 --- a/packages/shared/src/lib/core/network/interfaces/chain-status.interface.ts +++ b/packages/shared/src/lib/core/network/interfaces/chain-status.interface.ts @@ -1,5 +1,5 @@ import { NetworkHealth } from '../enums' export interface IChainStatus { - health?: NetworkHealth + health: NetworkHealth } diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuth.ts b/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuth.ts index 787df53c38..ba6f38ca74 100644 --- a/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuth.ts +++ b/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuth.ts @@ -1,22 +1,19 @@ -import { checkOrConnectLedger } from '@core/ledger/actions' +import { checkOrConnectLedgerAsync } from '@core/ledger/actions' import { LedgerAppName } from '@core/ledger/enums' import { SupportedNetworkId } from '@core/network' import { activeProfile, isActiveLedgerProfile, isSoftwareProfile } from '@core/profile/stores' -import { checkOrUnlockStronghold } from '@core/stronghold/actions' +import { checkOrUnlockStrongholdAsync } from '@core/stronghold/actions' import { get } from 'svelte/store' -export function checkActiveProfileAuth( - callback: () => Promise = async () => {}, - reopenPopup?: { stronghold?: boolean; ledger?: boolean; props?: Record }, +export async function checkActiveProfileAuth( ledgerAppName: LedgerAppName = get(activeProfile)?.network?.id === SupportedNetworkId.Iota ? LedgerAppName.Iota - : LedgerAppName.Shimmer, - onCancel: () => void = (): void => {} -): Promise { + : LedgerAppName.Shimmer +): Promise { if (get(isSoftwareProfile)) { - return checkOrUnlockStronghold(callback, reopenPopup?.stronghold, reopenPopup?.props, onCancel) + await checkOrUnlockStrongholdAsync() } else if (get(isActiveLedgerProfile)) { - return checkOrConnectLedger(callback, reopenPopup?.ledger, ledgerAppName, reopenPopup?.props, onCancel) + await checkOrConnectLedgerAsync(ledgerAppName) } return Promise.resolve() } diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuthAsync.ts b/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuthAsync.ts deleted file mode 100644 index a6135933aa..0000000000 --- a/packages/shared/src/lib/core/profile/actions/active-profile/checkActiveProfileAuthAsync.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { checkOrConnectLedgerAsync } from '@core/ledger/actions' -import { LedgerAppName } from '@core/ledger/enums' -import { SupportedNetworkId } from '@core/network' -import { activeProfile, isActiveLedgerProfile, isSoftwareProfile } from '@core/profile/stores' -import { checkOrUnlockStrongholdAsync } from '@core/stronghold/actions' -import { get } from 'svelte/store' - -export async function checkActiveProfileAuthAsync( - ledgerAppName: LedgerAppName = get(activeProfile)?.network?.id === SupportedNetworkId.Iota - ? LedgerAppName.Iota - : LedgerAppName.Shimmer -): Promise { - if (get(isSoftwareProfile)) { - await checkOrUnlockStrongholdAsync() - } else if (get(isActiveLedgerProfile)) { - await checkOrConnectLedgerAsync(ledgerAppName) - } - return Promise.resolve() -} diff --git a/packages/shared/src/lib/core/profile/actions/active-profile/index.ts b/packages/shared/src/lib/core/profile/actions/active-profile/index.ts index 56e70c65f1..4180bb8264 100644 --- a/packages/shared/src/lib/core/profile/actions/active-profile/index.ts +++ b/packages/shared/src/lib/core/profile/actions/active-profile/index.ts @@ -1,5 +1,4 @@ export * from './checkActiveProfileAuth' -export * from './checkActiveProfileAuthAsync' export * from './checkAndRemoveProfilePicture' export * from './checkAndUpdateActiveProfileNetwork' export * from './getBaseToken'