diff options
Refactor to store estimated gas and price in local state, return promise from actions.
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 60 |
1 files changed, 18 insertions, 42 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) |