aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-30 07:53:18 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-10-30 07:53:18 +0800
commit274e4b3bcd1633e8fe78a33528d63b7567355f9e (patch)
tree3f5dbc8e7af9ef5d57c915a8cb51b91b2e045451 /packages/instant/src
parenta49fc27042f9797f7a035e5471e572b148679456 (diff)
downloaddexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.tar
dexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.tar.gz
dexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.tar.bz2
dexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.tar.lz
dexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.tar.xz
dexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.tar.zst
dexon-sol-tools-274e4b3bcd1633e8fe78a33528d63b7567355f9e.zip
Introduce constants for eth gas station and coinbase
Diffstat (limited to 'packages/instant/src')
-rw-r--r--packages/instant/src/constants.ts2
-rw-r--r--packages/instant/src/util/coinbase_api.ts5
-rw-r--r--packages/instant/src/util/gas_price_estimator.ts9
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<BigNumber> => {
- 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);
};