-
Notifications
You must be signed in to change notification settings - Fork 2
/
collection-js-inscription-id.js
38 lines (30 loc) · 1.48 KB
/
collection-js-inscription-id.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const collectionJsonInscriptionId = 'collection-json-inscription-id.json';
const rendererJsInscriptionId = 'renderer-js-inscription-id.js';
const renderSize = {width: 150, height: 150};
async function createInscriptionHtml() {
const collectionMetadataPromise = fetch(
`/bitgen-example/content/${collectionJsonInscriptionId}`,
).then((response) => response.json());
const inscriptionTraitsList = document.querySelector('script[t]').getAttribute('t').split(',');
const rendererScript = document.createElement('script');
rendererScript.setAttribute('async', '');
rendererScript.src = `/bitgen-example/content/${rendererJsInscriptionId}`;
const renderPromise = new Promise((resolve, reject) => {
rendererScript.addEventListener('load', async () => {
try {
const collectionMetadata = await collectionMetadataPromise;
const traitInscriptionIds = inscriptionTraitsList.map(
(traitIndex, layerIndex) =>
collectionMetadata.layers[layerIndex].traits[traitIndex]?.inscriptionId,
);
resolve(await render(renderSize, ...traitInscriptionIds.filter((id) => !!id)));
} catch (error) {
console.error(error);
reject(error);
}
});
});
document.head.appendChild(rendererScript);
return await renderPromise;
}
createInscriptionHtml().then((result) => (document.body.innerHTML = result));