Clean up whitelist file contents prior to collection creation
This commit is contained in:
parent
a29cd50886
commit
2579e449be
@ -2,6 +2,8 @@ import clsx from 'clsx'
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { toast } from 'react-hot-toast'
|
import { toast } from 'react-hot-toast'
|
||||||
|
|
||||||
|
import { isValidAddress } from '../utils/isValidAddress'
|
||||||
|
|
||||||
interface WhitelistUploadProps {
|
interface WhitelistUploadProps {
|
||||||
onChange: (data: string[]) => void
|
onChange: (data: string[]) => void
|
||||||
}
|
}
|
||||||
@ -9,16 +11,30 @@ interface WhitelistUploadProps {
|
|||||||
export const WhitelistUpload = ({ onChange }: WhitelistUploadProps) => {
|
export const WhitelistUpload = ({ onChange }: WhitelistUploadProps) => {
|
||||||
const onFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const onFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (!event.target.files) return toast.error('Error opening file')
|
if (!event.target.files) return toast.error('Error opening file')
|
||||||
if (event.target.files[0].type !== 'text/plain') return toast.error('Invalid file type')
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||||
|
if (event.target.files[0]?.type !== 'text/plain') {
|
||||||
|
toast.error('Invalid file type')
|
||||||
|
return onChange([])
|
||||||
|
}
|
||||||
|
if (event.target.files.length === 0) {
|
||||||
|
toast.error('No file selected')
|
||||||
|
return onChange([])
|
||||||
|
}
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = (e: ProgressEvent<FileReader>) => {
|
reader.onload = (e: ProgressEvent<FileReader>) => {
|
||||||
const text = e.target?.result?.toString()
|
const text = e.target?.result?.toString()
|
||||||
let newline = '\n'
|
let newline = '\n'
|
||||||
if (text?.includes('\r')) newline = '\r'
|
if (text?.includes('\r')) newline = '\r'
|
||||||
if (text?.includes('\r\n')) newline = '\r\n'
|
if (text?.includes('\r\n')) newline = '\r\n'
|
||||||
const data = text?.split(newline)
|
|
||||||
|
|
||||||
return onChange([...new Set(data?.filter((address) => address !== '') || [])])
|
const cleanText = text?.toLowerCase().replace(/,/g, '').replace(/"/g, '').replace(/'/g, '').replace(/ /g, '')
|
||||||
|
const data = cleanText?.split(newline)
|
||||||
|
|
||||||
|
return onChange([
|
||||||
|
...new Set(
|
||||||
|
data?.filter((address) => address !== '' && isValidAddress(address) && address.startsWith('stars')) || [],
|
||||||
|
),
|
||||||
|
])
|
||||||
}
|
}
|
||||||
reader.readAsText(event.target.files[0])
|
reader.readAsText(event.target.files[0])
|
||||||
}
|
}
|
||||||
@ -37,7 +53,7 @@ export const WhitelistUpload = ({ onChange }: WhitelistUploadProps) => {
|
|||||||
'before:absolute before:inset-0 before:hover:bg-white/5 before:transition',
|
'before:absolute before:inset-0 before:hover:bg-white/5 before:transition',
|
||||||
)}
|
)}
|
||||||
id="whitelist-file"
|
id="whitelist-file"
|
||||||
multiple
|
multiple={false}
|
||||||
onChange={onFileChange}
|
onChange={onFileChange}
|
||||||
type="file"
|
type="file"
|
||||||
/>
|
/>
|
||||||
|
@ -39,7 +39,7 @@ export const WhitelistDetails = ({ onChange }: WhitelistDetailsProps) => {
|
|||||||
defaultValue: '',
|
defaultValue: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
const uniPriceState = useNumberInputState({
|
const unitPriceState = useNumberInputState({
|
||||||
id: 'unit-price',
|
id: 'unit-price',
|
||||||
name: 'unitPrice',
|
name: 'unitPrice',
|
||||||
title: 'Unit Price',
|
title: 'Unit Price',
|
||||||
@ -72,7 +72,7 @@ export const WhitelistDetails = ({ onChange }: WhitelistDetailsProps) => {
|
|||||||
whitelistType: whitelistState,
|
whitelistType: whitelistState,
|
||||||
contractAddress: whitelistAddressState.value,
|
contractAddress: whitelistAddressState.value,
|
||||||
members: whitelistArray,
|
members: whitelistArray,
|
||||||
unitPrice: uniPriceState.value ? (Number(uniPriceState.value) * 1_000_000).toString() : '',
|
unitPrice: unitPriceState.value ? (Number(unitPriceState.value) * 1_000_000).toString() : '',
|
||||||
startTime: startDate ? (startDate.getTime() * 1_000_000).toString() : '',
|
startTime: startDate ? (startDate.getTime() * 1_000_000).toString() : '',
|
||||||
endTime: endDate ? (endDate.getTime() * 1_000_000).toString() : '',
|
endTime: endDate ? (endDate.getTime() * 1_000_000).toString() : '',
|
||||||
perAddressLimit: perAddressLimitState.value,
|
perAddressLimit: perAddressLimitState.value,
|
||||||
@ -82,7 +82,7 @@ export const WhitelistDetails = ({ onChange }: WhitelistDetailsProps) => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [
|
}, [
|
||||||
whitelistAddressState.value,
|
whitelistAddressState.value,
|
||||||
uniPriceState.value,
|
unitPriceState.value,
|
||||||
memberLimitState.value,
|
memberLimitState.value,
|
||||||
perAddressLimitState.value,
|
perAddressLimitState.value,
|
||||||
startDate,
|
startDate,
|
||||||
@ -160,7 +160,7 @@ export const WhitelistDetails = ({ onChange }: WhitelistDetailsProps) => {
|
|||||||
<Conditional test={whitelistState === 'new'}>
|
<Conditional test={whitelistState === 'new'}>
|
||||||
<div className="grid grid-cols-2">
|
<div className="grid grid-cols-2">
|
||||||
<FormGroup subtitle="Information about your minting settings" title="Whitelist Minting Details">
|
<FormGroup subtitle="Information about your minting settings" title="Whitelist Minting Details">
|
||||||
<NumberInput isRequired {...uniPriceState} />
|
<NumberInput isRequired {...unitPriceState} />
|
||||||
<NumberInput isRequired {...memberLimitState} />
|
<NumberInput isRequired {...memberLimitState} />
|
||||||
<NumberInput isRequired {...perAddressLimitState} />
|
<NumberInput isRequired {...perAddressLimitState} />
|
||||||
<FormControl
|
<FormControl
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "stargaze-studio",
|
"name": "stargaze-studio",
|
||||||
"version": "0.2.4",
|
"version": "0.2.5",
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user