Skip to content

Commit

Permalink
Consolidate multiple queries for chain ID into one query
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Dec 23, 2024
1 parent d51b4ca commit 2b1cce4
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/__swaps__/screens/Swap/resources/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { isAddress } from '@ethersproject/address';
import { useQuery, useQueries } from '@tanstack/react-query';
import qs from 'qs';
import { parseTokenSearch } from './utils';
import { useBackendNetworksStore } from '@/state/backendNetworks/backendNetworks';

const ALL_VERIFIED_TOKENS_PARAM = '/?list=verifiedAssets';

Expand Down Expand Up @@ -150,22 +149,8 @@ export function useTokenSearchAllNetworks(
{ query }: Omit<TokenSearchArgs, 'list' | 'chainId' | 'fromChainId'>,
config: QueryConfigWithSelect<TokenSearchResult, Error, TokenSearchResult, TokenSearchQueryKey> = {}
) {
const getSupportedChainIds = useBackendNetworksStore(state => state.getSupportedChainIds);
const supportedChains = getSupportedChainIds();

const queries = useQueries({
queries: supportedChains.map(id => {
return {
queryKey: tokenSearchQueryKey({ chainId: id, query }),
queryFn: tokenSearchQueryFunction,
refetchOnWindowFocus: false,
...config,
};
}),
return useQuery(tokenSearchQueryKey({ query }), tokenSearchQueryFunction, {
...config,
keepPreviousData: true,
});

return {
data: queries.map(({ data: assets }) => assets || []).flat(),
isFetching: queries.some(({ isFetching }) => isFetching),
};
}

0 comments on commit 2b1cce4

Please sign in to comment.