aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-05-20 05:46:50 +0800
committerDan Finlay <dan@danfinlay.com>2016-05-20 05:46:50 +0800
commit60270de53d214edffad7b90356bbe06081a55443 (patch)
tree67a648b43cbb604507ccd793e9a44cbbe24deb23
parent22a77b80411350bd844313b51ea58312940b9738 (diff)
downloadtangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.tar
tangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.tar.gz
tangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.tar.bz2
tangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.tar.lz
tangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.tar.xz
tangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.tar.zst
tangerine-wallet-browser-60270de53d214edffad7b90356bbe06081a55443.zip
Add full precision to send tx value field.
-rw-r--r--CHANGELOG.md9
-rw-r--r--test/unit/util_test.js14
-rw-r--r--ui/app/send.js4
-rw-r--r--ui/app/util.js15
4 files changed, 36 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b713433a2..8681c9517 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,10 +2,11 @@
## Current Master
-- UI Overhaul per Vlad Todirut's designs
-- Replaced identicons with jazzicons
-- Fixed glitchy transitions
-- Added support for capitalization-based address checksums
+- UI Overhaul per Vlad Todirut's designs.
+- Replaced identicons with jazzicons.
+- Fixed glitchy transitions.
+- Added support for capitalization-based address checksums.
+- Send value is no longer limited by javascript number precision, and is always in ETH.
## 1.8.4 2016-05-13
diff --git a/test/unit/util_test.js b/test/unit/util_test.js
index 5f28dbb25..b091d5bc7 100644
--- a/test/unit/util_test.js
+++ b/test/unit/util_test.js
@@ -159,6 +159,20 @@ describe('util', function() {
})
})
+ describe('normalizeEthStringToWei', function() {
+ it('should convert decimal eth to pure wei BN', function() {
+ var input = '1.23456789'
+ var output = util.normalizeEthStringToWei(input)
+ assert.equal(output.toString(10), '1234567890000000000')
+ })
+
+ it('should convert 1 to expected wei', function() {
+ var input = '1'
+ var output = util.normalizeEthStringToWei(input)
+ assert.equal(output.toString(10), ethInWei)
+ })
+ })
+
describe('#normalizeNumberToWei', function() {
it('should handle a simple use case', function() {
diff --git a/ui/app/send.js b/ui/app/send.js
index ea9dd7c0c..926c3e29a 100644
--- a/ui/app/send.js
+++ b/ui/app/send.js
@@ -209,8 +209,8 @@ SendTransactionScreen.prototype.back = function() {
SendTransactionScreen.prototype.onSubmit = function() {
const recipient = document.querySelector('input[name="address"]').value
- const inputAmount = parseFloat(document.querySelector('input[name="amount"]').value)
- const value = util.normalizeNumberToWei(inputAmount, 'ether')
+ const input = document.querySelector('input[name="amount"]').value
+ const value = util.normalizeEthStringToWei(input)
const txData = document.querySelector('input[name="txData"]').value
const balance = this.props.balance
diff --git a/ui/app/util.js b/ui/app/util.js
index 7597c2df8..31c147877 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -31,6 +31,7 @@ module.exports = {
ethToWei: ethToWei,
weiToEth: weiToEth,
normalizeToWei: normalizeToWei,
+ normalizeEthStringToWei: normalizeEthStringToWei,
normalizeNumberToWei: normalizeNumberToWei,
valueTable: valueTable,
bnTable: bnTable,
@@ -120,6 +121,20 @@ function normalizeToWei(amount, currency) {
return amount
}
+function normalizeEthStringToWei(str) {
+ const parts = str.split('.')
+ let eth = new ethUtil.BN(parts[0], 10).mul(bnTable.wei)
+ if (parts[1]) {
+ var decimal = parts[1]
+ while(decimal.length < 18) {
+ decimal += '0'
+ }
+ const decimalBN = new ethUtil.BN(decimal, 10)
+ eth = eth.add(decimalBN)
+ }
+ return eth
+}
+
var multiple = new ethUtil.BN('10000', 10)
function normalizeNumberToWei(n, currency) {
var enlarged = n * 10000