commit 693183f98323b6397014c3c5a768c90dd34ec52a
parent 87ac764282dff02bc8523b5ad172f9a9f9a19d86
Author: lash <dev@holbrook.no>
Date: Sun, 19 Feb 2023 19:11:35 +0000
Connect qr scan to mint function
Diffstat:
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/js/qrread.html b/js/qrread.html
@@ -56,10 +56,10 @@ var canvas;
var ctx;
// Load init
-window.addEventListener('load', test);
+window.addEventListener('load', live);
function test() {
- signAndSend("7F8301136a596D64f1b7E5C882FCB0FCD0623745");
+ signAndSend("0x7F8301136a596D64f1b7E5C882FCB0FCD0623745");
}
function live() {
@@ -75,12 +75,27 @@ function scan() {
const code = jsQR(imageData, 800, 800);
if (code) {
console.log("Found QR code", code);
+ signAndSend(code.data);
return;
}
setTimeout(scan, 10);
}
async function signAndSend(addr) {
+ if (addr.length < 40) {
+ console.error('invalid ethereum address (too short)', addr);
+ return;
+ }
+ if (addr.substring(0, 2) == '0x') {
+ addr = addr.substring(2);
+ }
+ const re = new RegExp("^[0-9a-fA-F]{40}$");
+ const m = addr.match(re);
+ if (m === null) {
+ console.error('invalid ethereum address (invalid hex or too long)', addr);
+ return;
+ }
+ console.info('found recipient address', addr);
let tx = txBase;
const nonce = await wallet.getTransactionCount();
addr = addressPrePad + addr;