mirror of https://github.com/trezor/trezor-wallet
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
939 B
39 lines
939 B
/* @flow */
|
|
|
|
import { RATE_UPDATE } from 'services/CoingeckoService';
|
|
|
|
import type { Action } from 'flowtype';
|
|
import type { FiatRateAction } from 'services/CoingeckoService';
|
|
|
|
export type Fiat = {
|
|
+network: string,
|
|
rates: { [string]: number },
|
|
};
|
|
|
|
export const initialState: Array<Fiat> = [];
|
|
|
|
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
|
|
const affected = state.find(f => f.network === action.network);
|
|
const otherRates = state.filter(d => d !== affected);
|
|
const { network, rates } = action;
|
|
|
|
Object.keys(rates).map(k => rates[k].toFixed(2));
|
|
|
|
return otherRates.concat([
|
|
{
|
|
network,
|
|
rates,
|
|
},
|
|
]);
|
|
};
|
|
|
|
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {
|
|
switch (action.type) {
|
|
case RATE_UPDATE:
|
|
return update(state, action);
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
};
|