Implement batch minting for 1/1 Collection Creation
This commit is contained in:
parent
3821e89c53
commit
5ff7f6f649
@ -51,7 +51,6 @@ export const UploadDetails = ({ onChange, minterType, baseMinterAcquisitionMetho
|
||||
const [metadataFileArrayIndex, setMetadataFileArrayIndex] = useState(0)
|
||||
const [refreshMetadata, setRefreshMetadata] = useState(false)
|
||||
|
||||
//let baseMinterMetadataFile: File | undefined
|
||||
const [baseMinterMetadataFile, setBaseMinterMetadataFile] = useState<File | undefined>()
|
||||
|
||||
const assetFilesRef = useRef<HTMLInputElement | null>(null)
|
||||
@ -138,11 +137,14 @@ export const UploadDetails = ({ onChange, minterType, baseMinterAcquisitionMetho
|
||||
const selectMetadata = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
setMetadataFilesArray([])
|
||||
if (event.target.files === null) return toast.error('No files selected.')
|
||||
if (minterType === 'vending' && event.target.files.length !== assetFilesArray.length) {
|
||||
if (
|
||||
(minterType === 'vending' || (minterType === 'base' && assetFilesArray.length > 1)) &&
|
||||
event.target.files.length !== assetFilesArray.length
|
||||
) {
|
||||
event.target.value = ''
|
||||
return toast.error('The number of metadata files should be equal to the number of asset files.')
|
||||
}
|
||||
if (minterType === 'vending') {
|
||||
if (minterType === 'vending' || (minterType === 'base' && assetFilesArray.length > 1)) {
|
||||
//sort the files
|
||||
const sortedFiles = Array.from(event.target.files).sort((a, b) => naturalCompare(a.name, b.name))
|
||||
//check if the sorted file names are in numerical order
|
||||
@ -150,7 +152,6 @@ export const UploadDetails = ({ onChange, minterType, baseMinterAcquisitionMetho
|
||||
for (let i = 0; i < sortedFileNames.length; i++) {
|
||||
if (isNaN(Number(sortedFileNames[i])) || parseInt(sortedFileNames[i]) !== i + 1) {
|
||||
toast.error('The file names should be in numerical order starting from 1.')
|
||||
//clear the input
|
||||
event.target.value = ''
|
||||
return
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ export const baseMinter = (client: SigningCosmWasmClient, txSigner: string): Bas
|
||||
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
||||
for (let i = 0; i < batchCount; i++) {
|
||||
const msg = {
|
||||
mint: { token_uri: `${baseUri}/${i}` },
|
||||
mint: { token_uri: `${baseUri}/${i + 1}` },
|
||||
}
|
||||
const executeContractMsg: MsgExecuteContractEncodeObject = {
|
||||
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
||||
@ -284,7 +284,7 @@ export const baseMinter = (client: SigningCosmWasmClient, txSigner: string): Bas
|
||||
const batchMint = (baseUri: string, batchCount: number): CustomMessage => {
|
||||
const msg: Record<string, unknown>[] = []
|
||||
for (let i = 0; i < batchCount; i++) {
|
||||
msg.push({ mint: { token_uri: `${baseUri}/${i}` } })
|
||||
msg.push({ mint: { token_uri: `${baseUri}/${i + 1}` } })
|
||||
}
|
||||
return {
|
||||
sender: txSigner,
|
||||
|
@ -244,22 +244,28 @@ const CollectionCreationPage: NextPage = () => {
|
||||
)
|
||||
|
||||
setUploading(false)
|
||||
|
||||
setBaseTokenUri(
|
||||
`${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
||||
0,
|
||||
(uploadDetails.baseMinterMetadataFile as File).name.lastIndexOf('.'),
|
||||
)}`,
|
||||
)
|
||||
if (uploadDetails.assetFiles.length === 1) {
|
||||
setBaseTokenUri(
|
||||
`${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
||||
0,
|
||||
(uploadDetails.baseMinterMetadataFile as File).name.lastIndexOf('.'),
|
||||
)}`,
|
||||
)
|
||||
} else {
|
||||
setBaseTokenUri(baseUri)
|
||||
}
|
||||
setCoverImageUrl(coverImageUri)
|
||||
|
||||
await instantiateBaseMinter(
|
||||
`ipfs://${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
||||
0,
|
||||
(uploadDetails.baseMinterMetadataFile as File).name.lastIndexOf('.'),
|
||||
)}`,
|
||||
coverImageUri,
|
||||
)
|
||||
if (uploadDetails.assetFiles.length === 1) {
|
||||
await instantiateBaseMinter(
|
||||
`ipfs://${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
||||
0,
|
||||
(uploadDetails.baseMinterMetadataFile as File).name.lastIndexOf('.'),
|
||||
)}`,
|
||||
coverImageUri,
|
||||
)
|
||||
} else {
|
||||
await instantiateBaseMinter(`ipfs://${baseUri}`, coverImageUri)
|
||||
}
|
||||
} else {
|
||||
setBaseTokenUri(uploadDetails?.baseTokenURI as string)
|
||||
setCoverImageUrl(uploadDetails?.imageUrl as string)
|
||||
@ -482,28 +488,51 @@ const CollectionCreationPage: NextPage = () => {
|
||||
setTransactionHash(data.transactionHash)
|
||||
setVendingMinterContractAddress(data.baseMinterAddress)
|
||||
setSg721ContractAddress(data.sg721Address)
|
||||
await toast
|
||||
.promise(
|
||||
baseMinterContract
|
||||
.use(data.baseMinterAddress)
|
||||
|
||||
?.mint(wallet.address, baseUri) as Promise<string>,
|
||||
{
|
||||
loading: 'Minting token...',
|
||||
success: (result) => {
|
||||
setIsMintingComplete(true)
|
||||
return `Token minted successfully! Tx Hash: ${result}`
|
||||
if (uploadDetails?.assetFiles.length === 1) {
|
||||
await toast
|
||||
.promise(
|
||||
baseMinterContract.use(data.baseMinterAddress)?.mint(wallet.address, baseUri) as Promise<string>,
|
||||
{
|
||||
loading: 'Minting token...',
|
||||
success: (result) => {
|
||||
setIsMintingComplete(true)
|
||||
return `Token minted successfully! Tx Hash: ${result}`
|
||||
},
|
||||
error: (error) => `Failed to mint token: ${error.message}`,
|
||||
},
|
||||
error: (error) => `Failed to mint token: ${error.message}`,
|
||||
},
|
||||
{ style: { maxWidth: 'none' } },
|
||||
)
|
||||
.catch((error) => {
|
||||
toast.error(error.message, { style: { maxWidth: 'none' } })
|
||||
setUploading(false)
|
||||
setIsMintingComplete(false)
|
||||
setCreatingCollection(false)
|
||||
})
|
||||
{ style: { maxWidth: 'none' } },
|
||||
)
|
||||
.catch((error) => {
|
||||
toast.error(error.message, { style: { maxWidth: 'none' } })
|
||||
setUploading(false)
|
||||
setIsMintingComplete(false)
|
||||
setCreatingCollection(false)
|
||||
})
|
||||
} else {
|
||||
console.log('Here')
|
||||
console.log(data.baseMinterAddress)
|
||||
await toast
|
||||
.promise(
|
||||
baseMinterContract
|
||||
.use(data.baseMinterAddress)
|
||||
?.batchMint(wallet.address, baseUri, uploadDetails?.assetFiles.length as number) as Promise<string>,
|
||||
{
|
||||
loading: 'Minting tokens...',
|
||||
success: (result) => {
|
||||
setIsMintingComplete(true)
|
||||
return `Tokens minted successfully! Tx Hash: ${result}`
|
||||
},
|
||||
error: (error) => `Failed to mint tokens: ${error.message}`,
|
||||
},
|
||||
{ style: { maxWidth: 'none' } },
|
||||
)
|
||||
.catch((error) => {
|
||||
toast.error(error.message, { style: { maxWidth: 'none' } })
|
||||
setUploading(false)
|
||||
setIsMintingComplete(false)
|
||||
setCreatingCollection(false)
|
||||
})
|
||||
}
|
||||
setUploading(false)
|
||||
setCreatingCollection(false)
|
||||
})
|
||||
@ -526,7 +555,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
uploadDetails.pinataSecretKey as string,
|
||||
)
|
||||
.then((assetUri: string) => {
|
||||
if (minterType === 'vending') {
|
||||
if (minterType === 'vending' || (minterType === 'base' && uploadDetails.assetFiles.length > 1)) {
|
||||
const fileArray: File[] = []
|
||||
let reader: FileReader
|
||||
|
||||
@ -577,7 +606,7 @@ const CollectionCreationPage: NextPage = () => {
|
||||
}
|
||||
reader.readAsText(uploadDetails.metadataFiles[i], 'utf8')
|
||||
}
|
||||
} else if (minterType === 'base') {
|
||||
} else if (minterType === 'base' && uploadDetails.assetFiles.length === 1) {
|
||||
const fileArray: File[] = []
|
||||
const reader: FileReader = new FileReader()
|
||||
|
||||
@ -636,9 +665,9 @@ const CollectionCreationPage: NextPage = () => {
|
||||
if (!uploadDetails) {
|
||||
throw new Error('Please select assets and metadata')
|
||||
}
|
||||
if (minterType === 'base' && uploadDetails.uploadMethod === 'new' && uploadDetails.assetFiles.length > 1) {
|
||||
throw new Error('Base Minter can only mint one asset at a time. Please select only one asset.')
|
||||
}
|
||||
// if (minterType === 'base' && uploadDetails.uploadMethod === 'new' && uploadDetails.assetFiles.length > 1) {
|
||||
// throw new Error('Base Minter can only mint one asset at a time. Please select only one asset.')
|
||||
// }
|
||||
if (uploadDetails.uploadMethod === 'new' && uploadDetails.assetFiles.length === 0) {
|
||||
throw new Error('Please select the assets')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user