From d6ab6bb4fa506c5fb9479b6e534ab74632c1b819 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 19 Apr 2016 18:56:22 -0700 Subject: Fix floating point input bug When sending a transaction, we were converting to BN before handling decimals, which meant we were losing any precision past a decimal point, since BN does not handle decimals! Put this numeric normalization into a utility function with a test around it and got it working. --- ui/app/util.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'ui/app/util.js') diff --git a/ui/app/util.js b/ui/app/util.js index 18862fade..bacf00c66 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -28,6 +28,7 @@ module.exports = { ethToWei: ethToWei, weiToEth: weiToEth, normalizeToWei: normalizeToWei, + normalizeNumberToWei: normalizeNumberToWei, valueTable: valueTable, bnTable: bnTable, } @@ -85,13 +86,20 @@ function dataSize(data) { // returns a BN in wei function normalizeToWei(amount, currency) { try { - var ether = amount.div(bnTable[currency]) - var wei = ether.mul(bnTable.wei) - return wei + return amount.mul(bnTable.wei).div(bnTable[currency]) } catch (e) {} return amount } +var multiple = new ethUtil.BN('1000', 10) +function normalizeNumberToWei(n, currency) { + var enlarged = n * 1000 + console.log(`Enlarged, we have ${enlarged}`) + var amount = new ethUtil.BN(String(enlarged), 10) + console.log("Amount inside is "+ amount.toString(10)) + return normalizeToWei(amount, currency).div(multiple) +} + function readableDate(ms) { var date = new Date(ms) var month = date.getMonth() -- cgit From 7276e8081672cd4d30f00cc76298d4fb28a9cca1 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 19 Apr 2016 18:58:34 -0700 Subject: Removed logs --- ui/app/util.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'ui/app/util.js') diff --git a/ui/app/util.js b/ui/app/util.js index bacf00c66..5dbcffa7e 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -94,9 +94,7 @@ function normalizeToWei(amount, currency) { var multiple = new ethUtil.BN('1000', 10) function normalizeNumberToWei(n, currency) { var enlarged = n * 1000 - console.log(`Enlarged, we have ${enlarged}`) var amount = new ethUtil.BN(String(enlarged), 10) - console.log("Amount inside is "+ amount.toString(10)) return normalizeToWei(amount, currency).div(multiple) } -- cgit