From 3d627e869bb7ba1dc0316ad179f9fff07e5cb83c Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 17:26:38 -0800 Subject: [PATCH 1/7] Add test for edge case. --- test/unit/util_test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 3a8b6bdfd..1d6e38c5d 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -201,6 +201,12 @@ describe('util', function () { var output = util.normalizeEthStringToWei(input) assert.equal(output.toString(10), ethInWei) }) + + it('should account for overflow numbers gracefully by dropping extra precision.', function () { + var input = '1.11111111111111111111' + var output = util.normalizeEthStringToWei(input) + assert.equal(output.toString(10), '1111111111111111111') + }) }) describe('#normalizeNumberToWei', function () { From 414f89668eb554e82ab22d3b3080322057388266 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 17:27:48 -0800 Subject: [PATCH 2/7] Fix some silly linting issues. --- app/scripts/lib/tx-gas-utils.js | 2 +- app/scripts/notice-controller.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/lib/tx-gas-utils.js b/app/scripts/lib/tx-gas-utils.js index 56bee19f7..247b34e47 100644 --- a/app/scripts/lib/tx-gas-utils.js +++ b/app/scripts/lib/tx-gas-utils.js @@ -26,7 +26,7 @@ module.exports = class txProvideUtil { err.message.includes('Transaction execution error.') || err.message.includes('gas required exceeds allowance or always failing transaction') ) - if ( simulationFailed ) { + if (simulationFailed) { txMeta.simulationFails = true return txMeta } diff --git a/app/scripts/notice-controller.js b/app/scripts/notice-controller.js index db2b8c4f4..14a63eae7 100644 --- a/app/scripts/notice-controller.js +++ b/app/scripts/notice-controller.js @@ -77,7 +77,7 @@ module.exports = class NoticeController extends EventEmitter { return uniqBy(oldNotices.concat(newNotices), 'id') } - _filterNotices(notices) { + _filterNotices (notices) { return notices.filter((newNotice) => { if ('version' in newNotice) { const satisfied = semver.satisfies(this.version, newNotice.version) From 3e562f1a1e594955f203b75a0be595e4bd6bca76 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 17:31:38 -0800 Subject: [PATCH 3/7] Add backend fix for util in normalizeethstringtowei. --- ui/app/util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/app/util.js b/ui/app/util.js index 3f8b4dcc3..293f4228c 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -193,6 +193,9 @@ function normalizeEthStringToWei (str) { while (decimal.length < 18) { decimal += '0' } + if (decimal.length > 18) { + decimal = decimal.slice(0, 18) + } const decimalBN = new ethUtil.BN(decimal, 10) eth = eth.add(decimalBN) } From adf4b89804af8b8f4e9a543a912f548715720d64 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 17:33:28 -0800 Subject: [PATCH 4/7] Add additional test to ui utils to account for exact wei values. --- test/unit/util_test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 1d6e38c5d..59048975a 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -207,6 +207,12 @@ describe('util', function () { var output = util.normalizeEthStringToWei(input) assert.equal(output.toString(10), '1111111111111111111') }) + + it('should not truncate very exact wei values that do not have extra precision.', function () { + var input = '1.100000000000000001' + var output = util.normalizeEthStringToWei(input) + assert.equal(output.toString(10), '1100000000000000001') + }) }) describe('#normalizeNumberToWei', function () { From 92eb16fc112eeac749c0ddfff163773ce3a35ef2 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 17:36:56 -0800 Subject: [PATCH 5/7] Add frontend validation to check if send ether input is a valid number. --- ui/app/send.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ui/app/send.js b/ui/app/send.js index e59c1130e..7b31eef7e 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -247,6 +247,12 @@ SendTransactionScreen.prototype.onSubmit = function () { const recipient = state.recipient || document.querySelector('input[name="address"]').value.replace(/^[.\s]+|[.\s]+$/g, '') const nickname = state.nickname || ' ' const input = document.querySelector('input[name="amount"]').value + + if (isNaN(input)) { + message = 'Invalid ether value.' + return this.props.dispatch(actions.displayWarning(message)) + } + const value = util.normalizeEthStringToWei(input) const txData = document.querySelector('input[name="txData"]').value const balance = this.props.balance From e682fb05fcdeca5f50a2176934d25935e13538f6 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 18:22:10 -0800 Subject: [PATCH 6/7] Add frontend validation to ensure that ether inputs are valid. --- ui/app/send.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/app/send.js b/ui/app/send.js index 7b31eef7e..09c9e03d4 100644 --- a/ui/app/send.js +++ b/ui/app/send.js @@ -247,16 +247,26 @@ SendTransactionScreen.prototype.onSubmit = function () { const recipient = state.recipient || document.querySelector('input[name="address"]').value.replace(/^[.\s]+|[.\s]+$/g, '') const nickname = state.nickname || ' ' const input = document.querySelector('input[name="amount"]').value + const parts = input.split('') - if (isNaN(input)) { + let message + + if (isNaN(input) || input === '') { message = 'Invalid ether value.' return this.props.dispatch(actions.displayWarning(message)) } + if (parts[1]) { + var decimal = parts[1] + if (decimal.length > 18) { + message = 'Ether amount is too precise.' + return this.props.dispatch(actions.displayWarning(message)) + } + } + const value = util.normalizeEthStringToWei(input) const txData = document.querySelector('input[name="txData"]').value const balance = this.props.balance - let message if (value.gt(balance)) { message = 'Insufficient funds.' From c3d85c0a66676a15b598424e379610237243cb10 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Wed, 27 Dec 2017 18:23:05 -0800 Subject: [PATCH 7/7] Bump Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c1c1dcb4..dfcd0d1b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Fix bug that prevented updating custom token details. - No longer mark long-pending transactions as failed, since we now have button to retry with higher gas. +- Fix rounding error when specifying an ether amount that has too much precision. ## 3.13.3 2017-12-14