1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

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

View File

@ -745,26 +745,27 @@ function updateGasData ({
}) { }) {
return (dispatch) => { return (dispatch) => {
dispatch(actions.gasLoadingStarted()) dispatch(actions.gasLoadingStarted())
let gasPrice
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
background.getGasPrice((err, data) => { background.getGasPrice((err, data) => {
if (err !== null) return reject(err) if (err) return reject(err)
return resolve(data) return resolve(data)
}) })
}) })
.then(estimateGasPrice => { .then(estimateGasPrice => {
gasPrice = estimateGasPrice return Promise.all([
return estimateGas({ Promise.resolve(estimateGasPrice),
estimateGasMethod: background.estimateGas, estimateGas({
blockGasLimit, estimateGasMethod: background.estimateGas,
selectedAddress, blockGasLimit,
selectedToken, selectedAddress,
to, selectedToken,
value, to,
gasPrice, value,
}) estimateGasPrice,
}),
])
}) })
.then(gas => { .then(([gasPrice, gas]) => {
dispatch(actions.setGasPrice(gasPrice)) dispatch(actions.setGasPrice(gasPrice))
dispatch(actions.setGasLimit(gas)) dispatch(actions.setGasLimit(gas))
return calcGasTotal(gas, gasPrice) return calcGasTotal(gas, gasPrice)