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
This commit is contained in:
Fernando 2021-06-03 11:49:09 -03:00 committed by GitHub
parent e66040d32f
commit 50a7a49d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 12 deletions

View File

@ -4,7 +4,7 @@ import { saveDefaultSafe, saveSafes } from 'src/logic/safe/utils'
import { REMOVE_SAFE } from 'src/logic/safe/store/actions/removeSafe' import { REMOVE_SAFE } from 'src/logic/safe/store/actions/removeSafe'
import { SET_DEFAULT_SAFE } from 'src/logic/safe/store/actions/setDefaultSafe' import { SET_DEFAULT_SAFE } from 'src/logic/safe/store/actions/setDefaultSafe'
import { UPDATE_SAFE } from 'src/logic/safe/store/actions/updateSafe' 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' import { SafeRecord } from '../models/safe'
const watchedActions = [REMOVE_SAFE, SET_DEFAULT_SAFE, UPDATE_SAFE] const watchedActions = [REMOVE_SAFE, SET_DEFAULT_SAFE, UPDATE_SAFE]
@ -24,12 +24,7 @@ export const safeStorageMiddleware = (store: Store) => (
if (watchedActions.includes(action.type)) { if (watchedActions.includes(action.type)) {
const state = store.getState() const state = store.getState()
const safes = safesMapSelector(state) const safes = safesMapSelector(state)
const safeNameMap = Object.fromEntries( await saveSafes(safes.filter((safe) => !safe.loadedViaUrl).toJSON())
safesListWithAddressBookNameSelector(state)
.map((safe) => [safe.address, safe.name])
.toJSON(),
)
await saveSafes(safes.filter((safe) => safeNameMap[safe.address]).toJSON())
switch (action.type) { switch (action.type) {
case SET_DEFAULT_SAFE: { case SET_DEFAULT_SAFE: {

View File

@ -35,10 +35,9 @@ export const safesListWithAddressBookNameSelector = createSelector(
.filter((safeRecord) => !safeRecord.loadedViaUrl) .filter((safeRecord) => !safeRecord.loadedViaUrl)
.map((safeRecord) => { .map((safeRecord) => {
const safe = safeRecord.toObject() const safe = safeRecord.toObject()
const name = addressBook?.[safe.address]?.name const name = addressBook?.[safe.address]?.name ?? ''
return { ...safe, name } return { ...safe, name }
}) })
.filter((safeRecord: SafeRecordWithName) => safeRecord.name)
}, },
) )

View File

@ -177,13 +177,13 @@ const Open = (): ReactElement => {
ownersAddresses = getAccountsFrom(pendingCreation) ownersAddresses = getAccountsFrom(pendingCreation)
} }
const safeProps = await buildSafe(safeAddress)
await dispatch(addOrUpdateSafe(safeProps))
const owners = ownersAddresses.map((address, index) => makeAddressBookEntry({ address, name: ownersNames[index] })) const owners = ownersAddresses.map((address, index) => makeAddressBookEntry({ address, name: ownersNames[index] }))
const safe = makeAddressBookEntry({ address: safeAddress, name }) const safe = makeAddressBookEntry({ address: safeAddress, name })
await dispatch(addressBookSafeLoad([...owners, safe])) await dispatch(addressBookSafeLoad([...owners, safe]))
const safeProps = await buildSafe(safeAddress)
await dispatch(addOrUpdateSafe(safeProps))
trackEvent({ trackEvent({
category: 'User', category: 'User',
action: 'Created a safe', action: 'Created a safe',