feat: have coinbase API return BigNumber for eth-usd price endpoint
This commit is contained in:
parent
03b235bb42
commit
09c5ae4e65
@ -1,5 +1,6 @@
|
|||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
|
||||||
|
import { BIG_NUMBER_ZERO } from '../constants';
|
||||||
import { ActionTypes } from '../types';
|
import { ActionTypes } from '../types';
|
||||||
import { coinbaseApi } from '../util/coinbase_api';
|
import { coinbaseApi } from '../util/coinbase_api';
|
||||||
|
|
||||||
@ -7,15 +8,15 @@ import { store } from './store';
|
|||||||
|
|
||||||
export const asyncData = {
|
export const asyncData = {
|
||||||
fetchAndDispatchToStore: async () => {
|
fetchAndDispatchToStore: async () => {
|
||||||
let ethUsdPriceStr = '0';
|
let ethUsdPrice = BIG_NUMBER_ZERO;
|
||||||
try {
|
try {
|
||||||
ethUsdPriceStr = await coinbaseApi.getEthUsdPrice();
|
ethUsdPrice = await coinbaseApi.getEthUsdPrice();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// ignore
|
// ignore
|
||||||
} finally {
|
} finally {
|
||||||
store.dispatch({
|
store.dispatch({
|
||||||
type: ActionTypes.UPDATE_ETH_USD_PRICE,
|
type: ActionTypes.UPDATE_ETH_USD_PRICE,
|
||||||
data: new BigNumber(ethUsdPriceStr),
|
data: ethUsdPrice,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
|
||||||
const baseEndpoint = 'https://api.coinbase.com/v2';
|
const baseEndpoint = 'https://api.coinbase.com/v2';
|
||||||
export const coinbaseApi = {
|
export const coinbaseApi = {
|
||||||
getEthUsdPrice: async (): Promise<string> => {
|
getEthUsdPrice: async (): Promise<BigNumber> => {
|
||||||
const res = await fetch(`${baseEndpoint}/prices/ETH-USD/buy`);
|
const res = await fetch(`${baseEndpoint}/prices/ETH-USD/buy`);
|
||||||
const resJson = await res.json();
|
const resJson = await res.json();
|
||||||
return resJson.data.amount;
|
return new BigNumber(resJson.data.amount);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user