aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-09-26 07:30:32 +0800
committerDan <danjm.com@gmail.com>2017-09-26 08:24:55 +0800
commit79bcb88db3946260c832402d97e0c800cdeba5a9 (patch)
tree26c3a2e562850a9a266177e77c5a57a4a47b8332 /ui
parent88c4226bf1dca8647a45f3921396daaa88bbf939 (diff)
downloadtangerine-wallet-browser-79bcb88db3946260c832402d97e0c800cdeba5a9.tar.gz
tangerine-wallet-browser-79bcb88db3946260c832402d97e0c800cdeba5a9.tar.zst
tangerine-wallet-browser-79bcb88db3946260c832402d97e0c800cdeba5a9.zip
Refactor to store estimated gas and price in local state, return promise from actions.
Diffstat (limited to 'ui')
-rw-r--r--ui/app/actions.js60
-rw-r--r--ui/app/reducers/metamask.js22
-rw-r--r--ui/app/send.js37
3 files changed, 38 insertions, 81 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index a43809fc0..a0dbbbf11 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -131,15 +131,7 @@ var actions = {
VIEW_PENDING_TX: 'VIEW_PENDING_TX',
// send screen
estimateGas,
- updateGasEstimate,
- UPDATE_GAS_ESTIMATE: 'UPDATE_GAS_ESTIMATE',
- updateGasPrice,
- UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE',
getGasPrice,
- CLEAR_GAS_ESTIMATE: 'CLEAR_GAS_ESTIMATE',
- CLEAR_GAS_PRICE: 'CLEAR_GAS_PRICE',
- clearGasEstimate,
- clearGasPrice,
// app messages
confirmSeedWords: confirmSeedWords,
showAccountDetail: showAccountDetail,
@@ -462,20 +454,30 @@ function signTx (txData) {
function estimateGas ({ to, amount }) {
return (dispatch) => {
- global.ethQuery.estimateGas({ to, amount }, (err, data) => {
- if (err) return dispatch(actions.displayWarning(err.message))
- dispatch(actions.hideWarning())
- dispatch(actions.updateGasEstimate(data))
+ return new Promise((resolve, reject) => {
+ global.ethQuery.estimateGas({ to, amount }, (err, data) => {
+ if (err) {
+ dispatch(actions.displayWarning(err.message))
+ return reject(err)
+ }
+ dispatch(actions.hideWarning())
+ return resolve(data)
+ })
})
}
}
function getGasPrice () {
return (dispatch) => {
- global.ethQuery.gasPrice((err, data) => {
- if (err) return dispatch(actions.displayWarning(err.message))
- dispatch(actions.hideWarning())
- dispatch(actions.updateGasPrice(data))
+ return new Promise((resolve, reject) => {
+ global.ethQuery.gasPrice((err, data) => {
+ if (err) {
+ dispatch(actions.displayWarning(err.message))
+ return reject(err)
+ }
+ dispatch(actions.hideWarning())
+ return resolve(data)
+ })
})
}
}
@@ -537,32 +539,6 @@ function txError (err) {
}
}
-function updateGasEstimate (gas) {
- return {
- type: actions.UPDATE_GAS_ESTIMATE,
- value: gas,
- }
-}
-
-function clearGasEstimate () {
- return {
- type: actions.CLEAR_GAS_ESTIMATE,
- }
-}
-
-function updateGasPrice (gasPrice) {
- return {
- type: actions.UPDATE_GAS_PRICE,
- value: gasPrice,
- }
-}
-
-function clearGasPrice () {
- return {
- type: actions.CLEAR_GAS_PRICE,
- }
-}
-
function cancelMsg (msgData) {
log.debug(`background.cancelMessage`)
background.cancelMessage(msgData.id)
diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js
index e78f51f3a..cdc98d05e 100644
--- a/ui/app/reducers/metamask.js
+++ b/ui/app/reducers/metamask.js
@@ -19,8 +19,6 @@ function reduceMetamask (state, action) {
addressBook: [],
selectedTokenAddress: null,
tokenExchangeRates: {},
- estimatedGas: null,
- blockGasPrice: null,
}, state.metamask)
switch (action.type) {
@@ -76,26 +74,6 @@ function reduceMetamask (state, action) {
},
})
- case actions.UPDATE_GAS_ESTIMATE:
- return extend(metamaskState, {
- estimatedGas: action.value,
- })
-
- case actions.UPDATE_GAS_PRICE:
- return extend(metamaskState, {
- blockGasPrice: action.value,
- })
-
- case actions.CLEAR_GAS_ESTIMATE:
- return extend(metamaskState, {
- estimatedGas: null,
- })
-
- case actions.CLEAR_GAS_PRICE:
- return extend(metamaskState, {
- blockGasPrice: null,
- })
-
case actions.COMPLETED_TX:
var stringId = String(action.id)
newState = extend(metamaskState, {
diff --git a/ui/app/send.js b/ui/app/send.js
index 4ce7fc475..033692910 100644
--- a/ui/app/send.js
+++ b/ui/app/send.js
@@ -18,8 +18,6 @@ const {
signTx,
estimateGas,
getGasPrice,
- clearGasEstimate,
- clearGasPrice,
} = require('./actions')
const { stripHexPrefix, addHexPrefix } = require('ethereumjs-util')
const { isHex, numericBalance, isValidAddress, allNull } = require('./util')
@@ -52,8 +50,6 @@ function mapStateToProps (state) {
addressBook,
conversionRate,
blockGasLimit,
- blockGasPrice,
- estimatedGas,
warning,
selectedIdentity,
error: warning && warning.split('.')[0],
@@ -73,16 +69,15 @@ function SendTransactionScreen () {
newTx: {
from: '',
to: '',
- amount: 0,
amountToSend: '0x0',
gasPrice: null,
gas: null,
amount: '0x0',
- gasPrice: null,
- gas: null,
txData: null,
memo: '',
},
+ blockGasPrice: null,
+ estimatedGas: null,
activeCurrency: 'USD',
tooltipIsOpen: false,
errors: {},
@@ -108,11 +103,6 @@ function SendTransactionScreen () {
this.renderErrorMessage = this.renderErrorMessage.bind(this)
}
-SendTransactionScreen.prototype.componentWillMount = function() {
- this.props.dispatch(clearGasEstimate())
- this.props.dispatch(clearGasPrice())
-}
-
SendTransactionScreen.prototype.renderErrorMessage = function(errorType, warning) {
const { errors } = this.state
const errorMessage = errors[errorType];
@@ -316,11 +306,16 @@ SendTransactionScreen.prototype.render = function () {
identities,
addressBook,
conversionRate,
- estimatedGas,
- blockGasPrice,
} = props
- const { blockGasLimit, newTx, activeCurrency, isValid } = this.state
+ const {
+ blockGasLimit,
+ newTx,
+ activeCurrency,
+ isValid,
+ blockGasPrice,
+ estimatedGas,
+ } = this.state
const { gas, gasPrice } = newTx
return (
@@ -386,8 +381,16 @@ SendTransactionScreen.prototype.estimateGasAndPrice = function () {
const { errors, sendAmount, newTx } = this.state
if (!errors.to && !errors.amount && newTx.amount > 0) {
- this.props.dispatch(getGasPrice())
- this.props.dispatch(estimateGas({ to: newTx.to, amount: sendAmount }))
+ Promise.all([
+ this.props.dispatch(getGasPrice()),
+ this.props.dispatch(estimateGas({ to: newTx.to, amount: sendAmount })),
+ ])
+ .then(([blockGasPrice, estimatedGas]) => {
+ this.setState({
+ blockGasPrice,
+ estimatedGas,
+ })
+ })
}
}