fix safe loading from storage

This commit is contained in:
mmv 2019-04-17 13:13:38 +04:00
parent dc185e893c
commit e3d7984486
1 changed files with 8 additions and 3 deletions

View File

@ -1,8 +1,9 @@
// @flow // @flow
import { Map } from 'immutable' import { Map, List } from 'immutable'
import { handleActions, type ActionType } from 'redux-actions' import { handleActions, type ActionType } from 'redux-actions'
import { ADD_SAFE, buildOwnersFrom } from '~/routes/safe/store/actions/addSafe' import { ADD_SAFE, buildOwnersFrom } from '~/routes/safe/store/actions/addSafe'
import SafeRecord, { type Safe, type SafeProps } from '~/routes/safe/store/models/safe' import SafeRecord, { type Safe, type SafeProps } from '~/routes/safe/store/models/safe'
import TokenBalance from '~/routes/safe/store/models/tokenBalance'
import { type OwnerProps } from '~/routes/safe/store/models/owner' import { type OwnerProps } from '~/routes/safe/store/models/owner'
import { loadFromStorage } from '~/utils/storage' import { loadFromStorage } from '~/utils/storage'
import { SAFES_KEY } from '~/logic/safe/utils' import { SAFES_KEY } from '~/logic/safe/utils'
@ -16,10 +17,14 @@ export const buildSafe = (storedSafe: SafeProps) => {
const names = storedSafe.owners.map((owner: OwnerProps) => owner.name) const names = storedSafe.owners.map((owner: OwnerProps) => owner.name)
const addresses = storedSafe.owners.map((owner: OwnerProps) => owner.address) const addresses = storedSafe.owners.map((owner: OwnerProps) => owner.address)
const owners = buildOwnersFrom(Array.from(names), Array.from(addresses)) const owners = buildOwnersFrom(Array.from(names), Array.from(addresses))
const activeTokens = List(storedSafe.activeTokens)
const balances = storedSafe.balances.map(balance => TokenBalance(balance))
const safe: SafeProps = { const safe: SafeProps = {
...storedSafe, ...storedSafe,
owners, owners,
balances,
activeTokens,
} }
return safe return safe
@ -56,7 +61,7 @@ export default handleActions<State, *>(
const safe = action.payload const safe = action.payload
const safeAddress = safe.address const safeAddress = safe.address
return state.mergeIn([safeAddress], safe) return state.update(safeAddress, prevSafe => prevSafe.merge(safe))
}, },
[ADD_SAFE]: (state: State, action: ActionType<Function>): State => { [ADD_SAFE]: (state: State, action: ActionType<Function>): State => {
const { safe }: { safe: SafeProps } = action.payload const { safe }: { safe: SafeProps } = action.payload
@ -66,7 +71,7 @@ export default handleActions<State, *>(
// with initial props and it would overwrite existing ones // with initial props and it would overwrite existing ones
if (state.has(safe.address)) { if (state.has(safe.address)) {
return state.mergeIn([safe.address], safe) return state.update(safe.address, prevSafe => prevSafe.merge(safe))
} }
return state.set(safe.address, SafeRecord(safe)) return state.set(safe.address, SafeRecord(safe))