From c173912190779317e36fd0862e4795b642df80b4 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Tue, 12 Apr 2022 22:44:03 -0600 Subject: [PATCH] Add FAB to home screen for quickly scanning any recognized barcode (tracking, drop box, crypto wallet) --- www/assets/css/customstyles.css | 7 ++++ www/assets/images/qrcode-viewfinder.svg | 2 + www/assets/js/crypto.js | 2 +- www/assets/js/home.js | 52 +++++++++++++++++++++++++ www/index.html | 1 + www/pages/home.html | 6 +++ www/routes.js | 11 ++++++ 7 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 www/assets/images/qrcode-viewfinder.svg create mode 100644 www/assets/js/home.js diff --git a/www/assets/css/customstyles.css b/www/assets/css/customstyles.css index 537641d..220c7b7 100644 --- a/www/assets/css/customstyles.css +++ b/www/assets/css/customstyles.css @@ -14,6 +14,13 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. height: calc(100% - calc(var(--f7-card-margin-vertical) * 2)); } +#scan-barcode-fab a svg { + height: calc(var(--f7-fab-size) / 2); + width: calc(var(--f7-fab-size) / 2); + fill: var(--f7-fab-text-color); +} + + /* Receipt viewer diff --git a/www/assets/images/qrcode-viewfinder.svg b/www/assets/images/qrcode-viewfinder.svg new file mode 100644 index 0000000..79f789a --- /dev/null +++ b/www/assets/images/qrcode-viewfinder.svg @@ -0,0 +1,2 @@ + + diff --git a/www/assets/js/crypto.js b/www/assets/js/crypto.js index df30dd6..15129d3 100644 --- a/www/assets/js/crypto.js +++ b/www/assets/js/crypto.js @@ -4,7 +4,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var walletPubKeyRegex = /^[0-9a-zA-Z]{25,}$/; +var walletPubKeyRegex = /^(bc1|[13]|D)[a-zA-HJ-NP-Z0-9]{25,}$/; function scanWalletQrCode(callback) { scanBarcode(function (result) { diff --git a/www/assets/js/home.js b/www/assets/js/home.js new file mode 100644 index 0000000..1271745 --- /dev/null +++ b/www/assets/js/home.js @@ -0,0 +1,52 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + + +function openGenericBarcodeScanner() { + scanBarcode(function (result) { + var code = ""; + var action = ""; + if (result.startsWith("https://helena.express/track#")) { + // tracking code from receipt + code = result.split("#")[1]; + action = "track"; + } else if (result.startsWith("https://helena.express/dropandsend#")) { + code = result.split("#")[1]; + action = "pickupcode"; + } else if (result.startsWith("https://helena.express/das/pickup#")) { + code = result.split("#")[1]; + action = "pickupcode"; + } else if (result.startsWith("http") && result.includes("#")) { + if (trackingcoderegex.test(result.split("#")[1])) { + code = result.split("#")[1]; + action = "track"; + } + } else if (walletPubKeyRegex.test(result)) { + code = result; + action = "cryptowallet"; + } else if (trackingcoderegex.test(result)) { + code = result; + action = "track"; + } + + switch (action) { + case "track": + openTrackingInfoPage(code); + break; + case "pickupcode": + sendPickupCode(code); + break; + case "cryptowallet": + router.navigate("/crypto/balance/" + code); + break; + default: + app.dialog.alert("This app can't understand what's in that barcode.", "Error"); + return; + } + }, function () { + app.dialog.alert("Something went wrong and we can't scan right now.", "Error"); + }); +} \ No newline at end of file diff --git a/www/index.html b/www/index.html index 4847dd8..be2052f 100644 --- a/www/index.html +++ b/www/index.html @@ -64,6 +64,7 @@ + diff --git a/www/pages/home.html b/www/pages/home.html index a617d85..465d2c9 100644 --- a/www/pages/home.html +++ b/www/pages/home.html @@ -22,6 +22,12 @@ +
+ + + +
+
diff --git a/www/routes.js b/www/routes.js index ea30c32..c755332 100644 --- a/www/routes.js +++ b/www/routes.js @@ -52,6 +52,17 @@ var routes = [ } } }, + { + path: '/crypto/balance/:walletaddress', + content: compiledPages.crypto(), + name: 'crypto', + on: { + pageAfterIn: function (e, page) { + console.log(page); + displayWalletBalance(page.route.params.walletaddress); + } + } + }, { path: '/home', name: 'home',