From ed56191e5660b31e3ef91f2cec3c96be76a9f69b Mon Sep 17 00:00:00 2001 From: Agustin Pane Date: Fri, 5 Jun 2020 11:08:29 -0300 Subject: [PATCH] Fix types --- src/logic/currencyValues/store/middleware/index.ts | 3 +++ .../currencyValues/store/model/currencyValues.ts | 12 ++++++++++-- .../store/utils/currencyValuesStorage.ts | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/logic/currencyValues/store/middleware/index.ts b/src/logic/currencyValues/store/middleware/index.ts index bcceecc9..92445da4 100644 --- a/src/logic/currencyValues/store/middleware/index.ts +++ b/src/logic/currencyValues/store/middleware/index.ts @@ -5,6 +5,7 @@ import { SET_CURRENT_CURRENCY } from 'src/logic/currencyValues/store/actions/set import { currencyValuesSelector } from 'src/logic/currencyValues/store/selectors' import { saveCurrencyValues } from 'src/logic/currencyValues/store/utils/currencyValuesStorage' import { AVAILABLE_CURRENCIES, CurrencyRateValue } from '../model/currencyValues' +import { Map } from 'immutable' const watchedActions = [SET_CURRENT_CURRENCY, SET_CURRENCY_RATE, SET_CURRENCY_BALANCES] @@ -22,6 +23,7 @@ const currencyValuesStorageMiddleware = (store) => (next) => async (action) => { case SET_CURRENCY_RATE: case SET_CURRENCY_BALANCES: { const currencyValues = currencyValuesSelector(state) + const currencyValuesWithoutBalances: Map = currencyValues.map((currencyValue) => { const currencyRate: number = currencyValue.get('currencyRate') const selectedCurrency: AVAILABLE_CURRENCIES = currencyValue.get('selectedCurrency') @@ -30,6 +32,7 @@ const currencyValuesStorageMiddleware = (store) => (next) => async (action) => { selectedCurrency, } }) + await saveCurrencyValues(currencyValuesWithoutBalances) break } diff --git a/src/logic/currencyValues/store/model/currencyValues.ts b/src/logic/currencyValues/store/model/currencyValues.ts index b2bbc166..dcfefb47 100644 --- a/src/logic/currencyValues/store/model/currencyValues.ts +++ b/src/logic/currencyValues/store/model/currencyValues.ts @@ -36,9 +36,17 @@ export enum AVAILABLE_CURRENCIES { MYR = 'MYR', } +type BalanceCurrencyRecord = { + currencyName?: string + tokenAddress?: string + balanceInBaseCurrency: string + balanceInSelectedCurrency: string +} + export type CurrencyRateValue = { - currencyRate: number - selectedCurrency: AVAILABLE_CURRENCIES + currencyRate?: number + selectedCurrency?: AVAILABLE_CURRENCIES + currencyBalances?: BalanceCurrencyRecord[] } export const makeBalanceCurrency = Record({ diff --git a/src/logic/currencyValues/store/utils/currencyValuesStorage.ts b/src/logic/currencyValues/store/utils/currencyValuesStorage.ts index ec3363c0..280169d2 100644 --- a/src/logic/currencyValues/store/utils/currencyValuesStorage.ts +++ b/src/logic/currencyValues/store/utils/currencyValuesStorage.ts @@ -1,5 +1,6 @@ import { loadFromStorage, saveToStorage } from 'src/utils/storage' import { CurrencyRateValue } from '../model/currencyValues' +import { Map } from 'immutable' const CURRENCY_VALUES_STORAGE_KEY = 'CURRENCY_VALUES_STORAGE_KEY' export const saveCurrencyValues = async (currencyValues: Map) => {