diff --git a/src/routes/safe/store/actions/addSafe.js b/src/routes/safe/store/actions/addSafe.js index a3395ac8..47c5e23e 100644 --- a/src/routes/safe/store/actions/addSafe.js +++ b/src/routes/safe/store/actions/addSafe.js @@ -1,10 +1,12 @@ // @flow import { List } from 'immutable' import { createAction } from 'redux-actions' -import type { Dispatch as ReduxDispatch } from 'redux' +import type { Dispatch as ReduxDispatch, GetState } from 'redux' import { type GlobalState } from '~/store' +import { safesListSelector } from '~/routes/safeList/store/selectors' import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe' import { makeOwner, type Owner } from '~/routes/safe/store/models/owner' +import setDefaultSafe from '~/routes/safe/store/actions/setDefaultSafe' export const ADD_SAFE = 'ADD_SAFE' @@ -24,8 +26,11 @@ export const addSafe = createAction(ADD_SAFE, (s const saveSafe = (name: string, address: string, threshold: number, ownersName: string[], ownersAddress: string[]) => ( dispatch: ReduxDispatch, + getState: GetState, ) => { const owners: List = buildOwnersFrom(ownersName, ownersAddress) + const state = getState() + const safeList = safesListSelector(state) const safe: Safe = SafeRecord({ name, @@ -35,6 +40,10 @@ const saveSafe = (name: string, address: string, threshold: number, ownersName: }) dispatch(addSafe(safe)) + console.log(safeList.size) + if (safeList.size === 0) { + setDefaultSafe(address) + } } export default saveSafe diff --git a/src/routes/safe/store/actions/loadDefaultSafe.js b/src/routes/safe/store/actions/loadDefaultSafe.js index 76a9dff3..71d4cc32 100644 --- a/src/routes/safe/store/actions/loadDefaultSafe.js +++ b/src/routes/safe/store/actions/loadDefaultSafe.js @@ -6,11 +6,9 @@ import setDefaultSafe from './setDefaultSafe' const loadDefaultSafe = () => async (dispatch: ReduxDispatch) => { try { - const defaultSafe: ?string = await getDefaultSafe() + const defaultSafe: string = await getDefaultSafe() - if (defaultSafe) { - dispatch(setDefaultSafe(defaultSafe)) - } + dispatch(setDefaultSafe(defaultSafe)) } catch (err) { // eslint-disable-next-line console.error('Error while getting defautl safe from storage:', err)