use addSafe instead updateSafe while adding a new safe
This commit is contained in:
parent
50a315b839
commit
f797e2db77
|
@ -8,16 +8,16 @@ import { loadFromStorage } from '~/utils/storage'
|
|||
import { SAFELIST_ADDRESS } from '~/routes/routes'
|
||||
import { history } from '~/store'
|
||||
import selector, { type SelectorProps } from './selector'
|
||||
import actions, { type Actions, type UpdateSafe } from './actions'
|
||||
import actions, { type Actions } from './actions'
|
||||
import Layout from '../components/Layout'
|
||||
import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '../components/fields'
|
||||
|
||||
type Props = SelectorProps & Actions
|
||||
|
||||
export const loadSafe = async (safeName: string, safeAddress: string, updateSafe: UpdateSafe) => {
|
||||
export const loadSafe = async (safeName: string, safeAddress: string, addSafe: Function) => {
|
||||
const safeRecord = await buildSafe(safeAddress, safeName)
|
||||
|
||||
await updateSafe(safeRecord)
|
||||
await addSafe(safeRecord)
|
||||
|
||||
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}
|
||||
storedSafes[safeAddress] = safeRecord.toJSON()
|
||||
|
@ -28,11 +28,11 @@ export const loadSafe = async (safeName: string, safeAddress: string, updateSafe
|
|||
class Load extends React.Component<Props> {
|
||||
onLoadSafeSubmit = async (values: Object) => {
|
||||
try {
|
||||
const { updateSafe } = this.props
|
||||
const { addSafe } = this.props
|
||||
const safeName = values[FIELD_LOAD_NAME]
|
||||
const safeAddress = values[FIELD_LOAD_ADDRESS]
|
||||
|
||||
await loadSafe(safeName, safeAddress, updateSafe)
|
||||
await loadSafe(safeName, safeAddress, addSafe)
|
||||
|
||||
const url = `${SAFELIST_ADDRESS}/${safeAddress}`
|
||||
history.push(url)
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
// @flow
|
||||
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||
|
||||
export type UpdateSafe = typeof updateSafe
|
||||
import { addSafe } from '~/routes/safe/store/actions/addSafe'
|
||||
|
||||
export type Actions = {
|
||||
updateSafe: typeof updateSafe,
|
||||
addSafe: Function,
|
||||
}
|
||||
|
||||
export default {
|
||||
updateSafe,
|
||||
addSafe,
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { List, Map } from 'immutable'
|
|||
import { type GlobalState } from '~/store/index'
|
||||
import { makeOwner } from '~/routes/safe/store/model/owner'
|
||||
import SafeRecord, { type SafeProps } from '~/routes/safe/store/model/safe'
|
||||
import updateSafe from '~/routes/safe/store/actions/updateSafe'
|
||||
import { addSafe } from '~/routes/safe/store/actions/addSafe'
|
||||
import { getOwners, getSafeName } from '~/logic/safe/utils'
|
||||
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
|
||||
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3'
|
||||
|
@ -42,7 +42,7 @@ export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalSta
|
|||
const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
|
||||
const safeRecord = await buildSafe(safeAddress, safeName)
|
||||
|
||||
return dispatch(updateSafe(safeRecord))
|
||||
return dispatch(addSafe(safeRecord))
|
||||
} catch (err) {
|
||||
// eslint-disable-next-line
|
||||
console.error('Error while updating safe information: ', err)
|
||||
|
|
|
@ -59,12 +59,7 @@ export default handleActions<State, *>(
|
|||
const safe = action.payload
|
||||
const safeAddress = safe.address
|
||||
|
||||
const hasSafe = !!state.get(safeAddress)
|
||||
if (hasSafe) {
|
||||
return state.update(safeAddress, prevSafe => (prevSafe.equals(safe) ? prevSafe : safe))
|
||||
}
|
||||
|
||||
return state.set(safeAddress, safe)
|
||||
return state.mergeIn(safeAddress, safe)
|
||||
},
|
||||
[ADD_SAFE]: (state: State, action: ActionType<Function>): State => {
|
||||
const { safe }: { safe: Safe } = action.payload
|
||||
|
|
Loading…
Reference in New Issue