Merge pull request #242 from public-awesome/develop

Sync dev > main
This commit is contained in:
Serkan Reis 2023-10-13 13:04:36 +03:00 committed by GitHub
commit d94ab200c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 95 additions and 10 deletions

View File

@ -119,7 +119,7 @@ export const UploadDetails = ({
if (event.target.files === null) return if (event.target.files === null) return
const thumbnailCompatibleAssetTypes: AssetType[] = ['video', 'audio', 'html'] const thumbnailCompatibleAssetTypes: AssetType[] = ['video', 'audio', 'html']
const thumbnailCompatibleFileNamesList: string[] = [] const thumbnailCompatibleFileNamesList: string[] = []
if (minterType === 'vending' || (minterType === 'base' && event.target.files.length > 1)) { if (minterType === 'vending') {
//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
@ -146,6 +146,38 @@ export const UploadDetails = ({
return return
} }
} }
} else if (minterType === 'base' && event.target.files.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
const sortedFileNames = sortedFiles.map((file) => file.name.split('.')[0])
sortedFiles.map((file) => {
if (thumbnailCompatibleAssetTypes.includes(getAssetType(file.name))) {
thumbnailCompatibleFileNamesList.push(file.name.split('.')[0])
}
})
setThumbnailCompatibleAssetFileNames(thumbnailCompatibleFileNamesList)
console.log('Thumbnail Compatible Files: ', thumbnailCompatibleFileNamesList)
for (let i = 0; i < sortedFileNames.length - 1; i++) {
if (
isNaN(Number(sortedFileNames[i])) ||
isNaN(Number(sortedFileNames[i + 1])) ||
parseInt(sortedFileNames[i]) !== parseInt(sortedFileNames[i + 1]) - 1
) {
toast.error('The file names should be in numerical order.')
setThumbnailCompatibleAssetFileNames([])
addLogItem({
id: uid(),
message: 'The file names should be in numerical order.',
type: 'Error',
timestamp: new Date(),
})
//clear the input
event.target.value = ''
return
}
}
} else if (minterType === 'base' && event.target.files.length === 1) { } else if (minterType === 'base' && event.target.files.length === 1) {
if (thumbnailCompatibleAssetTypes.includes(getAssetType(event.target.files[0].name))) { if (thumbnailCompatibleAssetTypes.includes(getAssetType(event.target.files[0].name))) {
thumbnailCompatibleFileNamesList.push(event.target.files[0].name.split('.')[0]) thumbnailCompatibleFileNamesList.push(event.target.files[0].name.split('.')[0])
@ -186,7 +218,23 @@ export const UploadDetails = ({
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' || (minterType === 'base' && assetFilesArray.length > 1)) { // compare the first file name for asset and metadata files
if (
minterType === 'base' &&
assetFilesArray.length > 1 &&
event.target.files[0].name.split('.')[0] !== assetFilesArray[0].name.split('.')[0]
) {
event.target.value = ''
toast.error('The metadata file names should match the asset file names.')
addLogItem({
id: uid(),
message: 'The metadata file names should match the asset file names.',
type: 'Error',
timestamp: new Date(),
})
return
}
if (minterType === 'vending') {
//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
@ -204,6 +252,28 @@ export const UploadDetails = ({
return return
} }
} }
} else if (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
const sortedFileNames = sortedFiles.map((file) => file.name.split('.')[0])
for (let i = 0; i < sortedFileNames.length - 1; i++) {
if (
isNaN(Number(sortedFileNames[i])) ||
isNaN(Number(sortedFileNames[i + 1])) ||
parseInt(sortedFileNames[i]) !== parseInt(sortedFileNames[i + 1]) - 1
) {
toast.error('The file names should be in numerical order.')
addLogItem({
id: uid(),
message: 'The file names should be in numerical order.',
type: 'Error',
timestamp: new Date(),
})
event.target.value = ''
return
}
}
} }
let loadedFileCount = 0 let loadedFileCount = 0
const files: File[] = [] const files: File[] = []

View File

@ -33,13 +33,13 @@ export interface BaseMinterInstance {
//Execute //Execute
mint: (senderAddress: string, tokenUri: string) => Promise<string> mint: (senderAddress: string, tokenUri: string) => Promise<string>
updateStartTradingTime: (senderAddress: string, time?: Timestamp) => Promise<string> updateStartTradingTime: (senderAddress: string, time?: Timestamp) => Promise<string>
batchMint: (senderAddress: string, recipient: string, batchCount: number) => Promise<string> batchMint: (senderAddress: string, recipient: string, batchCount: number, startFrom: number) => Promise<string>
} }
export interface BaseMinterMessages { export interface BaseMinterMessages {
mint: (tokenUri: string) => MintMessage mint: (tokenUri: string) => MintMessage
updateStartTradingTime: (time: Timestamp) => UpdateStartTradingTimeMessage updateStartTradingTime: (time: Timestamp) => UpdateStartTradingTimeMessage
batchMint: (recipient: string, batchNumber: number) => CustomMessage batchMint: (recipient: string, batchNumber: number, startFrom: number) => CustomMessage
} }
export interface MintMessage { export interface MintMessage {
@ -178,7 +178,12 @@ export const baseMinter = (client: SigningCosmWasmClient, txSigner: string): Bas
return res.transactionHash return res.transactionHash
} }
const batchMint = async (senderAddress: string, baseUri: string, batchCount: number): Promise<string> => { const batchMint = async (
senderAddress: string,
baseUri: string,
batchCount: number,
startFrom: number,
): Promise<string> => {
const txHash = await getConfig().then(async (response) => { const txHash = await getConfig().then(async (response) => {
const factoryParameters = await toast.promise(getFactoryParameters(response?.config?.factory), { const factoryParameters = await toast.promise(getFactoryParameters(response?.config?.factory), {
loading: 'Querying Factory Parameters...', loading: 'Querying Factory Parameters...',
@ -198,7 +203,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 + 1}` }, mint: { token_uri: `${baseUri}/${i + startFrom}` },
} }
const executeContractMsg: MsgExecuteContractEncodeObject = { const executeContractMsg: MsgExecuteContractEncodeObject = {
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract', typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
@ -282,10 +287,10 @@ export const baseMinter = (client: SigningCosmWasmClient, txSigner: string): Bas
} }
} }
const batchMint = (baseUri: string, batchCount: number): CustomMessage => { const batchMint = (baseUri: string, batchCount: number, startFrom: 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 + 1}` } }) msg.push({ mint: { token_uri: `${baseUri}/${i + startFrom}` } })
} }
return { return {
sender: txSigner, sender: txSigner,

View File

@ -449,7 +449,12 @@ const CollectionCreationPage: NextPage = () => {
setBaseTokenUri(baseUri) setBaseTokenUri(baseUri)
const result = await baseMinterContract const result = await baseMinterContract
.use(baseMinterDetails?.existingBaseMinter as string) .use(baseMinterDetails?.existingBaseMinter as string)
?.batchMint(wallet.address, `ipfs://${baseUri}`, uploadDetails.assetFiles.length) ?.batchMint(
wallet.address,
`ipfs://${baseUri}`,
uploadDetails.assetFiles.length,
parseInt(uploadDetails.assetFiles[0].name.split('.')[0]),
)
console.log(result) console.log(result)
return result return result
}) })
@ -698,7 +703,12 @@ const CollectionCreationPage: NextPage = () => {
.promise( .promise(
baseMinterContract baseMinterContract
.use(data.baseMinterAddress) .use(data.baseMinterAddress)
?.batchMint(wallet.address, baseUri, uploadDetails?.assetFiles.length as number) as Promise<string>, ?.batchMint(
wallet.address,
baseUri,
uploadDetails?.assetFiles.length as number,
parseInt(uploadDetails?.assetFiles[0].name.split('.')[0] as string),
) as Promise<string>,
{ {
loading: 'Minting tokens...', loading: 'Minting tokens...',
success: (result) => { success: (result) => {