@visualizevalue/mint-app-base 0.1.124 → 0.1.126
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.
- package/app.config.ts +7 -7
- package/composables/collections.ts +37 -18
- package/package.json +1 -1
- package/utils/ipfs.ts +5 -3
- package/utils/urls.ts +0 -1
package/app.config.ts
CHANGED
|
@@ -9,13 +9,13 @@ export default defineAppConfig({
|
|
|
9
9
|
address: '0xe5d2da253c7d4b7609afce15332bb1a1fb461d09',
|
|
10
10
|
description: 'The default renderer',
|
|
11
11
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
{
|
|
13
|
+
component: 'Markdown',
|
|
14
|
+
name: 'Markdown Renderer',
|
|
15
|
+
version: 1n,
|
|
16
|
+
address: '0x6a517e2432b43b6c7db589059f4e5ef10fd3a90e',
|
|
17
|
+
description: 'Renders markdown content as onchain text artifacts',
|
|
18
|
+
},
|
|
19
19
|
{
|
|
20
20
|
component: 'P5',
|
|
21
21
|
name: 'P5 Renderer',
|
|
@@ -6,6 +6,15 @@ import type { MintEvent } from '~/utils/types'
|
|
|
6
6
|
export const CURRENT_STATE_VERSION = 9
|
|
7
7
|
export const MAX_BLOCK_RANGE = 1800n
|
|
8
8
|
export const MINT_BLOCKS = BLOCKS_PER_DAY
|
|
9
|
+
export const MAX_RENDERERS = 20
|
|
10
|
+
|
|
11
|
+
const inflightRequests = new Map<string, Promise<any>>()
|
|
12
|
+
function dedupe<T>(key: string, fn: () => Promise<T>): Promise<T> {
|
|
13
|
+
if (!inflightRequests.has(key)) {
|
|
14
|
+
inflightRequests.set(key, fn().finally(() => inflightRequests.delete(key)))
|
|
15
|
+
}
|
|
16
|
+
return inflightRequests.get(key)!
|
|
17
|
+
}
|
|
9
18
|
|
|
10
19
|
export const useOnchainStore = () => {
|
|
11
20
|
const { $wagmi } = useNuxtApp()
|
|
@@ -44,8 +53,8 @@ export const useOnchainStore = () => {
|
|
|
44
53
|
|
|
45
54
|
return this.artist(address).collections
|
|
46
55
|
.map(c => state.collections[c])
|
|
47
|
-
.sort((a, b) => a.initBlock > b.initBlock ? -1 : 1)
|
|
48
56
|
.filter(c => !!c)
|
|
57
|
+
.sort((a, b) => a.initBlock > b.initBlock ? -1 : 1)
|
|
49
58
|
}
|
|
50
59
|
},
|
|
51
60
|
forArtistOnlyMinted () {
|
|
@@ -54,10 +63,12 @@ export const useOnchainStore = () => {
|
|
|
54
63
|
hasCollection: (state) => (address: `0x${string}`) => state.collections[address] !== undefined,
|
|
55
64
|
collection: (state) => (address: `0x${string}`) => state.collections[address],
|
|
56
65
|
tokens: (state) => (address: `0x${string}`) =>
|
|
57
|
-
|
|
58
|
-
.
|
|
66
|
+
state.collections[address]
|
|
67
|
+
? Object.values(state.collections[address].tokens)
|
|
68
|
+
.sort((a: Token, b: Token) => a.tokenId > b.tokenId ? -1 : 1)
|
|
69
|
+
: [],
|
|
59
70
|
tokenMints: (state) => (address: `0x${string}`, tokenId: bigint): MintEvent[] =>
|
|
60
|
-
state.collections[address]
|
|
71
|
+
state.collections[address]?.tokens[tokenId.toString()]?.mints ?? [],
|
|
61
72
|
tokenBalance: (state) => (address: `0x${string}`, tokenId: bigint): bigint | null =>
|
|
62
73
|
(state.tokenBalances[address] && (state.tokenBalances[address][`${tokenId}`] !== undefined))
|
|
63
74
|
? state.tokenBalances[address][`${tokenId}`]
|
|
@@ -166,6 +177,10 @@ export const useOnchainStore = () => {
|
|
|
166
177
|
},
|
|
167
178
|
|
|
168
179
|
async fetchCollection (address: `0x${string}`): Promise<Collection> {
|
|
180
|
+
return dedupe(`collection:${address}`, () => this._fetchCollection(address))
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
async _fetchCollection (address: `0x${string}`): Promise<Collection> {
|
|
169
184
|
this.ensureStoreVersion()
|
|
170
185
|
|
|
171
186
|
if (this.hasCollection(address) && this.collection(address).latestTokenId > 0n) {
|
|
@@ -243,7 +258,7 @@ export const useOnchainStore = () => {
|
|
|
243
258
|
const renderers = this.collections[address].renderers
|
|
244
259
|
|
|
245
260
|
let index = renderers.length
|
|
246
|
-
while (
|
|
261
|
+
while (index < MAX_RENDERERS) {
|
|
247
262
|
try {
|
|
248
263
|
const rendererAddress = (await readContract($wagmi, {
|
|
249
264
|
abi: MINT_ABI,
|
|
@@ -297,22 +312,29 @@ export const useOnchainStore = () => {
|
|
|
297
312
|
// If we have all tokens we don't need to do anything
|
|
298
313
|
if (BigInt(existingTokenIds.size) === collection.latestTokenId) return this.tokens(address)
|
|
299
314
|
|
|
300
|
-
//
|
|
315
|
+
// Collect missing token IDs
|
|
316
|
+
const missingIds: bigint[] = []
|
|
301
317
|
let id = collection.latestTokenId
|
|
302
318
|
while (id > 0n) {
|
|
303
|
-
if (!
|
|
304
|
-
|
|
305
|
-
} else {
|
|
306
|
-
console.info(`Skipping token #${id} since we already have it.`)
|
|
319
|
+
if (!existingTokenIds.has(id)) {
|
|
320
|
+
missingIds.push(id)
|
|
307
321
|
}
|
|
322
|
+
id--
|
|
323
|
+
}
|
|
308
324
|
|
|
309
|
-
|
|
325
|
+
// Fetch in parallel chunks of 5
|
|
326
|
+
for (const chunk of chunkArray(missingIds, 5)) {
|
|
327
|
+
await Promise.all(chunk.map(tokenId => this.fetchToken(address, tokenId)))
|
|
310
328
|
}
|
|
311
329
|
|
|
312
330
|
return this.tokens(address)
|
|
313
331
|
},
|
|
314
332
|
|
|
315
|
-
async fetchToken (address: `0x${string}`, id: number | string | bigint, tries
|
|
333
|
+
async fetchToken (address: `0x${string}`, id: number | string | bigint, tries: number = 0): Promise<void> {
|
|
334
|
+
return dedupe(`token:${address}:${id}`, () => this._fetchToken(address, id, tries))
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
async _fetchToken (address: `0x${string}`, id: number | string | bigint, tries: number = 0): Promise<void> {
|
|
316
338
|
const client = getPublicClient($wagmi, { chainId }) as PublicClient
|
|
317
339
|
const mintContract = getContract({
|
|
318
340
|
address,
|
|
@@ -328,9 +350,6 @@ export const useOnchainStore = () => {
|
|
|
328
350
|
// Normalize token ID
|
|
329
351
|
const tokenId = BigInt(id)
|
|
330
352
|
|
|
331
|
-
// Default (empty) metadata
|
|
332
|
-
let metadata = {}
|
|
333
|
-
|
|
334
353
|
try {
|
|
335
354
|
console.info(`Fetching token #${tokenId}`)
|
|
336
355
|
const currentBlock = await client.getBlock()
|
|
@@ -385,7 +404,7 @@ export const useOnchainStore = () => {
|
|
|
385
404
|
// Retry 3 times
|
|
386
405
|
if (tries < 3) {
|
|
387
406
|
console.info(`Retrying fetching data ${tries + 1}`)
|
|
388
|
-
return await this.
|
|
407
|
+
return await this._fetchToken(address, id, tries + 1)
|
|
389
408
|
} else {
|
|
390
409
|
// TODO: Handle impossible to load token
|
|
391
410
|
}
|
|
@@ -499,7 +518,7 @@ export const useOnchainStore = () => {
|
|
|
499
518
|
}) as MintEvent).reverse()
|
|
500
519
|
},
|
|
501
520
|
|
|
502
|
-
|
|
521
|
+
addTokenMints (token: Token, mints: MintEvent[], location: 'prepend'|'append' = 'prepend') {
|
|
503
522
|
const storedToken = this.collections[token.collection].tokens[token.tokenId.toString()]
|
|
504
523
|
|
|
505
524
|
storedToken.mints = location === 'prepend'
|
|
@@ -516,7 +535,7 @@ export const useOnchainStore = () => {
|
|
|
516
535
|
|
|
517
536
|
if (! this.hasArtist(collection.owner)) {
|
|
518
537
|
this.initializeArtist(collection.owner)
|
|
519
|
-
this.fetchArtistProfile(collection.owner)
|
|
538
|
+
this.fetchArtistProfile(collection.owner).catch(e => console.warn(`Failed to fetch artist profile`, e))
|
|
520
539
|
}
|
|
521
540
|
|
|
522
541
|
this.artists[collection.owner].collections = Array.from(new Set([
|
package/package.json
CHANGED
package/utils/ipfs.ts
CHANGED
|
@@ -18,10 +18,12 @@ export const getValidIpfsURI = (cid: string): string => {
|
|
|
18
18
|
return validated ? `ipfs://${validated}` : ''
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
const DEFAULT_IPFS_GATEWAY = 'https://ipfs.io/ipfs/'
|
|
22
|
+
|
|
21
23
|
export const ipfsToHttpURI = (
|
|
22
24
|
url: string,
|
|
23
|
-
gateway
|
|
25
|
+
gateway?: string,
|
|
24
26
|
) => url
|
|
25
|
-
.replace('https://ipfs.io/ipfs/', gateway)
|
|
26
|
-
.replace('ipfs://', gateway)
|
|
27
|
+
.replace('https://ipfs.io/ipfs/', gateway || DEFAULT_IPFS_GATEWAY)
|
|
28
|
+
.replace('ipfs://', gateway || DEFAULT_IPFS_GATEWAY)
|
|
27
29
|
|
package/utils/urls.ts
CHANGED
|
@@ -9,7 +9,6 @@ export const validateURI = (url: string, config: UrlValidationConfig = {}) => {
|
|
|
9
9
|
let validated = url.trim()
|
|
10
10
|
|
|
11
11
|
// Normalize protocol
|
|
12
|
-
// if (validated.startsWith('ipfs://') || validated.contains('ipfs')) {
|
|
13
12
|
if (validated.indexOf('ipfs') > -1) {
|
|
14
13
|
validated = ipfsToHttpURI(validated, config.ipfsGateway)
|
|
15
14
|
}
|