mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #2549 from danjm/NewUI-flat-send-amount-fixes
[NewUI] Fix issues with amount max
This commit is contained in:
commit
a21f6f5f63
@ -11,11 +11,6 @@ function CurrencyDisplay () {
|
|||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidInput (text) {
|
|
||||||
const re = /^([1-9]\d*|0)(\.|\.\d*)?$/
|
|
||||||
return re.test(text)
|
|
||||||
}
|
|
||||||
|
|
||||||
function toHexWei (value) {
|
function toHexWei (value) {
|
||||||
return conversionUtil(value, {
|
return conversionUtil(value, {
|
||||||
fromNumericBase: 'dec',
|
fromNumericBase: 'dec',
|
||||||
@ -36,6 +31,28 @@ CurrencyDisplay.prototype.getAmount = function (value) {
|
|||||||
: toHexWei(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 () {
|
CurrencyDisplay.prototype.render = function () {
|
||||||
const {
|
const {
|
||||||
className = 'currency-display',
|
className = 'currency-display',
|
||||||
@ -46,17 +63,10 @@ CurrencyDisplay.prototype.render = function () {
|
|||||||
convertedCurrency,
|
convertedCurrency,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
inError = false,
|
inError = false,
|
||||||
value,
|
|
||||||
handleChange,
|
handleChange,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const valueToRender = conversionUtil(value, {
|
const valueToRender = this.getValueToRender()
|
||||||
fromNumericBase: 'hex',
|
|
||||||
toNumericBase: 'dec',
|
|
||||||
fromDenomination: 'WEI',
|
|
||||||
numberOfDecimals: 6,
|
|
||||||
conversionRate,
|
|
||||||
})
|
|
||||||
|
|
||||||
const convertedValue = conversionUtil(valueToRender, {
|
const convertedValue = conversionUtil(valueToRender, {
|
||||||
fromNumericBase: 'dec',
|
fromNumericBase: 'dec',
|
||||||
@ -66,8 +76,6 @@ CurrencyDisplay.prototype.render = function () {
|
|||||||
conversionRate,
|
conversionRate,
|
||||||
})
|
})
|
||||||
|
|
||||||
const inputSizeMultiplier = readOnly ? 1 : 1.2
|
|
||||||
|
|
||||||
return h('div', {
|
return h('div', {
|
||||||
className,
|
className,
|
||||||
style: {
|
style: {
|
||||||
|
@ -307,7 +307,6 @@ SendTransactionScreen.prototype.handleAmountChange = function (value) {
|
|||||||
SendTransactionScreen.prototype.setAmountToMax = function () {
|
SendTransactionScreen.prototype.setAmountToMax = function () {
|
||||||
const {
|
const {
|
||||||
from: { balance },
|
from: { balance },
|
||||||
gasTotal,
|
|
||||||
updateSendAmount,
|
updateSendAmount,
|
||||||
updateSendErrors,
|
updateSendErrors,
|
||||||
updateGasPrice,
|
updateGasPrice,
|
||||||
@ -323,14 +322,16 @@ SendTransactionScreen.prototype.setAmountToMax = function () {
|
|||||||
? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
|
? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
|
||||||
: subtractCurrencies(
|
: subtractCurrencies(
|
||||||
ethUtil.addHexPrefix(balance),
|
ethUtil.addHexPrefix(balance),
|
||||||
ethUtil.addHexPrefix(gasTotal),
|
ethUtil.addHexPrefix(MIN_GAS_TOTAL),
|
||||||
{ toNumericBase: 'hex' }
|
{ toNumericBase: 'hex' }
|
||||||
)
|
)
|
||||||
|
|
||||||
updateSendErrors({ amount: null })
|
updateSendErrors({ amount: null })
|
||||||
updateGasPrice(MIN_GAS_PRICE_HEX)
|
if (!selectedToken) {
|
||||||
updateGasLimit(MIN_GAS_LIMIT_HEX)
|
updateGasPrice(MIN_GAS_PRICE_HEX)
|
||||||
updateGasTotal(MIN_GAS_TOTAL)
|
updateGasLimit(MIN_GAS_LIMIT_HEX)
|
||||||
|
updateGasTotal(MIN_GAS_TOTAL)
|
||||||
|
}
|
||||||
updateSendAmount(maxAmount)
|
updateSendAmount(maxAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user