aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-05-22 16:10:06 +0800
committerDan <danjm.com@gmail.com>2018-05-31 07:24:31 +0800
commit166fda58777748141859c0a674a5fce454cfc3d3 (patch)
treeb8f743c927ff55ee02be61b013d3c726711381c3 /ui/app/actions.js
parent17909465f283179aad39166b1191dbaba3770bf6 (diff)
downloadtangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.tar
tangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.tar.gz
tangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.tar.bz2
tangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.tar.lz
tangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.tar.xz
tangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.tar.zst
tangerine-wallet-browser-166fda58777748141859c0a674a5fce454cfc3d3.zip
Simplify gas estimate actions and add local estimateGasPriceFromRecentBlocks method.
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js51
1 files changed, 7 insertions, 44 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index bec9a8cfb..70ec3aed8 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -6,6 +6,8 @@ const {
calcGasTotal,
getParamsForGasEstimate,
calcTokenBalance,
+ estimateGas,
+ estimateGasPriceFromRecentBlocks,
} = require('./components/send_/send.utils')
const ethUtil = require('ethereumjs-util')
const { fetchLocale } = require('../i18n-helper')
@@ -160,9 +162,6 @@ var actions = {
updateTransactionParams,
UPDATE_TRANSACTION_PARAMS: 'UPDATE_TRANSACTION_PARAMS',
// send screen
- estimateGas,
- getGasEstimate,
- getGasPrice,
UPDATE_GAS_LIMIT: 'UPDATE_GAS_LIMIT',
UPDATE_GAS_PRICE: 'UPDATE_GAS_PRICE',
UPDATE_GAS_TOTAL: 'UPDATE_GAS_TOTAL',
@@ -705,22 +704,6 @@ 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.setGasLimit(data))
- return resolve(data)
- })
- })
- }
-}
-
function setGasLimit (gasLimit) {
return {
type: actions.UPDATE_GAS_LIMIT,
@@ -728,22 +711,6 @@ function setGasLimit (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.setGasPrice(data))
- return resolve(data)
- })
- })
- }
-}
-
function setGasPrice (gasPrice) {
return {
type: actions.UPDATE_GAS_PRICE,
@@ -758,22 +725,18 @@ function setGasTotal (gasTotal) {
}
}
-function getGasEstimate ({ selectedAddress, selectedToken, data }) {
+function updateGasData ({ recentBlocks, selectedAddress, selectedToken, data }) {
return (dispatch) => {
const estimateGasParams = getParamsForGasEstimate(selectedAddress, selectedToken, data)
return Promise.all([
- dispatch(actions.getGasPrice()),
- dispatch(actions.estimateGas(estimateGasParams)),
+ Promise.resolve(estimateGasPriceFromRecentBlocks(recentBlocks)),
+ estimateGas(estimateGasParams),
])
.then(([gasPrice, gas]) => {
+ dispatch(actions.setGasPrice(gasPrice))
+ dispatch(actions.setGasLimit(gas))
return calcGasTotal(gas, gasPrice)
})
- }
-}
-
-function updateGasData ({ selectedAddress, selectedToken, data }) {
- return (dispatch) => {
- return dispatch(actions.getGasEstimate({ selectedAddress, selectedToken, data }))
.then((gasEstimate) => {
dispatch(actions.setGasTotal(gasEstimate))
dispatch(updateSendErrors({ gasLoadingError: null }))