Skip to content

Commit

Permalink
Revert "fix: fix migrated tokens showing up in legacy balance (race c… (
Browse files Browse the repository at this point in the history
  • Loading branch information
wraeth-eth authored Feb 19, 2024
1 parent 4271eb9 commit 308af57
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
18 changes: 6 additions & 12 deletions src/hooks/JBV3Token/contractReader/useTotalLegacyTokenBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -11,12 +10,9 @@ export function useV2UnclaimedBalanceForV3Token({
const { userAddress } = useWallet()
const v2TokenStoreContract = useJBTokenStoreForV3Token()

return useV2ContractReader<BigNumber>({
contract: v2TokenStoreContract,
functionName: 'unclaimedBalanceOf',
args:
userAddress && projectId && v2TokenStoreContract
? [userAddress, projectId]
: null,
return useUnclaimedTokenBalance({
userAddress,
projectId,
JBTokenStore: v2TokenStoreContract,
})
}
8 changes: 7 additions & 1 deletion src/hooks/v2v3/contractReader/useUnclaimedTokenBalance.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
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: V2V3ContractName.JBTokenStore,
contract: JBTokenStore ?? V2V3ContractName.JBTokenStore,
functionName: 'unclaimedBalanceOf',
args:
userAddress && projectId
? [userAddress, BigNumber.from(projectId).toHexString()]
: null,
valueDidChange: bigNumbersDiff,
})
}

0 comments on commit 308af57

Please sign in to comment.