From 7e0f7e632aefb4372cf93a1d0d6033f00f3e8b2f Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 5 Nov 2024 16:43:37 +0200 Subject: [PATCH] TW-1578: [evm] Fix lots of failing node requests on large accounts --- .../components/EvmChainCollectiblesTab.tsx | 3 +++ .../components/EvmCollectiblesTab.tsx | 3 +++ .../components/MultiChainCollectiblesTab.tsx | 3 +++ .../CollectiblesTab/components/evm-meta-loading.ts} | 11 ++++++----- src/app/root-hooks/index.tsx | 2 -- src/lib/balances/hooks.ts | 3 ++- src/temple/evm/index.ts | 12 ++++++++++-- 7 files changed, 27 insertions(+), 10 deletions(-) rename src/app/{root-hooks/evm/collectibles-metadata-loading.ts => pages/Collectibles/CollectiblesTab/components/evm-meta-loading.ts} (91%) diff --git a/src/app/pages/Collectibles/CollectiblesTab/components/EvmChainCollectiblesTab.tsx b/src/app/pages/Collectibles/CollectiblesTab/components/EvmChainCollectiblesTab.tsx index 6b30966575..c162364f39 100644 --- a/src/app/pages/Collectibles/CollectiblesTab/components/EvmChainCollectiblesTab.tsx +++ b/src/app/pages/Collectibles/CollectiblesTab/components/EvmChainCollectiblesTab.tsx @@ -7,6 +7,7 @@ import { useEvmChainByChainId } from 'temple/front/chains'; import { EvmCollectibleItem } from './CollectibleItem'; import { CollectiblesTabBase } from './CollectiblesTabBase'; +import { useEvmCollectiblesMetadataLoading } from './evm-meta-loading'; interface EvmChainCollectiblesTabProps { chainId: number; @@ -22,6 +23,8 @@ export const EvmChainCollectiblesTab = memo(({ cha const { isInSearchMode, paginatedSlugs, isSyncing, loadNext, searchValue, setSearchValue } = useEvmChainCollectiblesListingLogic(publicKeyHash, chainId, manageActive); + useEvmCollectiblesMetadataLoading(publicKeyHash); + const contentElement = useMemo( () => (
diff --git a/src/app/pages/Collectibles/CollectiblesTab/components/EvmCollectiblesTab.tsx b/src/app/pages/Collectibles/CollectiblesTab/components/EvmCollectiblesTab.tsx index d7686d4256..097ef0f6b9 100644 --- a/src/app/pages/Collectibles/CollectiblesTab/components/EvmCollectiblesTab.tsx +++ b/src/app/pages/Collectibles/CollectiblesTab/components/EvmCollectiblesTab.tsx @@ -8,6 +8,7 @@ import { useEthereumMainnetChain } from 'temple/front'; import { EvmCollectibleItem } from './CollectibleItem'; import { CollectiblesTabBase } from './CollectiblesTabBase'; +import { useEvmCollectiblesMetadataLoading } from './evm-meta-loading'; interface EvmCollectiblesTabProps { publicKeyHash: HexString; @@ -22,6 +23,8 @@ export const EvmCollectiblesTab = memo(({ publicKeyHash const { isInSearchMode, paginatedSlugs, isSyncing, loadNext, searchValue, setSearchValue } = useEvmAccountCollectiblesListingLogic(publicKeyHash, manageActive); + useEvmCollectiblesMetadataLoading(publicKeyHash); + const contentElement = useMemo( () => (
diff --git a/src/app/pages/Collectibles/CollectiblesTab/components/MultiChainCollectiblesTab.tsx b/src/app/pages/Collectibles/CollectiblesTab/components/MultiChainCollectiblesTab.tsx index 65db28c47d..97809a5e05 100644 --- a/src/app/pages/Collectibles/CollectiblesTab/components/MultiChainCollectiblesTab.tsx +++ b/src/app/pages/Collectibles/CollectiblesTab/components/MultiChainCollectiblesTab.tsx @@ -8,6 +8,7 @@ import { TempleChainKind } from 'temple/types'; import { EvmCollectibleItem, TezosCollectibleItem } from './CollectibleItem'; import { CollectiblesTabBase } from './CollectiblesTabBase'; +import { useEvmCollectiblesMetadataLoading } from './evm-meta-loading'; interface MultiChainCollectiblesTabProps { accountTezAddress: string; @@ -23,6 +24,8 @@ export const MultiChainCollectiblesTab = memo( const { isInSearchMode, paginatedSlugs, isSyncing, loadNext, searchValue, setSearchValue } = useAccountCollectiblesListingLogic(accountTezAddress, accountEvmAddress, manageActive); + useEvmCollectiblesMetadataLoading(accountEvmAddress); + const contentElement = useMemo( () => (
diff --git a/src/app/root-hooks/evm/collectibles-metadata-loading.ts b/src/app/pages/Collectibles/CollectiblesTab/components/evm-meta-loading.ts similarity index 91% rename from src/app/root-hooks/evm/collectibles-metadata-loading.ts rename to src/app/pages/Collectibles/CollectiblesTab/components/evm-meta-loading.ts index 12c81b7b50..ac62f6982d 100644 --- a/src/app/root-hooks/evm/collectibles-metadata-loading.ts +++ b/src/app/pages/Collectibles/CollectiblesTab/components/evm-meta-loading.ts @@ -1,4 +1,4 @@ -import { memo, useEffect, useRef } from 'react'; +import { useEffect, useRef } from 'react'; import { dispatch } from 'app/store'; import { setEvmCollectiblesMetadataLoading } from 'app/store/evm/actions'; @@ -14,7 +14,10 @@ import { isSupportedChainId } from 'lib/apis/temple/endpoints/evm/api.utils'; import { fetchEvmCollectiblesMetadataFromChain } from 'lib/evm/on-chain/metadata'; import { useEnabledEvmChains } from 'temple/front'; -export const AppEvmCollectiblesMetadataLoading = memo<{ publicKeyHash: HexString }>(({ publicKeyHash }) => { +/** TODO: Might wanna tune this loading logic either via pagination or queueing. + * Pagination for Collectibles is planned for the future. + */ +export const useEvmCollectiblesMetadataLoading = (publicKeyHash: HexString) => { const evmChains = useEnabledEvmChains(); const isLoading = useEvmCollectiblesMetadataLoadingSelector(); @@ -61,6 +64,4 @@ export const AppEvmCollectiblesMetadataLoading = memo<{ publicKeyHash: HexString }) ).then(() => void dispatch(setEvmCollectiblesMetadataLoading(false))); }, [evmChains, storedCollectiblesRecord, publicKeyHash]); - - return null; -}); +}; diff --git a/src/app/root-hooks/index.tsx b/src/app/root-hooks/index.tsx index 4b918a2231..b321ddd6ec 100644 --- a/src/app/root-hooks/index.tsx +++ b/src/app/root-hooks/index.tsx @@ -22,7 +22,6 @@ import { useAccountAddressForEvm, useAccountAddressForTezos } from 'temple/front import { AppTezosAssetsLoading } from './assets-loading'; import { AppTezosBalancesLoading } from './balances-loading'; import { AppEvmBalancesLoading } from './evm/balances-loading'; -import { AppEvmCollectiblesMetadataLoading } from './evm/collectibles-metadata-loading'; import { AppEvmTokensExchangeRatesLoading } from './evm/tokens-exchange-rates-loading'; import { AppEvmTokensMetadataLoading } from './evm/tokens-metadata-loading'; import { AppTezosTokensMetadataLoading } from './metadata-loading'; @@ -87,7 +86,6 @@ const EvmAccountHooks = memo<{ publicKeyHash: HexString }>(({ publicKeyHash }) = <> - )); diff --git a/src/lib/balances/hooks.ts b/src/lib/balances/hooks.ts index c9fb4ffd31..086ac3ea9a 100644 --- a/src/lib/balances/hooks.ts +++ b/src/lib/balances/hooks.ts @@ -245,7 +245,8 @@ function useEvmAssetRawBalance( refreshBalanceOnChain(); }, [usingStore, refreshBalanceOnChain], - EVM_BALANCES_SYNC_INTERVAL + EVM_BALANCES_SYNC_INTERVAL, + false ); if (usingStore) diff --git a/src/temple/evm/index.ts b/src/temple/evm/index.ts index 6fe06a4f53..9ff2875f16 100644 --- a/src/temple/evm/index.ts +++ b/src/temple/evm/index.ts @@ -1,5 +1,5 @@ import memoizee from 'memoizee'; -import { Transport, Chain, createPublicClient, http, PublicClient } from 'viem'; +import { Transport, Chain, createPublicClient, http, PublicClient, HttpTransportConfig } from 'viem'; import { rejectOnTimeout } from 'lib/utils'; import { EvmChain } from 'temple/front'; @@ -7,10 +7,18 @@ import { MAX_MEMOIZED_TOOLKITS } from 'temple/misc'; import { getViemChainsList } from './utils'; +/** See: https://viem.sh/docs/clients/transports/http */ +const READ_ONLY_CLIENT_TRANSPORT_CONFIG: HttpTransportConfig = { + /** Defaults to 3 */ + retryCount: 1, + /** Defaults to 150 */ + retryDelay: 300 +}; + export const getReadOnlyEvm = memoizee( (rpcUrl: string): PublicClient => createPublicClient({ - transport: http(rpcUrl) + transport: http(rpcUrl, READ_ONLY_CLIENT_TRANSPORT_CONFIG) }), { max: MAX_MEMOIZED_TOOLKITS } );