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

39 lines
953 B

6 years ago
/* @flow */
6 years ago
import { RATE_UPDATE } from 'services/CoinmarketcapService';
import type { Action } from 'flowtype';
import type { FiatRateAction } from 'services/CoinmarketcapService';
6 years ago
export type Fiat = {
+network: string;
value: string;
}
export const initialState: Array<Fiat> = [];
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
const newState: Array<Fiat> = [...state];
6 years ago
const exists: ?Fiat = newState.find(f => f.network === action.network);
if (exists) {
exists.value = action.rate.price_usd;
} else {
newState.push({
network: action.network,
value: action.rate.price_usd,
});
6 years ago
}
return newState;
};
6 years ago
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {
6 years ago
switch (action.type) {
case RATE_UPDATE:
6 years ago
return update(state, action);
default:
return state;
}
};