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.
37 lines
951 B
37 lines
951 B
7 years ago
|
/* @flow */
|
||
6 years ago
|
|
||
6 years ago
|
import { RATE_UPDATE } from 'services/CoinmarketcapService';
|
||
7 years ago
|
|
||
6 years ago
|
import type { Action } from 'flowtype';
|
||
6 years ago
|
import type { FiatRateAction } from 'services/CoinmarketcapService';
|
||
7 years ago
|
|
||
7 years ago
|
export type Fiat = {
|
||
|
+network: string;
|
||
|
value: string;
|
||
|
}
|
||
|
|
||
|
export const initialState: Array<Fiat> = [];
|
||
|
|
||
7 years ago
|
const update = (state: Array<Fiat>, action: FiatRateAction): Array<Fiat> => {
|
||
6 years ago
|
const newState: Array<Fiat> = [...state];
|
||
7 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,
|
||
6 years ago
|
value: action.rate.price_usd,
|
||
|
});
|
||
7 years ago
|
}
|
||
|
return newState;
|
||
6 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
export default (state: Array<Fiat> = initialState, action: Action): Array<Fiat> => {
|
||
7 years ago
|
switch (action.type) {
|
||
6 years ago
|
case RATE_UPDATE:
|
||
7 years ago
|
return update(state, action);
|
||
|
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
6 years ago
|
};
|