Skip to content

Commit 5284132

Browse files
committed
fix: always fetch a fresh result for fetchTokenBalance
1 parent c5e33a5 commit 5284132

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/curve-ui-kit/src/queries/token-balance.query.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ const getERC20QueryContracts = ({ chainId, userAddress, tokenAddress }: ChainQue
3232
/** In the Curve ecosystem all native chain gas tokens are the 0xeee...eee address */
3333
const isNative = ({ tokenAddress }: TokenQuery) => isAddressEqual(tokenAddress, ethAddress)
3434

35-
/** Imperatively fetch token balance */
35+
/** Imperatively fetch token balance. Uses a staletime of 0 to always be guaranteed of a fresh result. */
3636
export const fetchTokenBalance = async (config: Config, query: ChainQuery & UserQuery & TokenQuery) =>
3737
isNative(query)
3838
? await queryClient
39-
.fetchQuery(getNativeBalanceQueryOptions(config, query))
39+
.fetchQuery({ ...getNativeBalanceQueryOptions(config, query), staleTime: 0 })
4040
.then((balance) => convertBalance({ value: balance.value, decimals: balance.decimals }))
4141
: await queryClient
42-
.fetchQuery(
43-
readContractsQueryOptions(config, {
42+
.fetchQuery({
43+
...readContractsQueryOptions(config, {
4444
allowFailure: false,
4545
contracts: getERC20QueryContracts(query),
4646
}),
47-
)
47+
staleTime: 0,
48+
})
4849
.then((balance) => convertBalance({ value: balance[0], decimals: balance[1] }))
4950

5051
/** Hook to fetch the token balance */

0 commit comments

Comments
 (0)