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