-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from citydaoproject/mnorman-issue3
chore: [#3] added back not eligible modal
- Loading branch information
Showing
2 changed files
with
100 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,118 @@ | ||
import React from 'react'; | ||
import DefaultButton, { DefaultButtonProps } from './common/DefaultButton'; | ||
|
||
export interface ClaimButtonProps extends DefaultButtonProps { | ||
export interface ClaimButtonProps extends Omit<DefaultButtonProps, 'onClick'> { | ||
allowance: number; | ||
walletAlreadyClaimed: number; | ||
withinClaimPeriod: boolean; | ||
onClaim: () => void; | ||
onShowMinted: () => void; | ||
onNotEligible: () => void; | ||
} | ||
|
||
const ClaimButton = ({ allowance, walletAlreadyClaimed, withinClaimPeriod, disabled, ...rest }: ClaimButtonProps) => { | ||
enum ClaimStatus { | ||
READY_TO_CLAIM = 'READY_TO_CLAIM', | ||
SOME_CLAIMED = 'SOME_CLAIMED', | ||
ALL_CLAIMED = 'ALL_CLAIMED', | ||
NOT_ELIGIBLE = 'NOT_ELIGIBLE', | ||
OUTSIDE_CLAIM_PERIOD = 'OUTSIDE_CLAIM_PERIOD', | ||
} | ||
|
||
const ClaimButton = ({ | ||
allowance, | ||
walletAlreadyClaimed, | ||
withinClaimPeriod, | ||
disabled, | ||
onClaim, | ||
onShowMinted, | ||
onNotEligible, | ||
...rest | ||
}: ClaimButtonProps) => { | ||
const claimStatus = determineClaimStatus(allowance, walletAlreadyClaimed, withinClaimPeriod); | ||
console.log('ClaimStatus:', claimStatus); | ||
|
||
const getClaimButtonText = () => { | ||
if (!withinClaimPeriod) { | ||
return 'CLAIM NFTS'; | ||
switch (claimStatus) { | ||
case ClaimStatus.READY_TO_CLAIM: | ||
case ClaimStatus.SOME_CLAIMED: | ||
return `Claim ${allowance - walletAlreadyClaimed} NFTs`; | ||
|
||
case ClaimStatus.ALL_CLAIMED: | ||
return `${walletAlreadyClaimed} NFTs Claimed`; | ||
|
||
case ClaimStatus.NOT_ELIGIBLE: | ||
case ClaimStatus.OUTSIDE_CLAIM_PERIOD: | ||
return 'Claim NFTs'; | ||
|
||
default: | ||
return 'Claim NFTs'; | ||
} | ||
}; | ||
|
||
if (allowance > 0 && allowance > walletAlreadyClaimed) { | ||
return `CLAIM ${allowance - walletAlreadyClaimed} NFTS`; | ||
const isDisabled = () => { | ||
if (disabled) { | ||
return true; | ||
} | ||
|
||
if (walletAlreadyClaimed > 0) { | ||
return `${walletAlreadyClaimed} NFTS CLAIMED`; | ||
switch (claimStatus) { | ||
case ClaimStatus.READY_TO_CLAIM: | ||
case ClaimStatus.SOME_CLAIMED: | ||
case ClaimStatus.ALL_CLAIMED: | ||
case ClaimStatus.NOT_ELIGIBLE: | ||
return false; | ||
|
||
case ClaimStatus.OUTSIDE_CLAIM_PERIOD: | ||
return true; | ||
|
||
default: | ||
return false; | ||
} | ||
}; | ||
|
||
return 'CLAIM NFTS'; | ||
const handleClick = () => { | ||
switch (claimStatus) { | ||
case ClaimStatus.READY_TO_CLAIM: | ||
case ClaimStatus.SOME_CLAIMED: | ||
onClaim(); | ||
break; | ||
|
||
case ClaimStatus.ALL_CLAIMED: | ||
onShowMinted(); | ||
break; | ||
|
||
case ClaimStatus.NOT_ELIGIBLE: | ||
onNotEligible(); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<DefaultButton | ||
{...rest} | ||
disabled={disabled || !withinClaimPeriod || (walletAlreadyClaimed === 0 && allowance === 0)} | ||
> | ||
<DefaultButton {...rest} disabled={isDisabled()} onClick={handleClick}> | ||
{getClaimButtonText()} | ||
</DefaultButton> | ||
); | ||
}; | ||
export default ClaimButton; | ||
|
||
const determineClaimStatus = (allowance: number, walletAlreadyClaimed: number, withinClaimPeriod: boolean) => { | ||
if (!withinClaimPeriod) { | ||
return ClaimStatus.OUTSIDE_CLAIM_PERIOD; | ||
} | ||
|
||
if (allowance === 0) { | ||
return ClaimStatus.NOT_ELIGIBLE; | ||
} | ||
|
||
if (walletAlreadyClaimed === 0) { | ||
return ClaimStatus.READY_TO_CLAIM; | ||
} | ||
|
||
if (walletAlreadyClaimed < allowance) { | ||
return ClaimStatus.SOME_CLAIMED; | ||
} | ||
|
||
return ClaimStatus.ALL_CLAIMED; | ||
}; |
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
848866d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
parcel-0-claim-portal – ./
parcel-0-test.vercel.app
parcel-0-claim-portal-git-main-city-dao.vercel.app
parcel-0-claim-portal-beta.vercel.app
parcel-0-claim-portal-city-dao.vercel.app