Skip to content

Commit

Permalink
[preferences-controller] Replace manual publish calls with subscripti…
Browse files Browse the repository at this point in the history
…on to observable store
  • Loading branch information
MajorLift committed Mar 13, 2024
1 parent 56eff3f commit 4f6a160
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
12 changes: 2 additions & 10 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ export default class PreferencesController {
});

this.messagingSystem = opts.messenger;
this.messagingSystem.registerActionHandler(
this.messagingSystem?.registerActionHandler(
`PreferencesController:getState`,
() => this.store.getState(),
);
this.messagingSystem.registerInitialEventPayload({
this.messagingSystem?.registerInitialEventPayload({
eventType: `PreferencesController:stateChange`,
getPayload: () => [this.store.getState(), []],
});
Expand Down Expand Up @@ -211,10 +211,6 @@ export default class PreferencesController {
*/
setUseTokenDetection(val) {
this.store.updateState({ useTokenDetection: val });
this.messagingSystem.publish('PreferencesController:stateChange', [
this.store.getState(),
[],
]);
this.tokenListController.updatePreventPollingOnNetworkRestart(!val);
if (val) {
this.tokenListController.start();
Expand Down Expand Up @@ -497,10 +493,6 @@ export default class PreferencesController {

selectedIdentity.lastSelected = Date.now();
this.store.updateState({ identities, selectedAddress: address });
this.messagingSystem.publish('PreferencesController:stateChange', [
this.store.getState(),
[],
]);
}

/**
Expand Down
5 changes: 5 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2456,6 +2456,11 @@ export default class MetamaskController extends EventEmitter {
} else {
this.txController.stopIncomingTransactionPolling();
}

this.controllerMessenger.publish(
`${this.preferencesController.name}:stateChange`,
[state, []],
);
});

this.controllerMessenger.subscribe(
Expand Down

0 comments on commit 4f6a160

Please sign in to comment.