craft-nft

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

qrcheck.js (2219B)


      1 ZEROADDR = '0x0000000000000000000000000000000000000000000000000000000000000000';
      2 
      3 function registerScan(address) {
      4 	let r = localStorage.getItem('holderAddressScanned');
      5 	if (r === null) {
      6 		r = 0;
      7 	}
      8 	r++;
      9 	localStorage.setItem('holderAddressScanned', r);
     10 	return r.toString();
     11 
     12 }
     13 
     14 async function handleScan(holderAddress) {
     15 	document.getElementById('scan').style.display = 'none';
     16 	document.getElementById('result').style.display = 'block';
     17 
     18 	setStatus('connecting to network', STATUS_BUSY);
     19 	providerString = document.getElementById('chainRpcUrl').value;
     20 	settings.provider = new ethers.providers.JsonRpcProvider(providerString);
     21 	settings.tokenAddress = document.getElementById('contractAddress').value;
     22 	const network = await settings.provider.getNetwork();
     23 	console.debug('connected to network', network, settings.provider);
     24 	console.debug('handling scan', network, settings.provider, settings.tokenAddress, holderAddress);
     25 
     26 	setStatus('check NFT balance', STATUS_BUSY);
     27 	const contract = new ethers.Contract(settings.tokenAddress, nftAbi, settings.provider);
     28 	let r = await contract.balanceOf(holderAddress);
     29 
     30 	const balance = r.toNumber();
     31 	let scans = '(not registered)';
     32 	if (balance > 0) {
     33 		scans = registerScan(holderAddress);
     34 		if (scans > 1) {
     35 			setStatus('address holds NFT (scanned ' + scans + ' times)', STATUS_WARN);
     36 		} else {
     37 			setStatus('address holds NFT', STATUS_OK);
     38 		}
     39 	} else {
     40 		setStatus('address ' + holderAddress + ' not holder', STATUS_WARN);
     41 	}
     42 	document.getElementById('resultHolderAddress').innerHTML = holderAddress;
     43 	document.getElementById('resultBalance').innerHTML = balance;
     44 	document.getElementById('resultHolderAddressTimes').innerHTML = scans;
     45 }
     46 
     47 function manualLookup() {
     48 	const holderAddress = document.getElementById('holderAddress').value;
     49 	try {
     50 		scanHandler(holderAddress, handleScan);
     51 	} catch(e) {
     52 		console.error(e);
     53 	}
     54 }
     55 
     56 function resetScan() {
     57 	document.getElementById('holderAddress').value = null;
     58 	document.getElementById('result').style.display = 'none';
     59 	document.getElementById('scan').style.display = 'block';
     60 	document.getElementById('resultHolderAddress').innerHTML = '';
     61 	document.getElementById('resultBalance').innerHTML = '';
     62 	live(handleScan);
     63 }