From c027c331e463d78c69d100565e96fd6f4af0cd7d Mon Sep 17 00:00:00 2001 From: h0ngcha0 Date: Sat, 2 Nov 2024 07:59:43 +0100 Subject: [PATCH 1/3] Only cache the selected items from storage --- packages/extension/src/shared/storage/hooks.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 } From f0aafd99df80929c7b897c3a49ed2434a0b57a73 Mon Sep 17 00:00:00 2001 From: h0ngcha0 Date: Sat, 2 Nov 2024 12:51:21 +0100 Subject: [PATCH 2/3] Clean up transactions infinite scroll cache --- .../extension/src/shared/account/selectors.ts | 5 ++++ .../src/shared/transactions/index.ts | 25 +++++++++++++++++++ packages/extension/src/ui/App.tsx | 2 ++ 3 files changed, 32 insertions(+) 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/transactions/index.ts b/packages/extension/src/shared/transactions/index.ts index f8f96a61d..a4b532055 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 } from "./transformers" import { getNetwork } from "../network" +import { walletStore } from "../wallet/walletStore" +import { getOtherAccountsSelector, withoutHiddenSelector } from "../account/selectors" +import { getAccounts } from "../account/store" export type Status = 'NOT_RECEIVED' | 'RECEIVED' | 'PENDING' | 'ACCEPTED_ON_MEMPOOL' | 'ACCEPTED_ON_L2' | 'ACCEPTED_ON_CHAIN' | 'REJECTED' | 'REMOVED_FROM_MEMPOOL'; @@ -129,3 +132,25 @@ 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) + } + } + } +} \ No newline at end of file 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 ( From 06d61b6ea626a651010d3aee5d0b82333af89304 Mon Sep 17 00:00:00 2001 From: h0ngcha0 Date: Sat, 2 Nov 2024 13:30:44 +0100 Subject: [PATCH 3/3] Update the broken logo image in README --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) ---