From 50a7a49d1bcf97aacd8cdaf7714e7d0be250a31e Mon Sep 17 00:00:00 2001 From: Fernando Date: Thu, 3 Jun 2021 11:49:09 -0300 Subject: [PATCH] keep safes with no name for the list of safes (#2387) * keep safes with no name for the list of safes * prevent storing only those safes whose `loadedViaUrl` flag is true * update AB before Safe store * default safe name to empty string if it is not available --- src/logic/safe/store/middleware/safeStorage.ts | 9 ++------- src/logic/safe/store/selectors/index.ts | 3 +-- src/routes/open/container/Open.tsx | 6 +++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/logic/safe/store/middleware/safeStorage.ts b/src/logic/safe/store/middleware/safeStorage.ts index 9184e2e8..091940f5 100644 --- a/src/logic/safe/store/middleware/safeStorage.ts +++ b/src/logic/safe/store/middleware/safeStorage.ts @@ -4,7 +4,7 @@ import { saveDefaultSafe, saveSafes } from 'src/logic/safe/utils' import { REMOVE_SAFE } from 'src/logic/safe/store/actions/removeSafe' import { SET_DEFAULT_SAFE } from 'src/logic/safe/store/actions/setDefaultSafe' import { UPDATE_SAFE } from 'src/logic/safe/store/actions/updateSafe' -import { safesListWithAddressBookNameSelector, safesMapSelector } from 'src/logic/safe/store/selectors' +import { safesMapSelector } from 'src/logic/safe/store/selectors' import { SafeRecord } from '../models/safe' const watchedActions = [REMOVE_SAFE, SET_DEFAULT_SAFE, UPDATE_SAFE] @@ -24,12 +24,7 @@ export const safeStorageMiddleware = (store: Store) => ( if (watchedActions.includes(action.type)) { const state = store.getState() const safes = safesMapSelector(state) - const safeNameMap = Object.fromEntries( - safesListWithAddressBookNameSelector(state) - .map((safe) => [safe.address, safe.name]) - .toJSON(), - ) - await saveSafes(safes.filter((safe) => safeNameMap[safe.address]).toJSON()) + await saveSafes(safes.filter((safe) => !safe.loadedViaUrl).toJSON()) switch (action.type) { case SET_DEFAULT_SAFE: { diff --git a/src/logic/safe/store/selectors/index.ts b/src/logic/safe/store/selectors/index.ts index 11c24303..145a5bcf 100644 --- a/src/logic/safe/store/selectors/index.ts +++ b/src/logic/safe/store/selectors/index.ts @@ -35,10 +35,9 @@ export const safesListWithAddressBookNameSelector = createSelector( .filter((safeRecord) => !safeRecord.loadedViaUrl) .map((safeRecord) => { const safe = safeRecord.toObject() - const name = addressBook?.[safe.address]?.name + const name = addressBook?.[safe.address]?.name ?? '' return { ...safe, name } }) - .filter((safeRecord: SafeRecordWithName) => safeRecord.name) }, ) diff --git a/src/routes/open/container/Open.tsx b/src/routes/open/container/Open.tsx index 771cf1f0..d27e5aca 100644 --- a/src/routes/open/container/Open.tsx +++ b/src/routes/open/container/Open.tsx @@ -177,13 +177,13 @@ const Open = (): ReactElement => { ownersAddresses = getAccountsFrom(pendingCreation) } - const safeProps = await buildSafe(safeAddress) - await dispatch(addOrUpdateSafe(safeProps)) - const owners = ownersAddresses.map((address, index) => makeAddressBookEntry({ address, name: ownersNames[index] })) const safe = makeAddressBookEntry({ address: safeAddress, name }) await dispatch(addressBookSafeLoad([...owners, safe])) + const safeProps = await buildSafe(safeAddress) + await dispatch(addOrUpdateSafe(safeProps)) + trackEvent({ category: 'User', action: 'Created a safe',