From f9bdc8043609d54048180c3eda25b299037749e4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 22 Aug 2019 07:04:52 -0700 Subject: Remove blockscale, replace with ethgasstation --- ui/app/ducks/gas/gas-duck.test.js | 24 +++--- ui/app/ducks/gas/gas.duck.js | 29 +++++--- ui/app/selectors/custom-gas.js | 34 ++++----- ui/app/selectors/custom-gas.test.js | 144 ++++++++++++++++++++---------------- 4 files changed, 130 insertions(+), 101 deletions(-) diff --git a/ui/app/ducks/gas/gas-duck.test.js b/ui/app/ducks/gas/gas-duck.test.js index 82a91d5e7..85450489d 100644 --- a/ui/app/ducks/gas/gas-duck.test.js +++ b/ui/app/ducks/gas/gas-duck.test.js @@ -321,10 +321,10 @@ describe('Gas Duck', () => { assert.deepEqual( global.fetch.getCall(0).args, [ - 'https://dev.blockscale.net/api/gasexpress.json', + 'https://ethgasstation.info/json/ethgasAPI.json', { 'headers': {}, - 'referrer': 'https://dev.blockscale.net/api/', + 'referrer': 'http://ethgasstation.info/json/', 'referrerPolicy': 'no-referrer-when-downgrade', 'body': null, 'method': 'GET', @@ -341,12 +341,12 @@ describe('Gas Duck', () => { [{ type: SET_BASIC_GAS_ESTIMATE_DATA, value: { - average: 20, + average: 2, blockTime: 'mockBlock_time', blockNum: 'mockBlockNum', - fast: 30, - fastest: 40, - safeLow: 10, + fast: 3, + fastest: 4, + safeLow: 1, }, }] ) @@ -420,10 +420,10 @@ describe('Gas Duck', () => { assert.deepEqual( global.fetch.getCall(0).args, [ - 'https://dev.blockscale.net/api/gasexpress.json', + 'https://ethgasstation.info/json/ethgasAPI.json', { 'headers': {}, - 'referrer': 'https://dev.blockscale.net/api/', + 'referrer': 'http://ethgasstation.info/json/', 'referrerPolicy': 'no-referrer-when-downgrade', 'body': null, 'method': 'GET', @@ -440,12 +440,12 @@ describe('Gas Duck', () => { [{ type: SET_BASIC_GAS_ESTIMATE_DATA, value: { - average: 20, + average: 2, blockTime: 'mockBlock_time', blockNum: 'mockBlockNum', - fast: 30, - fastest: 40, - safeLow: 10, + fast: 3, + fastest: 4, + safeLow: 1, }, }] ) diff --git a/ui/app/ducks/gas/gas.duck.js b/ui/app/ducks/gas/gas.duck.js index e272455fc..700fec6b0 100644 --- a/ui/app/ducks/gas/gas.duck.js +++ b/ui/app/ducks/gas/gas.duck.js @@ -198,23 +198,31 @@ export function fetchBasicGasEstimates () { } async function fetchExternalBasicGasEstimates (dispatch) { - const response = await fetch('https://dev.blockscale.net/api/gasexpress.json', { + const response = await fetch('https://ethgasstation.info/json/ethgasAPI.json', { 'headers': {}, - 'referrer': 'https://dev.blockscale.net/api/', + 'referrer': 'http://ethgasstation.info/json/', 'referrerPolicy': 'no-referrer-when-downgrade', 'body': null, 'method': 'GET', - 'mode': 'cors'} - ) + 'mode': 'cors', + }) + const { - safeLow, - standard: average, - fast, - fastest, + safeLow: safeLowTimes10, + average: averageTimes10, + fast: fastTimes10, + fastest: fastestTimes10, block_time: blockTime, blockNum, } = await response.json() + const [average, fast, fastest, safeLow] = [ + averageTimes10, + fastTimes10, + fastestTimes10, + safeLowTimes10, + ].map(price => (new BigNumber(price)).div(10).toNumber()) + const basicEstimates = { safeLow, average, @@ -260,8 +268,9 @@ async function fetchExternalBasicGasAndTimeEstimates (dispatch) { 'referrerPolicy': 'no-referrer-when-downgrade', 'body': null, 'method': 'GET', - 'mode': 'cors'} - ) + 'mode': 'cors', + }) + const { average: averageTimes10, avgWait, diff --git a/ui/app/selectors/custom-gas.js b/ui/app/selectors/custom-gas.js index 1f7ee8f9f..79dd0b8f4 100644 --- a/ui/app/selectors/custom-gas.js +++ b/ui/app/selectors/custom-gas.js @@ -239,10 +239,10 @@ function getRenderableBasicEstimateData (state, gasLimit) { gas: { basicEstimates: { safeLow, + average, fast, - fastest, safeLowWait, - fastestWait, + avgWait, fastWait, }, }, @@ -260,21 +260,21 @@ function getRenderableBasicEstimateData (state, gasLimit) { }, { labelKey: 'average', - feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit), + feeInPrimaryCurrency: getRenderableEthFee(average, gasLimit), feeInSecondaryCurrency: showFiat - ? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate) + ? getRenderableConvertedCurrencyFee(average, gasLimit, currentCurrency, conversionRate) : '', - timeEstimate: fastWait && getRenderableTimeEstimate(fastWait), - priceInHexWei: getGasPriceInHexWei(fast), + timeEstimate: avgWait && getRenderableTimeEstimate(avgWait), + priceInHexWei: getGasPriceInHexWei(average), }, { labelKey: 'fast', - feeInPrimaryCurrency: getRenderableEthFee(fastest, gasLimit), + feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit), feeInSecondaryCurrency: showFiat - ? getRenderableConvertedCurrencyFee(fastest, gasLimit, currentCurrency, conversionRate) + ? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate) : '', - timeEstimate: fastestWait && getRenderableTimeEstimate(fastestWait), - priceInHexWei: getGasPriceInHexWei(fastest), + timeEstimate: fastWait && getRenderableTimeEstimate(fastWait), + priceInHexWei: getGasPriceInHexWei(fast), }, ] } @@ -294,8 +294,8 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { gas: { basicEstimates: { safeLow, + average, fast, - fastest, }, }, } = state @@ -312,18 +312,18 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { { labelKey: 'average', feeInSecondaryCurrency: showFiat - ? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate) + ? getRenderableConvertedCurrencyFee(average, gasLimit, currentCurrency, conversionRate) : '', - feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), - priceInHexWei: getGasPriceInHexWei(fast, true), + feeInPrimaryCurrency: getRenderableEthFee(average, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), + priceInHexWei: getGasPriceInHexWei(average, true), }, { labelKey: 'fast', feeInSecondaryCurrency: showFiat - ? getRenderableConvertedCurrencyFee(fastest, gasLimit, currentCurrency, conversionRate) + ? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate) : '', - feeInPrimaryCurrency: getRenderableEthFee(fastest, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), - priceInHexWei: getGasPriceInHexWei(fastest, true), + feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), + priceInHexWei: getGasPriceInHexWei(fast, true), }, ] } diff --git a/ui/app/selectors/custom-gas.test.js b/ui/app/selectors/custom-gas.test.js index 6df4a60c7..efdc9db48 100644 --- a/ui/app/selectors/custom-gas.test.js +++ b/ui/app/selectors/custom-gas.test.js @@ -85,18 +85,18 @@ describe('custom-gas selectors', () => { }, { labelKey: 'average', + feeInPrimaryCurrency: '0.000084 ETH', + feeInSecondaryCurrency: '$0.02', + priceInHexWei: '0xee6b2800', + timeEstimate: '~5 min 18 sec', + }, + { + labelKey: 'fast', feeInSecondaryCurrency: '$0.03', feeInPrimaryCurrency: '0.000105 ETH', timeEstimate: '~3 min 18 sec', priceInHexWei: '0x12a05f200', }, - { - labelKey: 'fast', - feeInSecondaryCurrency: '$0.05', - feeInPrimaryCurrency: '0.00021 ETH', - timeEstimate: '~30 sec', - priceInHexWei: '0x2540be400', - }, ], mockState: { metamask: { @@ -114,6 +114,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 2.5, safeLowWait: 6.6, + average: 4, + avgWait: 5.3, fast: 5, fastWait: 3.3, fastest: 10, @@ -132,19 +134,19 @@ describe('custom-gas selectors', () => { priceInHexWei: '0x12a05f200', }, { + feeInPrimaryCurrency: '0.000147 ETH', + feeInSecondaryCurrency: '$0.38', labelKey: 'average', + priceInHexWei: '0x1a13b8600', + timeEstimate: '~10 min 6 sec', + }, + { + labelKey: 'fast', feeInSecondaryCurrency: '$0.54', feeInPrimaryCurrency: '0.00021 ETH', timeEstimate: '~6 min 36 sec', priceInHexWei: '0x2540be400', }, - { - labelKey: 'fast', - feeInSecondaryCurrency: '$1.07', - feeInPrimaryCurrency: '0.00042 ETH', - timeEstimate: '~1 min', - priceInHexWei: '0x4a817c800', - }, ], mockState: { metamask: { @@ -165,6 +167,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 5, safeLowWait: 13.2, + average: 7, + avgWait: 10.1, fast: 10, fastWait: 6.6, fastest: 20, @@ -184,17 +188,17 @@ describe('custom-gas selectors', () => { }, { labelKey: 'average', + feeInPrimaryCurrency: '0.000147 ETH', feeInSecondaryCurrency: '', - feeInPrimaryCurrency: '0.00021 ETH', - timeEstimate: '~6 min 36 sec', - priceInHexWei: '0x2540be400', + timeEstimate: '~10 min 6 sec', + priceInHexWei: '0x1a13b8600', }, { labelKey: 'fast', feeInSecondaryCurrency: '', - feeInPrimaryCurrency: '0.00042 ETH', - timeEstimate: '~1 min', - priceInHexWei: '0x4a817c800', + feeInPrimaryCurrency: '0.00021 ETH', + timeEstimate: '~6 min 36 sec', + priceInHexWei: '0x2540be400', }, ], mockState: { @@ -216,6 +220,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 5, safeLowWait: 13.2, + average: 7, + avgWait: 10.1, fast: 10, fastWait: 6.6, fastest: 20, @@ -235,18 +241,18 @@ describe('custom-gas selectors', () => { }, { labelKey: 'average', + feeInPrimaryCurrency: '0.000147 ETH', + feeInSecondaryCurrency: '$0.38', + priceInHexWei: '0x1a13b8600', + timeEstimate: '~10 min 6 sec', + }, + { + labelKey: 'fast', feeInSecondaryCurrency: '$0.54', feeInPrimaryCurrency: '0.00021 ETH', timeEstimate: '~6 min 36 sec', priceInHexWei: '0x2540be400', }, - { - labelKey: 'fast', - feeInSecondaryCurrency: '$1.07', - feeInPrimaryCurrency: '0.00042 ETH', - timeEstimate: '~1 min', - priceInHexWei: '0x4a817c800', - }, ], mockState: { metamask: { @@ -267,6 +273,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 5, safeLowWait: 13.2, + average: 7, + avgWait: 10.1, fast: 10, fastWait: 6.6, fastest: 20, @@ -286,18 +294,18 @@ describe('custom-gas selectors', () => { }, { labelKey: 'average', + feeInPrimaryCurrency: '0.000147 ETH', + feeInSecondaryCurrency: '$0.38', + priceInHexWei: '0x1a13b8600', + timeEstimate: '~10 min 6 sec', + }, + { + labelKey: 'fast', feeInSecondaryCurrency: '$0.54', feeInPrimaryCurrency: '0.00021 ETH', timeEstimate: '~6 min 36 sec', priceInHexWei: '0x2540be400', }, - { - labelKey: 'fast', - feeInSecondaryCurrency: '$1.07', - feeInPrimaryCurrency: '0.00042 ETH', - timeEstimate: '~1 min', - priceInHexWei: '0x4a817c800', - }, ], mockState: { metamask: { @@ -318,6 +326,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 5, safeLowWait: 13.2, + average: 7, + avgWait: 10.1, fast: 10, fastWait: 6.6, fastest: 20, @@ -349,16 +359,16 @@ describe('custom-gas selectors', () => { priceInHexWei: '0x5d21dba00', }, { - feeInSecondaryCurrency: '$0.27', - feeInPrimaryCurrency: '0.00105 ETH', + feeInSecondaryCurrency: '$0.16', + feeInPrimaryCurrency: '0.00063 ETH', labelKey: 'average', - priceInHexWei: '0xba43b7400', + priceInHexWei: '0x6fc23ac00', }, { - feeInSecondaryCurrency: '$0.54', - feeInPrimaryCurrency: '0.0021 ETH', + feeInSecondaryCurrency: '$0.27', + feeInPrimaryCurrency: '0.00105 ETH', labelKey: 'fast', - priceInHexWei: '0x174876e800', + priceInHexWei: '0xba43b7400', }, ], mockState: { @@ -380,6 +390,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 25, safeLowWait: 6.6, + average: 30, + avgWait: 5.5, fast: 50, fastWait: 3.3, fastest: 100, @@ -397,16 +409,16 @@ describe('custom-gas selectors', () => { priceInHexWei: '0xba43b7400', }, { - feeInSecondaryCurrency: '$5.37', - feeInPrimaryCurrency: '0.0021 ETH', + feeInSecondaryCurrency: '$4.03', + feeInPrimaryCurrency: '0.00157 ETH', labelKey: 'average', - priceInHexWei: '0x174876e800', + priceInHexWei: '0x1176592e00', }, { - feeInSecondaryCurrency: '$10.74', - feeInPrimaryCurrency: '0.0042 ETH', + feeInSecondaryCurrency: '$5.37', + feeInPrimaryCurrency: '0.0021 ETH', labelKey: 'fast', - priceInHexWei: '0x2e90edd000', + priceInHexWei: '0x174876e800', }, ], mockState: { @@ -428,6 +440,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 50, safeLowWait: 13.2, + average: 75, + avgWait: 9.6, fast: 100, fastWait: 6.6, fastest: 200, @@ -446,15 +460,15 @@ describe('custom-gas selectors', () => { }, { feeInSecondaryCurrency: '', - feeInPrimaryCurrency: '0.0021 ETH', + feeInPrimaryCurrency: '0.00157 ETH', labelKey: 'average', - priceInHexWei: '0x174876e800', + priceInHexWei: '0x1176592e00', }, { feeInSecondaryCurrency: '', - feeInPrimaryCurrency: '0.0042 ETH', + feeInPrimaryCurrency: '0.0021 ETH', labelKey: 'fast', - priceInHexWei: '0x2e90edd000', + priceInHexWei: '0x174876e800', }, ], mockState: { @@ -476,6 +490,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 50, safeLowWait: 13.2, + average: 75, + avgWait: 9.6, fast: 100, fastWait: 6.6, fastest: 200, @@ -493,16 +509,16 @@ describe('custom-gas selectors', () => { priceInHexWei: '0xba43b7400', }, { - feeInSecondaryCurrency: '$5.37', - feeInPrimaryCurrency: '0.0021 ETH', + feeInSecondaryCurrency: '$4.03', + feeInPrimaryCurrency: '0.00157 ETH', labelKey: 'average', - priceInHexWei: '0x174876e800', + priceInHexWei: '0x1176592e00', }, { - feeInSecondaryCurrency: '$10.74', - feeInPrimaryCurrency: '0.0042 ETH', + feeInSecondaryCurrency: '$5.37', + feeInPrimaryCurrency: '0.0021 ETH', labelKey: 'fast', - priceInHexWei: '0x2e90edd000', + priceInHexWei: '0x174876e800', }, ], mockState: { @@ -524,6 +540,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 50, safeLowWait: 13.2, + average: 75, + avgWait: 9.6, fast: 100, fastWait: 6.6, fastest: 200, @@ -541,16 +559,16 @@ describe('custom-gas selectors', () => { priceInHexWei: '0xba43b7400', }, { - feeInSecondaryCurrency: '$5.37', - feeInPrimaryCurrency: '0.0021 ETH', + feeInSecondaryCurrency: '$4.03', + feeInPrimaryCurrency: '0.00157 ETH', labelKey: 'average', - priceInHexWei: '0x174876e800', + priceInHexWei: '0x1176592e00', }, { - feeInSecondaryCurrency: '$10.74', - feeInPrimaryCurrency: '0.0042 ETH', + feeInSecondaryCurrency: '$5.37', + feeInPrimaryCurrency: '0.0021 ETH', labelKey: 'fast', - priceInHexWei: '0x2e90edd000', + priceInHexWei: '0x174876e800', }, ], mockState: { @@ -572,6 +590,8 @@ describe('custom-gas selectors', () => { blockTime: 14.16326530612245, safeLow: 50, safeLowWait: 13.2, + average: 75, + avgWait: 9.6, fast: 100, fastWait: 6.6, fastest: 200, -- cgit