aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-12-08 01:46:28 +0800
committerGitHub <noreply@github.com>2017-12-08 01:46:28 +0800
commit845aec82b976b1676c504832f152d6d9142c11e1 (patch)
treef6306a17629d68e217488ab15af7ce5029c07335 /ui
parentbd5ce9461e5119c13ab8be29db5cdfc57228bac8 (diff)
parent2e9137dddd4abd07cc45caa670f09bdc9559bbbb (diff)
downloadtangerine-wallet-browser-845aec82b976b1676c504832f152d6d9142c11e1.tar.gz
tangerine-wallet-browser-845aec82b976b1676c504832f152d6d9142c11e1.tar.zst
tangerine-wallet-browser-845aec82b976b1676c504832f152d6d9142c11e1.zip
Merge branch 'NewUI-flat' into MM-333-auto-add-users-to-new-UI
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/first-time/init-menu.js7
-rw-r--r--ui/app/reducers/metamask.js9
-rw-r--r--ui/app/selectors.js5
-rw-r--r--ui/app/send-v2.js24
7 files changed, 61 insertions, 16 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index bba2a014f..ed0518184 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,
@@ -642,6 +644,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/first-time/init-menu.js b/ui/app/first-time/init-menu.js
index cc7c51bd3..b4587f1ee 100644
--- a/ui/app/first-time/init-menu.js
+++ b/ui/app/first-time/init-menu.js
@@ -8,6 +8,8 @@ const actions = require('../actions')
const Tooltip = require('../components/tooltip')
const getCaretCoordinates = require('textarea-caret')
+let isSubmitting = false
+
module.exports = connect(mapStateToProps)(InitializeMenuScreen)
inherits(InitializeMenuScreen, Component)
@@ -164,7 +166,10 @@ InitializeMenuScreen.prototype.createNewVaultAndKeychain = function () {
return
}
- this.props.dispatch(actions.createNewVaultAndKeychain(password))
+ if (!isSubmitting) {
+ isSubmitting = true
+ this.props.dispatch(actions.createNewVaultAndKeychain(password))
+ }
}
InitializeMenuScreen.prototype.inputChanged = function (event) {
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
index c496625c7..95b41e5f3 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: {},
@@ -259,6 +260,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 8aea7864a..22ef439c4 100644
--- a/ui/app/selectors.js
+++ b/ui/app/selectors.js
@@ -25,6 +25,7 @@ const selectors = {
getSelectedTokenToFiatRate,
getSelectedTokenContract,
autoAddToBetaUI,
+ getSendMaxModeState,
}
module.exports = selectors
@@ -136,6 +137,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', [