Skip to content

Commit

Permalink
🚸 Start nft id with existing count to avoid collisioon
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jan 24, 2024
1 parent 3055dfa commit 1636f0b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pages/mint-nft/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ const nftMintDefaultData = ref<any>(null)
const nftMintCount = ref(100)
const nftData = ref<any>(null)
const nftCSVData = ref('')
const existingNftCount = ref(0)
const iscnId = computed(() => iscnData.value?.['@id'])
const classId = computed(() => classData.value?.id)
Expand Down Expand Up @@ -593,9 +594,14 @@ async function onClickMintByInputting () {
external_url: externalUrl.value
}
}
if (!isCreatingClass.value) {
const { nfts } = await getNFTs({ classId: classId.value as string })
existingNftCount.value = nfts.length
}
const csvDataString = generateCsvData({
prefix: state.nftIdPrefix,
nftMintCount: nftMintCount.value,
nftExisitngCount: existingNftCount.value,
imgUrl: imageUrl.value,
uri: uri.value
})
Expand Down
4 changes: 2 additions & 2 deletions utils/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function getNFTAuthzGrants (granter: string, grantee: string) {
return grants[0]
}

export async function getNFTs ({ classId = '', owner = '', needCount }) {
export async function getNFTs ({ classId = '', owner = '', needCount = 0 }) {
const needPages = Math.ceil(needCount / 100)
const c = (await getSigningClient()).getISCNQueryClient()
const client = await c.getQueryClient()
Expand All @@ -106,7 +106,7 @@ export async function getNFTs ({ classId = '', owner = '', needCount }) {
);
(next = res.pagination?.nextKey)
nfts.push(...res.nfts)
if (pageCounts > needPages) { break }
if (needPages && pageCounts > needPages) { break }
pageCounts += 1
} while (next && next.length)
return { nfts }
Expand Down
4 changes: 3 additions & 1 deletion utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,20 @@ export function downloadFile ({ data, fileName, fileType }:{data:any, fileName:s

export function generateCsvData ({
prefix,
nftExisitngCount = 0,
nftMintCount,
imgUrl,
uri
}: {
prefix: string;
nftMintCount: number;
nftExisitngCount?: number;
imgUrl: string;
uri: string ;
}) {
const csvData = []
csvData.push('"nftId","uri","image","metadata"')
for (let i = 0; i <= nftMintCount - 1; i++) {
for (let i = nftExisitngCount; i <= nftExisitngCount + nftMintCount - 1; i++) {
const nftId = `${prefix}-${i.toString().padStart(4, '0')}`
csvData.push(`"${nftId}","${uri}","${imgUrl}",""`)
}
Expand Down

0 comments on commit 1636f0b

Please sign in to comment.