From 450aeedf2001b2f6d1d2a0c2bacb8dcd20281513 Mon Sep 17 00:00:00 2001 From: "Michael D. Norman" Date: Wed, 11 May 2022 22:57:15 -0500 Subject: [PATCH] chore: [#3] disable claim button when no more to claim - extracted parcel nft loading logic --- .github/workflows/ci.yml | 6 +- components/ClaimButton.tsx | 27 +++ components/common/DefaultButton.tsx | 8 + constants/ethereum.ts | 12 ++ .../ParcelProperties/ParcelProperties.tsx | 24 +-- contants.ts | 6 - context/StateProvider.tsx | 21 +- hooks/contractHooks.ts | 157 +++++++++++++++ hooks/parcelNFT.ts | 60 ++++++ hooks/useWallet.tsx | 64 ++++--- pages/index.tsx | 180 ++++++++---------- 11 files changed, 394 insertions(+), 171 deletions(-) create mode 100644 components/ClaimButton.tsx create mode 100644 components/common/DefaultButton.tsx create mode 100644 constants/ethereum.ts delete mode 100644 contants.ts create mode 100644 hooks/contractHooks.ts create mode 100644 hooks/parcelNFT.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 077cc90..4119316 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,8 @@ jobs: - name: Check out code uses: actions/checkout@v3 - name: Install dependencies - run: npm ci + run: yarn install --frozen-lockfile - name: Build - run: npm run build + run: yarn build - name: Lint - run: npm run lint + run: yarn lint diff --git a/components/ClaimButton.tsx b/components/ClaimButton.tsx new file mode 100644 index 0000000..eb701e2 --- /dev/null +++ b/components/ClaimButton.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import DefaultButton, { DefaultButtonProps } from './common/DefaultButton'; + +export interface ClaimButtonProps extends DefaultButtonProps { + allowance: number; + walletAlreadyClaimed: number; +} + +const ClaimButton = ({ allowance, walletAlreadyClaimed, disabled, ...rest }: ClaimButtonProps) => { + const getClaimButtonText = () => { + if (walletAlreadyClaimed === 0 && allowance === 0) { + return 'CLAIM PLOTS'; + } else if (walletAlreadyClaimed > 0) { + return `${walletAlreadyClaimed} PLOTS CLAIMED`; + } else if (allowance > 0) { + return `CLAIM ${allowance} PLOTS`; + } + return ''; + }; + + return ( + + {getClaimButtonText()} + + ); +}; +export default ClaimButton; diff --git a/components/common/DefaultButton.tsx b/components/common/DefaultButton.tsx new file mode 100644 index 0000000..4efe67d --- /dev/null +++ b/components/common/DefaultButton.tsx @@ -0,0 +1,8 @@ +import React from 'react'; + +export interface DefaultButtonProps extends React.ButtonHTMLAttributes {} + +const DefaultButton = ({ disabled, ...rest }: DefaultButtonProps) => ( + + onClick={walletAlreadyClaimed === 0 ? handleOpenClaimModal : showMintedNfts} + /> - - + + ); }; - export default Home;