Skip to content

Commit

Permalink
fix: load only supported chains tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Oct 11, 2022
1 parent 8ead9ae commit 882beb7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/widget/src/hooks/useTokens.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import { isItemAllowed, useLiFi, useWidgetConfig } from '../providers';
import type { Token } from '../types';
import { useChains } from './useChains';
import { useFeaturedTokens } from './useFeaturedTokens';

export const useTokens = (selectedChainId?: number) => {
const lifi = useLiFi();
const { getChainById, isLoading: isSupportedChainsLoading } = useChains();
const featuredTokens = useFeaturedTokens(selectedChainId);
const { tokens, chains, disabledChains } = useWidgetConfig();
const { data, isLoading } = useQuery(
Expand All @@ -20,6 +22,7 @@ export const useTokens = (selectedChainId?: number) => {
async () => {
const chainAllowed =
selectedChainId &&
getChainById(selectedChainId) &&
isItemAllowed(selectedChainId, chains, disabledChains);
if (!chainAllowed) {
return [];
Expand Down Expand Up @@ -52,6 +55,9 @@ export const useTokens = (selectedChainId?: number) => {
) ?? []),
] as Token[];
},
{
enabled: !isSupportedChainsLoading,
},
);
return {
tokens: data,
Expand Down

0 comments on commit 882beb7

Please sign in to comment.