aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--app/scripts/lib/tx-gas-utils.js2
-rw-r--r--app/scripts/notice-controller.js2
-rw-r--r--test/unit/util_test.js12
-rw-r--r--ui/app/send.js18
-rw-r--r--ui/app/util.js3
6 files changed, 35 insertions, 3 deletions
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
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)
diff --git a/test/unit/util_test.js b/test/unit/util_test.js
index 3a8b6bdfd..59048975a 100644
--- a/test/unit/util_test.js
+++ b/test/unit/util_test.js
@@ -201,6 +201,18 @@ 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')
+ })
+
+ 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 () {
diff --git a/ui/app/send.js b/ui/app/send.js
index e59c1130e..09c9e03d4 100644
--- a/ui/app/send.js
+++ b/ui/app/send.js
@@ -247,10 +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('')
+
+ 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.'
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)
}