Add limit type selection to OE MintingDetails

This commit is contained in:
Serkan Reis 2023-12-19 13:53:41 +03:00
parent 9a7e2fea5e
commit 0f1c4a027b

View File

@ -1,5 +1,6 @@
/* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable no-nested-ternary */ /* eslint-disable no-nested-ternary */
import { Conditional } from 'components/Conditional'
import { FormControl } from 'components/FormControl' import { FormControl } from 'components/FormControl'
import { FormGroup } from 'components/FormGroup' import { FormGroup } from 'components/FormGroup'
import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks' import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks'
@ -15,6 +16,8 @@ import { useWallet } from 'utils/wallet'
import { NumberInput, TextInput } from '../forms/FormInput' import { NumberInput, TextInput } from '../forms/FormInput'
import type { UploadMethod } from './OffChainMetadataUploadDetails' import type { UploadMethod } from './OffChainMetadataUploadDetails'
export type LimitType = 'count_limited' | 'time_limited'
interface MintingDetailsProps { interface MintingDetailsProps {
onChange: (data: MintingDetailsDataProps) => void onChange: (data: MintingDetailsDataProps) => void
uploadMethod: UploadMethod uploadMethod: UploadMethod
@ -27,9 +30,11 @@ export interface MintingDetailsDataProps {
unitPrice: string unitPrice: string
perAddressLimit: number perAddressLimit: number
startTime: string startTime: string
endTime: string endTime?: string
tokenCountLimit?: number
paymentAddress?: string paymentAddress?: string
selectedMintToken?: TokenInfo selectedMintToken?: TokenInfo
limitType: LimitType
} }
export const MintingDetails = ({ export const MintingDetails = ({
@ -45,6 +50,7 @@ export const MintingDetails = ({
const [endTimestamp, setEndTimestamp] = useState<Date | undefined>() const [endTimestamp, setEndTimestamp] = useState<Date | undefined>()
const [selectedMintToken, setSelectedMintToken] = useState<TokenInfo | undefined>(stars) const [selectedMintToken, setSelectedMintToken] = useState<TokenInfo | undefined>(stars)
const [mintingDetailsImported, setMintingDetailsImported] = useState(false) const [mintingDetailsImported, setMintingDetailsImported] = useState(false)
const [limitType, setLimitType] = useState<LimitType>('time_limited')
const { timezone } = useGlobalSettings() const { timezone } = useGlobalSettings()
const unitPriceState = useNumberInputState({ const unitPriceState = useNumberInputState({
@ -65,6 +71,14 @@ export const MintingDetails = ({
placeholder: '1', placeholder: '1',
}) })
const tokenCountLimitState = useNumberInputState({
id: 'tokencountlimit',
name: 'tokencountlimit',
title: 'Maximum Token Count',
subtitle: 'Total number of mintable tokens',
placeholder: '100',
})
const paymentAddressState = useInputState({ const paymentAddressState = useInputState({
id: 'payment-address', id: 'payment-address',
name: 'paymentAddress', name: 'paymentAddress',
@ -97,6 +111,8 @@ export const MintingDetails = ({
endTime: endTimestamp ? (endTimestamp.getTime() * 1_000_000).toString() : '', endTime: endTimestamp ? (endTimestamp.getTime() * 1_000_000).toString() : '',
paymentAddress: paymentAddressState.value.trim(), paymentAddress: paymentAddressState.value.trim(),
selectedMintToken, selectedMintToken,
limitType,
tokenCountLimit: limitType === 'count_limited' ? tokenCountLimitState.value : undefined,
} }
onChange(data) onChange(data)
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
@ -107,6 +123,8 @@ export const MintingDetails = ({
endTimestamp, endTimestamp,
paymentAddressState.value, paymentAddressState.value,
selectedMintToken, selectedMintToken,
tokenCountLimitState.value,
limitType,
]) ])
useEffect(() => { useEffect(() => {
@ -168,6 +186,32 @@ export const MintingDetails = ({
} }
/> />
</FormControl> </FormControl>
<div className="flex-row mt-2 w-full form-control">
<h1 className="mt-2 font-bold text-md">Limit Type: </h1>
<label className="justify-start ml-6 cursor-pointer label">
<span className="mr-2">Time</span>
<input
checked={limitType === 'time_limited'}
className={`${limitType === 'time_limited' ? `bg-stargaze` : `bg-gray-600`} checkbox`}
onClick={() => {
setLimitType('time_limited' as LimitType)
}}
type="checkbox"
/>
</label>
<label className="justify-start ml-4 cursor-pointer label">
<span className="mr-2">Token Count</span>
<input
checked={limitType === 'count_limited'}
className={`${limitType === 'count_limited' ? `bg-stargaze` : `bg-gray-600`} checkbox`}
onClick={() => {
setLimitType('count_limited' as LimitType)
}}
type="checkbox"
/>
</label>
</div>
<Conditional test={limitType === 'time_limited'}>
<FormControl <FormControl
htmlId="endTimestamp" htmlId="endTimestamp"
isRequired isRequired
@ -192,6 +236,10 @@ export const MintingDetails = ({
} }
/> />
</FormControl> </FormControl>
</Conditional>
<Conditional test={limitType === 'count_limited'}>
<NumberInput {...tokenCountLimitState} isRequired />
</Conditional>
</FormGroup> </FormGroup>
<TextInput className="pr-4 pl-4 mt-3" {...paymentAddressState} /> <TextInput className="pr-4 pl-4 mt-3" {...paymentAddressState} />
</div> </div>