feat: Keep PreferencesController in sync with keyring state#3799
Merged
feat: Keep PreferencesController in sync with keyring state#3799
PreferencesController in sync with keyring state#3799Conversation
f628c6e to
656be76
Compare
mcmire
reviewed
Jan 19, 2024
Contributor
mcmire
left a comment
There was a problem hiding this comment.
One question, but otherwise looks good.
packages/preferences-controller/src/PreferencesController.test.ts
Outdated
Show resolved
Hide resolved
The `PreferencesController` now listens for `KeyringController` state changes, and updates its own state in response to account removals or additions. New accounts are added to the `identities` state and given default labels. Removed accounts are removed from the `identities` state, and the `selectedAddress` is updated if it was removed. The dependency between these two packages has been flipped; the `@metamask/preferences-controller` package now depends upon `@metamask/keyring-controller` rather than the other away around, so that the `KeyringController` state type and state change event can be accessed. The dependency the other way was just to get the types for the four `PreferencesController` methods that are passed into the `KeyringController` constructor. These types were easily inlined, and these methods will soon be removed anyway. A `getDefaultKeyringState` export was added to the `@metamask/keyring-controller` package to make it easier to write the necessary `PreferencesController` tests. Closes #3794
bd4819d to
f8b7715
Compare
…roller-in-sync-with-keyrings * origin/main: chore(deps): bump @metamask/eth-keyring-controller from 17.0.0 to 17.0.1 (#3805) fix: custody keyring name (#3803) chore: update dependencies for `@metamask/accounts-controller` (#3747) fix: quick succession of submit password causing Accounts Controller state to be cleared (#3802) feat: add methods to support ERC-4337 accounts (#3602) feat: add getAccount action to AccountsController (#1892)
Member
Author
|
Merged in |
abdaeea to
ee153a6
Compare
ee153a6 to
1ee4f74
Compare
mikesposito
previously approved these changes
Jan 22, 2024
legobeat
previously approved these changes
Jan 23, 2024
Member
Author
|
Updated to use new latest keyring-controller version and bump lockfile |
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.
Explanation
The
PreferencesControllernow listens forKeyringControllerstate changes, and updates its own state in response to account removals or additions. New accounts are added to theidentitiesstate and given default labels. Removed accounts are removed from theidentitiesstate, and theselectedAddressis updated if it was removed.The dependency between these two packages has been flipped; the
@metamask/preferences-controllerpackage now depends upon@metamask/keyring-controllerrather than the other away around, so that theKeyringControllerstate type and state change event can be accessed. The dependency the other way was just to get the types for the fourPreferencesControllermethods that are passed into theKeyringControllerconstructor. These types were easily inlined, and these methods will soon be removed anyway.A
getDefaultKeyringStateexport was added to the@metamask/keyring-controllerpackage to make it easier to write the necessaryPreferencesControllertests.References
Closes #3794
Changelog
@metamask/keyring-controllerAdded
getDefaultKeyringStatefunctionRemoved
peerDependencyanddevDependencyupon@metamask/preferences-controller@metamask/preferences-controllerChanged
PreferencesControllerstate synchronized withKeyringControllerstateKeyringController:stateChangeevent is now required by thePreferencesControllermessenger, which is a breaking change.@metamask/keyring-controllerhas been added as apeerDependencyand as adevDependency, which is a breaking change.syncIdentitiesorupdateIdentities. Calling these methods is no longer required.Checklist