mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-01 04:38:15 +00:00
39 lines
929 B
JavaScript
39 lines
929 B
JavaScript
|
/* @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;
|