diff options
Simplify gas estimate actions and add local estimateGasPriceFromRecentBlocks method.
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r-- | ui/app/actions.js | 51 |
1 files changed, 7 insertions, 44 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js index bec9a8cfb..70ec3aed8 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -6,6 +6,8 @@ const { calcGasTotal, getParamsForGasEstimate, calcTokenBalance, + estimateGas, + estimateGasPriceFromRecentBlocks, } = require('./components/send_/send.utils') const ethUtil = require('ethereumjs-util') const { fetchLocale } = require('../i18n-helper') @@ -160,9 +162,6 @@ var actions = { updateTransactionParams, UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS', // send screen - estimateGas, - getGasEstimate, - getGasPrice, UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT', UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE', UPDATE_GAS_TOTAL: 'UPDATE_GAS_TOTAL', @@ -705,22 +704,6 @@ function signTx (txData) { } } -function estimateGas (params = {}) { - return (dispatch) => { - return new Promise((resolve, reject) => { - global.ethQuery.estimateGas(params, (err, data) => { - if (err) { - dispatch(actions.displayWarning(err.message)) - return reject(err) - } - dispatch(actions.hideWarning()) - dispatch(actions.setGasLimit(data)) - return resolve(data) - }) - }) - } -} - function setGasLimit (gasLimit) { return { type: actions.UPDATE_GAS_LIMIT, @@ -728,22 +711,6 @@ function setGasLimit (gasLimit) { } } -function getGasPrice () { - return (dispatch) => { - return new Promise((resolve, reject) => { - global.ethQuery.gasPrice((err, data) => { - if (err) { - dispatch(actions.displayWarning(err.message)) - return reject(err) - } - dispatch(actions.hideWarning()) - dispatch(actions.setGasPrice(data)) - return resolve(data) - }) - }) - } -} - function setGasPrice (gasPrice) { return { type: actions.UPDATE_GAS_PRICE, @@ -758,22 +725,18 @@ function setGasTotal (gasTotal) { } } -function getGasEstimate ({ selectedAddress, selectedToken, data }) { +function updateGasData ({ recentBlocks, selectedAddress, selectedToken, data }) { return (dispatch) => { const estimateGasParams = getParamsForGasEstimate(selectedAddress, selectedToken, data) return Promise.all([ - dispatch(actions.getGasPrice()), - dispatch(actions.estimateGas(estimateGasParams)), + Promise.resolve(estimateGasPriceFromRecentBlocks(recentBlocks)), + estimateGas(estimateGasParams), ]) .then(([gasPrice, gas]) => { + dispatch(actions.setGasPrice(gasPrice)) + dispatch(actions.setGasLimit(gas)) return calcGasTotal(gas, gasPrice) }) - } -} - -function updateGasData ({ selectedAddress, selectedToken, data }) { - return (dispatch) => { - return dispatch(actions.getGasEstimate({ selectedAddress, selectedToken, data })) .then((gasEstimate) => { dispatch(actions.setGasTotal(gasEstimate)) dispatch(updateSendErrors({ gasLoadingError: null })) |