From 2b1cce454bfe0c167cc5e874ad92029914d504ad Mon Sep 17 00:00:00 2001 From: jinchung Date: Mon, 23 Dec 2024 11:30:23 -0500 Subject: [PATCH] Consolidate multiple queries for chain ID into one query --- .../screens/Swap/resources/search/search.ts | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/__swaps__/screens/Swap/resources/search/search.ts b/src/__swaps__/screens/Swap/resources/search/search.ts index 7b4710fe7e5..c560b26c84f 100644 --- a/src/__swaps__/screens/Swap/resources/search/search.ts +++ b/src/__swaps__/screens/Swap/resources/search/search.ts @@ -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'; @@ -150,22 +149,8 @@ export function useTokenSearchAllNetworks( { query }: Omit, config: QueryConfigWithSelect = {} ) { - 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), - }; }