aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
authorDan J Miller <danjm.com@gmail.com>2018-06-05 03:08:01 +0800
committerGitHub <noreply@github.com>2018-06-05 03:08:01 +0800
commit139f930185f134ef50d547ca07a580e11b5cf731 (patch)
tree4e184b7dc5f97d9d4da28e6b72b256e955b0a937 /ui/app/actions.js
parent2ca084b0557242b34733107701a14ba0724363b3 (diff)
parentada59054c9d102cc99b950f1377256cac5545649 (diff)
downloadtangerine-wallet-browser-139f930185f134ef50d547ca07a580e11b5cf731.tar.gz
tangerine-wallet-browser-139f930185f134ef50d547ca07a580e11b5cf731.tar.zst
tangerine-wallet-browser-139f930185f134ef50d547ca07a580e11b5cf731.zip
Merge pull request #4350 from MetaMask/i3914-fix-newui-send-gas-estimation
NewUI gas estimation produces same results as old-ui (exception: contract addresses)
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js79
1 files changed, 32 insertions, 47 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index ae6b9637d..465b3d5fe 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -4,8 +4,9 @@ const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
const { getTokenAddressFromTokenObject } = require('./util')
const {
calcGasTotal,
- getParamsForGasEstimate,
calcTokenBalance,
+ estimateGas,
+ estimateGasPriceFromRecentBlocks,
} = require('./components/send_/send.utils')
const ethUtil = require('ethereumjs-util')
const { fetchLocale } = require('../i18n-helper')
@@ -160,8 +161,6 @@ var actions = {
updateTransactionParams,
UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS',
// send screen
- estimateGas,
- getGasPrice,
UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT',
UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE',
UPDATE_GAS_TOTAL: 'UPDATE_GAS_TOTAL',
@@ -176,9 +175,9 @@ var actions = {
CLEAR_SEND: 'CLEAR_SEND',
OPEN_FROM_DROPDOWN: 'OPEN_FROM_DROPDOWN',
CLOSE_FROM_DROPDOWN: 'CLOSE_FROM_DROPDOWN',
- updateGasLimit,
- updateGasPrice,
- updateGasTotal,
+ setGasLimit,
+ setGasPrice,
+ updateGasData,
setGasTotal,
setSendTokenBalance,
updateSendTokenBalance,
@@ -710,46 +709,14 @@ 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.updateGasLimit(data))
- return resolve(data)
- })
- })
- }
-}
-
-function updateGasLimit (gasLimit) {
+function setGasLimit (gasLimit) {
return {
type: actions.UPDATE_GAS_LIMIT,
value: 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.updateGasPrice(data))
- return resolve(data)
- })
- })
- }
-}
-
-function updateGasPrice (gasPrice) {
+function setGasPrice (gasPrice) {
return {
type: actions.UPDATE_GAS_PRICE,
value: gasPrice,
@@ -763,17 +730,35 @@ function setGasTotal (gasTotal) {
}
}
-function updateGasTotal ({ selectedAddress, selectedToken, data }) {
+function updateGasData ({
+ blockGasLimit,
+ recentBlocks,
+ selectedAddress,
+ selectedToken,
+ to,
+ value,
+}) {
+ const estimatedGasPrice = estimateGasPriceFromRecentBlocks(recentBlocks)
return (dispatch) => {
- const { symbol } = selectedToken || {}
- const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
return Promise.all([
- dispatch(actions.getGasPrice()),
- dispatch(actions.estimateGas(estimateGasParams)),
+ Promise.resolve(estimatedGasPrice),
+ estimateGas({
+ estimateGasMethod: background.estimateGas,
+ blockGasLimit,
+ selectedAddress,
+ selectedToken,
+ to,
+ value,
+ gasPrice: estimatedGasPrice,
+ }),
])
.then(([gasPrice, gas]) => {
- const newGasTotal = calcGasTotal(gas, gasPrice)
- dispatch(actions.setGasTotal(newGasTotal))
+ dispatch(actions.setGasPrice(gasPrice))
+ dispatch(actions.setGasLimit(gas))
+ return calcGasTotal(gas, gasPrice)
+ })
+ .then((gasEstimate) => {
+ dispatch(actions.setGasTotal(gasEstimate))
dispatch(updateSendErrors({ gasLoadingError: null }))
})
.catch(err => {