From 7d7662191af708621549cfd67592375436263eb3 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 4 Jul 2018 21:26:02 -0230 Subject: [PATCH] Improve error and promise resolution handling in action.js updateGasData(). --- ui/app/actions.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ui/app/actions.js b/ui/app/actions.js index 408bc700b..ad890f565 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -745,26 +745,27 @@ function updateGasData ({ }) { return (dispatch) => { dispatch(actions.gasLoadingStarted()) - let gasPrice return new Promise((resolve, reject) => { background.getGasPrice((err, data) => { - if (err !== null) return reject(err) + if (err) return reject(err) return resolve(data) }) }) .then(estimateGasPrice => { - gasPrice = estimateGasPrice - return estimateGas({ - estimateGasMethod: background.estimateGas, - blockGasLimit, - selectedAddress, - selectedToken, - to, - value, - gasPrice, - }) + return Promise.all([ + Promise.resolve(estimateGasPrice), + estimateGas({ + estimateGasMethod: background.estimateGas, + blockGasLimit, + selectedAddress, + selectedToken, + to, + value, + estimateGasPrice, + }), + ]) }) - .then(gas => { + .then(([gasPrice, gas]) => { dispatch(actions.setGasPrice(gasPrice)) dispatch(actions.setGasLimit(gas)) return calcGasTotal(gas, gasPrice)