From de01a6f112716cad8ebc1fd56dd304f1818704f4 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 28 Jun 2018 13:17:44 -0230 Subject: [PATCH 1/4] 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) From 7babacf062cd77235ecfba3ca352a65f3a702728 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 28 Jun 2018 21:40:06 -0230 Subject: [PATCH 2/4] Remove unnecessary anonymous function call in actions.js gas estimation. --- ui/app/actions.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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({ From c47a4ce2c93d50425f580c2a166c1698cf1c508f Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 4 Jul 2018 16:44:56 -0230 Subject: [PATCH 3/4] Update new-ui-send integration tests to always explicitly set gas price. (e2e tests handle auto-setting and defaults) --- test/integration/lib/send-new-ui.js | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/test/integration/lib/send-new-ui.js b/test/integration/lib/send-new-ui.js index 72e4a8cb1..85885f118 100644 --- a/test/integration/lib/send-new-ui.js +++ b/test/integration/lib/send-new-ui.js @@ -114,19 +114,8 @@ async function runSendFlowTest(assert, done) { errorMessage = $('.send-v2__error') assert.equal(errorMessage.length, 0, 'send should stop rendering amount error message after amount is corrected') - const sendGasField = await queryAsync($, '.send-v2__gas-fee-display') - assert.equal( - sendGasField.find('.currency-display__input-wrapper > input').val(), - '0.000021', - 'send gas field should show estimated gas total' - ) - assert.equal( - sendGasField.find('.currency-display__converted-value')[0].textContent, - '$0.03 USD', - 'send gas field should show estimated gas total converted to USD' - ) - await customizeGas(assert, 0, 21000, '0', '$0.00 USD') + await customizeGas(assert, 1, 21000, '0.000021', '$0.03 USD') await customizeGas(assert, 500, 60000, '0.03', '$36.03 USD') const sendButton = await queryAsync($, 'button.btn-primary.btn--large.page-container__footer-button') From 7d7662191af708621549cfd67592375436263eb3 Mon Sep 17 00:00:00 2001 From: Dan Date: Wed, 4 Jul 2018 21:26:02 -0230 Subject: [PATCH 4/4] Improve error and promise resolution handling in action.js updateGasData(). --- ui/app/actions.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) 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)