From d0e5bf7f4ceeff403853d8487fadd31db7bb7da9 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Thu, 15 Jun 2023 13:51:08 +0300 Subject: [PATCH] Customized minting details for open edition minter --- components/openEdition/MintingDetails.tsx | 99 +++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 components/openEdition/MintingDetails.tsx diff --git a/components/openEdition/MintingDetails.tsx b/components/openEdition/MintingDetails.tsx new file mode 100644 index 0000000..8b6acd5 --- /dev/null +++ b/components/openEdition/MintingDetails.tsx @@ -0,0 +1,99 @@ +/* eslint-disable eslint-comments/disable-enable-pair */ +/* eslint-disable no-nested-ternary */ +import { FormControl } from 'components/FormControl' +import { FormGroup } from 'components/FormGroup' +import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks' +import { InputDateTime } from 'components/InputDateTime' +import React, { useEffect, useState } from 'react' +import { resolveAddress } from 'utils/resolveAddress' + +import { useWallet } from '../../contexts/wallet' +import { NumberInput, TextInput } from '../forms/FormInput' +import type { UploadMethod } from './OffChainMetadataUploadDetails' + +interface MintingDetailsProps { + onChange: (data: MintingDetailsDataProps) => void + uploadMethod: UploadMethod + minimumMintPrice: number +} + +export interface MintingDetailsDataProps { + unitPrice: string + perAddressLimit: number + startTime: string + endTime: string + paymentAddress?: string +} + +export const MintingDetails = ({ onChange, uploadMethod, minimumMintPrice }: MintingDetailsProps) => { + const wallet = useWallet() + + const [timestamp, setTimestamp] = useState() + const [endTimestamp, setEndTimestamp] = useState() + + const unitPriceState = useNumberInputState({ + id: 'unitPrice', + name: 'unitPrice', + title: 'Unit Price', + subtitle: `Price of each token (min. ${minimumMintPrice} STARS)`, + placeholder: '50', + }) + + const perAddressLimitState = useNumberInputState({ + id: 'peraddresslimit', + name: 'peraddresslimit', + title: 'Per Address Limit', + subtitle: '', + placeholder: '1', + }) + + const paymentAddressState = useInputState({ + id: 'payment-address', + name: 'paymentAddress', + title: 'Payment Address (optional)', + subtitle: 'Address to receive minting revenues (defaults to current wallet address)', + placeholder: 'stars1234567890abcdefghijklmnopqrstuvwxyz...', + }) + + const resolvePaymentAddress = async () => { + await resolveAddress(paymentAddressState.value.trim(), wallet).then((resolvedAddress) => { + paymentAddressState.onChange(resolvedAddress) + }) + } + + useEffect(() => { + void resolvePaymentAddress() + }, [paymentAddressState.value]) + + useEffect(() => { + const data: MintingDetailsDataProps = { + unitPrice: unitPriceState.value + ? (Number(unitPriceState.value) * 1_000_000).toString() + : unitPriceState.value === 0 + ? '0' + : '', + perAddressLimit: perAddressLimitState.value, + startTime: timestamp ? (timestamp.getTime() * 1_000_000).toString() : '', + endTime: endTimestamp ? (endTimestamp.getTime() * 1_000_000).toString() : '', + paymentAddress: paymentAddressState.value.trim(), + } + onChange(data) + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [unitPriceState.value, perAddressLimitState.value, timestamp, endTimestamp, paymentAddressState.value]) + + return ( +
+ + + + + setTimestamp(date)} value={timestamp} /> + + + setEndTimestamp(date)} value={endTimestamp} /> + + + +
+ ) +}