craft-nft

A standalone NFT implementation for real-world arts and crafts assets
Log | Files | Refs | README

commit 18bbc3c6b226e8b1488348c2bf9a78fc85a0e17a
parent 58bec7f9fb3478b29d539a514a509ee91305c23e
Author: lash <dev@holbrook.no>
Date:   Sat, 17 Dec 2022 20:11:49 +0000

Fix mint available check in batches view

Diffstat:
Mjs/manual_test_browser.js | 18+++++++++---------
Mjs/src/engine.js | 3+++
2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/js/manual_test_browser.js b/js/manual_test_browser.js @@ -22,7 +22,7 @@ window.addEventListener('tokenBatch', (e) => { li.setAttribute('id', 'token_' + e.detail.tokenId + ' _batch_' + e.detail.batch); span.innerHTML = 'used ' + e.detail.cursor + ' of ' + e.detail.count; li.appendChild(span); - if (window.craftnft.isMintAvailable(e.detail.tokenId, e.detail.batch)) { + if (window.craftnft.isMintAvailable(session, e.detail.tokenId, e.detail.batch)) { const a = document.createElement('a'); a.setAttribute('onClick', 'uiMintToken("' + e.detail.tokenId + '", ' + e.detail.batch + ')'); a.innerHTML = 'mint'; @@ -93,17 +93,17 @@ async function uiMintToken(tokenId, batch) { async function uiViewTokenSingle(tokenId) { + let li = document.createElement('li'); + li.setAttribute('id', 'token_' + tokenId + '_single'); if (!await window.craftnft.isMintAvailable(session, tokenId, 0)) { console.debug('token ' + tokenId + ' is already minted'); - return; + li.innerHTML = '(already minted)'; + } else { + let a = document.createElement('a'); + a.setAttribute('onClick', 'uiMintToken("' + tokenId + '", ' + 0 + ')'); + a.innerHTML = 'mint'; + li.appendChild(a); } - const li = document.createElement('li'); - li.setAttribute('id', 'token_' + tokenId + '_single'); - - let a = document.createElement('a'); - a.setAttribute('onClick', 'uiMintToken("' + tokenId + '", ' + 0 + ')'); - a.innerHTML = 'mint'; - li.appendChild(a); const batch = document.getElementById('token_batches'); batch.appendChild(li); diff --git a/js/src/engine.js b/js/src/engine.js @@ -63,6 +63,9 @@ async function mintToken(session, tokenId, batch, recipient) { async function isMintAvailable(session, tokenId, batch) { let token = await session.contract.methods.token('0x' + tokenId, batch).call({from: session.account}); + if (token === undefined) { + return false; + } if (batch == 0) { if (token.count == 0) { return token.cursor == 0;