diff --git a/src/hooks/JBV3Token/contractReader/useTotalLegacyTokenBalance.ts b/src/hooks/JBV3Token/contractReader/useTotalLegacyTokenBalance.ts index 66d8ef0d1b..f9751edc98 100644 --- a/src/hooks/JBV3Token/contractReader/useTotalLegacyTokenBalance.ts +++ b/src/hooks/JBV3Token/contractReader/useTotalLegacyTokenBalance.ts @@ -13,21 +13,15 @@ export function useTotalLegacyTokenBalance({ const v1UnclaimedBalance = useV1UnclaimedBalanceForV3Token() const v1ClaimedBalance = v1TotalBalance?.sub(v1UnclaimedBalance) - const { data: v2TotalBalance, loading: v2BalanceLoading } = useV2TotalBalance( - { projectId }, - ) - const { data: v2UnclaimedBalance, loading: unclaimedBalanceLoading } = - useV2UnclaimedBalanceForV3Token({ - projectId, - }) - - if (v2BalanceLoading || unclaimedBalanceLoading) return BigNumber.from(0) - - const totalLegacyTokenBalance = v1TotalBalance?.add(v2TotalBalance ?? 0) - + const { data: v2TotalBalance } = useV2TotalBalance({ projectId }) + const { data: v2UnclaimedBalance } = useV2UnclaimedBalanceForV3Token({ + projectId, + }) const v2ClaimedBalance = v2TotalBalance?.sub(v2UnclaimedBalance ?? 0) ?? BigNumber.from(0) + const totalLegacyTokenBalance = v1TotalBalance?.add(v2TotalBalance ?? 0) + return { v1TotalBalance, v1UnclaimedBalance, diff --git a/src/hooks/JBV3Token/contractReader/useV2UnclaimedBalanceForV3Token.ts b/src/hooks/JBV3Token/contractReader/useV2UnclaimedBalanceForV3Token.ts index 50a486f1a6..50079a24de 100644 --- a/src/hooks/JBV3Token/contractReader/useV2UnclaimedBalanceForV3Token.ts +++ b/src/hooks/JBV3Token/contractReader/useV2UnclaimedBalanceForV3Token.ts @@ -1,6 +1,5 @@ -import { BigNumber } from 'ethers' import { useWallet } from 'hooks/Wallet' -import useV2ContractReader from 'hooks/v2v3/contractReader/useV2ContractReader' +import { useUnclaimedTokenBalance } from 'hooks/v2v3/contractReader/useUnclaimedTokenBalance' import { useJBTokenStoreForV3Token } from '../contracts/useJBTokenStoreForV3Token' export function useV2UnclaimedBalanceForV3Token({ @@ -11,12 +10,9 @@ export function useV2UnclaimedBalanceForV3Token({ const { userAddress } = useWallet() const v2TokenStoreContract = useJBTokenStoreForV3Token() - return useV2ContractReader({ - contract: v2TokenStoreContract, - functionName: 'unclaimedBalanceOf', - args: - userAddress && projectId && v2TokenStoreContract - ? [userAddress, projectId] - : null, + return useUnclaimedTokenBalance({ + userAddress, + projectId, + JBTokenStore: v2TokenStoreContract, }) } diff --git a/src/hooks/v2v3/contractReader/useUnclaimedTokenBalance.ts b/src/hooks/v2v3/contractReader/useUnclaimedTokenBalance.ts index d0a2b426e9..eeb93f4604 100644 --- a/src/hooks/v2v3/contractReader/useUnclaimedTokenBalance.ts +++ b/src/hooks/v2v3/contractReader/useUnclaimedTokenBalance.ts @@ -1,4 +1,7 @@ import { BigNumber } from 'ethers' +import { bigNumbersDiff } from 'utils/bigNumbers' + +import { Contract } from 'ethers' import { V2V3ContractName } from 'models/v2v3/contracts' import useContractReader from './useV2ContractReader' @@ -6,16 +9,19 @@ import useContractReader from './useV2ContractReader' export function useUnclaimedTokenBalance({ projectId, userAddress, + JBTokenStore, }: { projectId: number | undefined userAddress: string | undefined + JBTokenStore?: Contract }) { return useContractReader({ - contract: V2V3ContractName.JBTokenStore, + contract: JBTokenStore ?? V2V3ContractName.JBTokenStore, functionName: 'unclaimedBalanceOf', args: userAddress && projectId ? [userAddress, BigNumber.from(projectId).toHexString()] : null, + valueDidChange: bigNumbersDiff, }) }