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.
trezor-wallet/src/reducers/FiatRateReducer.js

34 lines
858 B

/* @flow */
import { RATE_UPDATE } from 'services/CoingeckoService';
import type { Action } from 'flowtype';
import type { FiatRateAction } from 'services/CoingeckoService';
export type Fiat = {
+network: string;
value: string;
};
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, rate } = action;
return otherRates.concat([{
network,
value: rate.toFixed(2),
}]);
};
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {
switch (action.type) {
case RATE_UPDATE:
return update(state, action);
default:
return state;
}
};