Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Airdrop/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 { useLocation } from 'react-router'; | import { useLocation } from 'react-router'; | ||||
| import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
| import { WalletContext, isWalletContextLoaded } from 'wallet/context'; | import { WalletContext, isWalletContextLoaded } from 'wallet/context'; | ||||
| import PrimaryButton, { SecondaryLink } from 'components/Common/Buttons'; | import PrimaryButton, { SecondaryLink } from 'components/Common/Buttons'; | ||||
| import CopyToClipboard from 'components/Common/CopyToClipboard'; | import CopyToClipboard from 'components/Common/CopyToClipboard'; | ||||
| import { | import { | ||||
| isValidTokenId, | isValidTokenId, | ||||
| isValidXecAirdrop, | isValidXecAirdrop, | ||||
| isValidAirdropExclusionArray, | isValidAirdropExclusionArray, | ||||
| } from 'validation'; | } from 'validation'; | ||||
| import { SwitchLabel, PageHeader } from 'components/Common/Atoms'; | import { SwitchLabel } from 'components/Common/Atoms'; | ||||
| import { | import { | ||||
| getAirdropTx, | getAirdropTx, | ||||
| getEqualAirdropTx, | getEqualAirdropTx, | ||||
| getAgoraHolders, | getAgoraHolders, | ||||
| getP2pkhHolders, | getP2pkhHolders, | ||||
| } from 'airdrop'; | } from 'airdrop'; | ||||
| import Communist from 'assets/communist.png'; | import Communist from 'assets/communist.png'; | ||||
| import { toast } from 'react-toastify'; | import { toast } from 'react-toastify'; | ||||
| import CashtabSwitch from 'components/Common/Switch'; | import CashtabSwitch from 'components/Common/Switch'; | ||||
| import { Input, TextArea, InputFlex } from 'components/Common/Inputs'; | import { Input, TextArea, InputFlex } from 'components/Common/Inputs'; | ||||
| import { CopyPasteIcon, AirdropIcon } from 'components/Common/CustomIcons'; | import ActionButtonRow from 'components/Common/ActionButtonRow'; | ||||
| import { CopyPasteIcon } from 'components/Common/CustomIcons'; | |||||
| import { getTokenGenesisInfo } from 'chronik'; | import { getTokenGenesisInfo } from 'chronik'; | ||||
| import { encodeOutputScript } from 'ecashaddrjs'; | import { encodeOutputScript } from 'ecashaddrjs'; | ||||
| import Spinner from 'components/Common/Spinner'; | import Spinner from 'components/Common/Spinner'; | ||||
| import { AirdropForm, FormRow, SwitchHolder, AirdropTitle } from './styled'; | import { | ||||
| AirdropForm, | |||||
| FormRow, | |||||
| SwitchHolder, | |||||
| AirdropTitle, | |||||
| AirdropContainer, | |||||
| } from './styled'; | |||||
| import { CashtabCachedTokenInfo } from 'config/CashtabCache'; | import { CashtabCachedTokenInfo } from 'config/CashtabCache'; | ||||
| const Airdrop = () => { | const Airdrop = () => { | ||||
| 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 366 Lines • ▼ Show 20 Lines | if (ignoreMinEtokenBalance && ignoreCustomAddresses) { | ||||
| // ignore custom addresses only | // ignore custom addresses only | ||||
| airdropCalcInputIsValid = | airdropCalcInputIsValid = | ||||
| tokenIdIsValid && | tokenIdIsValid && | ||||
| totalAirdropIsValid && | totalAirdropIsValid && | ||||
| ignoreCustomAddressesListIsValid; | ignoreCustomAddressesListIsValid; | ||||
| } | } | ||||
| return ( | return ( | ||||
| <> | <AirdropContainer> | ||||
| <PageHeader> | <ActionButtonRow variant="tools" activeIndex={1} /> | ||||
| Airdrop <AirdropIcon /> | |||||
| </PageHeader> | |||||
| {calculatingAirdrop && <Spinner />} | {calculatingAirdrop && <Spinner />} | ||||
| <AirdropForm> | <AirdropForm> | ||||
| <FormRow> | <FormRow> | ||||
| <InputFlex> | <InputFlex> | ||||
| <Input | <Input | ||||
| placeholder="Enter the eToken ID" | placeholder="Enter the eToken ID" | ||||
| label="Token ID" | |||||
| name="tokenId" | name="tokenId" | ||||
| value={formData.tokenId} | value={formData.tokenId} | ||||
| handleInput={handleTokenIdInput} | handleInput={handleTokenIdInput} | ||||
| error={ | error={ | ||||
| tokenIdIsValid === false | tokenIdIsValid === false | ||||
| ? 'Invalid eToken ID' | ? 'Invalid eToken ID' | ||||
| : false | : false | ||||
| } | } | ||||
| /> | /> | ||||
| </InputFlex> | </InputFlex> | ||||
| </FormRow> | </FormRow> | ||||
| <FormRow> | <FormRow> | ||||
| <InputFlex> | <InputFlex> | ||||
| <Input | <Input | ||||
| placeholder="Enter the total XEC airdrop" | placeholder="Enter the total XEC airdrop" | ||||
| label="Total XEC airdrop" | |||||
| name="totalAirdrop" | name="totalAirdrop" | ||||
| type="number" | type="number" | ||||
| value={formData.totalAirdrop} | value={formData.totalAirdrop} | ||||
| handleInput={handleTotalAirdropInput} | handleInput={handleTotalAirdropInput} | ||||
| error={ | error={ | ||||
| totalAirdropIsValid === false | totalAirdropIsValid === false | ||||
| ? 'Invalid total XEC airdrop' | ? 'Invalid total XEC airdrop' | ||||
| : false | : false | ||||
| ▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | return ( | ||||
| disabled={!airdropRecipients} | disabled={!airdropRecipients} | ||||
| > | > | ||||
| Copy to Send screen | Copy to Send screen | ||||
| </SecondaryLink> | </SecondaryLink> | ||||
| </FormRow> | </FormRow> | ||||
| </> | </> | ||||
| )} | )} | ||||
| </AirdropForm> | </AirdropForm> | ||||
| </> | </AirdropContainer> | ||||
| ); | ); | ||||
| }; | }; | ||||
| export default Airdrop; | export default Airdrop; | ||||