Skip to content

Commit bfc4993

Browse files
authored
fix: query key (#247)
1 parent e44f65f commit bfc4993

File tree

9 files changed

+41
-66
lines changed

9 files changed

+41
-66
lines changed

packages/app-portal/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"@fuel-bridge/solidity-contracts": "0.5.0",
2020
"@fuels/assets": "^0.17.0",
2121
"@fuels/connectors": "0.1.0",
22-
"@fuels/react": "^0.17.0",
22+
"@fuels/react": "0.17.0",
2323
"@fuels/react-xstore": "^0.17.0",
2424
"@fuels/ui": "workspace:*",
2525
"@hookform/resolvers": "^3.1.1",
@@ -58,4 +58,4 @@
5858
"tailwindcss-radix": "2.8.0",
5959
"typescript": "5.3.3"
6060
}
61-
}
61+
}

packages/app-portal/src/systems/Bridge/hooks/useBridge.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '~portal/systems/Chains';
1717

1818
import { FUEL_CHAIN } from 'app-commons';
19+
import { useEthBalance } from '~portal/systems/Chains/eth/hooks/useEthBalance';
1920
import { BridgeStatus } from '../machines';
2021
import type { BridgeMachineState } from '../machines';
2122
import { getChainFromUrlParam } from '../utils';
@@ -79,14 +80,14 @@ export function useBridge() {
7980
address: ethAddress,
8081
handlers: ethHandlers,
8182
isConnecting: ethIsConnecting,
82-
balance: ethBalance,
8383
walletClient: ethWalletClient,
8484
publicClient: ethPublicClient,
85-
} = useEthAccountConnection({
86-
erc20Address: ethAssetAddress?.startsWith('0x')
85+
} = useEthAccountConnection();
86+
const { ethBalance } = useEthBalance(
87+
ethAssetAddress?.startsWith('0x')
8788
? (ethAssetAddress as `0x${string}`)
8889
: undefined,
89-
});
90+
);
9091

9192
const {
9293
account: fuelAccount,
@@ -121,13 +122,15 @@ export function useBridge() {
121122

122123
return bn(0);
123124
}, [ethBalance, fromNetwork, fuelBalance]);
125+
124126
const status = store.useSelector(
125127
Services.bridge,
126128
selectors.status({ ethAccount: ethAddress, fuelAccount, assetBalance }),
127129
);
128130

129131
const router = useRouter();
130132
const params = useSearchParams();
133+
131134
// console.log(params);
132135
// const location = useLocation();
133136
// const queryParams = new URLSearchParams(location.search);

packages/app-portal/src/systems/Bridge/hooks/useWithdrawDelay.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function useWithdrawDelay() {
88
const publicClient = usePublicClient();
99

1010
const { fuelChainState } = useNamedQuery('fuelChainState', {
11-
queryKey: ['bridge', 'withdraw', 'state'],
11+
queryKey: ['fuel', 'bridge', 'withdraw', 'state'],
1212
queryFn: getBridgeSolidityContracts,
1313
select: (bridgeSolidityContracts) => {
1414
return EthConnectorService.connectToFuelChainState({
@@ -21,7 +21,7 @@ export function useWithdrawDelay() {
2121
});
2222

2323
return useNamedQuery('timeToWithdrawFormatted', {
24-
queryKey: ['bridge', 'withdraw', 'formatted'],
24+
queryKey: ['fuel', 'bridge', 'withdraw', 'formatted'],
2525
queryFn: async () => {
2626
const [blocksPerCommitInterval, timeToFinalize] = (await Promise.all([
2727
fuelChainState?.read.BLOCKS_PER_COMMIT_INTERVAL(),

packages/app-portal/src/systems/Chains/eth/hooks/useEthAccountConnection.tsx

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useModal } from 'connectkit';
22
import {
33
useAccount,
4-
useBalance,
54
useDisconnect,
65
useEnsAvatar,
76
useEnsName,
@@ -14,18 +13,11 @@ import { useEffect } from 'react';
1413
import { useOverlay } from '~portal/systems/Overlay';
1514
import { parseEthAddressToFuel } from '../utils';
1615

17-
export function useEthAccountConnection(props?: {
18-
erc20Address?: `0x${string}`;
19-
}) {
16+
export function useEthAccountConnection() {
2017
const overlay = useOverlay();
21-
const { erc20Address } = props || {};
2218
const { address, isConnected } = useAccount();
2319
const { data: ensName } = useEnsName({ address });
2420
const { data: ensAvatar } = useEnsAvatar({ name: address });
25-
const { data: balance } = useBalance({
26-
address,
27-
token: erc20Address,
28-
});
2921
const publicClient = usePublicClient();
3022
const { data: walletClient } = useWalletClient();
3123

@@ -72,6 +64,5 @@ export function useEthAccountConnection(props?: {
7264
signer: walletClient || undefined,
7365
walletClient: walletClient || undefined,
7466
publicClient: publicClient || undefined,
75-
balance,
7667
};
7768
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useAccount, useBalance, useBlockNumber } from 'wagmi';
2+
3+
import { useQueryClient } from '@tanstack/react-query';
4+
import { useEffect } from 'react';
5+
6+
export function useEthBalance(token?: `0x${string}`) {
7+
const queryClient = useQueryClient();
8+
9+
const { address } = useAccount();
10+
const { data: blockNumber } = useBlockNumber({ watch: true });
11+
const { data: ethBalance, queryKey: ethBalanceQueryKey } = useBalance({
12+
address,
13+
token,
14+
});
15+
16+
useEffect(() => {
17+
queryClient.invalidateQueries({ queryKey: ethBalanceQueryKey });
18+
}, [queryClient, blockNumber, ethBalanceQueryKey]);
19+
20+
return {
21+
ethBalance,
22+
};
23+
}

packages/app-portal/src/systems/Chains/fuel/hooks/useBalance.tsx

-32
This file was deleted.

packages/app-portal/src/systems/Chains/fuel/hooks/useFuelAccountConnection.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
useAccount,
3+
useBalance,
34
useConnectUI,
45
useDisconnect,
56
useFuel,
@@ -12,17 +13,14 @@ import { store } from '~portal/store';
1213
import type { AssetFuel } from '~portal/systems/Assets/utils';
1314
import { useFuelNetwork } from '~portal/systems/Settings/providers/FuelNetworkProvider';
1415

15-
import { useBalance } from './useBalance';
16-
1716
export const useFuelAccountConnection = (props?: { assetId?: string }) => {
1817
const { assetId } = props || {};
1918
const { fuel } = useFuel();
2019
const { fuelProvider, isLoading: isLoadingProvider } = useFuelNetwork();
2120
const { account, isLoading: isLoadingAccount } = useAccount();
2221
const { balance, isLoading: isLoadingBalance } = useBalance({
2322
assetId,
24-
address: account || '',
25-
provider: fuelProvider,
23+
address: account || undefined,
2624
});
2725

2826
const { isLoading: isLoadingConnected } = useIsConnected();

packages/app-portal/src/systems/Settings/providers/FuelNetworkProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createProvider } from '~portal/systems/Chains/fuel/utils/provider';
44

55
export const useFuelNetwork = () => {
66
return useNamedQuery('fuelProvider', {
7-
queryKey: ['bridge', 'fuel', 'provider'],
7+
queryKey: ['fuel', 'bridge', 'fuel', 'provider'],
88
queryFn: async () => {
99
const provider = await createProvider(FUEL_CHAIN.providerUrl);
1010
return provider;

pnpm-lock.yaml

+3-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)