From 274e4b3bcd1633e8fe78a33528d63b7567355f9e Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 29 Oct 2018 16:53:18 -0700 Subject: Introduce constants for eth gas station and coinbase --- packages/instant/src/constants.ts | 2 ++ packages/instant/src/util/coinbase_api.ts | 5 +++-- packages/instant/src/util/gas_price_estimator.ts | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/instant/src/constants.ts b/packages/instant/src/constants.ts index 47cb2eaeb..424f35ecb 100644 --- a/packages/instant/src/constants.ts +++ b/packages/instant/src/constants.ts @@ -5,3 +5,5 @@ export const DEFAULT_ZERO_EX_CONTAINER_SELECTOR = '#zeroExInstantContainer'; export const WEB_3_WRAPPER_TRANSACTION_FAILED_ERROR_MSG_PREFIX = 'Transaction failed'; export const GWEI_IN_WEI = new BigNumber(1000000000); export const DEFAULT_GAS_PRICE = GWEI_IN_WEI.mul(6); +export const ETH_GAS_STATION_API_BASE_URL = 'https://ethgasstation.info'; +export const COINBASE_API_BASE_URL = 'https://api.coinbase.com/v2'; diff --git a/packages/instant/src/util/coinbase_api.ts b/packages/instant/src/util/coinbase_api.ts index 080421f98..32401e423 100644 --- a/packages/instant/src/util/coinbase_api.ts +++ b/packages/instant/src/util/coinbase_api.ts @@ -1,9 +1,10 @@ import { BigNumber } from '@0x/utils'; -const baseEndpoint = 'https://api.coinbase.com/v2'; +import { COINBASE_API_BASE_URL } from '../constants'; + export const coinbaseApi = { getEthUsdPrice: async (): Promise => { - const res = await fetch(`${baseEndpoint}/prices/ETH-USD/buy`); + const res = await fetch(`${COINBASE_API_BASE_URL}/prices/ETH-USD/buy`); const resJson = await res.json(); return new BigNumber(resJson.data.amount); }, diff --git a/packages/instant/src/util/gas_price_estimator.ts b/packages/instant/src/util/gas_price_estimator.ts index 9eccfe510..818bf6f92 100644 --- a/packages/instant/src/util/gas_price_estimator.ts +++ b/packages/instant/src/util/gas_price_estimator.ts @@ -1,8 +1,8 @@ import { BigNumber } from '@0x/utils'; -import { DEFAULT_GAS_PRICE } from '../constants'; +import { DEFAULT_GAS_PRICE, ETH_GAS_STATION_API_BASE_URL } from '../constants'; -interface GasStationResult { +interface EthGasStationResult { average: number; fastestWait: number; fastWait: number; @@ -16,10 +16,9 @@ interface GasStationResult { safeLow: number; } -const endpointUrl = 'https://ethgasstation.info/json/ethgasAPI.json'; const fetchFastAmountInWei = async () => { - const res = await fetch(endpointUrl); - const gasInfo = (await res.json()) as GasStationResult; + const res = await fetch(`${ETH_GAS_STATION_API_BASE_URL}/json/ethgasAPI.json`); + const gasInfo = (await res.json()) as EthGasStationResult; const gasPriceInGwei = new BigNumber(gasInfo.fast / 10); return gasPriceInGwei.mul(1000000000); }; -- cgit v1.2.3