From 68efd8d361538bfe9e76bb525d897cda005117fc Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Mon, 27 Feb 2023 19:01:38 +0300 Subject: [PATCH] Implement Mint by Minter for Badge Actions --- components/badges/actions/Action.tsx | 37 +++++++++++++++++++++++++++- components/badges/actions/actions.ts | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/components/badges/actions/Action.tsx b/components/badges/actions/Action.tsx index 0d8b69f..9096a24 100644 --- a/components/badges/actions/Action.tsx +++ b/components/badges/actions/Action.tsx @@ -3,18 +3,23 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ // import { AirdropUpload } from 'components/AirdropUpload' import { toUtf8 } from '@cosmjs/encoding' +import { Alert } from 'components/Alert' import type { DispatchExecuteArgs } from 'components/badges/actions/actions' import { dispatchExecute, isEitherType, previewExecutePayload } from 'components/badges/actions/actions' import { ActionsCombobox } from 'components/badges/actions/Combobox' import { useActionsComboboxState } from 'components/badges/actions/Combobox.hooks' import { Button } from 'components/Button' +import { Conditional } from 'components/Conditional' import { FormControl } from 'components/FormControl' import { FormGroup } from 'components/FormGroup' +import { AddressList } from 'components/forms/AddressList' +import { useAddressListState } from 'components/forms/AddressList.hooks' import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks' import { MetadataAttributes } from 'components/forms/MetadataAttributes' import { useMetadataAttributesState } from 'components/forms/MetadataAttributes.hooks' import { JsonPreview } from 'components/JsonPreview' import { TransactionHash } from 'components/TransactionHash' +import { WhitelistUpload } from 'components/WhitelistUpload' import { useWallet } from 'contexts/wallet' import type { Badge, BadgeHubInstance } from 'contracts/badgeHub' import * as crypto from 'crypto' @@ -26,6 +31,7 @@ import { FaArrowRight } from 'react-icons/fa' import { useMutation } from 'react-query' import * as secp256k1 from 'secp256k1' import { sha256 } from 'utils/hash' +import { isValidAddress } from 'utils/isValidAddress' import { resolveAddress } from 'utils/resolveAddress' import { BadgeAirdropListUpload } from '../../BadgeAirdropListUpload' @@ -54,6 +60,7 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage const [triggerDispatch, setTriggerDispatch] = useState(false) const [keyPairs, setKeyPairs] = useState([]) const [signature, setSignature] = useState('') + const [ownerList, setOwnerList] = useState([]) const actionComboboxState = useActionsComboboxState() const type = actionComboboxState.value?.id @@ -147,6 +154,8 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage defaultValue: wallet.address, }) + const ownerListState = useAddressListState() + const pubkeyState = useInputState({ id: 'pubkey', name: 'pubkey', @@ -179,6 +188,7 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage const showOwnerField = isEitherType(type, ['mint_by_key', 'mint_by_keys']) const showPrivateKeyField = isEitherType(type, ['mint_by_key', 'mint_by_keys', 'airdrop_by_key']) const showAirdropFileField = isEitherType(type, ['airdrop_by_key']) + const showOwnerList = isEitherType(type, ['mint_by_minter']) const payload: DispatchExecuteArgs = { badge: { @@ -235,7 +245,14 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage signature, keys: [], limit: limitState.value, - owners: [], + owners: [ + ...new Set( + ownerListState.values + .map((a) => a.address.trim()) + .filter((address) => address !== '' && isValidAddress(address.trim()) && address.startsWith('stars')) + .concat(ownerList), + ), + ], recipients: airdropAllocationArray, privateKey: privateKeyState.value, nft: nftState.value, @@ -517,6 +534,24 @@ export const BadgeActions = ({ badgeHubContractAddress, badgeId, badgeHubMessage )} {showPrivateKeyField && } + +
+ + + You may optionally choose a text file of additional owner addresses. + + +
+
+ {showAirdropFileField && (