Fix types

This commit is contained in:
Agustin Pane 2020-06-05 11:08:29 -03:00
parent 3deb37da26
commit ed56191e56
3 changed files with 14 additions and 2 deletions

View File

@ -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<string, CurrencyRateValue> = 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
}

View File

@ -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({

View File

@ -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<string, CurrencyRateValue>) => {