Skip to content

Commit

Permalink
Move preferences-controller store subscription with publish listene…
Browse files Browse the repository at this point in the history
…r into controller constructor
  • Loading branch information
MajorLift committed Mar 13, 2024
1 parent b825ed4 commit b669ccf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ export default class PreferencesController {
eventType: `PreferencesController:stateChange`,
getPayload: () => [this.store.getState(), []],
});
this.store.subscribe((state) => {
this.messagingSystem?.publish(`PreferencesController:stateChange`, [
state,
[],
]);
});

global.setPreference = (key, value) => {
return this.setFeatureFlag(key, value);
Expand Down
10 changes: 9 additions & 1 deletion app/scripts/controllers/preferences.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe('preferences controller', () => {
let onKeyringStateChangeListener;

beforeEach(() => {
const tokenListMessenger = new ControllerMessenger().getRestricted({
const controllerMessenger = new ControllerMessenger();

const tokenListMessenger = controllerMessenger.getRestricted({
name: 'TokenListController',
});
tokenListController = new TokenListController({
Expand All @@ -38,8 +40,14 @@ describe('preferences controller', () => {
messenger: tokenListMessenger,
});

const preferencesMessenger = controllerMessenger.getRestricted({
name: 'PreferencesController',
allowedActions: ['PreferencesController:getState'],
allowedEvents: ['PreferencesController:stateChange'],
});
preferencesController = new PreferencesController({
initLangCode: 'en_US',
messenger: preferencesMessenger,
tokenListController,
networkConfigurations: NETWORK_CONFIGURATION_DATA,
onKeyringStateChange: (listener) => {
Expand Down
6 changes: 0 additions & 6 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2456,12 +2456,6 @@ export default class MetamaskController extends EventEmitter {
} else {
this.txController.stopIncomingTransactionPolling();
}

// TODO: Remove once the preferences controller has been replaced with the core monorepo implementation
this.controllerMessenger.publish(
`${this.preferencesController.name}:stateChange`,
[state, []],
);
});

this.controllerMessenger.subscribe(
Expand Down

0 comments on commit b669ccf

Please sign in to comment.