From 13eca3d113fc3558f82bc4951598cca79f270cd0 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 13 Oct 2016 07:07:22 -0700 Subject: Fix wallet bugs --- public/js/wallet.coffee | 7 ++++--- public/js/wallet.js | 9 ++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/public/js/wallet.coffee b/public/js/wallet.coffee index 53734be6..3158c99d 100644 --- a/public/js/wallet.coffee +++ b/public/js/wallet.coffee @@ -274,7 +274,7 @@ createWallet = -> getBalance = -> $.get("#{g.api}/addrs/#{g.user.username}/balance?omitWalletAddresses=true", (data) -> balance = data.final_balance - g.balance = balance.toBTC() + g.balance = parseFloat(balance.toBTC()) fiat = balance.toFiat() $('#balance').html(g.balance) $('#fiat').html("#{fiat} #{g.user.currency}") @@ -352,7 +352,7 @@ sendTransaction = -> else data.signatures = data.tosign.map((tosign, i) -> path = data.tx.inputs[i].hd_path.split('/') - key = g.key.derive(path[1]).derive(path[2]) + key = g.key.derive(parseInt(path[1])).derive(parseInt(path[2])) data.pubkeys.push(key.keyPair.getPublicKeyBuffer().toString('hex')) key.keyPair.sign(new buffer.Buffer(tosign, "hex")).toDER().toString("hex") ) @@ -404,6 +404,7 @@ displayErrors = (data, dialog) -> convertedAmount = -> + g.amount = amount unless g.amount and isNumeric(g.amount) amount = parseFloat($('#amount').val() * multiplier() / g.exchange).toFixed(precision()) difference = parseFloat(Math.abs(g.amount - amount).toFixed(precision())) tolerance = parseFloat((.00000002 * g.exchange * multiplier()).toFixed(precision())) @@ -442,7 +443,7 @@ Number.prototype.toBTC = -> parseFloat((this / 100000000 * multiplier())).toFixed(precision()) Number.prototype.toFiat = -> - (this * g.exchange / 100000000).toFixed(2) + parseFloat((this * g.exchange / 100000000)).toFixed(2) Number.prototype.toSatoshis = -> parseInt(this * 100000000 / multiplier()) diff --git a/public/js/wallet.js b/public/js/wallet.js index c7cdd4c3..c9bb846f 100644 --- a/public/js/wallet.js +++ b/public/js/wallet.js @@ -324,7 +324,7 @@ return $.get("" + g.api + "/addrs/" + g.user.username + "/balance?omitWalletAddresses=true", function(data) { var balance, fiat; balance = data.final_balance; - g.balance = balance.toBTC(); + g.balance = parseFloat(balance.toBTC()); fiat = balance.toFiat(); $('#balance').html(g.balance); $('#fiat').html("" + fiat + " " + g.user.currency); @@ -424,7 +424,7 @@ data.signatures = data.tosign.map(function(tosign, i) { var key, path; path = data.tx.inputs[i].hd_path.split('/'); - key = g.key.derive(path[1]).derive(path[2]); + key = g.key.derive(parseInt(path[1])).derive(parseInt(path[2])); data.pubkeys.push(key.keyPair.getPublicKeyBuffer().toString('hex')); return key.keyPair.sign(new buffer.Buffer(tosign, "hex")).toDER().toString("hex"); }); @@ -491,6 +491,9 @@ convertedAmount = function() { var amount, difference, tolerance; + if (!(g.amount && isNumeric(g.amount))) { + g.amount = amount; + } amount = parseFloat($('#amount').val() * multiplier() / g.exchange).toFixed(precision()); difference = parseFloat(Math.abs(g.amount - amount).toFixed(precision())); tolerance = parseFloat((.00000002 * g.exchange * multiplier()).toFixed(precision())); @@ -543,7 +546,7 @@ }; Number.prototype.toFiat = function() { - return (this * g.exchange / 100000000).toFixed(2); + return parseFloat(this * g.exchange / 100000000).toFixed(2); }; Number.prototype.toSatoshis = function() { -- cgit v1.2.3