@visualizevalue/mint-app-base 0.1.88 → 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.
@@ -46,7 +46,7 @@ const collections = computed(() => isMe.value
46
46
  // Force update collections with no mints
47
47
  if (store.forArtist(id.value).length !== collections.length) {
48
48
  store.forArtist(id.value)
49
- .filter(c => c.latestTokenId === 0n)
49
+ .filter(c => c?.latestTokenId === 0n)
50
50
  .forEach(c => store.fetchCollection(c.address))
51
51
  }
52
52
  </script>
@@ -44,6 +44,7 @@ export const useOnchainStore = () => {
44
44
  return this.artist(address).collections
45
45
  .map(c => state.collections[c])
46
46
  .sort((a, b) => a.initBlock > b.initBlock ? -1 : 1)
47
+ .filter(c => !!c)
47
48
  }
48
49
  },
49
50
  forArtistOnlyMinted () {
@@ -204,24 +205,29 @@ export const useOnchainStore = () => {
204
205
  }) as Promise<GetBalanceReturnType>,
205
206
  ])
206
207
 
208
+ const artist = owner.toLowerCase() as `0x${string}`
207
209
  const json = Buffer.from(data.substring(29), `base64`).toString()
208
- const metadata = JSON.parse(json)
209
210
 
210
- const artist = owner.toLowerCase() as `0x${string}`
211
+ try {
212
+ const metadata = JSON.parse(json)
211
213
 
212
- return await this.addCollection({
213
- image: metadata.image,
214
- name: metadata.name,
215
- symbol: metadata.symbol,
216
- description: metadata.description,
217
- address,
218
- initBlock,
219
- latestTokenId,
220
- owner: artist,
221
- tokens: {},
222
- balance: balance.value,
223
- renderers: [],
224
- })
214
+ return await this.addCollection({
215
+ image: metadata.image,
216
+ name: metadata.name,
217
+ symbol: metadata.symbol,
218
+ description: metadata.description,
219
+ address,
220
+ initBlock,
221
+ latestTokenId,
222
+ owner: artist,
223
+ tokens: {},
224
+ balance: balance.value,
225
+ renderers: [],
226
+ })
227
+ } catch (e) {
228
+ console.warn(`Error parsing collection`, e)
229
+ this.artists[artist].collections = this.artists[artist].collections.filter(c => c !== address)
230
+ }
225
231
  },
226
232
 
227
233
  async fetchCollectionBalance (address: `0x${string}`) {
@@ -300,7 +306,7 @@ export const useOnchainStore = () => {
300
306
  return this.tokens(address)
301
307
  },
302
308
 
303
- async fetchToken (address: `0x${string}`, id: number | string | bigint) {
309
+ async fetchToken (address: `0x${string}`, id: number | string | bigint, tries?: number = 0) {
304
310
  const client = getPublicClient($wagmi, { chainId }) as PublicClient
305
311
  const mintContract = getContract({
306
312
  address,
@@ -316,25 +322,38 @@ export const useOnchainStore = () => {
316
322
  // Normalize token ID
317
323
  const tokenId = BigInt(id)
318
324
 
325
+ // Default (empty) metadata
326
+ let metadata = {}
327
+
319
328
  try {
320
329
  console.info(`Fetching token #${tokenId}`)
321
330
 
322
- const [data, dataUri, closeAt] = await Promise.all([
331
+ const [data, dataUri] = await Promise.all([
323
332
  mintContract.read.get([tokenId]) as Promise<[string, string, `0x${string}`[], bigint, bigint, bigint, bigint]>,
324
333
  mintContract.read.uri([tokenId], { gas: 100_000_000_000 }) as Promise<string>,
325
- mintContract.read.mintOpenUntil([tokenId]) as Promise<bigint>,
326
334
  ])
327
335
 
328
- const [ name, description, _artifact, _renderer, mintedBlock, _closeAt, _extraData ] = data
336
+ const [ _name, _description, _artifact, _renderer, mintedBlock, closeAt, _extraData ] = data
329
337
 
330
- const json = Buffer.from(dataUri.substring(29), `base64`).toString()
331
- const metadata = JSON.parse(json)
338
+ let metadata
339
+ try {
340
+ const json = Buffer.from(dataUri.substring(29), `base64`).toString()
341
+ metadata = JSON.parse(json)
342
+ } catch (e) {
343
+ metadata = {
344
+ name: '',
345
+ description: '',
346
+ image: '',
347
+ animationUrl: '',
348
+ }
349
+ console.warn(`Parsing data uri failed`, e)
350
+ }
332
351
 
333
352
  const token: Token = {
334
353
  tokenId,
335
354
  collection: address,
336
- name,
337
- description,
355
+ name: metadata.name,
356
+ description: metadata.description,
338
357
  image: metadata.image,
339
358
  animationUrl: metadata.animation_url,
340
359
 
@@ -348,7 +367,13 @@ export const useOnchainStore = () => {
348
367
 
349
368
  this.collections[address].tokens[`${token.tokenId}`] = token
350
369
  } catch (e) {
351
- 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
+ }
352
377
  }
353
378
  },
354
379
 
@@ -116,8 +116,8 @@ export const useCreateMintFlow = (collection: Collection, txFlow: Ref) => {
116
116
  address: collection.address,
117
117
  functionName: 'create',
118
118
  args: [
119
- name.value,
120
- description.value,
119
+ sanitizeForJson(name.value),
120
+ sanitizeForJson(description.value),
121
121
  multiTransactionPrepare ? [] : artifactByteArray,
122
122
  renderer.value,
123
123
  0n, // Additional Data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visualizevalue/mint-app-base",
3
- "version": "0.1.88",
3
+ "version": "0.1.90",
4
4
  "type": "module",
5
5
  "main": "./nuxt.config.ts",
6
6
  "dependencies": {
@@ -129,9 +129,9 @@ const deployRequest = computed(() => async () => {
129
129
  address: config.public.factoryAddress,
130
130
  functionName: creationType.value,
131
131
  args: [
132
- title.value,
133
- symbol.value,
134
- description.value,
132
+ sanitizeForJson(title.value),
133
+ sanitizeForJson(symbol.value),
134
+ sanitizeForJson(description.value),
135
135
  toByteArray(image.value),
136
136
  ],
137
137
  })
package/utils/strings.ts CHANGED
@@ -28,3 +28,6 @@ export const extractURLs = (str: string) => {
28
28
  urls: str.match(urlPattern),
29
29
  }
30
30
  }
31
+
32
+ // Replace special characters with their escaped counterparts
33
+ export const sanitizeForJson = (input: string): string => JSON.stringify(input).slice(1, -1)