fix(store): filter unsupported chains out of read paths for addedSafes - #8187
Closed
TenderDeve (tenderdeve) wants to merge 1 commit into
Closed
fix(store): filter unsupported chains out of read paths for addedSafes#8187TenderDeve (tenderdeve) wants to merge 1 commit into
TenderDeve (tenderdeve) wants to merge 1 commit into
Conversation
Persisted chainId-keyed slices (addedSafes, address book, undeployed Safes, …) hold entries for chains the gateway no longer lists, so consumers that iterate the raw maps surface stale state — see safe-global#2584. Add a generic pickSupportedChainEntries util and a memoised selectAllAddedSafesOnSupportedChains selector, then route the local Safes alert through it so the on-this-browser count stops including stale-chain Safes. Refactor _sanitizeNotifiableSafes to delegate to the shared util. This is the first slice — follow-ups can extend the same pattern to the address book, pinned Safe apps, undeployed Safes, etc., without mutating localStorage. Resolves safe-global#2585
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it solves
Resolves: #2585
Persisted chainId-keyed slices (
addedSafes, address book, undeployed Safes, pinned Safe apps, …) hold entries for chains the gateway no longer lists. Consumers that iterate the raw maps surface stale state — this was the original trigger behind the linked incident in #2584.Maintainer guidance on the issue was to filter at READ time rather than mutate localStorage. There was already a private
_sanitizeNotifiableSafesdoing exactly this for push-notification registration. This PR lifts that into a shared util and starts wiring it through the rest of the read paths.How this PR fixes it
apps/web/src/utils/chainEntries.ts— new genericpickSupportedChainEntries(byChainId, chains)util (kept out ofutils/chains.tsto avoid pulling the store-init graph back into the slice file).addedSafesSlice— new memoisedselectAllAddedSafesOnSupportedChains(state, chains)selector.LocalSafesAlert(Spaces sign-in entry point) routed through the sanitised selector so the on-this-browser count stops including Safes on chains the gateway dropped._sanitizeNotifiableSafescollapsed to delegate to the shared util — no behavioural change, just removes the duplicate.First slice; the same
pickSupportedChainEntries+ per-slice memoised selector pattern can be extended toaddressBook,undeployedSafes,pinnedSafeApps,visitedSafes, etc. in follow-ups. Doing them all in one PR would touch ~150 call sites and make review hard.How to test it
useChainsmock).LocalSafesAlertcounts the stale-chain Safe. After: it's excluded; the count matches the actual usable list.Unit tests cover the util's filter / no-mutation / empty-chains semantics, the new sanitised selector, and the updated alert behaviour.
Affected flows
LocalSafesAlertcountBlast radius
_sanitizeNotifiableSafeskeeps its signature, only its body now reuses the utilLocalSafesAlertis the only consumer migrated to the sanitised selectorRisks / not checked
useAllSafes,AddAccounts,useOnboardingSafes,DataWidget, …) still read rawselectAllAddedSafes— incremental follow-upsuseChains().configs(or equivalent) for the filter to engageVisual summary
Checklist
CLA signature
I have read and hereby sign the Contributor License Agreement.