From 72bea815f2e9242bb8bdd956462d75a79a23a460 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Mon, 12 Nov 2018 12:39:24 +0100 Subject: [PATCH] fix fiat rate value in reducer --- src/reducers/FiatRateReducer.js | 21 ++++++------------- src/services/CoingeckoService.js | 2 +- .../components/AccountMenu/index.js | 2 +- .../Summary/components/Balance/index.js | 5 ++--- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/reducers/FiatRateReducer.js b/src/reducers/FiatRateReducer.js index a0b21603..1b5164f6 100644 --- a/src/reducers/FiatRateReducer.js +++ b/src/reducers/FiatRateReducer.js @@ -13,23 +13,14 @@ export type Fiat = { export const initialState: Array = []; const update = (state: Array, action: FiatRateAction): Array => { - const newState: Array = [...state]; - let exists: ?Fiat = newState.find(f => f.network === action.network); + const affected = state.find(f => f.network === action.network); + const otherRates = state.filter(d => d !== affected); const { network, rate } = action; - if (exists) { - exists = { - network, - value: rate, - }; - } else { - newState.push({ - network, - value: rate, - }); - } - - return newState; + return otherRates.concat([{ + network, + value: rate.toFixed(2), + }]); }; export default (state: Array = initialState, action: Action): Array => { diff --git a/src/services/CoingeckoService.js b/src/services/CoingeckoService.js index c6607840..612af829 100644 --- a/src/services/CoingeckoService.js +++ b/src/services/CoingeckoService.js @@ -19,7 +19,7 @@ export const RATE_UPDATE: 'rate__update' = 'rate__update'; export type FiatRateAction = { type: typeof RATE_UPDATE; network: string; - rate: any; + rate: number; } const loadRateAction = (): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { diff --git a/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js b/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js index e137f0ae..f41efa2a 100644 --- a/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js +++ b/src/views/Wallet/components/LeftNavigation/components/AccountMenu/index.js @@ -136,7 +136,7 @@ const AccountMenu = (props: Props) => { balance = `${availableBalance} ${network.symbol}`; if (fiatRate) { const accountBalance = new BigNumber(availableBalance); - const fiat = accountBalance.times(parseInt(fiatRate.value, 10)).toFixed(2); + const fiat = accountBalance.times(fiatRate.value).toFixed(2); balance = `${availableBalance} ${network.symbol} / $${fiat}`; } } diff --git a/src/views/Wallet/views/Account/Summary/components/Balance/index.js b/src/views/Wallet/views/Account/Summary/components/Balance/index.js index d0614f40..c7c978fc 100644 --- a/src/views/Wallet/views/Account/Summary/components/Balance/index.js +++ b/src/views/Wallet/views/Account/Summary/components/Balance/index.js @@ -106,14 +106,13 @@ class AccountBalance extends PureComponent { render() { const { network } = this.props; - const fiatRate: any = this.props.fiat.find(f => f.network === network.shortcut); + const fiatRate = this.props.fiat.find(f => f.network === network.shortcut); let accountBalance = ''; let fiatRateValue = ''; let fiat = ''; if (fiatRate) { - const fiatValue = Math.round(fiatRate.value * 100) / 100; accountBalance = new BigNumber(this.props.balance); - fiatRateValue = new BigNumber(fiatValue).toFixed(2); + fiatRateValue = new BigNumber(fiatRate.value).toFixed(2); fiat = accountBalance.times(fiatRateValue).toFixed(2); }