From de01a6f112716cad8ebc1fd56dd304f1818704f4 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 28 Jun 2018 13:17:44 -0230 Subject: Use background gas price estimation method in new ui. --- ui/app/actions.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'ui/app/actions.js') diff --git a/ui/app/actions.js b/ui/app/actions.js index 41fc3c504..f118251eb 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -746,20 +746,26 @@ function updateGasData ({ }) { return (dispatch) => { dispatch(actions.gasLoadingStarted()) - const estimatedGasPrice = estimateGasPriceFromRecentBlocks(recentBlocks) - return Promise.all([ - Promise.resolve(estimatedGasPrice), - estimateGas({ + let gasPrice + return (() => new Promise((resolve, reject) => { + background.getGasPrice((err, data) => { + if(err !== null) return reject(err); + return resolve(data); + }) + }))() + .then(estimateGasPrice => { + gasPrice = estimateGasPrice + return estimateGas({ estimateGasMethod: background.estimateGas, blockGasLimit, selectedAddress, selectedToken, to, value, - gasPrice: estimatedGasPrice, - }), - ]) - .then(([gasPrice, gas]) => { + gasPrice, + }) + }) + .then(gas => { dispatch(actions.setGasPrice(gasPrice)) dispatch(actions.setGasLimit(gas)) return calcGasTotal(gas, gasPrice) -- cgit From 7babacf062cd77235ecfba3ca352a65f3a702728 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 28 Jun 2018 21:40:06 -0230 Subject: Remove unnecessary anonymous function call in actions.js gas estimation. --- ui/app/actions.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'ui/app/actions.js') diff --git a/ui/app/actions.js b/ui/app/actions.js index f118251eb..408bc700b 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -6,7 +6,6 @@ const { calcGasTotal, calcTokenBalance, estimateGas, - estimateGasPriceFromRecentBlocks, } = require('./components/send_/send.utils') const ethUtil = require('ethereumjs-util') const { fetchLocale } = require('../i18n-helper') @@ -747,12 +746,12 @@ function updateGasData ({ return (dispatch) => { dispatch(actions.gasLoadingStarted()) let gasPrice - return (() => new Promise((resolve, reject) => { - background.getGasPrice((err, data) => { - if(err !== null) return reject(err); - return resolve(data); - }) - }))() + return new Promise((resolve, reject) => { + background.getGasPrice((err, data) => { + if (err !== null) return reject(err) + return resolve(data) + }) + }) .then(estimateGasPrice => { gasPrice = estimateGasPrice return estimateGas({ -- cgit From 7d7662191af708621549cfd67592375436263eb3 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 4 Jul 2018 21:26:02 -0230 Subject: Improve error and promise resolution handling in action.js updateGasData(). --- ui/app/actions.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'ui/app/actions.js') diff --git a/ui/app/actions.js b/ui/app/actions.js index 408bc700b..ad890f565 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -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) -- cgit