Skip to content

Commit

Permalink
Revert "Revert "fix: fix migrated tokens showing up in legacy balance…
Browse files Browse the repository at this point in the history
… (race c…" (#4259)
  • Loading branch information
tomquirk authored Feb 19, 2024
1 parent 6911fc1 commit fed149a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ export function useTotalLegacyTokenBalance({
const { data: v2UnclaimedBalance } = useV2UnclaimedBalanceForV3Token({
projectId,
})
const v2ClaimedBalance =
v2TotalBalance?.sub(v2UnclaimedBalance ?? 0) ?? BigNumber.from(0)

const totalLegacyTokenBalance = v1TotalBalance?.add(v2TotalBalance ?? 0)

const v2ClaimedBalance =
v2TotalBalance?.sub(v2UnclaimedBalance ?? 0) ?? BigNumber.from(0)

return {
v1TotalBalance,
v1UnclaimedBalance,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BigNumber } from 'ethers'
import { useWallet } from 'hooks/Wallet'
import { useUnclaimedTokenBalance } from 'hooks/v2v3/contractReader/useUnclaimedTokenBalance'
import useV2ContractReader from 'hooks/v2v3/contractReader/useV2ContractReader'
import { useJBTokenStoreForV3Token } from '../contracts/useJBTokenStoreForV3Token'

export function useV2UnclaimedBalanceForV3Token({
Expand All @@ -10,9 +11,12 @@ export function useV2UnclaimedBalanceForV3Token({
const { userAddress } = useWallet()
const v2TokenStoreContract = useJBTokenStoreForV3Token()

return useUnclaimedTokenBalance({
userAddress,
projectId,
JBTokenStore: v2TokenStoreContract,
return useV2ContractReader<BigNumber>({
contract: v2TokenStoreContract,
functionName: 'unclaimedBalanceOf',
args:
userAddress && projectId && v2TokenStoreContract
? [userAddress, projectId]
: null,
})
}
8 changes: 1 addition & 7 deletions src/hooks/v2v3/contractReader/useUnclaimedTokenBalance.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { BigNumber } from 'ethers'
import { bigNumbersDiff } from 'utils/bigNumbers'

import { Contract } from 'ethers'
import { V2V3ContractName } from 'models/v2v3/contracts'
import useContractReader from './useV2ContractReader'

/** Returns unclaimed balance of user with `userAddress`. */
export function useUnclaimedTokenBalance({
projectId,
userAddress,
JBTokenStore,
}: {
projectId: number | undefined
userAddress: string | undefined
JBTokenStore?: Contract
}) {
return useContractReader<BigNumber>({
contract: JBTokenStore ?? V2V3ContractName.JBTokenStore,
contract: V2V3ContractName.JBTokenStore,
functionName: 'unclaimedBalanceOf',
args:
userAddress && projectId
? [userAddress, BigNumber.from(projectId).toHexString()]
: null,
valueDidChange: bigNumbersDiff,
})
}

0 comments on commit fed149a

Please sign in to comment.