blob: f8dbe9fd4a18cc2a425150ad237f5d21c34263d8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import * as _ from 'lodash';
import { BIG_NUMBER_ZERO } from '../constants';
import { assetUtils } from '../util/asset';
import { coinbaseApi } from '../util/coinbase_api';
import { actions } from './actions';
import { Store } from './store';
export const asyncData = {
fetchEthPriceAndDispatchToStore: async (store: Store) => {
let ethUsdPrice = BIG_NUMBER_ZERO;
try {
ethUsdPrice = await coinbaseApi.getEthUsdPrice();
} catch (e) {
// ignore
} finally {
store.dispatch(actions.updateEthUsdPrice(ethUsdPrice));
}
},
fetchAvailableAssetDatasAndDispatchToStore: async (store: Store) => {
const { assetBuyer, assetMetaDataMap, network } = store.getState();
if (!_.isUndefined(assetBuyer)) {
try {
const assetDatas = await assetBuyer.getAvailableAssetDatasAsync();
const assets = assetUtils.createAssetsFromAssetDatas(assetDatas, assetMetaDataMap, network);
store.dispatch(actions.setAvailableAssets(assets));
} catch (e) {
// ignore
}
}
},
};
|