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_FLEX_CODE_ID,
} from 'utils/constants'
import { checkTokenUri } from 'utils/isValidTokenUri'
import { withMetadata } from 'utils/layout'
import { links } from 'utils/links'
import { uid } from 'utils/random'
@ -176,6 +177,8 @@ const CollectionCreationPage: NextPage = () => {
setReadyToCreateBm(false)
checkUploadDetails()
checkCollectionDetails()
void checkExistingTokenURI()
.then(() => {
void checkRoyaltyDetails()
.then(() => {
checkWhitelistDetails()
@ -194,6 +197,12 @@ const CollectionCreationPage: NextPage = () => {
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateBm(false)
})
})
.catch((error) => {
toast.error(`Error in Existing Token URI: ${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToCreateBm(false)
})
} catch (error: any) {
toast.error(error.message, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
@ -205,6 +214,8 @@ const CollectionCreationPage: NextPage = () => {
try {
setReadyToUploadAndMint(false)
checkUploadDetails()
checkExistingTokenURI()
.then(() => {
checkWhitelistDetails()
.then(() => {
setReadyToUploadAndMint(true)
@ -214,6 +225,12 @@ const CollectionCreationPage: NextPage = () => {
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToUploadAndMint(false)
})
})
.catch((error) => {
toast.error(`Error in Token URI: ${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
setReadyToUploadAndMint(false)
})
} catch (error: any) {
toast.error(error.message, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
@ -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 = () => {
if (!collectionDetails) throw new Error('Please fill out the collection details')
if (collectionDetails.name === '') throw new Error('Collection name is required')