From 91d3aa8592eb016458e056124d715f1b20062b7f Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Fri, 7 Aug 2020 16:49:29 +0200 Subject: [PATCH] Bug/safe crash when accessing from link (#1209) * use updateSafeAction for adding modules * Fix address parameter naming issue Add comment to ADD_SAFE_MODULE behaviour * fetchSafe batch everything to updateSafe * remove addSafeModules action Co-authored-by: Mikhail Mikheev --- .../safe/store/actions/addSafeModules.ts | 7 ------ src/routes/safe/store/actions/fetchSafe.ts | 23 ++++++------------- src/routes/safe/store/reducer/safe.ts | 5 ---- 3 files changed, 7 insertions(+), 28 deletions(-) delete mode 100644 src/routes/safe/store/actions/addSafeModules.ts diff --git a/src/routes/safe/store/actions/addSafeModules.ts b/src/routes/safe/store/actions/addSafeModules.ts deleted file mode 100644 index 6c36075c..00000000 --- a/src/routes/safe/store/actions/addSafeModules.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { createAction } from 'redux-actions' - -export const ADD_SAFE_MODULES = 'ADD_SAFE_MODULES' - -const addSafeModules = createAction(ADD_SAFE_MODULES) - -export default addSafeModules diff --git a/src/routes/safe/store/actions/fetchSafe.ts b/src/routes/safe/store/actions/fetchSafe.ts index a41ce5bb..976528b6 100644 --- a/src/routes/safe/store/actions/fetchSafe.ts +++ b/src/routes/safe/store/actions/fetchSafe.ts @@ -15,7 +15,6 @@ import { makeOwner } from 'src/routes/safe/store/models/owner' import { checksumAddress } from 'src/utils/checksumAddress' import { ModulePair, SafeOwner } from 'src/routes/safe/store/models/safe' import { Dispatch } from 'redux' -import addSafeModules from './addSafeModules' import { SENTINEL_ADDRESS } from 'src/logic/contracts/safeContracts' const buildOwnersFrom = ( @@ -49,7 +48,7 @@ const buildModulesLinkedList = (modules: string[] | undefined, nextModule: strin return null } -export const buildSafe = async (safeAdd, safeName, latestMasterContractVersion?: any) => { +export const buildSafe = async (safeAdd: string, safeName: string, latestMasterContractVersion?: any) => { const safeAddress = checksumAddress(safeAdd) const safeParams = ['getThreshold', 'nonce', 'VERSION', 'getOwners'] @@ -105,24 +104,16 @@ export const checkAndUpdateSafe = (safeAdd: string) => async (dispatch: Dispatch // Converts from [ { address, ownerName} ] to address array const localOwners = localSafe ? localSafe.owners.map((localOwner) => localOwner.address) : undefined - const localThreshold = localSafe ? localSafe.threshold : undefined - const localNonce = localSafe ? localSafe.nonce : undefined dispatch( - addSafeModules({ - safeAddress, - modulesAddresses: buildModulesLinkedList(modules?.array, modules?.next), + updateSafe({ + address: safeAddress, + modules: buildModulesLinkedList(modules?.array, modules?.next), + nonce: Number(remoteNonce), + threshold: Number(remoteThreshold), }), ) - if (localNonce !== Number(remoteNonce)) { - dispatch(updateSafe({ address: safeAddress, nonce: Number(remoteNonce) })) - } - - if (localThreshold !== Number(remoteThreshold)) { - dispatch(updateSafe({ address: safeAddress, threshold: Number(remoteThreshold) })) - } - // If the remote owners does not contain a local address, we remove that local owner if (localOwners) { localOwners.forEach((localAddress) => { @@ -149,7 +140,7 @@ export const checkAndUpdateSafe = (safeAdd: string) => async (dispatch: Dispatch } // eslint-disable-next-line consistent-return -export default (safeAdd) => async (dispatch, getState) => { +export default (safeAdd: string) => async (dispatch, getState) => { try { const safeAddress = checksumAddress(safeAdd) const safeName = (await getSafeName(safeAddress)) || 'LOADED SAFE' diff --git a/src/routes/safe/store/reducer/safe.ts b/src/routes/safe/store/reducer/safe.ts index 8d71f7e3..10543706 100644 --- a/src/routes/safe/store/reducer/safe.ts +++ b/src/routes/safe/store/reducer/safe.ts @@ -15,7 +15,6 @@ import { makeOwner } from 'src/routes/safe/store/models/owner' import makeSafe from 'src/routes/safe/store/models/safe' import { checksumAddress } from 'src/utils/checksumAddress' import { SafeReducerMap } from './types/safe' -import { ADD_SAFE_MODULES } from 'src/routes/safe/store/actions/addSafeModules' export const SAFE_REDUCER_ID = 'safes' export const DEFAULT_SAFE_INITIAL_STATE = 'NOT_ASKED' @@ -128,10 +127,6 @@ export default handleActions( return prevSafe.merge({ owners: updatedOwners }) }) }, - [ADD_SAFE_MODULES]: (state: SafeReducerMap, action) => { - const { modulesAddresses, safeAddress } = action.payload - return state.setIn(['safes', safeAddress, 'modules'], modulesAddresses) - }, [SET_DEFAULT_SAFE]: (state: SafeReducerMap, action) => state.set('defaultSafe', action.payload), [SET_LATEST_MASTER_CONTRACT_VERSION]: (state: SafeReducerMap, action) => state.set('latestMasterContractVersion', action.payload),