Commit a01db1d4 authored by Daniel Edgecumbe's avatar Daniel Edgecumbe

Use instascan for QR scanning in the wallet

parent 7ce4ba87
Pipeline #312 passed with stages
in 29 seconds
......@@ -29,3 +29,8 @@
* CC-BY-SA 3.0
* Timothy Miller
* https://www.iconfinder.com/tmthymllr
## instascan.min.js
* MIT License
* Copyright (c) 2016 Chris Schmich
* https://github.com/schmich/instascan
......@@ -451,3 +451,10 @@ input#debug-console-input {
font-weight: bold;
border: none;
}
video#qrscan {
width: 100%;
height: 30rem;
background-color: var(--neutral-5);
border-radius: 0.3rem;
}
......@@ -28,6 +28,7 @@ along with bitcoin-top. If not, see <http://www.gnu.org/licenses/>.
<script src="qrcode.min.js"></script>
<script src="d3.v5.min.js"></script>
<script src="c3.min.js"></script>
<script src="instascan.min.js"></script>
<script src="index.js"></script>
</head>
......@@ -199,6 +200,12 @@ along with bitcoin-top. If not, see <http://www.gnu.org/licenses/>.
<span class="waladdr">{{ unused_address }}</span>
</template>
<video
id="qrscan"
v-on:click="toggleScanner(null)">
<div>wat</div>
</video>
<template v-if="walletinfo">
<h2>send some bitcoins</h2>
<span>address</span>
......
......@@ -188,6 +188,24 @@ onload = function() {
},
},
methods: {
toggleScanner: function() {
if (SCANNER_ENABLED) {
SCANNER.stop();
SCANNER_ENABLED = false;
return;
}
Instascan.Camera.getCameras().then(function (cameras) {
if (cameras.length > 0) {
SCANNER.start(cameras[0]);
SCANNER_ENABLED = true;
} else {
console.error('No cameras found.');
}
}).catch(function (e) {
console.error(e);
});
},
submitSubmitPSBT: function() {
if (app.wallet_createpsbt === null) { return; }
let psbt = app.wallet_createpsbt.psbt;
......@@ -342,6 +360,10 @@ onload = function() {
}
let dealWithSubmitPSBT = function(r, j) {
if (j.result !== null) {
app.wallet_send_address = null;
app.wallet_createpsbt = null;
}
console.log(j);
}
......@@ -860,6 +882,15 @@ onload = function() {
return ((a % b) + b) % b;
}
let processQrCode = function(a) {
app.toggleScanner();
if (a.startsWith("bitcoin:")) {
a = a.replace("bitcoin:","");
}
app.wallet_send_address = a;
app.submitCreatePSBT();
}
document.onkeydown = function(e) {
if ((e.key == "ArrowDown") || (e.key === "ArrowUp")) {
let i;
......@@ -881,4 +912,8 @@ onload = function() {
e.preventDefault();
}
}
var SCANNER = new Instascan.Scanner({ video: document.getElementById("qrscan") });
SCANNER.addListener('scan', processQrCode);
var SCANNER_ENABLED = false;
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment