Merge remote-tracking branch 'origin/develop' into Version-v8.0.0

* origin/develop:
  Add envar for ETH Gas Station API key (#8870)
feature/default_network_editable
Mark Stacey 4 years ago
commit 595e08fbbb
  1. 1
      development/build/scripts.js
  2. 4
      test/e2e/webdriver/index.js
  3. 4
      test/integration/lib/confirm-sig-requests.js
  4. 4
      test/integration/lib/currency-localization.js
  5. 80
      ui/app/ducks/gas/gas-duck.test.js
  6. 53
      ui/app/ducks/gas/gas.duck.js

@ -338,6 +338,7 @@ function createScriptTasks ({ browserPlatforms, livereload }) {
IN_TEST: opts.testing ? 'true' : false, IN_TEST: opts.testing ? 'true' : false,
PUBNUB_SUB_KEY: process.env.PUBNUB_SUB_KEY || '', PUBNUB_SUB_KEY: process.env.PUBNUB_SUB_KEY || '',
PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '', PUBNUB_PUB_KEY: process.env.PUBNUB_PUB_KEY || '',
ETH_GAS_STATION_API_KEY: process.env.ETH_GAS_STATION_API_KEY || '',
CONF: opts.devMode ? conf : ({}), CONF: opts.devMode ? conf : ({}),
}), { }), {
global: true, global: true,

@ -41,9 +41,9 @@ async function setupFetchMocking (driver) {
window.origFetch = window.fetch.bind(window) window.origFetch = window.fetch.bind(window)
window.fetch = async (...args) => { window.fetch = async (...args) => {
const url = args[0] const url = args[0]
if (url === 'https://ethgasstation.info/json/ethgasAPI.json') { if (url.match(/^http(s)?:\/\/ethgasstation\.info\/json\/ethgasAPI.*/u)) {
return { json: async () => clone(fetchMockResponses.ethGasBasic) } return { json: async () => clone(fetchMockResponses.ethGasBasic) }
} else if (url === 'https://ethgasstation.info/json/predictTable.json') { } else if (url.match(/http(s?):\/\/ethgasstation\.info\/json\/predictTable.*/u)) {
return { json: async () => clone(fetchMockResponses.ethGasPredictTable) } return { json: async () => clone(fetchMockResponses.ethGasPredictTable) }
} else if (url.match(/chromeextensionmm/)) { } else if (url.match(/chromeextensionmm/)) {
return { json: async () => clone(fetchMockResponses.metametrics) } return { json: async () => clone(fetchMockResponses.metametrics) }

@ -24,9 +24,9 @@ async function runConfirmSigRequestsTest (assert) {
const realFetch = window.fetch.bind(window) const realFetch = window.fetch.bind(window)
window.fetch = (...args) => { window.fetch = (...args) => {
if (args[0] === 'https://ethgasstation.info/json/ethgasAPI.json') { if (args[0].match(/^http(s)?:\/\/ethgasstation\.info\/json\/ethgasAPI.*/u)) {
return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) }) return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) })
} else if (args[0] === 'https://ethgasstation.info/json/predictTable.json') { } else if (args[0].match(/http(s?):\/\/ethgasstation\.info\/json\/predictTable.*/u)) {
return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) }) return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) })
} else if (args[0].match(/chromeextensionmm/)) { } else if (args[0].match(/chromeextensionmm/)) {
return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) }) return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) })

@ -23,9 +23,9 @@ async function runCurrencyLocalizationTest (assert) {
const realFetch = window.fetch.bind(window) const realFetch = window.fetch.bind(window)
window.fetch = (...args) => { window.fetch = (...args) => {
if (args[0] === 'https://ethgasstation.info/json/ethgasAPI.json') { if (args[0].match(/^http(s)?:\/\/ethgasstation\.info\/json\/ethgasAPI.*/u)) {
return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) }) return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasBasic)) })
} else if (args[0] === 'https://ethgasstation.info/json/predictTable.json') { } else if (args[0].match(/http(s?):\/\/ethgasstation\.info\/json\/predictTable.*/u)) {
return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) }) return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.ethGasPredictTable)) })
} else if (args[0].match(/chromeextensionmm/)) { } else if (args[0].match(/chromeextensionmm/)) {
return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) }) return Promise.resolve({ json: () => Promise.resolve(JSON.parse(fetchMockResponses.metametrics)) })

@ -290,19 +290,9 @@ describe('Gas Duck', function () {
mockDistpatch.getCall(0).args, mockDistpatch.getCall(0).args,
[{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ] [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ]
) )
assert.deepEqual( assert.ok(
window.fetch.getCall(0).args, window.fetch.getCall(0).args[0].startsWith('https://ethgasstation.info/json/ethgasAPI.json'),
[ 'should fetch ETH Gas Station',
'https://ethgasstation.info/json/ethgasAPI.json',
{
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
},
]
) )
assert.deepEqual( assert.deepEqual(
mockDistpatch.getCall(1).args, mockDistpatch.getCall(1).args,
@ -389,19 +379,9 @@ describe('Gas Duck', function () {
mockDistpatch.getCall(0).args, mockDistpatch.getCall(0).args,
[{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ] [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ]
) )
assert.deepEqual( assert.ok(
window.fetch.getCall(0).args, window.fetch.getCall(0).args[0].startsWith('https://ethgasstation.info/json/ethgasAPI.json'),
[ 'should fetch ETH Gas Station',
'https://ethgasstation.info/json/ethgasAPI.json',
{
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
},
]
) )
assert.deepEqual( assert.deepEqual(
mockDistpatch.getCall(1).args, mockDistpatch.getCall(1).args,
@ -443,19 +423,9 @@ describe('Gas Duck', function () {
mockDistpatch.getCall(0).args, mockDistpatch.getCall(0).args,
[{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ] [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ]
) )
assert.deepEqual( assert.ok(
window.fetch.getCall(0).args, window.fetch.getCall(0).args[0].startsWith('https://ethgasstation.info/json/ethgasAPI.json'),
[ 'should fetch ETH Gas Station',
'https://ethgasstation.info/json/ethgasAPI.json',
{
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
},
]
) )
assert.deepEqual( assert.deepEqual(
@ -564,19 +534,9 @@ describe('Gas Duck', function () {
mockDistpatch.getCall(0).args, mockDistpatch.getCall(0).args,
[{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ] [{ type: BASIC_GAS_ESTIMATE_LOADING_STARTED } ]
) )
assert.deepEqual( assert.ok(
window.fetch.getCall(0).args, window.fetch.getCall(0).args[0].startsWith('https://ethgasstation.info/json/ethgasAPI.json'),
[ 'should fetch ETH Gas Station',
'https://ethgasstation.info/json/ethgasAPI.json',
{
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
},
]
) )
assert.deepEqual( assert.deepEqual(
@ -625,19 +585,9 @@ describe('Gas Duck', function () {
mockDistpatch.getCall(0).args, mockDistpatch.getCall(0).args,
[{ type: GAS_ESTIMATE_LOADING_STARTED } ] [{ type: GAS_ESTIMATE_LOADING_STARTED } ]
) )
assert.deepEqual( assert.ok(
window.fetch.getCall(0).args, window.fetch.getCall(0).args[0].startsWith('https://ethgasstation.info/json/predictTable.json'),
[ 'should fetch ETH Gas Station',
'https://ethgasstation.info/json/predictTable.json',
{
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
},
]
) )
assert.deepEqual( assert.deepEqual(

@ -172,6 +172,32 @@ export function gasEstimatesLoadingFinished () {
} }
} }
async function queryEthGasStationBasic () {
const apiKey = process.env.ETH_GAS_STATION_API_KEY ? `?api-key=${process.env.ETH_GAS_STATION_API_KEY}` : ''
const url = `https://ethgasstation.info/json/ethgasAPI.json${apiKey}`
return await window.fetch(url, {
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
})
}
async function queryEthGasStationPredictionTable () {
const apiKey = process.env.ETH_GAS_STATION_API_KEY ? `?api-key=${process.env.ETH_GAS_STATION_API_KEY}` : ''
const url = `https://ethgasstation.info/json/predictTable.json${apiKey}`
return await window.fetch(url, {
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors' }
)
}
export function fetchBasicGasEstimates () { export function fetchBasicGasEstimates () {
return async (dispatch, getState) => { return async (dispatch, getState) => {
const { basicPriceEstimatesLastRetrieved } = getState().gas const { basicPriceEstimatesLastRetrieved } = getState().gas
@ -195,14 +221,7 @@ export function fetchBasicGasEstimates () {
} }
async function fetchExternalBasicGasEstimates (dispatch) { async function fetchExternalBasicGasEstimates (dispatch) {
const response = await window.fetch('https://ethgasstation.info/json/ethgasAPI.json', { const response = await queryEthGasStationBasic()
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
})
const { const {
safeLow: safeLowTimes10, safeLow: safeLowTimes10,
@ -259,14 +278,7 @@ export function fetchBasicGasAndTimeEstimates () {
} }
async function fetchExternalBasicGasAndTimeEstimates (dispatch) { async function fetchExternalBasicGasAndTimeEstimates (dispatch) {
const response = await window.fetch('https://ethgasstation.info/json/ethgasAPI.json', { const response = await queryEthGasStationBasic()
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors',
})
const { const {
average: averageTimes10, average: averageTimes10,
@ -377,14 +389,7 @@ export function fetchGasEstimates (blockTime) {
dispatch(gasEstimatesLoadingStarted()) dispatch(gasEstimatesLoadingStarted())
const promiseToFetch = Date.now() - timeLastRetrieved > 75000 const promiseToFetch = Date.now() - timeLastRetrieved > 75000
? window.fetch('https://ethgasstation.info/json/predictTable.json', { ? queryEthGasStationPredictionTable()
'headers': {},
'referrer': 'http://ethgasstation.info/json/',
'referrerPolicy': 'no-referrer-when-downgrade',
'body': null,
'method': 'GET',
'mode': 'cors' }
)
.then((r) => r.json()) .then((r) => r.json())
.then((r) => { .then((r) => {
const estimatedPricesAndTimes = r.map(({ expectedTime, expectedWait, gasprice }) => ({ expectedTime, expectedWait, gasprice })) const estimatedPricesAndTimes = r.map(({ expectedTime, expectedWait, gasprice }) => ({ expectedTime, expectedWait, gasprice }))

Loading…
Cancel
Save