commit 93b364d2c00351f74090b969471c66a91e953cfd
parent fb6b7cde2e07ec16f09949a5f9b6d31125ae7dd7
Author: lash <dev@holbrook.no>
Date: Mon, 6 Feb 2023 16:43:39 +0000
Join erc721, opensea metadata defs, display image
Diffstat:
3 files changed, 38 insertions(+), 12 deletions(-)
diff --git a/js/index.html b/js/index.html
@@ -80,6 +80,8 @@ dt {
<dd id="token_name"></dd>
<dt>description</dt>
<dd id="token_description"></dd>
+ <dt>image</dt>
+ <dd id="token_image"></dd>
<dt>supply</dt>
<dd id="token_cap"></dd>
<dt class="token_batch_list">batches</dt>
diff --git a/js/manual_test_browser.js b/js/manual_test_browser.js
@@ -60,9 +60,15 @@ window.addEventListener('tokenBatch', async (e) => {
* Interpreted parameters are emitted with the tokenRequest event.
*/
async function generateAllocation() {
- let tokenData = {
+ let tokenData_ERC721 = {
name: undefined,
description: undefined,
+ image: undefined,
+ };
+ let tokenData_openSea = {
+ attributes: [],
+ };
+ let tokenData_native = {
amount: 0,
attachments: [],
};
@@ -71,23 +77,28 @@ async function generateAllocation() {
if (amount === '') {
amount = '0';
}
- tokenData.amount = parseInt(amount, 10);
- if (isNaN(tokenData.amount)) {
+ tokenData_native.amount = parseInt(amount, 10);
+ if (isNaN(tokenData_native.amount)) {
throw 'amount must be numeric';
}
- tokenData.name = document.getElementById('panel_title').value;
- tokenData.description = document.getElementById('panel_description').value;
- const s = JSON.stringify(tokenData);
-
- const sha_raw = new jsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
- sha_raw.update(s);
- const digest = sha_raw.getHash("HEX");
+ tokenData_ERC721.name = document.getElementById('panel_title').value;
+ tokenData_ERC721.description = document.getElementById('panel_description').value;
const attachments = document.getElementById('panel_attachment_list').children;
for (let i = 0; i < attachments.length; i++) {
- tokenData.attachments.push(attachments[i].innerHTML);
+ if (tokenData_ERC721.image === undefined) {
+ tokenData_ERC721.image = attachments[i].innerHTML;
+ }
+ tokenData_native.attachments.push(attachments[i].innerHTML);
}
+ tokenData = Object.assign(tokenData_ERC721, tokenData_native, tokenData_openSea);
+ const s = JSON.stringify(tokenData_ERC721);
+
+ const sha_raw = new jsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
+ sha_raw.update(s);
+ const digest = sha_raw.getHash("HEX");
+
if (session.contentGateway !== undefined) {
try {
let r = await session.contentGateway.put(s);
@@ -215,6 +226,16 @@ async function uiViewToken(tokenId) {
const tokenChainData = await window.craftnft.getTokenChainData(session, tokenId);
console.debug('retrieved token chain data', tokenChainData);
+ console.debug('getting image hash', tokenData.image);
+ if (tokenData.image !== undefined) {
+ image_hash = tokenData.image.substring(7);
+ session.contentGateway.get(image_hash, true).then((v) => {
+ let img = document.createElement('img');
+ console.debug('img img', img);
+ img.src = URL.createObjectURL(v);
+ document.getElementById('token_image').appendChild(img);
+ });
+ }
document.getElementById('token_id').innerHTML = tokenId;
document.getElementById('token_name').innerHTML = tokenData.name;
document.getElementById('token_description').innerHTML = tokenData.description;
diff --git a/js/src/wala.js b/js/src/wala.js
@@ -18,12 +18,15 @@ Wala.prototype.put = async function(v, filename, mimetype) {
return r.text();
}
-Wala.prototype.get = async function(k) {
+Wala.prototype.get = async function(k, binary=false) {
const url = this.url(k)
let r = await fetch(url);
if (!r.ok) {
throw ('failed get');
}
+ if (binary) {
+ return r.blob();
+ }
return r.text();
}