refactor add safe action
This commit is contained in:
parent
477221d415
commit
22d258bacc
|
@ -4,6 +4,9 @@ import { createAction } from 'redux-actions'
|
|||
import { type Safe, makeSafe } from '~/routes/safe/store/model/safe'
|
||||
import { saveSafes, setOwners } from '~/utils/localStorage'
|
||||
import { makeOwner, type Owner } from '~/routes/safe/store/model/owner'
|
||||
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
|
||||
import { type GlobalState } from '~/store/index'
|
||||
import { safesMapSelector } from '~/routes/safeList/store/selectors/index';
|
||||
|
||||
export const ADD_SAFE = 'ADD_SAFE'
|
||||
|
||||
|
@ -30,8 +33,9 @@ const saveSafe = (
|
|||
threshold: number,
|
||||
ownersName: string[],
|
||||
ownersAddress: string[],
|
||||
) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||
) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState> ) => {
|
||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||
const state: GlobalState = getState()
|
||||
|
||||
const safe: Safe = makeSafe({
|
||||
name,
|
||||
|
@ -39,8 +43,13 @@ const saveSafe = (
|
|||
threshold,
|
||||
owners,
|
||||
})
|
||||
setOwners(safe.address, safe.owners)
|
||||
saveSafes(safes.toJSON())
|
||||
const safes = safesMapSelector(state)
|
||||
const newSafes = safes.set(address, safe)
|
||||
|
||||
setOwners(address, owners)
|
||||
saveSafes(newSafes.toJSON())
|
||||
|
||||
dispatch(addSafe(safe))
|
||||
}
|
||||
|
||||
export default addSafe
|
||||
export default saveSafe
|
||||
|
|
|
@ -3,4 +3,4 @@ import { createAction } from 'redux-actions'
|
|||
|
||||
export const ADD_TRANSACTIONS = 'ADD_TRANSACTIONS'
|
||||
|
||||
export default createAction(ADD_TRANSACTIONS)
|
||||
export default createAction<string, *>(ADD_TRANSACTIONS)
|
||||
|
|
|
@ -3,6 +3,6 @@ import { createAction } from 'redux-actions'
|
|||
|
||||
export const UPDATE_SAFE = 'UPDATE_SAFE'
|
||||
|
||||
const updateSafe = createAction(UPDATE_SAFE)
|
||||
const updateSafe = createAction<string, *>(UPDATE_SAFE)
|
||||
|
||||
export default updateSafe
|
||||
|
|
|
@ -3,6 +3,6 @@ import { createAction } from 'redux-actions'
|
|||
|
||||
export const UPDATE_SAFES = 'UPDATE_SAFES'
|
||||
|
||||
const updateSafesInBatch = createAction(UPDATE_SAFES)
|
||||
const updateSafesInBatch = createAction<string, *>(UPDATE_SAFES)
|
||||
|
||||
export default updateSafesInBatch
|
||||
|
|
|
@ -67,13 +67,9 @@ export default handleActions<State, *>(
|
|||
return state.set(safeAddress, safe)
|
||||
},
|
||||
[ADD_SAFE]: (state: State, action: ActionType<typeof addSafe>): State => {
|
||||
const safe: Safe = makeSafe(action.payload)
|
||||
setOwners(safe.get('address'), safe.get('owners'))
|
||||
const { safe }: { safe: Safe } = action.payload
|
||||
|
||||
const safes = state.set(action.payload.address, safe)
|
||||
saveSafes(safes.toJSON())
|
||||
|
||||
return state.set(action.payload.address, safe)
|
||||
return state.set(safe.address, safe)
|
||||
},
|
||||
},
|
||||
Map(),
|
||||
|
|
|
@ -6,8 +6,9 @@ import { type Safe } from '~/routes/safe/store/model/safe'
|
|||
import { userAccountSelector } from '~/logic/wallets/store/selectors'
|
||||
import { type Owner } from '~/routes/safe/store/model/owner'
|
||||
import { sameAddress } from '~/logic/wallets/ethAddresses'
|
||||
import { SAFE_REDUCER_ID } from '~/routes/safe/store/reducer/safe'
|
||||
|
||||
export const safesMapSelector = (state: GlobalState): Map<string, Safe> => state.safes
|
||||
export const safesMapSelector = (state: GlobalState): Map<string, Safe> => state[SAFE_REDUCER_ID]
|
||||
|
||||
const safesListSelector: Selector<GlobalState, {}, List<Safe>> = createSelector(
|
||||
safesMapSelector,
|
||||
|
|
Loading…
Reference in New Issue