diff --git a/Readme.md b/Readme.md index 81df50191..74de8f315 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ -![Alephium Logo](https://raw.githubusercontent.com/alephium/alephium-brand-guide/master/logos/light/Logo-Horizontal-Light.png#gh-dark-mode-only) ![Alephium Logo](https://raw.githubusercontent.com/alephium/alephium-brand-guide/master/logos/dark/Logo-Horizontal-Dark.png#gh-light-mode-only) +![Alephium Logo](https://raw.githubusercontent.com/alephium/alephium-brand-guide/refs/heads/master/logos/Alephium-Logo-Light-WithText.svg#gh-dark-mode-only) ![Alephium Logo](https://raw.githubusercontent.com/alephium/alephium-brand-guide/refs/heads/master/logos/Alephium-Logo-Dark-WithText.svg#gh-light-mode-only) --- diff --git a/packages/extension/src/shared/account/selectors.ts b/packages/extension/src/shared/account/selectors.ts index 23fa11011..2648df83a 100644 --- a/packages/extension/src/shared/account/selectors.ts +++ b/packages/extension/src/shared/account/selectors.ts @@ -8,6 +8,11 @@ export const getAccountSelector = memoize( accountsEqual(account, baseAccount), ) +export const getOtherAccountsSelector = memoize( + (baseAccount: BaseWalletAccount) => (account: StoredWalletAccount) => + !accountsEqual(account, baseAccount), +) + export const getNetworkSelector = memoize( (networkId: string) => (account: StoredWalletAccount) => account.networkId === networkId, diff --git a/packages/extension/src/shared/storage/hooks.ts b/packages/extension/src/shared/storage/hooks.ts index da2c0433a..54e68d39b 100644 --- a/packages/extension/src/shared/storage/hooks.ts +++ b/packages/extension/src/shared/storage/hooks.ts @@ -85,10 +85,10 @@ export function useArrayStorage( ) useEffect(() => { - storage.get().then(set) + storage.get(selector).then(set) const sub = storage.subscribe(set) return () => sub() }, [selector, storage, set]) - return useMemo(() => value.filter(selector), [value, selector]) + return value } diff --git a/packages/extension/src/shared/transactions/index.ts b/packages/extension/src/shared/transactions/index.ts index 8142f9a86..8d888c2b9 100644 --- a/packages/extension/src/shared/transactions/index.ts +++ b/packages/extension/src/shared/transactions/index.ts @@ -6,6 +6,9 @@ import { WalletAccount } from "../wallet.model" import { AlephiumExplorerTransaction } from "../explorer/type" import { mapAlephiumTransactionToTransaction, signedChainedTxResultToReviewTransactionResult, transactionParamsToSignChainedTxParams } from "./transformers" import { getNetwork } from "../network" +import { walletStore } from "../wallet/walletStore" +import { getOtherAccountsSelector, withoutHiddenSelector } from "../account/selectors" +import { getAccounts } from "../account/store" import { BaseTokenWithBalance } from "../token/type" import { BigNumber } from "ethers" import { addTokenToBalances, getBalances } from "../token/balance" @@ -135,6 +138,28 @@ function buildGetTransactionsFn(metadataTransactions: Transaction[]) { } } +export async function pruneTransactionsInfiniteScrollCache() { + const selectedAccount = await walletStore.get("selected") + const accountSelector = selectedAccount ? getOtherAccountsSelector(selectedAccount) : withoutHiddenSelector + const accounts = await getAccounts(accountSelector) + + for (const account of accounts) { + const network = await getNetwork(account.networkId) + const explorerApiUrl = network?.explorerApiUrl + if (!explorerApiUrl) { + continue + } + + const transactionsInfiniteScrollCacheKey = `${explorerApiUrl}/addresses/${account.address}/transactions` + for (let i = 0; i < localStorage.length; i++) { + const key = localStorage.key(i) + if (key && key.includes(transactionsInfiniteScrollCacheKey)) { + localStorage.removeItem(key) + } + } + } +} + export async function tryBuildChainedTransactions( nodeUrl: string, walletAccounts: WalletAccount[], diff --git a/packages/extension/src/ui/App.tsx b/packages/extension/src/ui/App.tsx index 08de1297f..3bb891992 100644 --- a/packages/extension/src/ui/App.tsx +++ b/packages/extension/src/ui/App.tsx @@ -15,11 +15,13 @@ import SoftReloadProvider from "./services/resetAndReload" import { useSentryInit } from "./services/sentry" import { swrCacheProvider } from "./services/swr" import { ThemeProvider, muiTheme } from "./theme" +import { pruneTransactionsInfiniteScrollCache } from "../shared/transactions" export const App: FC = () => { useTracking() useSentryInit() updateTokenList() + pruneTransactionsInfiniteScrollCache() return (