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. --- app/scripts/metamask-controller.js | 1 + ui/app/actions.js | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index d40a351a5..2055a2dc2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -338,6 +338,7 @@ module.exports = class MetamaskController extends EventEmitter { markAccountsFound: this.markAccountsFound.bind(this), markPasswordForgotten: this.markPasswordForgotten.bind(this), unMarkPasswordForgotten: this.unMarkPasswordForgotten.bind(this), + getGasPrice: (cb) => cb(null, this.getGasPrice()), // coinbase buyEth: this.buyEth.bind(this), 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