fix storing safe in localstorage

This commit is contained in:
Mikhail Mikheev 2019-04-16 16:41:36 +04:00
parent 3373b83a27
commit 7e49f8dd16
2 changed files with 15 additions and 16 deletions

View File

@ -1,12 +1,10 @@
// @flow
import { List } from 'immutable'
import { createAction } from 'redux-actions'
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
import type { Dispatch as ReduxDispatch } from 'redux'
import { type GlobalState } from '~/store'
import { saveSafes, setOwners } from '~/logic/safe/utils'
import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe'
import { makeOwner, type Owner } from '~/routes/safe/store/models/owner'
import { safesMapSelector } from '~/routes/safeList/store/selectors/index'
export const ADD_SAFE = 'ADD_SAFE'
@ -33,9 +31,8 @@ const saveSafe = (
threshold: number,
ownersName: string[],
ownersAddress: string[],
) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState>) => {
) => async (dispatch: ReduxDispatch<GlobalState>) => {
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
const state: GlobalState = getState()
const safe: Safe = SafeRecord({
name,
@ -43,11 +40,6 @@ const saveSafe = (
threshold,
owners,
})
const safes = safesMapSelector(state)
const newSafes = safes.set(address, safe)
setOwners(address, owners)
saveSafes(newSafes.toJSON())
dispatch(addSafe(safe))
}

View File

@ -1,20 +1,27 @@
// @flow
import { ADD_SAFE } from '~/routes/safe/store/actions/addSafe'
import { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
import { saveToStorage } from '~/utils/storage'
import { SAFES_KEY } from '~/logic/safe/utils'
import type { GetState } from 'redux'
import type { Store, AnyAction } from 'redux'
import { type GlobalState } from '~/store/'
import { saveSafes, setOwners } from '~/logic/safe/utils'
import { safesMapSelector } from '~/routes/safeList/store/selectors/index'
const watchedActions = [ADD_SAFE, UPDATE_SAFE]
const safeStorageMware = store => next => async (action) => {
const safeStorageMware = (store: Store<GlobalState>) => (next: Function) => async (action: AnyAction) => {
const handledAction = next(action)
if (watchedActions.includes(action.type)) {
const { getState }: { getState: GetState } = store
const state: GlobalState = store.getState()
console.log(state)
const safes = safesMapSelector(state)
saveSafes(safes.toJSON())
if (action.type === ADD_SAFE) {
const { safe } = action.payload
setOwners(safe.address, safe.owners)
}
}
return handledAction
}