From 49e0aa36c07f85d195aee7a859a7c40872c46b5b 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 | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/__swaps__/screens/Swap/resources/search/search.ts b/src/__swaps__/screens/Swap/resources/search/search.ts index 7b4710fe7e5..c7f506707fb 100644 --- a/src/__swaps__/screens/Swap/resources/search/search.ts +++ b/src/__swaps__/screens/Swap/resources/search/search.ts @@ -5,10 +5,9 @@ import { RainbowError, logger } from '@/logger'; import { RainbowFetchClient } from '@/rainbow-fetch'; import { QueryConfigWithSelect, QueryFunctionArgs, QueryFunctionResult, createQueryKey, queryClient } from '@/react-query'; import { isAddress } from '@ethersproject/address'; -import { useQuery, useQueries } from '@tanstack/react-query'; +import { useQuery } 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), - }; }