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,21 +177,29 @@ const CollectionCreationPage: NextPage = () => {
setReadyToCreateBm(false)
checkUploadDetails()
checkCollectionDetails()
void checkRoyaltyDetails()
void checkExistingTokenURI()
.then(() => {
checkWhitelistDetails()
void checkRoyaltyDetails()
.then(() => {
checkwalletBalance()
setReadyToCreateBm(true)
checkWhitelistDetails()
.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) => {
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() })
setReadyToCreateBm(false)
})
})
.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() })
setReadyToCreateBm(false)
})
@ -205,12 +214,20 @@ const CollectionCreationPage: NextPage = () => {
try {
setReadyToUploadAndMint(false)
checkUploadDetails()
checkWhitelistDetails()
checkExistingTokenURI()
.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) => {
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() })
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 = () => {
if (!collectionDetails) throw new Error('Please fill out the collection details')
if (collectionDetails.name === '') throw new Error('Collection name is required')