Fix types
This commit is contained in:
parent
3deb37da26
commit
ed56191e56
|
@ -5,6 +5,7 @@ import { SET_CURRENT_CURRENCY } from 'src/logic/currencyValues/store/actions/set
|
||||||
import { currencyValuesSelector } from 'src/logic/currencyValues/store/selectors'
|
import { currencyValuesSelector } from 'src/logic/currencyValues/store/selectors'
|
||||||
import { saveCurrencyValues } from 'src/logic/currencyValues/store/utils/currencyValuesStorage'
|
import { saveCurrencyValues } from 'src/logic/currencyValues/store/utils/currencyValuesStorage'
|
||||||
import { AVAILABLE_CURRENCIES, CurrencyRateValue } from '../model/currencyValues'
|
import { AVAILABLE_CURRENCIES, CurrencyRateValue } from '../model/currencyValues'
|
||||||
|
import { Map } from 'immutable'
|
||||||
|
|
||||||
const watchedActions = [SET_CURRENT_CURRENCY, SET_CURRENCY_RATE, SET_CURRENCY_BALANCES]
|
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_RATE:
|
||||||
case SET_CURRENCY_BALANCES: {
|
case SET_CURRENCY_BALANCES: {
|
||||||
const currencyValues = currencyValuesSelector(state)
|
const currencyValues = currencyValuesSelector(state)
|
||||||
|
|
||||||
const currencyValuesWithoutBalances: Map<string, CurrencyRateValue> = currencyValues.map((currencyValue) => {
|
const currencyValuesWithoutBalances: Map<string, CurrencyRateValue> = currencyValues.map((currencyValue) => {
|
||||||
const currencyRate: number = currencyValue.get('currencyRate')
|
const currencyRate: number = currencyValue.get('currencyRate')
|
||||||
const selectedCurrency: AVAILABLE_CURRENCIES = currencyValue.get('selectedCurrency')
|
const selectedCurrency: AVAILABLE_CURRENCIES = currencyValue.get('selectedCurrency')
|
||||||
|
@ -30,6 +32,7 @@ const currencyValuesStorageMiddleware = (store) => (next) => async (action) => {
|
||||||
selectedCurrency,
|
selectedCurrency,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await saveCurrencyValues(currencyValuesWithoutBalances)
|
await saveCurrencyValues(currencyValuesWithoutBalances)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,17 @@ export enum AVAILABLE_CURRENCIES {
|
||||||
MYR = 'MYR',
|
MYR = 'MYR',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BalanceCurrencyRecord = {
|
||||||
|
currencyName?: string
|
||||||
|
tokenAddress?: string
|
||||||
|
balanceInBaseCurrency: string
|
||||||
|
balanceInSelectedCurrency: string
|
||||||
|
}
|
||||||
|
|
||||||
export type CurrencyRateValue = {
|
export type CurrencyRateValue = {
|
||||||
currencyRate: number
|
currencyRate?: number
|
||||||
selectedCurrency: AVAILABLE_CURRENCIES
|
selectedCurrency?: AVAILABLE_CURRENCIES
|
||||||
|
currencyBalances?: BalanceCurrencyRecord[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export const makeBalanceCurrency = Record({
|
export const makeBalanceCurrency = Record({
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { loadFromStorage, saveToStorage } from 'src/utils/storage'
|
import { loadFromStorage, saveToStorage } from 'src/utils/storage'
|
||||||
import { CurrencyRateValue } from '../model/currencyValues'
|
import { CurrencyRateValue } from '../model/currencyValues'
|
||||||
|
import { Map } from 'immutable'
|
||||||
|
|
||||||
const CURRENCY_VALUES_STORAGE_KEY = 'CURRENCY_VALUES_STORAGE_KEY'
|
const CURRENCY_VALUES_STORAGE_KEY = 'CURRENCY_VALUES_STORAGE_KEY'
|
||||||
export const saveCurrencyValues = async (currencyValues: Map<string, CurrencyRateValue>) => {
|
export const saveCurrencyValues = async (currencyValues: Map<string, CurrencyRateValue>) => {
|
||||||
|
|
Loading…
Reference in New Issue