From 7788bf691d29802394b2c6b0579645b40cbcbbce Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Mon, 12 Nov 2018 10:36:40 +0100 Subject: [PATCH] Review implemented --- src/reducers/FiatRateReducer.js | 19 +++++++++++++++---- src/services/CoingeckoService.js | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/reducers/FiatRateReducer.js b/src/reducers/FiatRateReducer.js index 6492fcec..a0b21603 100644 --- a/src/reducers/FiatRateReducer.js +++ b/src/reducers/FiatRateReducer.js @@ -14,10 +14,21 @@ export const initialState: Array = []; const update = (state: Array, action: FiatRateAction): Array => { const newState: Array = [...state]; - newState.push({ - network: action.network, - value: action.rate.current_price.usd, - }); + let exists: ?Fiat = newState.find(f => f.network === action.network); + const { network, rate } = action; + + if (exists) { + exists = { + network, + value: rate, + }; + } else { + newState.push({ + network, + value: rate, + }); + } + return newState; }; diff --git a/src/services/CoingeckoService.js b/src/services/CoingeckoService.js index b8fc96a4..c6607840 100644 --- a/src/services/CoingeckoService.js +++ b/src/services/CoingeckoService.js @@ -33,7 +33,7 @@ const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: G dispatch({ type: RATE_UPDATE, network: response.symbol, - rate: response.market_data, + rate: response.market_data.current_price.usd, }); } });