From 3d70dc2289f683fbcad25b9372dbba91259c2fda Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 6 Apr 2022 23:40:20 -0600 Subject: [PATCH] Add wallet balance check (#9) --- www/assets/images/crypto/BCH.svg | 17 +++++++++ www/assets/images/crypto/BTC.svg | 15 ++++++++ www/assets/images/crypto/DOGE.svg | 1 + www/assets/images/crypto/ETH.svg | 21 +++++++++++ www/assets/images/crypto/LTC.svg | 1 + www/assets/images/crypto/USDC.svg | 5 +++ www/assets/js/crypto.js | 60 +++++++++++++++++++++++++++++++ www/index.html | 1 + www/pages/crypto.html | 46 ++++++++++++++++++++++-- www/settings.js | 3 +- 10 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 www/assets/images/crypto/BCH.svg create mode 100644 www/assets/images/crypto/BTC.svg create mode 100644 www/assets/images/crypto/DOGE.svg create mode 100644 www/assets/images/crypto/ETH.svg create mode 100644 www/assets/images/crypto/LTC.svg create mode 100644 www/assets/images/crypto/USDC.svg create mode 100644 www/assets/js/crypto.js diff --git a/www/assets/images/crypto/BCH.svg b/www/assets/images/crypto/BCH.svg new file mode 100644 index 0000000..6f541ea --- /dev/null +++ b/www/assets/images/crypto/BCH.svg @@ -0,0 +1,17 @@ + + + + + + + diff --git a/www/assets/images/crypto/BTC.svg b/www/assets/images/crypto/BTC.svg new file mode 100644 index 0000000..2b75c99 --- /dev/null +++ b/www/assets/images/crypto/BTC.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + diff --git a/www/assets/images/crypto/DOGE.svg b/www/assets/images/crypto/DOGE.svg new file mode 100644 index 0000000..c435731 --- /dev/null +++ b/www/assets/images/crypto/DOGE.svg @@ -0,0 +1 @@ +Dogecoin (DOGE) \ No newline at end of file diff --git a/www/assets/images/crypto/ETH.svg b/www/assets/images/crypto/ETH.svg new file mode 100644 index 0000000..684e968 --- /dev/null +++ b/www/assets/images/crypto/ETH.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + diff --git a/www/assets/images/crypto/LTC.svg b/www/assets/images/crypto/LTC.svg new file mode 100644 index 0000000..13e76a4 --- /dev/null +++ b/www/assets/images/crypto/LTC.svg @@ -0,0 +1 @@ +litecoin-ltc-logo \ No newline at end of file diff --git a/www/assets/images/crypto/USDC.svg b/www/assets/images/crypto/USDC.svg new file mode 100644 index 0000000..5dfea92 --- /dev/null +++ b/www/assets/images/crypto/USDC.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/www/assets/js/crypto.js b/www/assets/js/crypto.js new file mode 100644 index 0000000..df30dd6 --- /dev/null +++ b/www/assets/js/crypto.js @@ -0,0 +1,60 @@ +/* + * 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/. + */ + +var walletPubKeyRegex = /^[0-9a-zA-Z]{25,}$/; + +function scanWalletQrCode(callback) { + scanBarcode(function (result) { + if (walletPubKeyRegex.test(result)) { + callback(result); + } else { + app.dialog.alert("That doesn't look like a valid wallet address.", "Error"); + return; + } + }, function () { + app.dialog.alert("Something went wrong and we can't scan right now.", "Error"); + }); +} + +function displayWalletBalance(address) { + if (!walletPubKeyRegex.test(address)) { + app.dialog.alert("That doesn't look like a valid wallet address.", "Error"); + return; + } + + app.dialog.preloader("Loading..."); + apirequest(SETTINGS.apis.walletbalance, { + walletaddress: address + }, function (resp) { + app.dialog.close(); + if (resp.status == "OK") { + $("#walletBalancePopup #walletBalanceAmount").text(resp.balance + " " + resp.currency); + $("#walletBalancePopup #walletFiatAmount").text(resp.usdvalue); + $("#walletBalancePopup #walletCurrency").text(resp.label); + $("#walletBalancePopup #walletBalanceAttribution").text(resp.attribution); + $("#walletBalancePopup #walletBalanceLogo").attr("src", "./assets/images/crypto/" + resp.currency + ".svg"); + app.popup.open("#walletBalancePopup"); + } else { + app.dialog.alert(resp.msg, "Error"); + } + }, function (error) { + app.dialog.close(); + try { + var error = $.parseJSON(error.responseText); + if (error && typeof error.msg != 'undefined') { + app.dialog.alert(error.msg, "Error"); + sendErrorReport("Crypto", "Couldn't get wallet balance", error.msg); + } else { + app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); + sendErrorReport("Crypto", "Couldn't get wallet balance", "Server/network problem: " + xhr.status + ": " + xhr.statusText); + } + } catch (ex) { + app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); + sendErrorReport("Crypto", "Couldn't get wallet balance", "Server/network problem: " + xhr.status + ": " + xhr.statusText); + } + }); + +} \ No newline at end of file diff --git a/www/index.html b/www/index.html index 85218f8..3739cc0 100644 --- a/www/index.html +++ b/www/index.html @@ -63,6 +63,7 @@ + diff --git a/www/pages/crypto.html b/www/pages/crypto.html index ecac78d..a7af1a2 100644 --- a/www/pages/crypto.html +++ b/www/pages/crypto.html @@ -21,12 +21,52 @@
-
-
- +
+
Check Wallet Balance
+
+ Check the current balance of your physical crypto wallet. Just press the button and point your camera at the Public Address code, or type in the address manually. +
+
+
  Scan Wallet
+
+
+
+
    +
  • +
    +
    + + +
    +
    +
  • +
+
+
  Check Manually
+ +
\ No newline at end of file diff --git a/www/settings.js b/www/settings.js index 9365a53..ea6d006 100644 --- a/www/settings.js +++ b/www/settings.js @@ -24,7 +24,8 @@ var SETTINGS = { shopitems: "http://localhost/helena.express/apis/shop/items", shopbuy: "http://localhost/helena.express/apis/shop/buy", getreceipts: "http://localhost/helena.express/apis/account/getreceipts", - getreceipt: "http://localhost/helena.express/apis/account/getreceipt" + getreceipt: "http://localhost/helena.express/apis/account/getreceipt", + walletbalance: "http://localhost/helena.express/apis/walletbalance" }, stripe_pubkey: "pk_test_51J6qFXCa1Fboir5UzPO3LCiMsVNiFP2lq4wR0dEcjJJVzAaJ3uRggDekZPB3qeYpMD3ayIYHKyD5sSn0IFLlEXMW001LqrvGSH", branding: {