From 22a77b80411350bd844313b51ea58312940b9738 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 19 May 2016 14:21:35 -0700 Subject: [PATCH] Increase send value precision --- test/unit/util_test.js | 8 ++++++++ ui/app/send.js | 2 +- ui/app/util.js | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 020fad783..5f28dbb25 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -61,6 +61,7 @@ describe('util', function() { var result = util.isValidAddress(address) assert.ok(!result) }) + }) describe('numericBalance', function() { @@ -160,6 +161,13 @@ describe('util', function() { describe('#normalizeNumberToWei', function() { + it('should handle a simple use case', function() { + var input = 0.0002 + var output = util.normalizeNumberToWei(input, 'ether') + var str = output.toString(10) + assert.equal(str, '200000000000000') + }) + it('should convert a kwei number to the appropriate equivalent wei', function() { var result = util.normalizeNumberToWei(1.111, 'kwei') assert.equal(result.toString(10), '1111', 'accepts decimals') diff --git a/ui/app/send.js b/ui/app/send.js index 044311b94..ea9dd7c0c 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -219,7 +219,7 @@ SendTransactionScreen.prototype.onSubmit = function() { return this.props.dispatch(actions.displayWarning(message)) } - if ((util.isValidAddress(recipient) && !txData) || (!recipient && !txData)) { + if ((!util.isValidAddress(recipient) && !txData) || (!recipient && !txData)) { var message = 'Recipient address is invalid.' return this.props.dispatch(actions.displayWarning(message)) } diff --git a/ui/app/util.js b/ui/app/util.js index d8a0313ea..7597c2df8 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -120,9 +120,9 @@ function normalizeToWei(amount, currency) { return amount } -var multiple = new ethUtil.BN('1000', 10) +var multiple = new ethUtil.BN('10000', 10) function normalizeNumberToWei(n, currency) { - var enlarged = n * 1000 + var enlarged = n * 10000 var amount = new ethUtil.BN(String(enlarged), 10) return normalizeToWei(amount, currency).div(multiple) }