Add token URI validation for 1/1 collection creation & token addition

This commit is contained in:
Serkan Reis 2023-07-03 17:17:16 +03:00
parent 2b5c5f3c32
commit f9559bf7eb

View File

@ -63,6 +63,7 @@ import {
WHITELIST_CODE_ID, WHITELIST_CODE_ID,
WHITELIST_FLEX_CODE_ID, WHITELIST_FLEX_CODE_ID,
} from 'utils/constants' } from 'utils/constants'
import { checkTokenUri } from 'utils/isValidTokenUri'
import { withMetadata } from 'utils/layout' import { withMetadata } from 'utils/layout'
import { links } from 'utils/links' import { links } from 'utils/links'
import { uid } from 'utils/random' import { uid } from 'utils/random'
@ -176,21 +177,29 @@ const CollectionCreationPage: NextPage = () => {
setReadyToCreateBm(false) setReadyToCreateBm(false)
checkUploadDetails() checkUploadDetails()
checkCollectionDetails() checkCollectionDetails()
void checkRoyaltyDetails() void checkExistingTokenURI()
.then(() => { .then(() => {
checkWhitelistDetails() void checkRoyaltyDetails()
.then(() => { .then(() => {
checkwalletBalance() checkWhitelistDetails()
setReadyToCreateBm(true) .then(() => {
checkwalletBalance()
setReadyToCreateBm(true)
})
.catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateBm(false)
})
}) })
.catch((error) => { .catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`Error in Royalty Configuration: ${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateBm(false) setReadyToCreateBm(false)
}) })
}) })
.catch((error) => { .catch((error) => {
toast.error(`Error in Royalty Configuration: ${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`Error in Existing Token URI: ${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateBm(false) setReadyToCreateBm(false)
}) })
@ -205,12 +214,20 @@ const CollectionCreationPage: NextPage = () => {
try { try {
setReadyToUploadAndMint(false) setReadyToUploadAndMint(false)
checkUploadDetails() checkUploadDetails()
checkWhitelistDetails() checkExistingTokenURI()
.then(() => { .then(() => {
setReadyToUploadAndMint(true) checkWhitelistDetails()
.then(() => {
setReadyToUploadAndMint(true)
})
.catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToUploadAndMint(false)
})
}) })
.catch((error) => { .catch((error) => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`Error in Token URI: ${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToUploadAndMint(false) setReadyToUploadAndMint(false)
}) })
@ -818,6 +835,12 @@ const CollectionCreationPage: NextPage = () => {
} }
} }
const checkExistingTokenURI = async () => {
if (minterType === 'base' && uploadDetails && uploadDetails.uploadMethod === 'existing') {
await checkTokenUri(uploadDetails.baseTokenURI as string)
}
}
const checkCollectionDetails = () => { const checkCollectionDetails = () => {
if (!collectionDetails) throw new Error('Please fill out the collection details') if (!collectionDetails) throw new Error('Please fill out the collection details')
if (collectionDetails.name === '') throw new Error('Collection name is required') if (collectionDetails.name === '') throw new Error('Collection name is required')