Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Rewards/index.tsx
| // Copyright (c) 2024 The Bitcoin developers | // Copyright (c) 2024 The Bitcoin developers | ||||
| // Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
| import React, { useState, useEffect, useContext } from 'react'; | import React, { useState, useEffect, useContext } from 'react'; | ||||
| import { | import { | ||||
| Wrapper, | Wrapper, | ||||
| ContentDiv, | ContentDiv, | ||||
| ButtonContainer, | |||||
| GameCardsContainer, | GameCardsContainer, | ||||
| GameCard, | GameCard, | ||||
| } from 'components/Rewards/styled'; | } from 'components/Rewards/styled'; | ||||
| import { WalletContext, isWalletContextLoaded } from 'wallet/context'; | import { WalletContext, isWalletContextLoaded } from 'wallet/context'; | ||||
| import ActionButtonRow from 'components/Common/ActionButtonRow'; | |||||
| import PrimaryButton from 'components/Common/Buttons'; | import PrimaryButton from 'components/Common/Buttons'; | ||||
| import { toast } from 'react-toastify'; | import { toast } from 'react-toastify'; | ||||
| import { token as tokenConfig } from 'config/token'; | import { token as tokenConfig } from 'config/token'; | ||||
| import { InlineLoader } from 'components/Common/Spinner'; | import { InlineLoader } from 'components/Common/Spinner'; | ||||
| import { PageHeader } from 'components/Common/Atoms'; | |||||
| import { RewardIcon } from 'components/Common/CustomIcons'; | |||||
| import TokenIcon from 'components/Etokens/TokenIcon'; | import TokenIcon from 'components/Etokens/TokenIcon'; | ||||
| import { EDJ_TOKEN_ID, BLITZ_CHIPS_TOKEN_ID } from 'constants/tokens'; | import { EDJ_TOKEN_ID, BLITZ_CHIPS_TOKEN_ID } from 'constants/tokens'; | ||||
| const Rewards = () => { | const Rewards = () => { | ||||
| const ContextValue = useContext(WalletContext); | const ContextValue = useContext(WalletContext); | ||||
| if (!isWalletContextLoaded(ContextValue)) { | if (!isWalletContextLoaded(ContextValue)) { | ||||
| // Confirm we have all context required to load the page | // Confirm we have all context required to load the page | ||||
| return null; | return null; | ||||
| ▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | useEffect(() => { | ||||
| }, 1000); | }, 1000); | ||||
| // Keep it in state so we can clear it when it gets to 0 | // Keep it in state so we can clear it when it gets to 0 | ||||
| setCountdownInterval(interval); | setCountdownInterval(interval); | ||||
| return () => clearInterval(interval); | return () => clearInterval(interval); | ||||
| }, [eligibleAgainTimestamp]); | }, [eligibleAgainTimestamp]); | ||||
| const showRewardsLink = | |||||
| import.meta.env.VITE_BUILD_ENV !== 'extension' && | |||||
| import.meta.env.VITE_TESTNET !== 'true'; | |||||
| return ( | return ( | ||||
| <Wrapper title="Rewards"> | <Wrapper title="Rewards"> | ||||
| <PageHeader> | <ActionButtonRow | ||||
| Rewards <RewardIcon /> | variant="tools" | ||||
| </PageHeader> | activeIndex={showRewardsLink ? 3 : -1} | ||||
| /> | |||||
| {import.meta.env.VITE_TESTNET !== 'true' ? ( | {import.meta.env.VITE_TESTNET !== 'true' ? ( | ||||
| <> | <ButtonContainer> | ||||
| <PrimaryButton | <PrimaryButton | ||||
| disabled={!isEligible || claimPending} | disabled={!isEligible || claimPending} | ||||
| onClick={handleClaim} | onClick={handleClaim} | ||||
| > | > | ||||
| {isEligible === null || claimPending ? ( | {isEligible === null || claimPending ? ( | ||||
| <center> | <center> | ||||
| <InlineLoader /> | <InlineLoader /> | ||||
| </center> | </center> | ||||
| ) : isEligible ? ( | ) : isEligible ? ( | ||||
| 'Claim Reward' | 'Claim Reward' | ||||
| ) : timeRemainingMs !== null ? ( | ) : timeRemainingMs !== null ? ( | ||||
| `Come back in ${hours}:${minutes}:${seconds}` | `Come back in ${hours}:${minutes}:${seconds}` | ||||
| ) : ( | ) : ( | ||||
| <center> | <center> | ||||
| <InlineLoader /> | <InlineLoader /> | ||||
| </center> | </center> | ||||
| )} | )} | ||||
| </PrimaryButton> | </PrimaryButton> | ||||
| </> | </ButtonContainer> | ||||
| ) : ( | ) : ( | ||||
| <p>Token Rewards are not enabled for Testnet</p> | <p>Token Rewards are not enabled for Testnet</p> | ||||
| )} | )} | ||||
| <ContentDiv> | <ContentDiv> | ||||
| <h3>What can I do with Cachet?</h3> | <h3>What can I do with Cachet?</h3> | ||||
| <GameCardsContainer> | <GameCardsContainer> | ||||
| <GameCard | <GameCard | ||||
| href="https://everydayjackpot.com" | href="https://everydayjackpot.com" | ||||
| Show All 21 Lines | |||||