Improve error and promise resolution handling in action.js updateGasData().

This commit is contained in:
Dan 2018-07-04 21:26:02 -02:30
parent c47a4ce2c9
commit 7d7662191a
1 changed files with 14 additions and 13 deletions

View File

@ -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)