Update max amount behaviour to meet new specs.

feature/default_network_editable
Dan 7 years ago committed by Chi Kei Chan
parent 373f8b72d0
commit 2e9137dddd
  1. 9
      ui/app/actions.js
  2. 22
      ui/app/components/customize-gas-modal/index.js
  3. 1
      ui/app/components/send/send-v2-container.js
  4. 9
      ui/app/reducers/metamask.js
  5. 5
      ui/app/selectors.js
  6. 24
      ui/app/send-v2.js

@ -149,6 +149,7 @@ var actions = {
UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT', UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT',
UPDATE_SEND_MEMO: 'UPDATE_SEND_MEMO', UPDATE_SEND_MEMO: 'UPDATE_SEND_MEMO',
UPDATE_SEND_ERRORS: 'UPDATE_SEND_ERRORS', UPDATE_SEND_ERRORS: 'UPDATE_SEND_ERRORS',
UPDATE_MAX_MODE: 'UPDATE_MAX_MODE',
UPDATE_SEND: 'UPDATE_SEND', UPDATE_SEND: 'UPDATE_SEND',
CLEAR_SEND: 'CLEAR_SEND', CLEAR_SEND: 'CLEAR_SEND',
updateGasLimit, updateGasLimit,
@ -160,6 +161,7 @@ var actions = {
updateSendAmount, updateSendAmount,
updateSendMemo, updateSendMemo,
updateSendErrors, updateSendErrors,
setMaxModeTo,
updateSend, updateSend,
clearSend, clearSend,
setSelectedAddress, setSelectedAddress,
@ -637,6 +639,13 @@ function updateSendErrors (error) {
} }
} }
function setMaxModeTo (bool) {
return {
type: actions.UPDATE_MAX_MODE,
value: bool,
}
}
function updateSend (newSend) { function updateSend (newSend) {
return { return {
type: actions.UPDATE_SEND, type: actions.UPDATE_SEND,

@ -5,6 +5,8 @@ const connect = require('react-redux').connect
const actions = require('../../actions') const actions = require('../../actions')
const GasModalCard = require('./gas-modal-card') const GasModalCard = require('./gas-modal-card')
const ethUtil = require('ethereumjs-util')
const { const {
MIN_GAS_PRICE_DEC, MIN_GAS_PRICE_DEC,
MIN_GAS_LIMIT_DEC, MIN_GAS_LIMIT_DEC,
@ -19,6 +21,7 @@ const {
conversionUtil, conversionUtil,
multiplyCurrencies, multiplyCurrencies,
conversionGreaterThan, conversionGreaterThan,
subtractCurrencies,
} = require('../../conversion-util') } = require('../../conversion-util')
const { const {
@ -30,6 +33,7 @@ const {
getSendFrom, getSendFrom,
getCurrentAccountWithSendEtherInfo, getCurrentAccountWithSendEtherInfo,
getSelectedTokenToFiatRate, getSelectedTokenToFiatRate,
getSendMaxModeState,
} = require('../../selectors') } = require('../../selectors')
function mapStateToProps (state) { function mapStateToProps (state) {
@ -42,6 +46,7 @@ function mapStateToProps (state) {
gasLimit: getGasLimit(state), gasLimit: getGasLimit(state),
conversionRate, conversionRate,
amount: getSendAmount(state), amount: getSendAmount(state),
maxModeOn: getSendMaxModeState(state),
balance: currentAccount.balance, balance: currentAccount.balance,
primaryCurrency: selectedToken && selectedToken.symbol, primaryCurrency: selectedToken && selectedToken.symbol,
selectedToken, selectedToken,
@ -55,6 +60,7 @@ function mapDispatchToProps (dispatch) {
updateGasPrice: newGasPrice => dispatch(actions.updateGasPrice(newGasPrice)), updateGasPrice: newGasPrice => dispatch(actions.updateGasPrice(newGasPrice)),
updateGasLimit: newGasLimit => dispatch(actions.updateGasLimit(newGasLimit)), updateGasLimit: newGasLimit => dispatch(actions.updateGasLimit(newGasLimit)),
updateGasTotal: newGasTotal => dispatch(actions.updateGasTotal(newGasTotal)), updateGasTotal: newGasTotal => dispatch(actions.updateGasTotal(newGasTotal)),
updateSendAmount: newAmount => dispatch(actions.updateSendAmount(newAmount)),
} }
} }
@ -93,8 +99,21 @@ CustomizeGasModal.prototype.save = function (gasPrice, gasLimit, gasTotal) {
updateGasLimit, updateGasLimit,
hideModal, hideModal,
updateGasTotal, updateGasTotal,
maxModeOn,
selectedToken,
balance,
updateSendAmount,
} = this.props } = this.props
if (maxModeOn && !selectedToken) {
const maxAmount = subtractCurrencies(
ethUtil.addHexPrefix(balance),
ethUtil.addHexPrefix(gasTotal),
{ toNumericBase: 'hex' }
)
updateSendAmount(maxAmount)
}
updateGasPrice(gasPrice) updateGasPrice(gasPrice)
updateGasLimit(gasLimit) updateGasLimit(gasLimit)
updateGasTotal(gasTotal) updateGasTotal(gasTotal)
@ -112,12 +131,13 @@ CustomizeGasModal.prototype.validate = function ({ gasTotal, gasLimit }) {
selectedToken, selectedToken,
amountConversionRate, amountConversionRate,
conversionRate, conversionRate,
maxModeOn,
} = this.props } = this.props
let error = null let error = null
const balanceIsSufficient = isBalanceSufficient({ const balanceIsSufficient = isBalanceSufficient({
amount: selectedToken ? '0' : amount, amount: selectedToken || maxModeOn ? '0' : amount,
gasTotal, gasTotal,
balance, balance,
selectedToken, selectedToken,

@ -78,5 +78,6 @@ function mapDispatchToProps (dispatch) {
goHome: () => dispatch(actions.goHome()), goHome: () => dispatch(actions.goHome()),
clearSend: () => dispatch(actions.clearSend()), clearSend: () => dispatch(actions.clearSend()),
backToConfirmScreen: editingTransactionId => dispatch(actions.showConfTxPage({ id: editingTransactionId })), backToConfirmScreen: editingTransactionId => dispatch(actions.showConfTxPage({ id: editingTransactionId })),
setMaxModeTo: bool => dispatch(actions.setMaxModeTo(bool)),
} }
} }

@ -33,6 +33,7 @@ function reduceMetamask (state, action) {
amount: '0x0', amount: '0x0',
memo: '', memo: '',
errors: {}, errors: {},
maxModeOn: false,
editingTransactionId: null, editingTransactionId: null,
}, },
coinOptions: {}, coinOptions: {},
@ -258,6 +259,14 @@ function reduceMetamask (state, action) {
}, },
}) })
case actions.UPDATE_MAX_MODE:
return extend(metamaskState, {
send: {
...metamaskState.send,
maxModeOn: action.value,
},
})
case actions.UPDATE_SEND: case actions.UPDATE_SEND:
return extend(metamaskState, { return extend(metamaskState, {
send: { send: {

@ -24,6 +24,7 @@ const selectors = {
getSendAmount, getSendAmount,
getSelectedTokenToFiatRate, getSelectedTokenToFiatRate,
getSelectedTokenContract, getSelectedTokenContract,
getSendMaxModeState,
} }
module.exports = selectors module.exports = selectors
@ -135,6 +136,10 @@ function getSendAmount (state) {
return state.metamask.send.amount return state.metamask.send.amount
} }
function getSendMaxModeState (state) {
return state.metamask.send.maxModeOn
}
function getCurrentCurrency (state) { function getCurrentCurrency (state) {
return state.metamask.currentCurrency return state.metamask.currentCurrency
} }

@ -13,8 +13,6 @@ const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
const { const {
MIN_GAS_TOTAL, MIN_GAS_TOTAL,
MIN_GAS_PRICE_HEX,
MIN_GAS_LIMIT_HEX,
} = require('./components/send/send-constants') } = require('./components/send/send-constants')
const { const {
@ -313,8 +311,9 @@ SendTransactionScreen.prototype.renderToRow = function () {
SendTransactionScreen.prototype.handleAmountChange = function (value) { SendTransactionScreen.prototype.handleAmountChange = function (value) {
const amount = value const amount = value
const { updateSendAmount } = this.props const { updateSendAmount, setMaxModeTo } = this.props
setMaxModeTo(false)
this.validateAmount(amount) this.validateAmount(amount)
updateSendAmount(amount) updateSendAmount(amount)
} }
@ -324,11 +323,9 @@ SendTransactionScreen.prototype.setAmountToMax = function () {
from: { balance }, from: { balance },
updateSendAmount, updateSendAmount,
updateSendErrors, updateSendErrors,
updateGasPrice,
updateGasLimit,
updateGasTotal,
tokenBalance, tokenBalance,
selectedToken, selectedToken,
gasTotal,
} = this.props } = this.props
const { decimals } = selectedToken || {} const { decimals } = selectedToken || {}
const multiplier = Math.pow(10, Number(decimals || 0)) const multiplier = Math.pow(10, Number(decimals || 0))
@ -337,16 +334,12 @@ SendTransactionScreen.prototype.setAmountToMax = function () {
? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'}) ? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
: subtractCurrencies( : subtractCurrencies(
ethUtil.addHexPrefix(balance), ethUtil.addHexPrefix(balance),
ethUtil.addHexPrefix(MIN_GAS_TOTAL), ethUtil.addHexPrefix(gasTotal),
{ toNumericBase: 'hex' } { toNumericBase: 'hex' }
) )
updateSendErrors({ amount: null }) updateSendErrors({ amount: null })
if (!selectedToken) {
updateGasPrice(MIN_GAS_PRICE_HEX)
updateGasLimit(MIN_GAS_LIMIT_HEX)
updateGasTotal(MIN_GAS_TOTAL)
}
updateSendAmount(maxAmount) updateSendAmount(maxAmount)
} }
@ -407,19 +400,22 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
amountConversionRate, amountConversionRate,
errors, errors,
amount, amount,
setMaxModeTo,
maxModeOn,
} = this.props } = this.props
return h('div.send-v2__form-row', [ return h('div.send-v2__form-row', [
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', { !errors.amount && h('div.send-v2__amount-max', {
onClick: (event) => { onClick: (event) => {
event.preventDefault() event.preventDefault()
setMaxModeTo(true)
this.setAmountToMax() this.setAmountToMax()
}, },
}, [ 'Max' ]), }, [ !maxModeOn ? 'Max' : '' ]),
]), ]),
h('div.send-v2__form-field', [ h('div.send-v2__form-field', [

Loading…
Cancel
Save