remove side effects from safes reducer wip

This commit is contained in:
Mikhail Mikheev 2019-03-29 20:36:11 +04:00
parent fffa24f858
commit 477221d415
2 changed files with 30 additions and 13 deletions

View File

@ -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 { const addSafe = createAction<string, *, *>(
address, ADD_SAFE,
name, (safe: Safe): ActionReturn => ({
threshold, safe,
owners, }),
}
},
) )
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

View File

@ -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(),