commit ba2a1c6ad3f9531900bce28ae409cb9384828acd
parent f4899995d51f200254b8de2745001a6df68c3fa6
Author: lash <dev@holbrook.no>
Date: Thu, 2 Mar 2023 14:43:47 +0000
Use nice NFT token names when metadata available
Diffstat:
3 files changed, 51 insertions(+), 29 deletions(-)
diff --git a/js/qrread.html b/js/qrread.html
@@ -49,7 +49,10 @@ window.addEventListener('load', () => {
const batches = document.getElementsByName('tokenBatch');
for(let i = 0; i < batches.length; i++){
if(batches[i].checked){
- tokenBatch = batches[i].value;
+ const tbid = batches[i].getAttribute('id');
+ const tbidp = tbid.split('.');
+ tokenBatch = tbidp[1] + '.' + tbidp[2];
+ console.debug('using batch', tokenBatch);
}
}
const amount = document.getElementById("requestAmount").value;
diff --git a/js/qrread.js b/js/qrread.js
@@ -227,7 +227,8 @@ async function keyFileHandler(v, passphrase) {
// make sure dom updates are executed before unlock
setTimeout(async () => {
try {
- settings.wallet = await ethers.Wallet.fromEncryptedJson(v, passphrase, unlockWalletProgress);
+ //settings.wallet = await ethers.Wallet.fromEncryptedJson(v, passphrase, unlockWalletProgress);
+ settings.wallet = ethers.Wallet.fromEncryptedJsonSync(v, passphrase);
} catch(e) {
state |= STATE.WALLET_SETTINGS;
const ev = new CustomEvent('uistate', {
@@ -301,7 +302,6 @@ async function checkContractOwner(contractAddress, voucherAddress) {
const voucher = new ethers.Contract(voucherAddress, erc20Abi, settings.provider);
const r = await contract.isWriter(settings.wallet.address);
const rr = true;
- //const rr = await voucher.isWriter(settings.wallet.address);
if (!(r && rr)) {
setStatus('address ' + settings.wallet.address + ' does not have mint access to contracts. plesae start over.', STATUS_ERROR);
const e = new CustomEvent('uistate', {
@@ -376,35 +376,50 @@ async function scanContractTokens(contractAddress, voucherAddress) {
const uri = await contract.tokenURI(ethers.BigNumber.from(tokenId));
let j = 0;
while (true) {
+ let batch = undefined;
try {
- const batch = await contract.token(tokenId, j);
- if (batch.count == 0) {
- console.debug('skipping unique token', tokenId);
- break;
- } else if (batch.sparse) {
- console.debug('skip sparse token', tokenId);
- j++;
- continue;
- }
- console.debug('count cursor', (batch.count - batch.cursor), settings.batchUnitValue);
- z += (batch.count - batch.cursor)
- const e = new CustomEvent('token', {
- detail: {
- tokenId: tokenId,
- batch: j,
- },
- bubbles: true,
- cancelable: true,
- composed: false,
- });
- window.dispatchEvent(e);
- c++;
- } catch {
+ batch = await contract.token(tokenId, j);
+ } catch(e) {
break;
}
+ if (batch.count == 0) {
+ console.debug('skipping unique token', tokenId);
+ break;
+ } else if (batch.sparse) {
+ console.debug('skip sparse token', tokenId);
+ j++;
+ continue;
+ }
+ let nice = null;
+ try {
+ const tokenMeta = await fetch(uri);
+ const o = await tokenMeta.json();
+ console.debug('token metadata retrieved', tokenId, o);
+ nice = o.name;
+ } catch(e) {
+ console.warn('metadata lookup fail', e);
+ }
+ console.debug('count cursor', (batch.count - batch.cursor), settings.batchUnitValue);
+ z += (batch.count - batch.cursor)
+ const e = new CustomEvent('token', {
+ detail: {
+ tokenId: tokenId,
+ batch: j,
+ nice: nice,
+ },
+ bubbles: true,
+ cancelable: true,
+ composed: false,
+ });
+ window.dispatchEvent(e);
+ c++;
j++;
}
}
+ if (c == 0) {
+ setStatus('no NFTs found. please fix and start over.', STATUS_ERROR);
+ throw 'missing at least one available NFT';
+ }
setStatus('found ' + c + ' available token batches in contract', STATUS_OK);
settings.tokenAddress = contractAddress;
setStatus('check fungible token coverage...', STATUS_BUSY);
diff --git a/js/qrread_ui.js b/js/qrread_ui.js
@@ -127,9 +127,13 @@ window.addEventListener('uistate', (e) => {
window.addEventListener('token', (e) => {
const ls = document.getElementById('tokenChooser');
- const v = e.detail.tokenId + '.' + e.detail.batch;
+ const tid = e.detail.tokenId + '.' + e.detail.batch;
+ let v = e.detail.nice + ' (batch ' + e.detail.batch + ')';
+ if (v === null) {
+ v = tid;
+ }
const input = document.createElement('input');
- input.setAttribute('id', 'tokenBatch.' + v);
+ input.setAttribute('id', 'tokenBatch.' + tid);
input.setAttribute('name', 'tokenBatch');
input.setAttribute('type', 'radio');
input.setAttribute('value', v);
@@ -138,7 +142,7 @@ window.addEventListener('token', (e) => {
input.setAttribute('checked', 'checked');
}
const label = document.createElement('label');
- label.setAttribute('for', v);
+ label.setAttribute('for', 'tokenBatch.' + tid);
label.innerHTML = v;
ls.appendChild(input);
ls.appendChild(label);