Update checks for minimum mint price on Collection Creation

This commit is contained in:
Serkan Reis 2023-04-07 12:24:38 +03:00
parent ec28295278
commit 3471aeb653
2 changed files with 19 additions and 4 deletions

View File

@ -13,6 +13,7 @@ interface MintingDetailsProps {
onChange: (data: MintingDetailsDataProps) => void onChange: (data: MintingDetailsDataProps) => void
numberOfTokens: number | undefined numberOfTokens: number | undefined
uploadMethod: UploadMethod uploadMethod: UploadMethod
minimumMintPrice: number
} }
export interface MintingDetailsDataProps { export interface MintingDetailsDataProps {
@ -23,7 +24,7 @@ export interface MintingDetailsDataProps {
paymentAddress?: string paymentAddress?: string
} }
export const MintingDetails = ({ onChange, numberOfTokens, uploadMethod }: MintingDetailsProps) => { export const MintingDetails = ({ onChange, numberOfTokens, uploadMethod, minimumMintPrice }: MintingDetailsProps) => {
const wallet = useWallet() const wallet = useWallet()
const [timestamp, setTimestamp] = useState<Date | undefined>() const [timestamp, setTimestamp] = useState<Date | undefined>()
@ -40,7 +41,7 @@ export const MintingDetails = ({ onChange, numberOfTokens, uploadMethod }: Minti
id: 'unitPrice', id: 'unitPrice',
name: 'unitPrice', name: 'unitPrice',
title: 'Unit Price', title: 'Unit Price',
subtitle: 'Price of each token (min. 50 STARS)', subtitle: `Price of each token (min. ${minimumMintPrice} STARS)`,
placeholder: '50', placeholder: '50',
}) })

View File

@ -94,6 +94,8 @@ const CollectionCreationPage: NextPage = () => {
const [baseMinterCreationFee, setBaseMinterCreationFee] = useState<string | null>(null) const [baseMinterCreationFee, setBaseMinterCreationFee] = useState<string | null>(null)
const [vendingMinterUpdatableCreationFee, setVendingMinterUpdatableCreationFee] = useState<string | null>(null) const [vendingMinterUpdatableCreationFee, setVendingMinterUpdatableCreationFee] = useState<string | null>(null)
const [baseMinterUpdatableCreationFee, setBaseMinterUpdatableCreationFee] = useState<string | null>(null) const [baseMinterUpdatableCreationFee, setBaseMinterUpdatableCreationFee] = useState<string | null>(null)
const [minimumMintPrice, setMinimumMintPrice] = useState<string | null>('0')
const [minimumUpdatableMintPrice, setMinimumUpdatableMintPrice] = useState<string | null>('0')
const [uploading, setUploading] = useState(false) const [uploading, setUploading] = useState(false)
const [isMintingComplete, setIsMintingComplete] = useState(false) const [isMintingComplete, setIsMintingComplete] = useState(false)
@ -784,8 +786,13 @@ const CollectionCreationPage: NextPage = () => {
const checkMintingDetails = () => { const checkMintingDetails = () => {
if (!mintingDetails) throw new Error('Please fill out the minting details') if (!mintingDetails) throw new Error('Please fill out the minting details')
if (mintingDetails.numTokens < 1 || mintingDetails.numTokens > 10000) throw new Error('Invalid number of tokens') if (mintingDetails.numTokens < 1 || mintingDetails.numTokens > 10000) throw new Error('Invalid number of tokens')
if (Number(mintingDetails.unitPrice) < 50000000) if (collectionDetails?.updatable) {
throw new Error('Invalid unit price: The minimum unit price is 50 STARS') if (Number(mintingDetails.unitPrice) < Number(minimumUpdatableMintPrice))
throw new Error(
`Invalid unit price: The minimum unit price is ${Number(minimumUpdatableMintPrice) / 1000000} STARS`,
)
} else if (Number(mintingDetails.unitPrice) < Number(minimumMintPrice))
throw new Error(`Invalid unit price: The minimum unit price is ${Number(minimumMintPrice) / 1000000} STARS`)
if ( if (
!mintingDetails.perAddressLimit || !mintingDetails.perAddressLimit ||
mintingDetails.perAddressLimit < 1 || mintingDetails.perAddressLimit < 1 ||
@ -929,12 +936,14 @@ const CollectionCreationPage: NextPage = () => {
if (VENDING_FACTORY_ADDRESS) { if (VENDING_FACTORY_ADDRESS) {
const vendingFactoryParameters = await client.queryContractSmart(VENDING_FACTORY_ADDRESS, { params: {} }) const vendingFactoryParameters = await client.queryContractSmart(VENDING_FACTORY_ADDRESS, { params: {} })
setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount) setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount)
setMinimumMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount)
} }
if (VENDING_FACTORY_UPDATABLE_ADDRESS) { if (VENDING_FACTORY_UPDATABLE_ADDRESS) {
const vendingFactoryUpdatableParameters = await client.queryContractSmart(VENDING_FACTORY_UPDATABLE_ADDRESS, { const vendingFactoryUpdatableParameters = await client.queryContractSmart(VENDING_FACTORY_UPDATABLE_ADDRESS, {
params: {}, params: {},
}) })
setVendingMinterUpdatableCreationFee(vendingFactoryUpdatableParameters?.params?.creation_fee?.amount) setVendingMinterUpdatableCreationFee(vendingFactoryUpdatableParameters?.params?.creation_fee?.amount)
setMinimumUpdatableMintPrice(vendingFactoryUpdatableParameters?.params?.min_mint_price?.amount)
} }
} }
@ -1285,6 +1294,11 @@ const CollectionCreationPage: NextPage = () => {
</Conditional> </Conditional>
<Conditional test={minterType === 'vending'}> <Conditional test={minterType === 'vending'}>
<MintingDetails <MintingDetails
minimumMintPrice={
collectionDetails?.updatable
? Number(minimumUpdatableMintPrice) / 1000000
: Number(minimumMintPrice) / 1000000
}
numberOfTokens={uploadDetails?.assetFiles.length} numberOfTokens={uploadDetails?.assetFiles.length}
onChange={setMintingDetails} onChange={setMintingDetails}
uploadMethod={uploadDetails?.uploadMethod as UploadMethod} uploadMethod={uploadDetails?.uploadMethod as UploadMethod}