aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-11-17 02:14:25 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-12-07 13:15:39 +0800
commit2e9137dddd4abd07cc45caa670f09bdc9559bbbb (patch)
tree8df2d0042aeefb678445d65b32476405253efa7d /ui
parent373f8b72d048d84f537d97d87c7f106e0b8db087 (diff)
downloadtangerine-wallet-browser-2e9137dddd4abd07cc45caa670f09bdc9559bbbb.tar.gz
tangerine-wallet-browser-2e9137dddd4abd07cc45caa670f09bdc9559bbbb.tar.zst
tangerine-wallet-browser-2e9137dddd4abd07cc45caa670f09bdc9559bbbb.zip
Update max amount behaviour to meet new specs.
Diffstat (limited to 'ui')
-rw-r--r--ui/app/actions.js9
-rw-r--r--ui/app/components/customize-gas-modal/index.js22
-rw-r--r--ui/app/components/send/send-v2-container.js1
-rw-r--r--ui/app/reducers/metamask.js9
-rw-r--r--ui/app/selectors.js5
-rw-r--r--ui/app/send-v2.js24
6 files changed, 55 insertions, 15 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index e79f4373e..326c361cd 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -149,6 +149,7 @@ var actions = {
UPDATE_SEND_AMOUNT: 'UPDATE_SEND_AMOUNT',
UPDATE_SEND_MEMO: 'UPDATE_SEND_MEMO',
UPDATE_SEND_ERRORS: 'UPDATE_SEND_ERRORS',
+ UPDATE_MAX_MODE: 'UPDATE_MAX_MODE',
UPDATE_SEND: 'UPDATE_SEND',
CLEAR_SEND: 'CLEAR_SEND',
updateGasLimit,
@@ -160,6 +161,7 @@ var actions = {
updateSendAmount,
updateSendMemo,
updateSendErrors,
+ setMaxModeTo,
updateSend,
clearSend,
setSelectedAddress,
@@ -637,6 +639,13 @@ function updateSendErrors (error) {
}
}
+function setMaxModeTo (bool) {
+ return {
+ type: actions.UPDATE_MAX_MODE,
+ value: bool,
+ }
+}
+
function updateSend (newSend) {
return {
type: actions.UPDATE_SEND,
diff --git a/ui/app/components/customize-gas-modal/index.js b/ui/app/components/customize-gas-modal/index.js
index 485dacf90..826d2cd4b 100644
--- a/ui/app/components/customize-gas-modal/index.js
+++ b/ui/app/components/customize-gas-modal/index.js
@@ -5,6 +5,8 @@ const connect = require('react-redux').connect
const actions = require('../../actions')
const GasModalCard = require('./gas-modal-card')
+const ethUtil = require('ethereumjs-util')
+
const {
MIN_GAS_PRICE_DEC,
MIN_GAS_LIMIT_DEC,
@@ -19,6 +21,7 @@ const {
conversionUtil,
multiplyCurrencies,
conversionGreaterThan,
+ subtractCurrencies,
} = require('../../conversion-util')
const {
@@ -30,6 +33,7 @@ const {
getSendFrom,
getCurrentAccountWithSendEtherInfo,
getSelectedTokenToFiatRate,
+ getSendMaxModeState,
} = require('../../selectors')
function mapStateToProps (state) {
@@ -42,6 +46,7 @@ function mapStateToProps (state) {
gasLimit: getGasLimit(state),
conversionRate,
amount: getSendAmount(state),
+ maxModeOn: getSendMaxModeState(state),
balance: currentAccount.balance,
primaryCurrency: selectedToken && selectedToken.symbol,
selectedToken,
@@ -55,6 +60,7 @@ function mapDispatchToProps (dispatch) {
updateGasPrice: newGasPrice => dispatch(actions.updateGasPrice(newGasPrice)),
updateGasLimit: newGasLimit => dispatch(actions.updateGasLimit(newGasLimit)),
updateGasTotal: newGasTotal => dispatch(actions.updateGasTotal(newGasTotal)),
+ updateSendAmount: newAmount => dispatch(actions.updateSendAmount(newAmount)),
}
}
@@ -93,8 +99,21 @@ CustomizeGasModal.prototype.save = function (gasPrice, gasLimit, gasTotal) {
updateGasLimit,
hideModal,
updateGasTotal,
+ maxModeOn,
+ selectedToken,
+ balance,
+ updateSendAmount,
} = this.props
+ if (maxModeOn && !selectedToken) {
+ const maxAmount = subtractCurrencies(
+ ethUtil.addHexPrefix(balance),
+ ethUtil.addHexPrefix(gasTotal),
+ { toNumericBase: 'hex' }
+ )
+ updateSendAmount(maxAmount)
+ }
+
updateGasPrice(gasPrice)
updateGasLimit(gasLimit)
updateGasTotal(gasTotal)
@@ -112,12 +131,13 @@ CustomizeGasModal.prototype.validate = function ({ gasTotal, gasLimit }) {
selectedToken,
amountConversionRate,
conversionRate,
+ maxModeOn,
} = this.props
let error = null
const balanceIsSufficient = isBalanceSufficient({
- amount: selectedToken ? '0' : amount,
+ amount: selectedToken || maxModeOn ? '0' : amount,
gasTotal,
balance,
selectedToken,
diff --git a/ui/app/components/send/send-v2-container.js b/ui/app/components/send/send-v2-container.js
index 4451a6113..655de8897 100644
--- a/ui/app/components/send/send-v2-container.js
+++ b/ui/app/components/send/send-v2-container.js
@@ -78,5 +78,6 @@ function mapDispatchToProps (dispatch) {
goHome: () => dispatch(actions.goHome()),
clearSend: () => dispatch(actions.clearSend()),
backToConfirmScreen: editingTransactionId => dispatch(actions.showConfTxPage({ id: editingTransactionId })),
+ setMaxModeTo: bool => dispatch(actions.setMaxModeTo(bool)),
}
}
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
index fb53bbaef..98207f23b 100644
--- a/ui/app/reducers/metamask.js
+++ b/ui/app/reducers/metamask.js
@@ -33,6 +33,7 @@ function reduceMetamask (state, action) {
amount: '0x0',
memo: '',
errors: {},
+ maxModeOn: false,
editingTransactionId: null,
},
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:
return extend(metamaskState, {
send: {
diff --git a/ui/app/selectors.js b/ui/app/selectors.js
index a5f9a75d8..f891f70c0 100644
--- a/ui/app/selectors.js
+++ b/ui/app/selectors.js
@@ -24,6 +24,7 @@ const selectors = {
getSendAmount,
getSelectedTokenToFiatRate,
getSelectedTokenContract,
+ getSendMaxModeState,
}
module.exports = selectors
@@ -135,6 +136,10 @@ function getSendAmount (state) {
return state.metamask.send.amount
}
+function getSendMaxModeState (state) {
+ return state.metamask.send.maxModeOn
+}
+
function getCurrentCurrency (state) {
return state.metamask.currentCurrency
}
diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js
index 788ae87b4..e1b88f0db 100644
--- a/ui/app/send-v2.js
+++ b/ui/app/send-v2.js
@@ -13,8 +13,6 @@ const GasFeeDisplay = require('./components/send/gas-fee-display-v2')
const {
MIN_GAS_TOTAL,
- MIN_GAS_PRICE_HEX,
- MIN_GAS_LIMIT_HEX,
} = require('./components/send/send-constants')
const {
@@ -313,8 +311,9 @@ SendTransactionScreen.prototype.renderToRow = function () {
SendTransactionScreen.prototype.handleAmountChange = function (value) {
const amount = value
- const { updateSendAmount } = this.props
+ const { updateSendAmount, setMaxModeTo } = this.props
+ setMaxModeTo(false)
this.validateAmount(amount)
updateSendAmount(amount)
}
@@ -324,11 +323,9 @@ SendTransactionScreen.prototype.setAmountToMax = function () {
from: { balance },
updateSendAmount,
updateSendErrors,
- updateGasPrice,
- updateGasLimit,
- updateGasTotal,
tokenBalance,
selectedToken,
+ gasTotal,
} = this.props
const { decimals } = selectedToken || {}
const multiplier = Math.pow(10, Number(decimals || 0))
@@ -337,16 +334,12 @@ SendTransactionScreen.prototype.setAmountToMax = function () {
? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
: subtractCurrencies(
ethUtil.addHexPrefix(balance),
- ethUtil.addHexPrefix(MIN_GAS_TOTAL),
+ ethUtil.addHexPrefix(gasTotal),
{ toNumericBase: 'hex' }
)
updateSendErrors({ amount: null })
- if (!selectedToken) {
- updateGasPrice(MIN_GAS_PRICE_HEX)
- updateGasLimit(MIN_GAS_LIMIT_HEX)
- updateGasTotal(MIN_GAS_TOTAL)
- }
+
updateSendAmount(maxAmount)
}
@@ -407,19 +400,22 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
amountConversionRate,
errors,
amount,
+ setMaxModeTo,
+ maxModeOn,
} = this.props
return h('div.send-v2__form-row', [
- h('div.send-v2__form-label', [
+ h('div.send-v2__form-label', [
'Amount:',
this.renderErrorMessage('amount'),
!errors.amount && h('div.send-v2__amount-max', {
onClick: (event) => {
event.preventDefault()
+ setMaxModeTo(true)
this.setAmountToMax()
},
- }, [ 'Max' ]),
+ }, [ !maxModeOn ? 'Max' : '' ]),
]),
h('div.send-v2__form-field', [