Skip to content

Commit

Permalink
Merge pull request #7059 from MetaMask/Gas-Estimation-Api
Browse files Browse the repository at this point in the history
Remove blockscale, replace with ethgasstation
  • Loading branch information
danfinlay authored Aug 22, 2019
2 parents ecbde20 + f9bdc80 commit fe2d053
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 101 deletions.
24 changes: 12 additions & 12 deletions ui/app/ducks/gas/gas-duck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
},
}]
)
Expand Down Expand Up @@ -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',
Expand All @@ -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,
},
}]
)
Expand Down
29 changes: 19 additions & 10 deletions ui/app/ducks/gas/gas.duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 17 additions & 17 deletions ui/app/selectors/custom-gas.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ function getRenderableBasicEstimateData (state, gasLimit) {
gas: {
basicEstimates: {
safeLow,
average,
fast,
fastest,
safeLowWait,
fastestWait,
avgWait,
fastWait,
},
},
Expand All @@ -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),
},
]
}
Expand All @@ -294,8 +294,8 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) {
gas: {
basicEstimates: {
safeLow,
average,
fast,
fastest,
},
},
} = state
Expand All @@ -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),
},
]
}
Loading

0 comments on commit fe2d053

Please sign in to comment.