1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Merge pull request #2549 from danjm/NewUI-flat-send-amount-fixes

[NewUI] Fix issues with amount max
This commit is contained in:
Daniel Tsui 2017-11-07 19:52:08 -06:00 committed by GitHub
commit a21f6f5f63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 20 deletions

View File

@ -11,11 +11,6 @@ function CurrencyDisplay () {
Component.call(this)
}
function isValidInput (text) {
const re = /^([1-9]\d*|0)(\.|\.\d*)?$/
return re.test(text)
}
function toHexWei (value) {
return conversionUtil(value, {
fromNumericBase: 'dec',
@ -36,6 +31,28 @@ CurrencyDisplay.prototype.getAmount = function (value) {
: toHexWei(value)
}
CurrencyDisplay.prototype.getValueToRender = function () {
const { selectedToken, conversionRate, value } = this.props
const { decimals, symbol } = selectedToken || {}
const multiplier = Math.pow(10, Number(decimals || 0))
return selectedToken
? conversionUtil(value, {
fromNumericBase: 'hex',
toCurrency: symbol,
conversionRate: multiplier,
invertConversionRate: true,
})
: conversionUtil(value, {
fromNumericBase: 'hex',
toNumericBase: 'dec',
fromDenomination: 'WEI',
numberOfDecimals: 6,
conversionRate,
})
}
CurrencyDisplay.prototype.render = function () {
const {
className = 'currency-display',
@ -46,17 +63,10 @@ CurrencyDisplay.prototype.render = function () {
convertedCurrency,
readOnly = false,
inError = false,
value,
handleChange,
} = this.props
const valueToRender = conversionUtil(value, {
fromNumericBase: 'hex',
toNumericBase: 'dec',
fromDenomination: 'WEI',
numberOfDecimals: 6,
conversionRate,
})
const valueToRender = this.getValueToRender()
const convertedValue = conversionUtil(valueToRender, {
fromNumericBase: 'dec',
@ -66,8 +76,6 @@ CurrencyDisplay.prototype.render = function () {
conversionRate,
})
const inputSizeMultiplier = readOnly ? 1 : 1.2
return h('div', {
className,
style: {

View File

@ -307,7 +307,6 @@ SendTransactionScreen.prototype.handleAmountChange = function (value) {
SendTransactionScreen.prototype.setAmountToMax = function () {
const {
from: { balance },
gasTotal,
updateSendAmount,
updateSendErrors,
updateGasPrice,
@ -323,14 +322,16 @@ SendTransactionScreen.prototype.setAmountToMax = function () {
? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
: subtractCurrencies(
ethUtil.addHexPrefix(balance),
ethUtil.addHexPrefix(gasTotal),
ethUtil.addHexPrefix(MIN_GAS_TOTAL),
{ toNumericBase: 'hex' }
)
updateSendErrors({ amount: null })
updateGasPrice(MIN_GAS_PRICE_HEX)
updateGasLimit(MIN_GAS_LIMIT_HEX)
updateGasTotal(MIN_GAS_TOTAL)
if (!selectedToken) {
updateGasPrice(MIN_GAS_PRICE_HEX)
updateGasLimit(MIN_GAS_LIMIT_HEX)
updateGasTotal(MIN_GAS_TOTAL)
}
updateSendAmount(maxAmount)
}