1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-01 04:38:15 +00:00
trezor-wallet/src/js/services/CoinmarketcapService.js

39 lines
929 B
JavaScript
Raw Normal View History

2018-02-20 09:30:36 +00:00
/* @flow */
'use strict';
import { LOCATION_CHANGE } from 'react-router-redux';
import { httpRequest } from '../utils/networkUtils';
import { resolveAfter } from '../utils/promiseUtils';
const loadRateAction = (): any => {
return async (dispatch, getState) => {
try {
const rate = await httpRequest('https://api.coinmarketcap.com/v1/ticker/ethereum/?convert=USD', 'json');
dispatch({
type: 'rate__update',
rate: rate[0]
})
} catch(error) {
}
await resolveAfter(50000);
// dispatch( loadRateAction() );
}
}
/**
* Middleware
*/
const LocalStorageService = (store: any) => (next: any) => (action: any) => {
if (action.type === LOCATION_CHANGE && !store.getState().router.location) {
store.dispatch(loadRateAction());
}
next(action);
};
export default LocalStorageService;