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 [metadataFileArrayIndex, setMetadataFileArrayIndex] = useState(0)
|
||||||
const [refreshMetadata, setRefreshMetadata] = useState(false)
|
const [refreshMetadata, setRefreshMetadata] = useState(false)
|
||||||
|
|
||||||
//let baseMinterMetadataFile: File | undefined
|
|
||||||
const [baseMinterMetadataFile, setBaseMinterMetadataFile] = useState<File | undefined>()
|
const [baseMinterMetadataFile, setBaseMinterMetadataFile] = useState<File | undefined>()
|
||||||
|
|
||||||
const assetFilesRef = useRef<HTMLInputElement | null>(null)
|
const assetFilesRef = useRef<HTMLInputElement | null>(null)
|
||||||
@ -138,11 +137,14 @@ export const UploadDetails = ({ onChange, minterType, baseMinterAcquisitionMetho
|
|||||||
const selectMetadata = (event: ChangeEvent<HTMLInputElement>) => {
|
const selectMetadata = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
setMetadataFilesArray([])
|
setMetadataFilesArray([])
|
||||||
if (event.target.files === null) return toast.error('No files selected.')
|
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 = ''
|
event.target.value = ''
|
||||||
return toast.error('The number of metadata files should be equal to the number of asset files.')
|
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
|
//sort the files
|
||||||
const sortedFiles = Array.from(event.target.files).sort((a, b) => naturalCompare(a.name, b.name))
|
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
|
//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++) {
|
for (let i = 0; i < sortedFileNames.length; i++) {
|
||||||
if (isNaN(Number(sortedFileNames[i])) || parseInt(sortedFileNames[i]) !== i + 1) {
|
if (isNaN(Number(sortedFileNames[i])) || parseInt(sortedFileNames[i]) !== i + 1) {
|
||||||
toast.error('The file names should be in numerical order starting from 1.')
|
toast.error('The file names should be in numerical order starting from 1.')
|
||||||
//clear the input
|
|
||||||
event.target.value = ''
|
event.target.value = ''
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ export const baseMinter = (client: SigningCosmWasmClient, txSigner: string): Bas
|
|||||||
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
||||||
for (let i = 0; i < batchCount; i++) {
|
for (let i = 0; i < batchCount; i++) {
|
||||||
const msg = {
|
const msg = {
|
||||||
mint: { token_uri: `${baseUri}/${i}` },
|
mint: { token_uri: `${baseUri}/${i + 1}` },
|
||||||
}
|
}
|
||||||
const executeContractMsg: MsgExecuteContractEncodeObject = {
|
const executeContractMsg: MsgExecuteContractEncodeObject = {
|
||||||
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
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 batchMint = (baseUri: string, batchCount: number): CustomMessage => {
|
||||||
const msg: Record<string, unknown>[] = []
|
const msg: Record<string, unknown>[] = []
|
||||||
for (let i = 0; i < batchCount; i++) {
|
for (let i = 0; i < batchCount; i++) {
|
||||||
msg.push({ mint: { token_uri: `${baseUri}/${i}` } })
|
msg.push({ mint: { token_uri: `${baseUri}/${i + 1}` } })
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
sender: txSigner,
|
sender: txSigner,
|
||||||
|
@ -244,15 +244,18 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
setUploading(false)
|
setUploading(false)
|
||||||
|
if (uploadDetails.assetFiles.length === 1) {
|
||||||
setBaseTokenUri(
|
setBaseTokenUri(
|
||||||
`${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
`${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
||||||
0,
|
0,
|
||||||
(uploadDetails.baseMinterMetadataFile as File).name.lastIndexOf('.'),
|
(uploadDetails.baseMinterMetadataFile as File).name.lastIndexOf('.'),
|
||||||
)}`,
|
)}`,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
setBaseTokenUri(baseUri)
|
||||||
|
}
|
||||||
setCoverImageUrl(coverImageUri)
|
setCoverImageUrl(coverImageUri)
|
||||||
|
if (uploadDetails.assetFiles.length === 1) {
|
||||||
await instantiateBaseMinter(
|
await instantiateBaseMinter(
|
||||||
`ipfs://${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
`ipfs://${baseUri}/${(uploadDetails.baseMinterMetadataFile as File).name.substring(
|
||||||
0,
|
0,
|
||||||
@ -260,6 +263,9 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
)}`,
|
)}`,
|
||||||
coverImageUri,
|
coverImageUri,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
await instantiateBaseMinter(`ipfs://${baseUri}`, coverImageUri)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setBaseTokenUri(uploadDetails?.baseTokenURI as string)
|
setBaseTokenUri(uploadDetails?.baseTokenURI as string)
|
||||||
setCoverImageUrl(uploadDetails?.imageUrl as string)
|
setCoverImageUrl(uploadDetails?.imageUrl as string)
|
||||||
@ -482,12 +488,10 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
setTransactionHash(data.transactionHash)
|
setTransactionHash(data.transactionHash)
|
||||||
setVendingMinterContractAddress(data.baseMinterAddress)
|
setVendingMinterContractAddress(data.baseMinterAddress)
|
||||||
setSg721ContractAddress(data.sg721Address)
|
setSg721ContractAddress(data.sg721Address)
|
||||||
|
if (uploadDetails?.assetFiles.length === 1) {
|
||||||
await toast
|
await toast
|
||||||
.promise(
|
.promise(
|
||||||
baseMinterContract
|
baseMinterContract.use(data.baseMinterAddress)?.mint(wallet.address, baseUri) as Promise<string>,
|
||||||
.use(data.baseMinterAddress)
|
|
||||||
|
|
||||||
?.mint(wallet.address, baseUri) as Promise<string>,
|
|
||||||
{
|
{
|
||||||
loading: 'Minting token...',
|
loading: 'Minting token...',
|
||||||
success: (result) => {
|
success: (result) => {
|
||||||
@ -504,6 +508,31 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
setIsMintingComplete(false)
|
setIsMintingComplete(false)
|
||||||
setCreatingCollection(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)
|
setUploading(false)
|
||||||
setCreatingCollection(false)
|
setCreatingCollection(false)
|
||||||
})
|
})
|
||||||
@ -526,7 +555,7 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
uploadDetails.pinataSecretKey as string,
|
uploadDetails.pinataSecretKey as string,
|
||||||
)
|
)
|
||||||
.then((assetUri: string) => {
|
.then((assetUri: string) => {
|
||||||
if (minterType === 'vending') {
|
if (minterType === 'vending' || (minterType === 'base' && uploadDetails.assetFiles.length > 1)) {
|
||||||
const fileArray: File[] = []
|
const fileArray: File[] = []
|
||||||
let reader: FileReader
|
let reader: FileReader
|
||||||
|
|
||||||
@ -577,7 +606,7 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
}
|
}
|
||||||
reader.readAsText(uploadDetails.metadataFiles[i], 'utf8')
|
reader.readAsText(uploadDetails.metadataFiles[i], 'utf8')
|
||||||
}
|
}
|
||||||
} else if (minterType === 'base') {
|
} else if (minterType === 'base' && uploadDetails.assetFiles.length === 1) {
|
||||||
const fileArray: File[] = []
|
const fileArray: File[] = []
|
||||||
const reader: FileReader = new FileReader()
|
const reader: FileReader = new FileReader()
|
||||||
|
|
||||||
@ -636,9 +665,9 @@ const CollectionCreationPage: NextPage = () => {
|
|||||||
if (!uploadDetails) {
|
if (!uploadDetails) {
|
||||||
throw new Error('Please select assets and metadata')
|
throw new Error('Please select assets and metadata')
|
||||||
}
|
}
|
||||||
if (minterType === 'base' && uploadDetails.uploadMethod === 'new' && uploadDetails.assetFiles.length > 1) {
|
// 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.')
|
// 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) {
|
if (uploadDetails.uploadMethod === 'new' && uploadDetails.assetFiles.length === 0) {
|
||||||
throw new Error('Please select the assets')
|
throw new Error('Please select the assets')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user