feat: have coinbase API return BigNumber for eth-usd price endpoint

This commit is contained in:
fragosti 2018-10-12 09:55:33 -07:00
parent 03b235bb42
commit 09c5ae4e65
2 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import { BigNumber } from '@0xproject/utils';
import { BIG_NUMBER_ZERO } from '../constants';
import { ActionTypes } from '../types';
import { coinbaseApi } from '../util/coinbase_api';
@ -7,15 +8,15 @@ import { store } from './store';
export const asyncData = {
fetchAndDispatchToStore: async () => {
let ethUsdPriceStr = '0';
let ethUsdPrice = BIG_NUMBER_ZERO;
try {
ethUsdPriceStr = await coinbaseApi.getEthUsdPrice();
ethUsdPrice = await coinbaseApi.getEthUsdPrice();
} catch (e) {
// ignore
} finally {
store.dispatch({
type: ActionTypes.UPDATE_ETH_USD_PRICE,
data: new BigNumber(ethUsdPriceStr),
data: ethUsdPrice,
});
}
},

View File

@ -1,8 +1,10 @@
import { BigNumber } from '@0xproject/utils';
const baseEndpoint = 'https://api.coinbase.com/v2';
export const coinbaseApi = {
getEthUsdPrice: async (): Promise<string> => {
getEthUsdPrice: async (): Promise<BigNumber> => {
const res = await fetch(`${baseEndpoint}/prices/ETH-USD/buy`);
const resJson = await res.json();
return resJson.data.amount;
return new BigNumber(resJson.data.amount);
},
};