Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Fix avilable claims issue on rinkeby (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadV91 authored Feb 18, 2022
1 parent 7319d6c commit e4364cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
28 changes: 22 additions & 6 deletions src/custom/pages/Claim/ClaimSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Trans } from '@lingui/macro'
import { CurrencyAmount, Currency } from '@uniswap/sdk-core'
import { CurrencyAmount, Currency, Token } from '@uniswap/sdk-core'
import CowProtocolLogo from 'components/CowProtocolLogo'
import { formatMax, formatSmartLocaleAware } from 'utils/format'
import { useClaimState } from 'state/claim/hooks'
Expand All @@ -10,6 +10,7 @@ import { AMOUNT_PRECISION } from 'constants/index'
import { useTokenBalance } from 'state/wallet/hooks'
import { V_COW } from 'constants/tokens'
import { useActiveWeb3React } from 'hooks'
import { JSBI } from '@uniswap/sdk'

type ClaimSummaryProps = Pick<ClaimCommonTypes, 'hasClaims' | 'isClaimed'> & {
unclaimedAmount: ClaimCommonTypes['tokenCurrencyAmount'] | undefined
Expand All @@ -19,16 +20,25 @@ export function ClaimSummary({ hasClaims, isClaimed, unclaimedAmount }: ClaimSum
const { chainId } = useActiveWeb3React()
const { activeClaimAccount, claimStatus, isInvestFlowActive } = useClaimState()

const vCowBalance = useTokenBalance(activeClaimAccount || undefined, chainId ? V_COW[chainId] : undefined)
const vCow = chainId ? V_COW[chainId] : undefined

const vCowBalance = useTokenBalance(activeClaimAccount || undefined, vCow)

const hasClaimSummary = claimStatus === ClaimStatus.DEFAULT && !isInvestFlowActive

if (!hasClaimSummary) return null
if (!hasClaimSummary || !vCow) return null

let totalAvailableAmount: CurrencyAmount<Token> | undefined = CurrencyAmount.fromRawAmount(vCow, JSBI.BigInt(0))

const totalAvailableAmount = hasClaims && activeClaimAccount && unclaimedAmount ? unclaimedAmount : vCowBalance
if (hasClaims && activeClaimAccount && unclaimedAmount) {
totalAvailableAmount = unclaimedAmount
} else if (isClaimed) {
totalAvailableAmount = vCowBalance
}

return (
<ClaimSummaryView
activeClaimAccount={activeClaimAccount}
showClaimText={!activeClaimAccount && !hasClaims}
totalAvailableAmount={totalAvailableAmount}
totalAvailableText={isClaimed ? 'Total claimed' : 'Total available to claim'}
Expand All @@ -40,9 +50,15 @@ type ClaimSummaryViewProps = {
showClaimText?: boolean
totalAvailableAmount?: CurrencyAmount<Currency>
totalAvailableText?: string
activeClaimAccount: string
}

export function ClaimSummaryView({ showClaimText, totalAvailableText, totalAvailableAmount }: ClaimSummaryViewProps) {
export function ClaimSummaryView({
showClaimText,
totalAvailableText,
totalAvailableAmount,
activeClaimAccount,
}: ClaimSummaryViewProps) {
return (
<ClaimSummaryWrapper>
<CowProtocolLogo size={100} />
Expand All @@ -53,7 +69,7 @@ export function ClaimSummaryView({ showClaimText, totalAvailableText, totalAvail
</Trans>
</ClaimSummaryTitle>
)}
{totalAvailableAmount && (
{totalAvailableAmount && activeClaimAccount && (
<div>
<ClaimTotal>
{totalAvailableText && <b>{totalAvailableText}</b>}
Expand Down
6 changes: 5 additions & 1 deletion src/custom/pages/Claim/InvestmentFlow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ export default function InvestmentFlow({ claims, hasClaims, isAirdropOnly, modal
{/* Invest flow: Step 2 > Review summary */}
{investFlowStep === 2 ? (
<InvestContent>
<ClaimSummaryView totalAvailableAmount={totalVCow} totalAvailableText={'Total amount to claim'} />
<ClaimSummaryView
activeClaimAccount={activeClaimAccount}
totalAvailableAmount={totalVCow}
totalAvailableText={'Total amount to claim'}
/>
<ClaimTable>
<InvestSummaryTable>
<thead>
Expand Down

0 comments on commit e4364cb

Please sign in to comment.