Setting 1 safe as default WIP
This commit is contained in:
parent
c882c6ff5f
commit
b531ffd057
|
@ -1,10 +1,12 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { List } from 'immutable'
|
import { List } from 'immutable'
|
||||||
import { createAction } from 'redux-actions'
|
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 { type GlobalState } from '~/store'
|
||||||
|
import { safesListSelector } from '~/routes/safeList/store/selectors'
|
||||||
import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe'
|
import SafeRecord, { type Safe } from '~/routes/safe/store/models/safe'
|
||||||
import { makeOwner, type Owner } from '~/routes/safe/store/models/owner'
|
import { makeOwner, type Owner } from '~/routes/safe/store/models/owner'
|
||||||
|
import setDefaultSafe from '~/routes/safe/store/actions/setDefaultSafe'
|
||||||
|
|
||||||
export const ADD_SAFE = 'ADD_SAFE'
|
export const ADD_SAFE = 'ADD_SAFE'
|
||||||
|
|
||||||
|
@ -24,8 +26,11 @@ export const addSafe = createAction<string, Function, ActionReturn>(ADD_SAFE, (s
|
||||||
|
|
||||||
const saveSafe = (name: string, address: string, threshold: number, ownersName: string[], ownersAddress: string[]) => (
|
const saveSafe = (name: string, address: string, threshold: number, ownersName: string[], ownersAddress: string[]) => (
|
||||||
dispatch: ReduxDispatch<GlobalState>,
|
dispatch: ReduxDispatch<GlobalState>,
|
||||||
|
getState: GetState<GlobalState>,
|
||||||
) => {
|
) => {
|
||||||
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
const owners: List<Owner> = buildOwnersFrom(ownersName, ownersAddress)
|
||||||
|
const state = getState()
|
||||||
|
const safeList = safesListSelector(state)
|
||||||
|
|
||||||
const safe: Safe = SafeRecord({
|
const safe: Safe = SafeRecord({
|
||||||
name,
|
name,
|
||||||
|
@ -35,6 +40,10 @@ const saveSafe = (name: string, address: string, threshold: number, ownersName:
|
||||||
})
|
})
|
||||||
|
|
||||||
dispatch(addSafe(safe))
|
dispatch(addSafe(safe))
|
||||||
|
console.log(safeList.size)
|
||||||
|
if (safeList.size === 0) {
|
||||||
|
setDefaultSafe(address)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default saveSafe
|
export default saveSafe
|
||||||
|
|
|
@ -6,11 +6,9 @@ import setDefaultSafe from './setDefaultSafe'
|
||||||
|
|
||||||
const loadDefaultSafe = () => async (dispatch: ReduxDispatch<GlobalState>) => {
|
const loadDefaultSafe = () => async (dispatch: ReduxDispatch<GlobalState>) => {
|
||||||
try {
|
try {
|
||||||
const defaultSafe: ?string = await getDefaultSafe()
|
const defaultSafe: string = await getDefaultSafe()
|
||||||
|
|
||||||
if (defaultSafe) {
|
dispatch(setDefaultSafe(defaultSafe))
|
||||||
dispatch(setDefaultSafe(defaultSafe))
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error('Error while getting defautl safe from storage:', err)
|
console.error('Error while getting defautl safe from storage:', err)
|
||||||
|
|
Loading…
Reference in New Issue