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

Split out getGasEstimate logic from updateGasTotal

This commit is contained in:
Dan 2018-05-17 12:44:46 -02:30
parent 6d8344d0d0
commit 8b6d08a15d

View File

@ -161,6 +161,7 @@ var actions = {
UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS', UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS',
// send screen // send screen
estimateGas, estimateGas,
getGasEstimate,
getGasPrice, getGasPrice,
UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT', UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT',
UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE', UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE',
@ -757,7 +758,7 @@ function setGasTotal (gasTotal) {
} }
} }
function updateGasTotal ({ selectedAddress, selectedToken, data }) { function getGasEstimate ({ selectedAddress, selectedToken, data }) {
return (dispatch) => { return (dispatch) => {
const { symbol } = selectedToken || {} const { symbol } = selectedToken || {}
const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data) const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
@ -766,8 +767,16 @@ function updateGasTotal ({ selectedAddress, selectedToken, data }) {
dispatch(actions.estimateGas(estimateGasParams)), dispatch(actions.estimateGas(estimateGasParams)),
]) ])
.then(([gasPrice, gas]) => { .then(([gasPrice, gas]) => {
const newGasTotal = calcGasTotal(gas, gasPrice) return calcGasTotal(gas, gasPrice)
dispatch(actions.setGasTotal(newGasTotal)) })
}
}
function updateGasTotal ({ selectedAddress, selectedToken, data }) {
return (dispatch) => {
return dispatch(actions.getGasEstimate({ selectedAddress, selectedToken, data }))
.then((gasEstimate) => {
dispatch(actions.setGasTotal(gasEstimate))
dispatch(updateSendErrors({ gasLoadingError: null })) dispatch(updateSendErrors({ gasLoadingError: null }))
}) })
.catch(err => { .catch(err => {