use addSafe instead updateSafe while adding a new safe

This commit is contained in:
Mikhail Mikheev 2019-04-12 15:46:56 +04:00
parent 50a315b839
commit f797e2db77
5 changed files with 11 additions and 18 deletions

View File

@ -8,16 +8,16 @@ import { loadFromStorage } from '~/utils/storage'
import { SAFELIST_ADDRESS } from '~/routes/routes' import { SAFELIST_ADDRESS } from '~/routes/routes'
import { history } from '~/store' import { history } from '~/store'
import selector, { type SelectorProps } from './selector' 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 Layout from '../components/Layout'
import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '../components/fields' import { FIELD_LOAD_NAME, FIELD_LOAD_ADDRESS } from '../components/fields'
type Props = SelectorProps & Actions 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) const safeRecord = await buildSafe(safeAddress, safeName)
await updateSafe(safeRecord) await addSafe(safeRecord)
const storedSafes = (await loadFromStorage(SAFES_KEY)) || {} const storedSafes = (await loadFromStorage(SAFES_KEY)) || {}
storedSafes[safeAddress] = safeRecord.toJSON() storedSafes[safeAddress] = safeRecord.toJSON()
@ -28,11 +28,11 @@ export const loadSafe = async (safeName: string, safeAddress: string, updateSafe
class Load extends React.Component<Props> { class Load extends React.Component<Props> {
onLoadSafeSubmit = async (values: Object) => { onLoadSafeSubmit = async (values: Object) => {
try { try {
const { updateSafe } = this.props const { addSafe } = this.props
const safeName = values[FIELD_LOAD_NAME] const safeName = values[FIELD_LOAD_NAME]
const safeAddress = values[FIELD_LOAD_ADDRESS] const safeAddress = values[FIELD_LOAD_ADDRESS]
await loadSafe(safeName, safeAddress, updateSafe) await loadSafe(safeName, safeAddress, addSafe)
const url = `${SAFELIST_ADDRESS}/${safeAddress}` const url = `${SAFELIST_ADDRESS}/${safeAddress}`
history.push(url) history.push(url)

View File

@ -1,12 +1,10 @@
// @flow // @flow
import updateSafe from '~/routes/safe/store/actions/updateSafe' import { addSafe } from '~/routes/safe/store/actions/addSafe'
export type UpdateSafe = typeof updateSafe
export type Actions = { export type Actions = {
updateSafe: typeof updateSafe, addSafe: Function,
} }
export default { export default {
updateSafe, addSafe,
} }

View File

@ -4,7 +4,7 @@ import { List, Map } from 'immutable'
import { type GlobalState } from '~/store/index' import { type GlobalState } from '~/store/index'
import { makeOwner } from '~/routes/safe/store/model/owner' import { makeOwner } from '~/routes/safe/store/model/owner'
import SafeRecord, { type SafeProps } from '~/routes/safe/store/model/safe' 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 { getOwners, getSafeName } from '~/logic/safe/utils'
import { getGnosisSafeContract } from '~/logic/contracts/safeContracts' import { getGnosisSafeContract } from '~/logic/contracts/safeContracts'
import { getWeb3, getBalanceInEtherOf } from '~/logic/wallets/getWeb3' 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 safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE'
const safeRecord = await buildSafe(safeAddress, safeName) const safeRecord = await buildSafe(safeAddress, safeName)
return dispatch(updateSafe(safeRecord)) return dispatch(addSafe(safeRecord))
} catch (err) { } catch (err) {
// eslint-disable-next-line // eslint-disable-next-line
console.error('Error while updating safe information: ', err) console.error('Error while updating safe information: ', err)

View File

@ -59,12 +59,7 @@ export default handleActions<State, *>(
const safe = action.payload const safe = action.payload
const safeAddress = safe.address const safeAddress = safe.address
const hasSafe = !!state.get(safeAddress) return state.mergeIn(safeAddress, safe)
if (hasSafe) {
return state.update(safeAddress, prevSafe => (prevSafe.equals(safe) ? prevSafe : safe))
}
return state.set(safeAddress, safe)
}, },
[ADD_SAFE]: (state: State, action: ActionType<Function>): State => { [ADD_SAFE]: (state: State, action: ActionType<Function>): State => {
const { safe }: { safe: Safe } = action.payload const { safe }: { safe: Safe } = action.payload