Skip to content

Commit 1c069e4

Browse files
committed
nit
1 parent 16e8886 commit 1c069e4

File tree

3 files changed

+62
-34
lines changed

3 files changed

+62
-34
lines changed

pages/_app.page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default function MyApp(props: MyAppProps) {
177177
<BridgeModal />
178178
<ReadOnlyModal />
179179
<CowOrderToast />
180-
</GasStationProvider>
180+
</GasStationProvider>
181181
</AppDataProvider>
182182
</SharedDependenciesProvider>
183183
</ModalContextProvider>

src/components/transactions/Switch/BaseSwitchModalContent.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,19 @@ export const BaseSwitchModalContent = ({
590590
setCowOpenOrdersTotalAmountFormatted(undefined);
591591

592592
getOrders(selectedChainId, user).then((orders) => {
593+
const token =
594+
modalType === ModalType.CollateralSwap
595+
? selectedInputToken.aToken
596+
: selectedOutputToken.aToken;
597+
598+
if (!token) {
599+
return;
600+
}
601+
593602
const cowOpenOrdersTotalAmount = orders
594603
.filter(
595604
(order) =>
596-
order.sellToken.toLowerCase() == selectedInputToken.address.toLowerCase() &&
605+
order.sellToken.toLowerCase() == token.toLowerCase() &&
597606
order.status == OrderStatus.OPEN
598607
)
599608
.map((order) => order.sellAmount)
@@ -609,7 +618,14 @@ export const BaseSwitchModalContent = ({
609618
} else {
610619
setCowOpenOrdersTotalAmountFormatted(undefined);
611620
}
612-
}, [selectedInputToken, selectedOutputToken, switchRates?.provider, selectedChainId, user]);
621+
}, [
622+
selectedInputToken,
623+
selectedOutputToken,
624+
switchRates?.provider,
625+
selectedChainId,
626+
user,
627+
modalType,
628+
]);
613629

614630
// Views
615631
if (!initialFromTokens && !initialToTokens) {

src/hooks/useTransactionHistory.tsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)