This repository was archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLAIM] Button refactor and error fix (#2218)
* export types * move Footer code into new file * if statement
- Loading branch information
Showing
4 changed files
with
140 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { Trans } from '@lingui/macro' | ||
import { isAddress } from '@ethersproject/address' | ||
import { useClaimDispatchers, useClaimState } from 'state/claim/hooks' | ||
import { ButtonPrimary, ButtonSecondary } from 'components/Button' | ||
import { ClaimStatus } from 'state/claim/actions' | ||
import { FooterNavButtons as FooterNavButtonsWrapper } from 'pages/Claim/styled' | ||
import { useActiveWeb3React } from 'hooks/web3' | ||
import { ClaimsTableProps } from './ClaimsTable' | ||
import { ClaimAddressProps } from './ClaimAddress' | ||
import { ReactNode } from 'react' | ||
|
||
type FooterNavButtonsProps = Pick<ClaimsTableProps, 'hasClaims' | 'isAirdropOnly'> & | ||
Pick<ClaimAddressProps, 'toggleWalletModal'> & { | ||
isPaidClaimsOnly: boolean | ||
resolvedAddress: string | null | ||
handleSubmitClaim: () => void | ||
handleCheckClaim: () => void | ||
} | ||
|
||
export default function FooterNavButtons({ | ||
hasClaims, | ||
isAirdropOnly, | ||
isPaidClaimsOnly, | ||
resolvedAddress, | ||
toggleWalletModal, | ||
handleSubmitClaim, | ||
handleCheckClaim, | ||
}: FooterNavButtonsProps) { | ||
const { account } = useActiveWeb3React() | ||
const { | ||
// account | ||
activeClaimAccount, | ||
// claiming | ||
claimStatus, | ||
// investment | ||
investFlowStep, | ||
isInvestFlowActive, | ||
// table select change | ||
selected, | ||
} = useClaimState() | ||
|
||
const { | ||
// investing | ||
setInvestFlowStep, | ||
setIsInvestFlowActive, | ||
} = useClaimDispatchers() | ||
|
||
const isInputAddressValid = isAddress(resolvedAddress || '') | ||
|
||
// User is connected and has some unclaimed claims | ||
const isConnectedAndHasClaims = !!activeClaimAccount && !!hasClaims && claimStatus === ClaimStatus.DEFAULT | ||
const noPaidClaimsSelected = !selected.length | ||
|
||
let buttonContent: ReactNode = null | ||
// Disconnected, show wallet connect | ||
if (!account) { | ||
buttonContent = ( | ||
<ButtonPrimary onClick={toggleWalletModal}> | ||
<Trans>Connect a wallet</Trans> | ||
</ButtonPrimary> | ||
) | ||
} | ||
|
||
// User has no set active claim account and/or has claims, show claim account search | ||
if (!activeClaimAccount || !hasClaims) { | ||
buttonContent = ( | ||
<ButtonPrimary disabled={!isInputAddressValid} type="text" onClick={handleCheckClaim}> | ||
<Trans>Check claimable vCOW</Trans> | ||
</ButtonPrimary> | ||
) | ||
} | ||
|
||
// USER is CONNECTED + HAS SOMETHING TO CLAIM | ||
if (isConnectedAndHasClaims) { | ||
if (!isInvestFlowActive) { | ||
buttonContent = ( | ||
<ButtonPrimary onClick={handleSubmitClaim} disabled={isPaidClaimsOnly && noPaidClaimsSelected}> | ||
<Trans>Claim vCOW</Trans> | ||
</ButtonPrimary> | ||
) | ||
} else if (!isAirdropOnly) { | ||
buttonContent = ( | ||
<> | ||
{investFlowStep === 0 ? ( | ||
<ButtonPrimary onClick={() => setInvestFlowStep(1)}> | ||
<Trans>Approve tokens</Trans> | ||
</ButtonPrimary> | ||
) : investFlowStep === 1 ? ( | ||
<ButtonPrimary onClick={() => setInvestFlowStep(2)}> | ||
<Trans>Review</Trans> | ||
</ButtonPrimary> | ||
) : ( | ||
<ButtonPrimary onClick={handleSubmitClaim}> | ||
<Trans>Claim and invest vCOW</Trans> | ||
</ButtonPrimary> | ||
)} | ||
|
||
<ButtonSecondary | ||
onClick={() => | ||
investFlowStep === 0 ? setIsInvestFlowActive(false) : setInvestFlowStep(investFlowStep - 1) | ||
} | ||
> | ||
<Trans>Go back</Trans> | ||
</ButtonSecondary> | ||
</> | ||
) | ||
} | ||
} | ||
|
||
return <FooterNavButtonsWrapper>{buttonContent}</FooterNavButtonsWrapper> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters