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,6 +177,8 @@ const CollectionCreationPage: NextPage = () => {
setReadyToCreateBm(false) setReadyToCreateBm(false)
checkUploadDetails() checkUploadDetails()
checkCollectionDetails() checkCollectionDetails()
void checkExistingTokenURI()
.then(() => {
void checkRoyaltyDetails() void checkRoyaltyDetails()
.then(() => { .then(() => {
checkWhitelistDetails() checkWhitelistDetails()
@ -194,6 +197,12 @@ const CollectionCreationPage: NextPage = () => {
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) => {
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) { } catch (error: any) {
toast.error(error.message, { style: { maxWidth: 'none' } }) toast.error(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() })
@ -205,6 +214,8 @@ const CollectionCreationPage: NextPage = () => {
try { try {
setReadyToUploadAndMint(false) setReadyToUploadAndMint(false)
checkUploadDetails() checkUploadDetails()
checkExistingTokenURI()
.then(() => {
checkWhitelistDetails() checkWhitelistDetails()
.then(() => { .then(() => {
setReadyToUploadAndMint(true) setReadyToUploadAndMint(true)
@ -214,6 +225,12 @@ const CollectionCreationPage: NextPage = () => {
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)
}) })
})
.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) { } catch (error: any) {
toast.error(error.message, { style: { maxWidth: 'none' } }) toast.error(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() })
@ -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')