Skip to content

Conversation

@Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jan 27, 2026

Explanation

There was some complexity in handling the order of operations between controller initialization and the event to persist state changes.

To simplify this, the controller has been updated such that it no longer persists state changes until after initialization. This makes the logic easier to follow, and lets us delete an instance variable and a few blocks of code.

The controller will be initialized as part of wallet initialization, so it will not be "constructed but uninitialized" for any significant length of time.

References

Related to changes made in this PR: #7413

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Streamlines persistence and storage sync for TokenListController.

  • Defers state-change persistence setup to initialize(); no StorageService writes occur before init, while pre-init state updates are persisted after init
  • Removes #chainsLoadedFromStorage and related skip logic; #onCacheChanged now consistently marks changed chains for debounced save
  • Simplifies #synchronizeCacheWithStorage: loads per-chain cache, merges without overwriting fresher in-memory data, and schedules persistence for chains already in state
  • Cleans up destroy/clear paths accordingly and maintains debounce/in-flight protections
  • Updates tests to call initialize() where required and adds coverage for pre-init/non-init persistence behaviors and storage error handling

Written by Cursor Bugbot for commit 11d2a4f. This will update automatically on new commits. Configure here.

@Gudahtt Gudahtt force-pushed the simplify-token-list-controller-init branch from 8bed328 to ca3acb1 Compare January 27, 2026 19:46
@Gudahtt Gudahtt marked this pull request as ready for review January 27, 2026 20:11
@Gudahtt Gudahtt requested a review from a team as a code owner January 27, 2026 20:11
@Gudahtt Gudahtt force-pushed the simplify-token-list-controller-init branch from ca3acb1 to 07a04f4 Compare January 27, 2026 20:11
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

* data loaded from storage would be immediately written back.
* Chains are removed from this set after being skipped once.
*/
readonly #chainsLoadedFromStorage: Set<Hex> = new Set();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for removing this! That was a workaround to avoid doing redundant writes 🙏

There was some complexity in handling the order of operations between
controller initialization and the event to persist state changes.

To simplify this, the controller has been updated such that it no
longer persists state changes until _after_ initialization. This
makes the logic easier to follow, and lets us delete an instance
variable and a few blocks of code.

The controller will be initialized as part of wallet initialization, so
it will not be "constructed but uninitialized" for any significant
length of time.
@Gudahtt Gudahtt force-pushed the simplify-token-list-controller-init branch from ad6a0f8 to 11d2a4f Compare January 27, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants