Merge pull request #7059 from MetaMask/Gas-Estimation-Api

Remove blockscale, replace with ethgasstation
feature/default_network_editable
Dan Finlay 5 years ago committed by GitHub
commit fe2d053435
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      ui/app/ducks/gas/gas-duck.test.js
  2. 29
      ui/app/ducks/gas/gas.duck.js
  3. 34
      ui/app/selectors/custom-gas.js
  4. 144
      ui/app/selectors/custom-gas.test.js

@ -321,10 +321,10 @@ describe('Gas Duck', () => {
assert.deepEqual( assert.deepEqual(
global.fetch.getCall(0).args, global.fetch.getCall(0).args,
[ [
'https://dev.blockscale.net/api/gasexpress.json', 'https://ethgasstation.info/json/ethgasAPI.json',
{ {
'headers': {}, 'headers': {},
'referrer': 'https://dev.blockscale.net/api/', 'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade', 'referrerPolicy': 'no-referrer-when-downgrade',
'body': null, 'body': null,
'method': 'GET', 'method': 'GET',
@ -341,12 +341,12 @@ describe('Gas Duck', () => {
[{ [{
type: SET_BASIC_GAS_ESTIMATE_DATA, type: SET_BASIC_GAS_ESTIMATE_DATA,
value: { value: {
average: 20, average: 2,
blockTime: 'mockBlock_time', blockTime: 'mockBlock_time',
blockNum: 'mockBlockNum', blockNum: 'mockBlockNum',
fast: 30, fast: 3,
fastest: 40, fastest: 4,
safeLow: 10, safeLow: 1,
}, },
}] }]
) )
@ -420,10 +420,10 @@ describe('Gas Duck', () => {
assert.deepEqual( assert.deepEqual(
global.fetch.getCall(0).args, global.fetch.getCall(0).args,
[ [
'https://dev.blockscale.net/api/gasexpress.json', 'https://ethgasstation.info/json/ethgasAPI.json',
{ {
'headers': {}, 'headers': {},
'referrer': 'https://dev.blockscale.net/api/', 'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade', 'referrerPolicy': 'no-referrer-when-downgrade',
'body': null, 'body': null,
'method': 'GET', 'method': 'GET',
@ -440,12 +440,12 @@ describe('Gas Duck', () => {
[{ [{
type: SET_BASIC_GAS_ESTIMATE_DATA, type: SET_BASIC_GAS_ESTIMATE_DATA,
value: { value: {
average: 20, average: 2,
blockTime: 'mockBlock_time', blockTime: 'mockBlock_time',
blockNum: 'mockBlockNum', blockNum: 'mockBlockNum',
fast: 30, fast: 3,
fastest: 40, fastest: 4,
safeLow: 10, safeLow: 1,
}, },
}] }]
) )

@ -198,23 +198,31 @@ export function fetchBasicGasEstimates () {
} }
async function fetchExternalBasicGasEstimates (dispatch) { 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': {}, 'headers': {},
'referrer': 'https://dev.blockscale.net/api/', 'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade', 'referrerPolicy': 'no-referrer-when-downgrade',
'body': null, 'body': null,
'method': 'GET', 'method': 'GET',
'mode': 'cors'} 'mode': 'cors',
) })
const { const {
safeLow, safeLow: safeLowTimes10,
standard: average, average: averageTimes10,
fast, fast: fastTimes10,
fastest, fastest: fastestTimes10,
block_time: blockTime, block_time: blockTime,
blockNum, blockNum,
} = await response.json() } = await response.json()
const [average, fast, fastest, safeLow] = [
averageTimes10,
fastTimes10,
fastestTimes10,
safeLowTimes10,
].map(price => (new BigNumber(price)).div(10).toNumber())
const basicEstimates = { const basicEstimates = {
safeLow, safeLow,
average, average,
@ -260,8 +268,9 @@ async function fetchExternalBasicGasAndTimeEstimates (dispatch) {
'referrerPolicy': 'no-referrer-when-downgrade', 'referrerPolicy': 'no-referrer-when-downgrade',
'body': null, 'body': null,
'method': 'GET', 'method': 'GET',
'mode': 'cors'} 'mode': 'cors',
) })
const { const {
average: averageTimes10, average: averageTimes10,
avgWait, avgWait,

@ -239,10 +239,10 @@ function getRenderableBasicEstimateData (state, gasLimit) {
gas: { gas: {
basicEstimates: { basicEstimates: {
safeLow, safeLow,
average,
fast, fast,
fastest,
safeLowWait, safeLowWait,
fastestWait, avgWait,
fastWait, fastWait,
}, },
}, },
@ -260,21 +260,21 @@ function getRenderableBasicEstimateData (state, gasLimit) {
}, },
{ {
labelKey: 'average', labelKey: 'average',
feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit), feeInPrimaryCurrency: getRenderableEthFee(average, gasLimit),
feeInSecondaryCurrency: showFiat feeInSecondaryCurrency: showFiat
? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate) ? getRenderableConvertedCurrencyFee(average, gasLimit, currentCurrency, conversionRate)
: '', : '',
timeEstimate: fastWait && getRenderableTimeEstimate(fastWait), timeEstimate: avgWait && getRenderableTimeEstimate(avgWait),
priceInHexWei: getGasPriceInHexWei(fast), priceInHexWei: getGasPriceInHexWei(average),
}, },
{ {
labelKey: 'fast', labelKey: 'fast',
feeInPrimaryCurrency: getRenderableEthFee(fastest, gasLimit), feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit),
feeInSecondaryCurrency: showFiat feeInSecondaryCurrency: showFiat
? getRenderableConvertedCurrencyFee(fastest, gasLimit, currentCurrency, conversionRate) ? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate)
: '', : '',
timeEstimate: fastestWait && getRenderableTimeEstimate(fastestWait), timeEstimate: fastWait && getRenderableTimeEstimate(fastWait),
priceInHexWei: getGasPriceInHexWei(fastest), priceInHexWei: getGasPriceInHexWei(fast),
}, },
] ]
} }
@ -294,8 +294,8 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) {
gas: { gas: {
basicEstimates: { basicEstimates: {
safeLow, safeLow,
average,
fast, fast,
fastest,
}, },
}, },
} = state } = state
@ -312,18 +312,18 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) {
{ {
labelKey: 'average', labelKey: 'average',
feeInSecondaryCurrency: showFiat feeInSecondaryCurrency: showFiat
? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate) ? getRenderableConvertedCurrencyFee(average, gasLimit, currentCurrency, conversionRate)
: '', : '',
feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), feeInPrimaryCurrency: getRenderableEthFee(average, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true),
priceInHexWei: getGasPriceInHexWei(fast, true), priceInHexWei: getGasPriceInHexWei(average, true),
}, },
{ {
labelKey: 'fast', labelKey: 'fast',
feeInSecondaryCurrency: showFiat feeInSecondaryCurrency: showFiat
? getRenderableConvertedCurrencyFee(fastest, gasLimit, currentCurrency, conversionRate) ? getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate)
: '', : '',
feeInPrimaryCurrency: getRenderableEthFee(fastest, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true), feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true),
priceInHexWei: getGasPriceInHexWei(fastest, true), priceInHexWei: getGasPriceInHexWei(fast, true),
}, },
] ]
} }

@ -85,18 +85,18 @@ describe('custom-gas selectors', () => {
}, },
{ {
labelKey: 'average', labelKey: 'average',
feeInPrimaryCurrency: '0.000084 ETH',
feeInSecondaryCurrency: '$0.02',
priceInHexWei: '0xee6b2800',
timeEstimate: '~5 min 18 sec',
},
{
labelKey: 'fast',
feeInSecondaryCurrency: '$0.03', feeInSecondaryCurrency: '$0.03',
feeInPrimaryCurrency: '0.000105 ETH', feeInPrimaryCurrency: '0.000105 ETH',
timeEstimate: '~3 min 18 sec', timeEstimate: '~3 min 18 sec',
priceInHexWei: '0x12a05f200', priceInHexWei: '0x12a05f200',
}, },
{
labelKey: 'fast',
feeInSecondaryCurrency: '$0.05',
feeInPrimaryCurrency: '0.00021 ETH',
timeEstimate: '~30 sec',
priceInHexWei: '0x2540be400',
},
], ],
mockState: { mockState: {
metamask: { metamask: {
@ -114,6 +114,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 2.5, safeLow: 2.5,
safeLowWait: 6.6, safeLowWait: 6.6,
average: 4,
avgWait: 5.3,
fast: 5, fast: 5,
fastWait: 3.3, fastWait: 3.3,
fastest: 10, fastest: 10,
@ -132,19 +134,19 @@ describe('custom-gas selectors', () => {
priceInHexWei: '0x12a05f200', priceInHexWei: '0x12a05f200',
}, },
{ {
feeInPrimaryCurrency: '0.000147 ETH',
feeInSecondaryCurrency: '$0.38',
labelKey: 'average', labelKey: 'average',
priceInHexWei: '0x1a13b8600',
timeEstimate: '~10 min 6 sec',
},
{
labelKey: 'fast',
feeInSecondaryCurrency: '$0.54', feeInSecondaryCurrency: '$0.54',
feeInPrimaryCurrency: '0.00021 ETH', feeInPrimaryCurrency: '0.00021 ETH',
timeEstimate: '~6 min 36 sec', timeEstimate: '~6 min 36 sec',
priceInHexWei: '0x2540be400', priceInHexWei: '0x2540be400',
}, },
{
labelKey: 'fast',
feeInSecondaryCurrency: '$1.07',
feeInPrimaryCurrency: '0.00042 ETH',
timeEstimate: '~1 min',
priceInHexWei: '0x4a817c800',
},
], ],
mockState: { mockState: {
metamask: { metamask: {
@ -165,6 +167,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 5, safeLow: 5,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 7,
avgWait: 10.1,
fast: 10, fast: 10,
fastWait: 6.6, fastWait: 6.6,
fastest: 20, fastest: 20,
@ -184,17 +188,17 @@ describe('custom-gas selectors', () => {
}, },
{ {
labelKey: 'average', labelKey: 'average',
feeInPrimaryCurrency: '0.000147 ETH',
feeInSecondaryCurrency: '', feeInSecondaryCurrency: '',
feeInPrimaryCurrency: '0.00021 ETH', timeEstimate: '~10 min 6 sec',
timeEstimate: '~6 min 36 sec', priceInHexWei: '0x1a13b8600',
priceInHexWei: '0x2540be400',
}, },
{ {
labelKey: 'fast', labelKey: 'fast',
feeInSecondaryCurrency: '', feeInSecondaryCurrency: '',
feeInPrimaryCurrency: '0.00042 ETH', feeInPrimaryCurrency: '0.00021 ETH',
timeEstimate: '~1 min', timeEstimate: '~6 min 36 sec',
priceInHexWei: '0x4a817c800', priceInHexWei: '0x2540be400',
}, },
], ],
mockState: { mockState: {
@ -216,6 +220,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 5, safeLow: 5,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 7,
avgWait: 10.1,
fast: 10, fast: 10,
fastWait: 6.6, fastWait: 6.6,
fastest: 20, fastest: 20,
@ -235,18 +241,18 @@ describe('custom-gas selectors', () => {
}, },
{ {
labelKey: 'average', labelKey: 'average',
feeInPrimaryCurrency: '0.000147 ETH',
feeInSecondaryCurrency: '$0.38',
priceInHexWei: '0x1a13b8600',
timeEstimate: '~10 min 6 sec',
},
{
labelKey: 'fast',
feeInSecondaryCurrency: '$0.54', feeInSecondaryCurrency: '$0.54',
feeInPrimaryCurrency: '0.00021 ETH', feeInPrimaryCurrency: '0.00021 ETH',
timeEstimate: '~6 min 36 sec', timeEstimate: '~6 min 36 sec',
priceInHexWei: '0x2540be400', priceInHexWei: '0x2540be400',
}, },
{
labelKey: 'fast',
feeInSecondaryCurrency: '$1.07',
feeInPrimaryCurrency: '0.00042 ETH',
timeEstimate: '~1 min',
priceInHexWei: '0x4a817c800',
},
], ],
mockState: { mockState: {
metamask: { metamask: {
@ -267,6 +273,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 5, safeLow: 5,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 7,
avgWait: 10.1,
fast: 10, fast: 10,
fastWait: 6.6, fastWait: 6.6,
fastest: 20, fastest: 20,
@ -286,18 +294,18 @@ describe('custom-gas selectors', () => {
}, },
{ {
labelKey: 'average', labelKey: 'average',
feeInPrimaryCurrency: '0.000147 ETH',
feeInSecondaryCurrency: '$0.38',
priceInHexWei: '0x1a13b8600',
timeEstimate: '~10 min 6 sec',
},
{
labelKey: 'fast',
feeInSecondaryCurrency: '$0.54', feeInSecondaryCurrency: '$0.54',
feeInPrimaryCurrency: '0.00021 ETH', feeInPrimaryCurrency: '0.00021 ETH',
timeEstimate: '~6 min 36 sec', timeEstimate: '~6 min 36 sec',
priceInHexWei: '0x2540be400', priceInHexWei: '0x2540be400',
}, },
{
labelKey: 'fast',
feeInSecondaryCurrency: '$1.07',
feeInPrimaryCurrency: '0.00042 ETH',
timeEstimate: '~1 min',
priceInHexWei: '0x4a817c800',
},
], ],
mockState: { mockState: {
metamask: { metamask: {
@ -318,6 +326,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 5, safeLow: 5,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 7,
avgWait: 10.1,
fast: 10, fast: 10,
fastWait: 6.6, fastWait: 6.6,
fastest: 20, fastest: 20,
@ -349,16 +359,16 @@ describe('custom-gas selectors', () => {
priceInHexWei: '0x5d21dba00', priceInHexWei: '0x5d21dba00',
}, },
{ {
feeInSecondaryCurrency: '$0.27', feeInSecondaryCurrency: '$0.16',
feeInPrimaryCurrency: '0.00105 ETH', feeInPrimaryCurrency: '0.00063 ETH',
labelKey: 'average', labelKey: 'average',
priceInHexWei: '0xba43b7400', priceInHexWei: '0x6fc23ac00',
}, },
{ {
feeInSecondaryCurrency: '$0.54', feeInSecondaryCurrency: '$0.27',
feeInPrimaryCurrency: '0.0021 ETH', feeInPrimaryCurrency: '0.00105 ETH',
labelKey: 'fast', labelKey: 'fast',
priceInHexWei: '0x174876e800', priceInHexWei: '0xba43b7400',
}, },
], ],
mockState: { mockState: {
@ -380,6 +390,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 25, safeLow: 25,
safeLowWait: 6.6, safeLowWait: 6.6,
average: 30,
avgWait: 5.5,
fast: 50, fast: 50,
fastWait: 3.3, fastWait: 3.3,
fastest: 100, fastest: 100,
@ -397,16 +409,16 @@ describe('custom-gas selectors', () => {
priceInHexWei: '0xba43b7400', priceInHexWei: '0xba43b7400',
}, },
{ {
feeInSecondaryCurrency: '$5.37', feeInSecondaryCurrency: '$4.03',
feeInPrimaryCurrency: '0.0021 ETH', feeInPrimaryCurrency: '0.00157 ETH',
labelKey: 'average', labelKey: 'average',
priceInHexWei: '0x174876e800', priceInHexWei: '0x1176592e00',
}, },
{ {
feeInSecondaryCurrency: '$10.74', feeInSecondaryCurrency: '$5.37',
feeInPrimaryCurrency: '0.0042 ETH', feeInPrimaryCurrency: '0.0021 ETH',
labelKey: 'fast', labelKey: 'fast',
priceInHexWei: '0x2e90edd000', priceInHexWei: '0x174876e800',
}, },
], ],
mockState: { mockState: {
@ -428,6 +440,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 50, safeLow: 50,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 75,
avgWait: 9.6,
fast: 100, fast: 100,
fastWait: 6.6, fastWait: 6.6,
fastest: 200, fastest: 200,
@ -446,15 +460,15 @@ describe('custom-gas selectors', () => {
}, },
{ {
feeInSecondaryCurrency: '', feeInSecondaryCurrency: '',
feeInPrimaryCurrency: '0.0021 ETH', feeInPrimaryCurrency: '0.00157 ETH',
labelKey: 'average', labelKey: 'average',
priceInHexWei: '0x174876e800', priceInHexWei: '0x1176592e00',
}, },
{ {
feeInSecondaryCurrency: '', feeInSecondaryCurrency: '',
feeInPrimaryCurrency: '0.0042 ETH', feeInPrimaryCurrency: '0.0021 ETH',
labelKey: 'fast', labelKey: 'fast',
priceInHexWei: '0x2e90edd000', priceInHexWei: '0x174876e800',
}, },
], ],
mockState: { mockState: {
@ -476,6 +490,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 50, safeLow: 50,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 75,
avgWait: 9.6,
fast: 100, fast: 100,
fastWait: 6.6, fastWait: 6.6,
fastest: 200, fastest: 200,
@ -493,16 +509,16 @@ describe('custom-gas selectors', () => {
priceInHexWei: '0xba43b7400', priceInHexWei: '0xba43b7400',
}, },
{ {
feeInSecondaryCurrency: '$5.37', feeInSecondaryCurrency: '$4.03',
feeInPrimaryCurrency: '0.0021 ETH', feeInPrimaryCurrency: '0.00157 ETH',
labelKey: 'average', labelKey: 'average',
priceInHexWei: '0x174876e800', priceInHexWei: '0x1176592e00',
}, },
{ {
feeInSecondaryCurrency: '$10.74', feeInSecondaryCurrency: '$5.37',
feeInPrimaryCurrency: '0.0042 ETH', feeInPrimaryCurrency: '0.0021 ETH',
labelKey: 'fast', labelKey: 'fast',
priceInHexWei: '0x2e90edd000', priceInHexWei: '0x174876e800',
}, },
], ],
mockState: { mockState: {
@ -524,6 +540,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 50, safeLow: 50,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 75,
avgWait: 9.6,
fast: 100, fast: 100,
fastWait: 6.6, fastWait: 6.6,
fastest: 200, fastest: 200,
@ -541,16 +559,16 @@ describe('custom-gas selectors', () => {
priceInHexWei: '0xba43b7400', priceInHexWei: '0xba43b7400',
}, },
{ {
feeInSecondaryCurrency: '$5.37', feeInSecondaryCurrency: '$4.03',
feeInPrimaryCurrency: '0.0021 ETH', feeInPrimaryCurrency: '0.00157 ETH',
labelKey: 'average', labelKey: 'average',
priceInHexWei: '0x174876e800', priceInHexWei: '0x1176592e00',
}, },
{ {
feeInSecondaryCurrency: '$10.74', feeInSecondaryCurrency: '$5.37',
feeInPrimaryCurrency: '0.0042 ETH', feeInPrimaryCurrency: '0.0021 ETH',
labelKey: 'fast', labelKey: 'fast',
priceInHexWei: '0x2e90edd000', priceInHexWei: '0x174876e800',
}, },
], ],
mockState: { mockState: {
@ -572,6 +590,8 @@ describe('custom-gas selectors', () => {
blockTime: 14.16326530612245, blockTime: 14.16326530612245,
safeLow: 50, safeLow: 50,
safeLowWait: 13.2, safeLowWait: 13.2,
average: 75,
avgWait: 9.6,
fast: 100, fast: 100,
fastWait: 6.6, fastWait: 6.6,
fastest: 200, fastest: 200,

Loading…
Cancel
Save