@visualizevalue/mint-app-base 0.1.89 → 0.1.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -306,7 +306,7 @@ export const useOnchainStore = () => {
306
306
  return this.tokens(address)
307
307
  },
308
308
 
309
- async fetchToken (address: `0x${string}`, id: number | string | bigint) {
309
+ async fetchToken (address: `0x${string}`, id: number | string | bigint, tries?: number = 0) {
310
310
  const client = getPublicClient($wagmi, { chainId }) as PublicClient
311
311
  const mintContract = getContract({
312
312
  address,
@@ -322,16 +322,18 @@ export const useOnchainStore = () => {
322
322
  // Normalize token ID
323
323
  const tokenId = BigInt(id)
324
324
 
325
+ // Default (empty) metadata
326
+ let metadata = {}
327
+
325
328
  try {
326
329
  console.info(`Fetching token #${tokenId}`)
327
330
 
328
- const [data, dataUri, closeAt] = await Promise.all([
331
+ const [data, dataUri] = await Promise.all([
329
332
  mintContract.read.get([tokenId]) as Promise<[string, string, `0x${string}`[], bigint, bigint, bigint, bigint]>,
330
333
  mintContract.read.uri([tokenId], { gas: 100_000_000_000 }) as Promise<string>,
331
- mintContract.read.mintOpenUntil([tokenId]) as Promise<bigint>,
332
334
  ])
333
335
 
334
- const [ name, description, _artifact, _renderer, mintedBlock, _closeAt, _extraData ] = data
336
+ const [ _name, _description, _artifact, _renderer, mintedBlock, closeAt, _extraData ] = data
335
337
 
336
338
  let metadata
337
339
  try {
@@ -339,16 +341,19 @@ export const useOnchainStore = () => {
339
341
  metadata = JSON.parse(json)
340
342
  } catch (e) {
341
343
  metadata = {
344
+ name: '',
345
+ description: '',
342
346
  image: '',
343
347
  animationUrl: '',
344
348
  }
349
+ console.warn(`Parsing data uri failed`, e)
345
350
  }
346
351
 
347
352
  const token: Token = {
348
353
  tokenId,
349
354
  collection: address,
350
- name,
351
- description,
355
+ name: metadata.name,
356
+ description: metadata.description,
352
357
  image: metadata.image,
353
358
  animationUrl: metadata.animation_url,
354
359
 
@@ -362,7 +367,13 @@ export const useOnchainStore = () => {
362
367
 
363
368
  this.collections[address].tokens[`${token.tokenId}`] = token
364
369
  } catch (e) {
365
- console.error(e)
370
+ // Retry 3 times
371
+ if (tries < 3) {
372
+ console.info(`Retrying fetching data ${tries + 1}`)
373
+ return await this.fetchToken(address, id, tries + 1)
374
+ } else {
375
+ // TODO: Handle impossible to load token
376
+ }
366
377
  }
367
378
  },
368
379
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visualizevalue/mint-app-base",
3
- "version": "0.1.89",
3
+ "version": "0.1.90",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "dependencies": {