MetaMask / MetaMask/metamask-extension
[P3] (optional) Extract `wireStatePersistence` seam + `parsePortInfo` / `loadPreinstalledSnaps` helpers
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
**Parent Epic:** [#44543 — `app/scripts/background.js` decomposition](https://github.com/MetaMask/metamask-extension/issues/44543)
**File:** `app/scripts/background.js`
**Size:** S
---
## Problem
Once the connection wiring is stable, three low-value-but-clean extractions remain: the store-persistence subscription block inside `setupController` (~1560–1673 — the `changedControllerKeys` diff + `store.on('stateChange'|'update'|'error')` → `persistenceManager.update/persist`), and two pure helpers — `parsePortInfo` (~208–221) and `loadPreinstalledSnaps` (~931–947, fetch + gzip-decompress, no controller/counters).
## Solution
`wireStatePersistence(controller, persistenceManager)` in `lib/startup/`; move `parsePortInfo` and `loadPreinstalledSnaps` into small `lib` helpers. **Sequence LAST** — extracting the persistence subscription earlier would churn against the connection wiring.
## Acceptance Criteria
- [ ] `wireStatePersistence` extracted only after the connection wiring has stopped moving.
- [ ] `parsePortInfo` / `loadPreinstalledSnaps` moved to `lib`; unit tests where meaningful.
- [ ] Persistence + preinstalled-snaps parity. Skip entirely if the churn outweighs the clarity gain.
Contributor guide
Research direction
Start in app/scripts/background.js at setupController, parsePortInfo, and loadPreinstalledSnaps, then compare the surrounding connection-wiring changes before touching the persistence subscription. Trace the store stateChange, update, and error handlers and the helper call sites. Done means the extractions preserve persistence and preinstalled-snaps behavior, with unit tests where meaningful; skip the work if connection churn makes it unclear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 54/100