/* * 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); } }); }