Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TW-1578: [evm] Fix lots of failing node requests on large accounts #1222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@ export const EvmChainCollectiblesTab = memo<EvmChainCollectiblesTabProps>(({ cha
const { isInSearchMode, paginatedSlugs, isSyncing, loadNext, searchValue, setSearchValue } =
useEvmChainCollectiblesListingLogic(publicKeyHash, chainId, manageActive);

useEvmCollectiblesMetadataLoading(publicKeyHash);

const contentElement = useMemo(
() => (
<div className={manageActive ? undefined : 'grid grid-cols-3 gap-2'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@ export const EvmCollectiblesTab = memo<EvmCollectiblesTabProps>(({ publicKeyHash
const { isInSearchMode, paginatedSlugs, isSyncing, loadNext, searchValue, setSearchValue } =
useEvmAccountCollectiblesListingLogic(publicKeyHash, manageActive);

useEvmCollectiblesMetadataLoading(publicKeyHash);

const contentElement = useMemo(
() => (
<div className={manageActive ? undefined : 'grid grid-cols-3 gap-2'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,8 @@ export const MultiChainCollectiblesTab = memo<MultiChainCollectiblesTabProps>(
const { isInSearchMode, paginatedSlugs, isSyncing, loadNext, searchValue, setSearchValue } =
useAccountCollectiblesListingLogic(accountTezAddress, accountEvmAddress, manageActive);

useEvmCollectiblesMetadataLoading(accountEvmAddress);

const contentElement = useMemo(
() => (
<div className={manageActive ? undefined : 'grid grid-cols-3 gap-2'}>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down Expand Up @@ -61,6 +64,4 @@ export const AppEvmCollectiblesMetadataLoading = memo<{ publicKeyHash: HexString
})
).then(() => void dispatch(setEvmCollectiblesMetadataLoading(false)));
}, [evmChains, storedCollectiblesRecord, publicKeyHash]);

return null;
});
};
2 changes: 0 additions & 2 deletions src/app/root-hooks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -87,7 +86,6 @@ const EvmAccountHooks = memo<{ publicKeyHash: HexString }>(({ publicKeyHash }) =
<>
<AppEvmTokensExchangeRatesLoading publicKeyHash={publicKeyHash} />
<AppEvmTokensMetadataLoading publicKeyHash={publicKeyHash} />
<AppEvmCollectiblesMetadataLoading publicKeyHash={publicKeyHash} />
<AppEvmBalancesLoading publicKeyHash={publicKeyHash} />
</>
));
3 changes: 2 additions & 1 deletion src/lib/balances/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ function useEvmAssetRawBalance(
refreshBalanceOnChain();
},
[usingStore, refreshBalanceOnChain],
EVM_BALANCES_SYNC_INTERVAL
EVM_BALANCES_SYNC_INTERVAL,
false
);

if (usingStore)
Expand Down
12 changes: 10 additions & 2 deletions src/temple/evm/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
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';
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 }
);
Expand Down
Loading