craft-nft

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

commit 58bec7f9fb3478b29d539a514a509ee91305c23e
parent e122f1e40c89bf8a5887b1dd5f7f8849f44d99f1
Author: lash <dev@holbrook.no>
Date:   Sat, 17 Dec 2022 20:01:47 +0000

Add ui contract owner indicator

Diffstat:
Mjs/index.html | 11++++++++++-
Mjs/manual_test_browser.js | 28++++++++++++++++++++++++++--
Mjs/src/engine.js | 11+++++++++++
3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/js/index.html b/js/index.html @@ -28,7 +28,16 @@ a:hover { <dt>account</dt> <dd id="data_account"></dd> <dt>contract</dt> - <dd id="data_contract"></dd> + <dd> + <dl> + <dt>address</dt> + <dd id="data_contract"></dd> + <dt>name</dt> + <dd id="data_name"></dd> + <dt>symbol</dt> + <dd id="data_symbol"></dd> + </dl> + </dd> </dl> <div id="interactive"> <form id="panel" action="#" onSubmit="return false;"> diff --git a/js/manual_test_browser.js b/js/manual_test_browser.js @@ -8,6 +8,7 @@ window.addEventListener('token', (e) => { document.getElementById('token_list').appendChild(li); }); + window.addEventListener('tokenBatch', (e) => { let currentTokenId = document.getElementById('token_id').innerHTML; if (currentTokenId.substring(0, 2) == '0x') { @@ -70,6 +71,7 @@ async function generatePayload() { window.dispatchEvent(tokenRequestEvent); } + async function generateMint() { const tokenId = document.getElementById('token_mint_id').innerHTML; let batch = document.getElementById('token_mint_batch').innerHTML; @@ -79,6 +81,7 @@ async function generateMint() { uiViewToken(tokenId); } + async function uiMintToken(tokenId, batch) { document.getElementById('token_mint_id').innerHTML = tokenId; document.getElementById('token_mint_batch').innerHTML = batch; @@ -88,6 +91,7 @@ async function uiMintToken(tokenId, batch) { document.getElementById('mint').style.visibility = 'visible' } + async function uiViewTokenSingle(tokenId) { if (!await window.craftnft.isMintAvailable(session, tokenId, 0)) { console.debug('token ' + tokenId + ' is already minted'); @@ -106,6 +110,7 @@ async function uiViewTokenSingle(tokenId) { } + async function uiViewToken(tokenId) { const r = await session.contentGateway.get(tokenId); const tokenData = JSON.parse(r); @@ -141,17 +146,36 @@ async function uiViewToken(tokenId) { document.getElementById('mint').style.visibility = 'hidden'; } + async function uiCreateToken() { document.getElementById('interactive').style.visibility = 'visible'; document.getElementById('detail').style.visibility = 'hidden'; document.getElementById('mint').style.visibility = 'hidden'; } -function run(w3, generated_session) { + +async function run(w3, generated_session) { session = generated_session; session.contentGateway = new Wala('http://localhost:8001'); - document.getElementById('data_account').innerHTML = session.account; + const account = document.getElementById('data_account'); + let s = document.createElement('span'); + s.innerHTML = session.account; + account.append(s); + + let f = document.createElement('font'); + if (await window.craftnft.isOwner(session, session.account)) { + f.setAttribute('color', 'green'); + f.innerHTML += ' (contract owner)'; + account.append(s); + } else { + f.setAttribute('color', 'red'); + f.innerHTML = ' (not contract owner!)'; + } + account.append(f); + document.getElementById('data_contract').innerHTML = session.contractAddress; + document.getElementById('data_name').innerHTML = session.name; + document.getElementById('data_symbol').innerHTML = session.symbol; document.getElementById('panel_submit').addEventListener('click', generatePayload); document.getElementById('mint_submit').addEventListener('click', generateMint); window.craftnft.getTokens(w3, session, (tokenId) => { diff --git a/js/src/engine.js b/js/src/engine.js @@ -94,6 +94,16 @@ async function getBatches(session, tokenId, callback) { } } +async function isOwner(session, address) { + let owner = await session.contract.methods.owner().call({from: session.account}); + + const w3 = new Web3(); + address = await w3.utils.toChecksumAddress(address); + owner = await w3.utils.toChecksumAddress(owner); + + return address == owner; +} + module.exports = { loadProvider: loadProvider, loadConn: loadConn, @@ -103,4 +113,5 @@ module.exports = { allocateToken: allocateToken, mintToken: mintToken, isMintAvailable: isMintAvailable, + isOwner: isOwner, };