fix storing safe in localstorage
This commit is contained in:
parent
3373b83a27
commit
7e49f8dd16
|
@ -1,12 +1,10 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { List } from 'immutable'
|
import { List } from 'immutable'
|
||||||
import { createAction } from 'redux-actions'
|
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 { type GlobalState } from '~/store'
|
||||||
import { saveSafes, setOwners } from '~/logic/safe/utils'
|
|
||||||
import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe'
|
import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe'
|
||||||
import { makeOwner, type Owner } from '~/routes/safe/store/models/owner'
|
import { makeOwner, type Owner } from '~/routes/safe/store/models/owner'
|
||||||
import { safesMapSelector } from '~/routes/safeList/store/selectors/index'
|
|
||||||
|
|
||||||
export const ADD_SAFE = 'ADD_SAFE'
|
export const ADD_SAFE = 'ADD_SAFE'
|
||||||
|
|
||||||
|
@ -33,9 +31,8 @@ const saveSafe = (
|
||||||
threshold: number,
|
threshold: number,
|
||||||
ownersName: string[],
|
ownersName: string[],
|
||||||
ownersAddress: string[],
|
ownersAddress: string[],
|
||||||
) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState>) => {
|
) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||||
const state: GlobalState = getState()
|
|
||||||
|
|
||||||
const safe: Safe = SafeRecord({
|
const safe: Safe = SafeRecord({
|
||||||
name,
|
name,
|
||||||
|
@ -43,11 +40,6 @@ const saveSafe = (
|
||||||
threshold,
|
threshold,
|
||||||
owners,
|
owners,
|
||||||
})
|
})
|
||||||
const safes = safesMapSelector(state)
|
|
||||||
const newSafes = safes.set(address, safe)
|
|
||||||
|
|
||||||
setOwners(address, owners)
|
|
||||||
saveSafes(newSafes.toJSON())
|
|
||||||
|
|
||||||
dispatch(addSafe(safe))
|
dispatch(addSafe(safe))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,27 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { ADD_SAFE } from '~/routes/safe/store/actions/addSafe'
|
import { ADD_SAFE } from '~/routes/safe/store/actions/addSafe'
|
||||||
import { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
|
import { UPDATE_SAFE } from '~/routes/safe/store/actions/updateSafe'
|
||||||
import { saveToStorage } from '~/utils/storage'
|
import type { Store, AnyAction } from 'redux'
|
||||||
import { SAFES_KEY } from '~/logic/safe/utils'
|
|
||||||
import type { GetState } from 'redux'
|
|
||||||
import { type GlobalState } from '~/store/'
|
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 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)
|
const handledAction = next(action)
|
||||||
|
|
||||||
if (watchedActions.includes(action.type)) {
|
if (watchedActions.includes(action.type)) {
|
||||||
const { getState }: { getState: GetState } = store
|
|
||||||
const state: GlobalState = store.getState()
|
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
|
return handledAction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue