From f5514a7f731cbfc1a1c53ed4f077a733f1b76ede Mon Sep 17 00:00:00 2001 From: Tuditi <45079109+Tuditi@users.noreply.github.com> Date: Tue, 19 Mar 2024 08:58:57 +0100 Subject: [PATCH] chore: type safe access to `activeProfileId` (#2161) * fix: access activeProfileId w/ type safety * chore: don't rely on global vars in sendAndPersistTxFromEvm * fix --------- Co-authored-by: Mark Nardi --- .../popups/EvmTransactionFromDappPopup.svelte | 18 +++++++++++------- .../popup/popups/SyncAccountsPopup.svelte | 5 +++-- .../views/ConnectedDappsDrawer.svelte | 2 +- .../views/TransactionSummaryView.svelte | 10 ++++++---- .../generateAndStoreActivitiesForAccount.ts | 6 +++++- ...linkTransactionsWithClaimingTransactions.ts | 6 +++--- .../stores/claimed-activities.store.ts | 6 ++---- .../activity/stores/hidden-activities.store.ts | 8 ++++---- .../stores/persisted-balance-changes.store.ts | 14 ++++++++------ .../nfts/actions/loadNftsForActiveProfile.ts | 4 ++-- .../profile/stores/active-profile-id.store.ts | 11 ++++++++++- .../transactions/stores/transactions.store.ts | 13 ++++++------- .../lib/core/wallet/actions/rejectActivity.ts | 5 ++--- .../send/sendAndPersistTransactionFromEvm.ts | 4 ++-- 14 files changed, 65 insertions(+), 47 deletions(-) diff --git a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte index 0d5685153e..f5f02abb44 100644 --- a/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte +++ b/packages/desktop/components/popup/popups/EvmTransactionFromDappPopup.svelte @@ -4,7 +4,7 @@ import { IConnectedDapp } from '@auxiliary/wallet-connect/interface' import { CallbackParameters } from '@auxiliary/wallet-connect/types' import { sendAndPersistTransactionFromEvm, signEvmTransaction } from '@core/wallet/actions' - import { selectedAccount } from '@core/account/stores' + import { getSelectedAccount, selectedAccount } from '@core/account/stores' import { ExplorerEndpoint, IChain, getDefaultExplorerUrl } from '@core/network' import { DappInfo, TransactionAssetSection } from '@ui' import PopupTemplate from '../PopupTemplate.svelte' @@ -31,7 +31,8 @@ import { LedgerAppName } from '@core/ledger' import { DappVerification, RpcMethod } from '@auxiliary/wallet-connect/enums' import { LegacyTransaction } from '@ethereumjs/tx' - import { activeProfileId } from '@core/profile/stores' + import { getActiveProfileId } from '@core/profile/stores' + import { IAccountState } from '@core/account' export let preparedTransaction: EvmTransactionData export let chain: IChain @@ -87,27 +88,30 @@ } } - async function getSignedTransaction(): Promise { + async function getSignedTransaction(account: IAccountState): Promise { if (preparedTransaction?.v && preparedTransaction?.s && preparedTransaction?.r) { const transaction = LegacyTransaction.fromTxData(preparedTransaction) return getHexEncodedTransaction(transaction) } else { - return await signEvmTransaction(preparedTransaction, chain, $selectedAccount) + return await signEvmTransaction(preparedTransaction, chain, account) } } async function signOrSend(): Promise { - const signedTransaction = await getSignedTransaction() + const profileId = getActiveProfileId() + const account = getSelectedAccount() + const signedTransaction = await getSignedTransaction(account) if (method === RpcMethod.EthSignTransaction) { callback({ result: signedTransaction }) return } + const transactionHash = await sendAndPersistTransactionFromEvm( preparedTransaction, signedTransaction, chain, - $selectedAccount, - $activeProfileId + profileId, + account ) callback({ result: transactionHash }) } diff --git a/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte b/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte index c06f02376c..d2b3dc892d 100644 --- a/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte +++ b/packages/desktop/components/popup/popups/SyncAccountsPopup.svelte @@ -9,7 +9,7 @@ import { DEFAULT_ACCOUNT_RECOVERY_CONFIGURATION } from '@core/profile' import { RecoverAccountsPayload, recoverAccounts } from '@core/profile-manager' import { checkActiveProfileAuth, getBaseToken, loadAccounts } from '@core/profile/actions' - import { activeAccounts, activeProfile, activeProfileId, visibleActiveAccounts } from '@core/profile/stores' + import { activeAccounts, activeProfile, getActiveProfileId, visibleActiveAccounts } from '@core/profile/stores' import { formatTokenAmountBestMatch } from '@core/token' import { refreshAccountTokensForActiveProfile } from '@core/token/actions' import { closePopup } from '@desktop/auxiliary/popup' @@ -140,8 +140,9 @@ onDestroy(async () => { if (hasUsedWalletFinder) { + const profileId = getActiveProfileId() await refreshAccountTokensForActiveProfile() - await generateAndStoreActivitiesForAllAccounts($activeProfileId) + await generateAndStoreActivitiesForAllAccounts(profileId) loadNftsForActiveProfile() } }) diff --git a/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte b/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte index 88d937b906..5db0622e91 100644 --- a/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte +++ b/packages/desktop/views/dashboard/drawers/dapp-config/views/ConnectedDappsDrawer.svelte @@ -27,7 +27,7 @@ let selectedIndex = 0 $: connectedDappsForProfile = $connectedDapps.filter( - (dapp) => !!$persistedDappNamespaces[$activeProfileId]?.[dapp.metadata?.url] + (dapp) => !!$persistedDappNamespaces[$activeProfileId as string]?.[dapp.metadata?.url ?? ''] ) $: displayedDapps = connectedDappsForProfile.filter( (dapp) => (selectedIndex === 0 && !!dapp.session) || (selectedIndex === 1 && !dapp.session) diff --git a/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte b/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte index 3bca53e586..39e632f437 100644 --- a/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte +++ b/packages/desktop/views/dashboard/send-flow/views/TransactionSummaryView.svelte @@ -1,7 +1,7 @@