Skip to content

Commit c970455

Browse files
fix(bridge): compute tokens from lists during render
1 parent 5528577 commit c970455

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

packages/arb-token-bridge-ui/src/components/TransferPanel/TokenSearchUtils.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ export function useTokensFromLists() {
1717
const { childChain, parentChain } = useNetworksRelationship(networks);
1818
const { data: tokenLists, isLoading: isLoadingTokenLists } = useTokenLists(childChain.id);
1919

20-
const { data = emptyData, isLoading } = useSWRImmutable(
21-
[tokenLists ?? [], parentChain.id, childChain.id, 'useTokensFromLists'],
22-
([_tokenLists, _parentChainId, _childChainId]) =>
23-
tokenListsToSearchableTokenStorage(
24-
_tokenLists,
25-
String(_parentChainId),
26-
String(_childChainId),
27-
),
28-
);
29-
30-
return { data, isLoading: isLoadingTokenLists || isLoading };
20+
// Derived synchronously so the tokens can never lag behind the fetched lists,
21+
// which an extra async hook allowed under heavy re-rendering
22+
const data = useMemo(() => {
23+
if (!tokenLists) {
24+
return emptyData;
25+
}
26+
27+
return tokenListsToSearchableTokenStorage(
28+
tokenLists,
29+
String(parentChain.id),
30+
String(childChain.id),
31+
);
32+
}, [tokenLists, parentChain.id, childChain.id]);
33+
34+
return { data, isLoading: isLoadingTokenLists };
3135
}
3236

3337
export function useTokensFromUser(): ContractStorage<ERC20BridgeToken> {

0 commit comments

Comments
 (0)