1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

Amount field shows insufficient funds error based on amoutn + gas total.

This commit is contained in:
Dan 2017-10-19 15:53:02 -02:30 committed by Chi Kei Chan
parent f01d119cc1
commit bd11e60b8c
2 changed files with 22 additions and 7 deletions

View File

@ -132,12 +132,16 @@ const conversionUtil = (value, {
});
const addCurrencies = (a, b, options = {}) => {
const { toNumericBase, numberOfDecimals } = options
const value = (new BigNumber(a)).add(b);
const {
aBase,
bBase,
...conversionOptions,
} = options
const value = (new BigNumber(a, aBase)).add(b, bBase);
return converter({
value,
toNumericBase,
numberOfDecimals,
...conversionOptions,
})
}

View File

@ -12,7 +12,11 @@ const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
const { showModal } = require('./actions')
const { multiplyCurrencies, conversionGreaterThan } = require('./conversion-util')
const {
multiplyCurrencies,
conversionGreaterThan,
addCurrencies,
} = require('./conversion-util')
const { isValidAddress } = require('./util')
module.exports = SendTransactionScreen
@ -225,12 +229,19 @@ SendTransactionScreen.prototype.validateAmount = function (value) {
conversionRate,
primaryCurrency,
toCurrency,
selectedToken
selectedToken,
gasTotal,
} = this.props
const amount = value
let amountError = null
const totalAmount = addCurrencies(amount, gasTotal, {
aBase: 16,
bBase: 16,
toNumericBase: 'hex',
})
const sufficientBalance = conversionGreaterThan(
{
value: balance,
@ -239,7 +250,7 @@ SendTransactionScreen.prototype.validateAmount = function (value) {
conversionRate,
},
{
value: amount,
value: totalAmount,
fromNumericBase: 'hex',
conversionRate: amountConversionRate,
fromCurrency: selectedToken || primaryCurrency,