@@ -107,7 +107,7 @@ export const useTransactionHistory = ({ isFilterActive }: { isFilterActive: bool
107107 useShallow ( ( state ) => [ state . currentMarketData , state . account ] )
108108 ) ;
109109
110- const { reserves } = useAppDataContext ( ) ;
110+ const { reserves, loading : reservesLoading } = useAppDataContext ( ) ;
111111
112112 const [ shouldKeepFetching , setShouldKeepFetching ] = useState ( false ) ;
113113
@@ -341,34 +341,41 @@ export const useTransactionHistory = ({ isFilterActive }: { isFilterActive: bool
341341
342342 const PAGE_SIZE = 100 ;
343343 // Pagination over multiple sources is not perfect but since we are using an infinite query, won't be noticeable
344- const { data, fetchNextPage, hasNextPage, isLoading, isFetchingNextPage, isError, error } =
345- useInfiniteQuery ( {
346- queryKey : queryKeysFactory . transactionHistory ( account , currentMarketData ) ,
347- queryFn : async ( { pageParam = 0 } ) => {
348- const response = await fetchTransactionHistory ( {
349- account,
350- subgraphUrl : currentMarketData . subgraphUrl ?? '' ,
351- first : PAGE_SIZE ,
352- skip : pageParam ,
353- v3 : ! ! currentMarketData . v3 ,
354- pool : selectedPool ,
355- } ) ;
356- const cowSwapOrders = await fetchCowSwapsHistory ( PAGE_SIZE , pageParam * PAGE_SIZE ) ;
357- return [ ...response , ...cowSwapOrders ] . sort ( ( a , b ) => b . timestamp - a . timestamp ) ;
358- } ,
359- enabled : ! ! account && ! ! currentMarketData . subgraphUrl ,
360- getNextPageParam : (
361- lastPage : TransactionHistoryItemUnion [ ] ,
362- allPages : TransactionHistoryItemUnion [ ] [ ]
363- ) => {
364- const moreDataAvailable = lastPage . length === PAGE_SIZE ;
365- if ( ! moreDataAvailable ) {
366- return undefined ;
367- }
368- return allPages . length * PAGE_SIZE ;
369- } ,
370- initialPageParam : 0 ,
371- } ) ;
344+ const {
345+ data,
346+ fetchNextPage,
347+ hasNextPage,
348+ isLoading : isLoadingHistory ,
349+ isFetchingNextPage,
350+ isError,
351+ error,
352+ } = useInfiniteQuery ( {
353+ queryKey : queryKeysFactory . transactionHistory ( account , currentMarketData ) ,
354+ queryFn : async ( { pageParam = 0 } ) => {
355+ const response = await fetchTransactionHistory ( {
356+ account,
357+ subgraphUrl : currentMarketData . subgraphUrl ?? '' ,
358+ first : PAGE_SIZE ,
359+ skip : pageParam ,
360+ v3 : ! ! currentMarketData . v3 ,
361+ pool : selectedPool ,
362+ } ) ;
363+ const cowSwapOrders = await fetchCowSwapsHistory ( PAGE_SIZE , pageParam * PAGE_SIZE ) ;
364+ return [ ...response , ...cowSwapOrders ] . sort ( ( a , b ) => b . timestamp - a . timestamp ) ;
365+ } ,
366+ enabled : ! ! account && ! ! currentMarketData . subgraphUrl && ! reservesLoading && ! ! reserves ,
367+ getNextPageParam : (
368+ lastPage : TransactionHistoryItemUnion [ ] ,
369+ allPages : TransactionHistoryItemUnion [ ] [ ]
370+ ) => {
371+ const moreDataAvailable = lastPage . length === PAGE_SIZE ;
372+ if ( ! moreDataAvailable ) {
373+ return undefined ;
374+ }
375+ return allPages . length * PAGE_SIZE ;
376+ } ,
377+ initialPageParam : 0 ,
378+ } ) ;
372379
373380 // If filter is active, keep fetching until all data is returned so that it's guaranteed all filter results will be returned
374381 useEffect ( ( ) => {
@@ -381,17 +388,22 @@ export const useTransactionHistory = ({ isFilterActive }: { isFilterActive: bool
381388
382389 // Trigger a fetch when shouldKeepFetching is set to true
383390 useEffect ( ( ) => {
391+ if ( reservesLoading ) {
392+ // Wait for reserves to load
393+ return ;
394+ }
395+
384396 if ( shouldKeepFetching ) {
385397 fetchNextPage ( ) ;
386398 }
387- } , [ shouldKeepFetching , fetchNextPage ] ) ;
399+ } , [ shouldKeepFetching , fetchNextPage , reservesLoading ] ) ;
388400
389401 return {
390402 data,
391403 fetchNextPage,
392404 isFetchingNextPage,
393405 hasNextPage,
394- isLoading,
406+ isLoading : reservesLoading || isLoadingHistory ,
395407 isError,
396408 error,
397409 fetchForDownload,
0 commit comments