2022-08-04 09:16:42 +00:00
|
|
|
import { FormControl } from 'components/FormControl'
|
|
|
|
import { FormGroup } from 'components/FormGroup'
|
2023-03-08 20:53:12 +00:00
|
|
|
import { AddressList } from 'components/forms/AddressList'
|
|
|
|
import { useAddressListState } from 'components/forms/AddressList.hooks'
|
2022-08-05 11:13:27 +00:00
|
|
|
import { useInputState, useNumberInputState } from 'components/forms/FormInput.hooks'
|
2022-08-04 09:16:42 +00:00
|
|
|
import { InputDateTime } from 'components/InputDateTime'
|
|
|
|
import React, { useEffect, useState } from 'react'
|
2023-03-08 20:53:12 +00:00
|
|
|
import { isValidAddress } from 'utils/isValidAddress'
|
2022-08-04 09:16:42 +00:00
|
|
|
|
|
|
|
import { Conditional } from '../../Conditional'
|
2022-08-05 11:13:27 +00:00
|
|
|
import { AddressInput, NumberInput } from '../../forms/FormInput'
|
2022-08-04 09:16:42 +00:00
|
|
|
import { JsonPreview } from '../../JsonPreview'
|
|
|
|
import { WhitelistUpload } from '../../WhitelistUpload'
|
|
|
|
|
|
|
|
interface WhitelistDetailsProps {
|
|
|
|
onChange: (data: WhitelistDetailsDataProps) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface WhitelistDetailsDataProps {
|
2022-08-05 11:13:27 +00:00
|
|
|
whitelistType: WhitelistState
|
2022-08-04 09:16:42 +00:00
|
|
|
contractAddress?: string
|
|
|
|
members?: string[]
|
|
|
|
unitPrice?: string
|
|
|
|
startTime?: string
|
|
|
|
endTime?: string
|
|
|
|
perAddressLimit?: number
|
|
|
|
memberLimit?: number
|
2023-03-08 20:53:12 +00:00
|
|
|
admins?: string[]
|
|
|
|
adminsMutable?: boolean
|
2022-08-04 09:16:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-05 11:13:27 +00:00
|
|
|
type WhitelistState = 'none' | 'existing' | 'new'
|
|
|
|
|
2022-08-04 09:16:42 +00:00
|
|
|
export const WhitelistDetails = ({ onChange }: WhitelistDetailsProps) => {
|
2022-08-05 11:13:27 +00:00
|
|
|
const [whitelistState, setWhitelistState] = useState<WhitelistState>('none')
|
2022-08-04 09:16:42 +00:00
|
|
|
const [startDate, setStartDate] = useState<Date | undefined>(undefined)
|
|
|
|
const [endDate, setEndDate] = useState<Date | undefined>(undefined)
|
|
|
|
const [whitelistArray, setWhitelistArray] = useState<string[]>([])
|
2023-03-18 08:18:34 +00:00
|
|
|
const [adminsMutable, setAdminsMutable] = useState<boolean>(true)
|
2022-08-04 09:16:42 +00:00
|
|
|
|
2022-08-05 11:13:27 +00:00
|
|
|
const whitelistAddressState = useInputState({
|
|
|
|
id: 'whitelist-address',
|
|
|
|
name: 'whitelistAddress',
|
|
|
|
title: 'Whitelist Address',
|
2022-08-09 11:42:55 +00:00
|
|
|
defaultValue: '',
|
2022-08-05 11:13:27 +00:00
|
|
|
})
|
|
|
|
|
2022-11-04 11:53:11 +00:00
|
|
|
const unitPriceState = useNumberInputState({
|
2022-08-04 09:16:42 +00:00
|
|
|
id: 'unit-price',
|
|
|
|
name: 'unitPrice',
|
|
|
|
title: 'Unit Price',
|
2023-04-07 09:28:19 +00:00
|
|
|
subtitle: 'Token price for whitelisted addresses \n (min. 0 STARS)',
|
2022-09-01 06:27:23 +00:00
|
|
|
placeholder: '25',
|
2022-08-04 09:16:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const memberLimitState = useNumberInputState({
|
|
|
|
id: 'member-limit',
|
|
|
|
name: 'memberLimit',
|
|
|
|
title: 'Member Limit',
|
2022-09-01 06:27:23 +00:00
|
|
|
subtitle: 'Maximum number of whitelisted addresses',
|
2022-08-04 09:16:42 +00:00
|
|
|
placeholder: '1000',
|
|
|
|
})
|
|
|
|
|
|
|
|
const perAddressLimitState = useNumberInputState({
|
|
|
|
id: 'per-address-limit',
|
|
|
|
name: 'perAddressLimit',
|
|
|
|
title: 'Per Address Limit',
|
2022-09-01 06:27:23 +00:00
|
|
|
subtitle: 'Maximum number of tokens per whitelisted address',
|
2022-08-04 09:16:42 +00:00
|
|
|
placeholder: '5',
|
|
|
|
})
|
|
|
|
|
2023-03-08 20:53:12 +00:00
|
|
|
const addressListState = useAddressListState()
|
|
|
|
|
2022-08-04 09:16:42 +00:00
|
|
|
const whitelistFileOnChange = (data: string[]) => {
|
|
|
|
setWhitelistArray(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const data: WhitelistDetailsDataProps = {
|
2022-08-05 11:13:27 +00:00
|
|
|
whitelistType: whitelistState,
|
2022-11-18 16:50:33 +00:00
|
|
|
contractAddress: whitelistAddressState.value
|
|
|
|
.toLowerCase()
|
|
|
|
.replace(/,/g, '')
|
|
|
|
.replace(/"/g, '')
|
|
|
|
.replace(/'/g, '')
|
|
|
|
.replace(/ /g, ''),
|
2022-08-04 09:16:42 +00:00
|
|
|
members: whitelistArray,
|
2022-11-04 11:53:11 +00:00
|
|
|
unitPrice: unitPriceState.value ? (Number(unitPriceState.value) * 1_000_000).toString() : '',
|
2022-08-04 09:16:42 +00:00
|
|
|
startTime: startDate ? (startDate.getTime() * 1_000_000).toString() : '',
|
|
|
|
endTime: endDate ? (endDate.getTime() * 1_000_000).toString() : '',
|
|
|
|
perAddressLimit: perAddressLimitState.value,
|
|
|
|
memberLimit: memberLimitState.value,
|
2023-03-08 20:53:12 +00:00
|
|
|
admins: [
|
|
|
|
...new Set(
|
|
|
|
addressListState.values
|
|
|
|
.map((a) => a.address.trim())
|
|
|
|
.filter((address) => address !== '' && isValidAddress(address.trim()) && address.startsWith('stars')),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
adminsMutable,
|
2022-08-04 09:16:42 +00:00
|
|
|
}
|
|
|
|
onChange(data)
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2022-08-09 11:42:55 +00:00
|
|
|
}, [
|
|
|
|
whitelistAddressState.value,
|
2022-11-04 11:53:11 +00:00
|
|
|
unitPriceState.value,
|
2022-08-09 11:42:55 +00:00
|
|
|
memberLimitState.value,
|
|
|
|
perAddressLimitState.value,
|
|
|
|
startDate,
|
|
|
|
endDate,
|
|
|
|
whitelistArray,
|
|
|
|
whitelistState,
|
2023-03-08 20:53:12 +00:00
|
|
|
addressListState.values,
|
|
|
|
adminsMutable,
|
2022-08-09 11:42:55 +00:00
|
|
|
])
|
2022-08-04 09:16:42 +00:00
|
|
|
|
|
|
|
return (
|
2022-08-05 11:13:27 +00:00
|
|
|
<div className="py-3 px-8 rounded border-2 border-white/20">
|
|
|
|
<div className="flex justify-center">
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={whitelistState === 'none'}
|
2022-09-13 05:19:04 +00:00
|
|
|
className="peer sr-only"
|
2022-08-05 11:13:27 +00:00
|
|
|
id="whitelistRadio1"
|
|
|
|
name="whitelistRadioOptions1"
|
|
|
|
onClick={() => {
|
|
|
|
setWhitelistState('none')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="None"
|
|
|
|
/>
|
2022-09-13 05:19:04 +00:00
|
|
|
<label
|
2022-09-19 08:14:30 +00:00
|
|
|
className="inline-block py-1 px-2 text-gray peer-checked:text-white hover:text-white peer-checked:bg-black hover:rounded-sm peer-checked:border-b-2 hover:border-b-2 peer-checked:border-plumbus hover:border-plumbus cursor-pointer form-check-label"
|
2022-09-13 05:19:04 +00:00
|
|
|
htmlFor="whitelistRadio1"
|
|
|
|
>
|
2022-08-05 11:13:27 +00:00
|
|
|
No whitelist
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={whitelistState === 'existing'}
|
2022-09-13 05:19:04 +00:00
|
|
|
className="peer sr-only"
|
2022-08-05 11:13:27 +00:00
|
|
|
id="whitelistRadio2"
|
|
|
|
name="whitelistRadioOptions2"
|
|
|
|
onClick={() => {
|
|
|
|
setWhitelistState('existing')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="Existing"
|
|
|
|
/>
|
2022-09-13 05:19:04 +00:00
|
|
|
<label
|
2022-09-19 08:14:30 +00:00
|
|
|
className="inline-block py-1 px-2 text-gray peer-checked:text-white hover:text-white peer-checked:bg-black hover:rounded-sm peer-checked:border-b-2 hover:border-b-2 peer-checked:border-plumbus hover:border-plumbus cursor-pointer form-check-label"
|
2022-09-13 05:19:04 +00:00
|
|
|
htmlFor="whitelistRadio2"
|
|
|
|
>
|
2022-08-05 11:13:27 +00:00
|
|
|
Existing whitelist
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={whitelistState === 'new'}
|
2022-09-13 05:19:04 +00:00
|
|
|
className="peer sr-only"
|
2022-08-05 11:13:27 +00:00
|
|
|
id="whitelistRadio3"
|
|
|
|
name="whitelistRadioOptions3"
|
|
|
|
onClick={() => {
|
|
|
|
setWhitelistState('new')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="New"
|
|
|
|
/>
|
2022-09-13 05:19:04 +00:00
|
|
|
<label
|
2022-09-19 08:14:30 +00:00
|
|
|
className="inline-block py-1 px-2 text-gray peer-checked:text-white hover:text-white peer-checked:bg-black hover:rounded-sm peer-checked:border-b-2 hover:border-b-2 peer-checked:border-plumbus hover:border-plumbus cursor-pointer form-check-label"
|
2022-09-13 05:19:04 +00:00
|
|
|
htmlFor="whitelistRadio3"
|
|
|
|
>
|
2022-08-05 11:13:27 +00:00
|
|
|
New whitelist
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Conditional test={whitelistState === 'existing'}>
|
2022-09-01 06:27:23 +00:00
|
|
|
<AddressInput {...whitelistAddressState} className="pb-5" isRequired />
|
2022-08-05 11:13:27 +00:00
|
|
|
</Conditional>
|
|
|
|
|
|
|
|
<Conditional test={whitelistState === 'new'}>
|
|
|
|
<div className="grid grid-cols-2">
|
|
|
|
<FormGroup subtitle="Information about your minting settings" title="Whitelist Minting Details">
|
2022-11-04 11:53:11 +00:00
|
|
|
<NumberInput isRequired {...unitPriceState} />
|
2022-08-05 11:13:27 +00:00
|
|
|
<NumberInput isRequired {...memberLimitState} />
|
|
|
|
<NumberInput isRequired {...perAddressLimitState} />
|
2022-09-01 06:27:23 +00:00
|
|
|
<FormControl
|
|
|
|
htmlId="start-date"
|
|
|
|
isRequired
|
|
|
|
subtitle="Start time for minting tokens to whitelisted addresses"
|
|
|
|
title="Start Time"
|
|
|
|
>
|
2022-08-05 11:13:27 +00:00
|
|
|
<InputDateTime minDate={new Date()} onChange={(date) => setStartDate(date)} value={startDate} />
|
|
|
|
</FormControl>
|
2022-09-01 06:27:23 +00:00
|
|
|
<FormControl
|
|
|
|
htmlId="end-date"
|
|
|
|
isRequired
|
|
|
|
subtitle="End time for minting tokens to whitelisted addresses"
|
|
|
|
title="End Time"
|
|
|
|
>
|
2022-08-05 11:13:27 +00:00
|
|
|
<InputDateTime minDate={new Date()} onChange={(date) => setEndDate(date)} value={endDate} />
|
|
|
|
</FormControl>
|
|
|
|
</FormGroup>
|
|
|
|
<div>
|
2023-03-18 08:18:34 +00:00
|
|
|
<div className="mt-2 ml-3 w-[65%] form-control">
|
2023-03-08 20:53:12 +00:00
|
|
|
<label className="justify-start cursor-pointer label">
|
|
|
|
<span className="mr-4 font-bold">Mutable Administrator Addresses</span>
|
|
|
|
<input
|
|
|
|
checked={adminsMutable}
|
|
|
|
className={`toggle ${adminsMutable ? `bg-stargaze` : `bg-gray-600`}`}
|
|
|
|
onClick={() => setAdminsMutable(!adminsMutable)}
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="my-4 ml-4">
|
|
|
|
<AddressList
|
|
|
|
entries={addressListState.entries}
|
|
|
|
isRequired
|
|
|
|
onAdd={addressListState.add}
|
|
|
|
onChange={addressListState.update}
|
|
|
|
onRemove={addressListState.remove}
|
|
|
|
subtitle="The list of administrator addresses"
|
|
|
|
title="Administrator Addresses"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-08-05 11:13:27 +00:00
|
|
|
<FormGroup subtitle="TXT file that contains the whitelisted addresses" title="Whitelist File">
|
|
|
|
<WhitelistUpload onChange={whitelistFileOnChange} />
|
|
|
|
</FormGroup>
|
|
|
|
<Conditional test={whitelistArray.length > 0}>
|
|
|
|
<JsonPreview content={whitelistArray} initialState title="File Contents" />
|
|
|
|
</Conditional>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Conditional>
|
2022-08-04 09:16:42 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|