Skip to content

Commit

Permalink
fix(wallet): refetch using query directly to avoid circular dep
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrishajev committed Sep 19, 2024
1 parent 6e4e991 commit 47420c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/deploy-web/src/context/WalletProvider/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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();
Expand All @@ -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]);

Expand Down
7 changes: 5 additions & 2 deletions apps/deploy-web/src/queries/useBalancesQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ async function getBalances(apiEndpoint: string, address: string): Promise<Balanc
};
}

export function useBalances(address: string, options?: Omit<UseQueryOptions<Balances, Error, any, QueryKey>, "queryKey" | "queryFn">) {
export function useBalances(address?: string, options?: Omit<UseQueryOptions<Balances, Error, any, QueryKey>, "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
});
}

0 comments on commit 47420c0

Please sign in to comment.