remove side effects from safes reducer wip
This commit is contained in:
parent
fffa24f858
commit
477221d415
|
@ -1,7 +1,8 @@
|
|||
// @flow
|
||||
import { List } from 'immutable'
|
||||
import { createAction } from 'redux-actions'
|
||||
import { type SafeProps } from '~/routes/safe/store/model/safe'
|
||||
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'
|
||||
|
||||
export const ADD_SAFE = 'ADD_SAFE'
|
||||
|
@ -12,18 +13,34 @@ export const buildOwnersFrom = (names: Array<string>, addresses: Array<string>)
|
|||
return List(owners)
|
||||
}
|
||||
|
||||
const addSafe = createAction(
|
||||
ADD_SAFE,
|
||||
(name: string, address: string, threshold: number, ownersName: string[], ownersAddress: string[]): SafeProps => {
|
||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||
|
||||
return {
|
||||
address,
|
||||
name,
|
||||
threshold,
|
||||
owners,
|
||||
type ActionReturn = {
|
||||
safe: Safe,
|
||||
}
|
||||
},
|
||||
|
||||
const addSafe = createAction<string, *, *>(
|
||||
ADD_SAFE,
|
||||
(safe: Safe): ActionReturn => ({
|
||||
safe,
|
||||
}),
|
||||
)
|
||||
|
||||
const saveSafe = (
|
||||
name: string,
|
||||
address: string,
|
||||
threshold: number,
|
||||
ownersName: string[],
|
||||
ownersAddress: string[],
|
||||
) => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||
|
||||
const safe: Safe = makeSafe({
|
||||
name,
|
||||
address,
|
||||
threshold,
|
||||
owners,
|
||||
})
|
||||
setOwners(safe.address, safe.owners)
|
||||
saveSafes(safes.toJSON())
|
||||
}
|
||||
|
||||
export default addSafe
|
||||
|
|
|
@ -73,7 +73,7 @@ export default handleActions<State, *>(
|
|||
const safes = state.set(action.payload.address, safe)
|
||||
saveSafes(safes.toJSON())
|
||||
|
||||
return safes
|
||||
return state.set(action.payload.address, safe)
|
||||
},
|
||||
},
|
||||
Map(),
|
||||
|
|
Loading…
Reference in New Issue