@visualizevalue/mint-app-base 0.1.89 → 0.1.91

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,22 @@ 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}`)
330
+ const currentBlock = await client.getBlock()
327
331
 
328
- const [data, dataUri, closeAt] = await Promise.all([
332
+ const [data, dataUri] = await Promise.all([
329
333
  mintContract.read.get([tokenId]) as Promise<[string, string, `0x${string}`[], bigint, bigint, bigint, bigint]>,
330
- mintContract.read.uri([tokenId], { gas: 100_000_000_000 }) as Promise<string>,
331
- mintContract.read.mintOpenUntil([tokenId]) as Promise<bigint>,
334
+ mintContract.read.uri([tokenId], {
335
+ gas: 100_000_000_000,
336
+ gasPrice: currentBlock.baseFeePerGas,
337
+ }) as Promise<string>,
332
338
  ])
333
339
 
334
- const [ name, description, _artifact, _renderer, mintedBlock, _closeAt, _extraData ] = data
340
+ const [ _name, _description, _artifact, _renderer, mintedBlock, closeAt, _extraData ] = data
335
341
 
336
342
  let metadata
337
343
  try {
@@ -339,16 +345,19 @@ export const useOnchainStore = () => {
339
345
  metadata = JSON.parse(json)
340
346
  } catch (e) {
341
347
  metadata = {
348
+ name: '',
349
+ description: '',
342
350
  image: '',
343
351
  animationUrl: '',
344
352
  }
353
+ console.warn(`Parsing data uri failed`, e)
345
354
  }
346
355
 
347
356
  const token: Token = {
348
357
  tokenId,
349
358
  collection: address,
350
- name,
351
- description,
359
+ name: metadata.name,
360
+ description: metadata.description,
352
361
  image: metadata.image,
353
362
  animationUrl: metadata.animation_url,
354
363
 
@@ -362,7 +371,13 @@ export const useOnchainStore = () => {
362
371
 
363
372
  this.collections[address].tokens[`${token.tokenId}`] = token
364
373
  } catch (e) {
365
- console.error(e)
374
+ // Retry 3 times
375
+ if (tries < 3) {
376
+ console.info(`Retrying fetching data ${tries + 1}`)
377
+ return await this.fetchToken(address, id, tries + 1)
378
+ } else {
379
+ // TODO: Handle impossible to load token
380
+ }
366
381
  }
367
382
  },
368
383
 
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.91",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "dependencies": {