mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Adds max amount feature for send-ether
This commit is contained in:
parent
67bdfe87e3
commit
319779ab08
@ -22,7 +22,7 @@ function isBalanceSufficient({
|
|||||||
toNumericBase: 'hex',
|
toNumericBase: 'hex',
|
||||||
})
|
})
|
||||||
|
|
||||||
const balanceIsSufficient = conversionGreaterThan(
|
const balanceIsSufficient = conversionGTE(
|
||||||
{
|
{
|
||||||
value: balance,
|
value: balance,
|
||||||
fromNumericBase: 'hex',
|
fromNumericBase: 'hex',
|
||||||
|
@ -66,6 +66,8 @@ function mapDispatchToProps (dispatch) {
|
|||||||
setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)),
|
setSelectedAddress: address => dispatch(actions.setSelectedAddress(address)),
|
||||||
addToAddressBook: address => dispatch(actions.addToAddressBook(address)),
|
addToAddressBook: address => dispatch(actions.addToAddressBook(address)),
|
||||||
updateGasTotal: newTotal => dispatch(actions.updateGasTotal(newTotal)),
|
updateGasTotal: newTotal => dispatch(actions.updateGasTotal(newTotal)),
|
||||||
|
updateGasPrice: newGasPrice => dispatch(actions.updateGasPrice(newGasPrice)),
|
||||||
|
updateGasLimit: newGasLimit => dispatch(actions.updateGasLimit(newGasLimit)),
|
||||||
updateSendTokenBalance: tokenBalance => dispatch(actions.updateSendTokenBalance(tokenBalance)),
|
updateSendTokenBalance: tokenBalance => dispatch(actions.updateSendTokenBalance(tokenBalance)),
|
||||||
updateSendFrom: newFrom => dispatch(actions.updateSendFrom(newFrom)),
|
updateSendFrom: newFrom => dispatch(actions.updateSendFrom(newFrom)),
|
||||||
updateSendTo: newTo => dispatch(actions.updateSendTo(newTo)),
|
updateSendTo: newTo => dispatch(actions.updateSendTo(newTo)),
|
||||||
|
@ -145,6 +145,20 @@ const addCurrencies = (a, b, options = {}) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const subtractCurrencies = (a, b, options = {}) => {
|
||||||
|
const {
|
||||||
|
aBase,
|
||||||
|
bBase,
|
||||||
|
...conversionOptions,
|
||||||
|
} = options
|
||||||
|
const value = (new BigNumber(a, aBase)).minus(b, bBase);
|
||||||
|
|
||||||
|
return converter({
|
||||||
|
value,
|
||||||
|
...conversionOptions,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const multiplyCurrencies = (a, b, options = {}) => {
|
const multiplyCurrencies = (a, b, options = {}) => {
|
||||||
const {
|
const {
|
||||||
multiplicandBase,
|
multiplicandBase,
|
||||||
@ -203,4 +217,5 @@ module.exports = {
|
|||||||
conversionGTE,
|
conversionGTE,
|
||||||
conversionLTE,
|
conversionLTE,
|
||||||
toNegative,
|
toNegative,
|
||||||
|
subtractCurrencies,
|
||||||
}
|
}
|
||||||
|
@ -629,6 +629,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&__amount-max {
|
||||||
|
color: $curious-blue;
|
||||||
|
font-family: Roboto;
|
||||||
|
font-size: 12px;
|
||||||
|
left: 8px;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
&__gas-fee-display {
|
&__gas-fee-display {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ const { inherits } = require('util')
|
|||||||
const PersistentForm = require('../lib/persistent-form')
|
const PersistentForm = require('../lib/persistent-form')
|
||||||
const h = require('react-hyperscript')
|
const h = require('react-hyperscript')
|
||||||
|
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
|
||||||
const Identicon = require('./components/identicon')
|
const Identicon = require('./components/identicon')
|
||||||
const FromDropdown = require('./components/send/from-dropdown')
|
const FromDropdown = require('./components/send/from-dropdown')
|
||||||
const ToAutoComplete = require('./components/send/to-autocomplete')
|
const ToAutoComplete = require('./components/send/to-autocomplete')
|
||||||
@ -9,12 +11,17 @@ const CurrencyDisplay = require('./components/send/currency-display')
|
|||||||
const MemoTextArea = require('./components/send/memo-textarea')
|
const MemoTextArea = require('./components/send/memo-textarea')
|
||||||
const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
|
const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
|
||||||
|
|
||||||
const { MIN_GAS_TOTAL } = require('./components/send/send-constants')
|
const {
|
||||||
|
MIN_GAS_TOTAL,
|
||||||
|
MIN_GAS_PRICE_HEX,
|
||||||
|
MIN_GAS_LIMIT_HEX,
|
||||||
|
} = require('./components/send/send-constants')
|
||||||
const abi = require('human-standard-token-abi')
|
const abi = require('human-standard-token-abi')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
multiplyCurrencies,
|
multiplyCurrencies,
|
||||||
conversionGreaterThan,
|
conversionGreaterThan,
|
||||||
|
subtractCurrencies,
|
||||||
} = require('./conversion-util')
|
} = require('./conversion-util')
|
||||||
const {
|
const {
|
||||||
calcTokenAmount,
|
calcTokenAmount,
|
||||||
@ -305,6 +312,30 @@ SendTransactionScreen.prototype.handleAmountChange = function (value) {
|
|||||||
updateSendAmount(amount)
|
updateSendAmount(amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendTransactionScreen.prototype.setAmountToMax = function () {
|
||||||
|
const {
|
||||||
|
from: { balance },
|
||||||
|
gasTotal,
|
||||||
|
updateSendAmount,
|
||||||
|
updateSendErrors,
|
||||||
|
updateGasPrice,
|
||||||
|
updateGasLimit,
|
||||||
|
updateGasTotal,
|
||||||
|
} = this.props
|
||||||
|
|
||||||
|
const maxAmount = subtractCurrencies(
|
||||||
|
ethUtil.addHexPrefix(balance),
|
||||||
|
ethUtil.addHexPrefix(MIN_GAS_TOTAL),
|
||||||
|
{ toNumericBase: 'hex' }
|
||||||
|
)
|
||||||
|
|
||||||
|
updateSendErrors({ amount: null })
|
||||||
|
updateGasPrice(MIN_GAS_PRICE_HEX)
|
||||||
|
updateGasLimit(MIN_GAS_LIMIT_HEX)
|
||||||
|
updateGasTotal(MIN_GAS_TOTAL)
|
||||||
|
updateSendAmount(maxAmount)
|
||||||
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.validateAmount = function (value) {
|
SendTransactionScreen.prototype.validateAmount = function (value) {
|
||||||
const {
|
const {
|
||||||
from: { balance },
|
from: { balance },
|
||||||
@ -370,6 +401,12 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
|
|||||||
h('div.send-v2__form-label', [
|
h('div.send-v2__form-label', [
|
||||||
'Amount:',
|
'Amount:',
|
||||||
this.renderErrorMessage('amount'),
|
this.renderErrorMessage('amount'),
|
||||||
|
!errors.amount && h('div.send-v2__amount-max', {
|
||||||
|
onClick: (event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
this.setAmountToMax()
|
||||||
|
},
|
||||||
|
}, [ 'Max' ]),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
h('div.send-v2__form-field', [
|
h('div.send-v2__form-field', [
|
||||||
|
Loading…
Reference in New Issue
Block a user