mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #2818 from MetaMask/i2782-ethroundingerror
Fix rounding error in ether input on send screen
This commit is contained in:
commit
a22e98910d
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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 () {
|
||||
|
@ -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.'
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user