WIP optimize connect with redux state in preferences pages.

This commit is contained in:
Ahmed Bouhuolia
2020-05-10 23:22:36 +02:00
parent a0653674ff
commit 464c36d532
32 changed files with 403 additions and 327 deletions

View File

@@ -2,9 +2,7 @@ import { createReducer } from '@reduxjs/toolkit';
import t from 'store/types';
const initialState = {
preferences: {
currencies: [],
},
data: {},
};
export default createReducer(initialState, {
@@ -14,8 +12,8 @@ export default createReducer(initialState, {
action.currencies.forEach((currency) => {
_currencies[currency.currency_code] = currency;
});
state.preferences.currencies = {
...state.preferences.currencies,
state.data = {
...state.data,
..._currencies,
};
},

View File

@@ -1,3 +1,9 @@
export const getCurrencyById = (items, id) => {
return items[id] || null;
// @flow
export const getCurrencyById = (currencies: Object, id: Integer) => {
return Object.values(currencies).find(c => c.id == id) || null;
};
export const getCurrencyByCode = (currencies: Object, currencyCode: String) => {
return currencies[currencyCode] || null;
};