diff --git a/apps/deploy-web/src/context/WalletProvider/WalletProvider.tsx b/apps/deploy-web/src/context/WalletProvider/WalletProvider.tsx index b1dfcbb79..52f710959 100644 --- a/apps/deploy-web/src/context/WalletProvider/WalletProvider.tsx +++ b/apps/deploy-web/src/context/WalletProvider/WalletProvider.tsx @@ -16,8 +16,8 @@ import { browserEnvConfig } from "@src/config/browser-env.config"; import { useAllowance } from "@src/hooks/useAllowance"; import { useManagedWallet } from "@src/hooks/useManagedWallet"; import { useUser } from "@src/hooks/useUser"; -import { useWalletBalance } from "@src/hooks/useWalletBalance"; import { useWhen } from "@src/hooks/useWhen"; +import { useBalances } from "@src/queries/useBalancesQuery"; import { txHttpService } from "@src/services/http/http.service"; import networkStore from "@src/store/networkStore"; import { AnalyticsEvents } from "@src/utils/analytics"; @@ -72,7 +72,6 @@ export const WalletProvider = ({ children }) => { const { enqueueSnackbar, closeSnackbar } = useSnackbar(); const router = useRouter(); const { settings } = useSettings(); - const { refetch: refetchBalances } = useWalletBalance(); const user = useUser(); const userWallet = useSelectedChain(); const { wallet: managedWallet, isLoading, create: createManagedWallet } = useManagedWallet(); @@ -84,6 +83,7 @@ export const WalletProvider = ({ children }) => { username, isWalletConnected } = useMemo(() => (selectedWalletType === "managed" && managedWallet) || userWallet, [managedWallet, userWallet, selectedWalletType]); + const { refetch: refetchBalances } = useBalances(walletAddress); const { addEndpoints } = useManager(); const isManaged = useMemo(() => !!managedWallet && managedWallet?.address === walletAddress, [walletAddress, managedWallet]); diff --git a/apps/deploy-web/src/queries/useBalancesQuery.ts b/apps/deploy-web/src/queries/useBalancesQuery.ts index e014af4f8..2deeded7c 100644 --- a/apps/deploy-web/src/queries/useBalancesQuery.ts +++ b/apps/deploy-web/src/queries/useBalancesQuery.ts @@ -61,7 +61,10 @@ async function getBalances(apiEndpoint: string, address: string): Promise, "queryKey" | "queryFn">) { +export function useBalances(address?: string, options?: Omit, "queryKey" | "queryFn">) { const { settings } = useSettings(); - return useQuery(QueryKeys.getBalancesKey(address), () => getBalances(settings.apiEndpoint, address), options); + return useQuery(QueryKeys.getBalancesKey(address), () => getBalances(settings.apiEndpoint, address), { + enabled: !!address, + ...options + }); }