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 12, 2024
1 parent 56eff3f commit 1d47a88
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ 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(), []],
});
this.store.subscribe((state) => {
this.messagingSystem?.publish(`PreferencesController:stateChange`, [
state,
[],
]);
});

global.setPreference = (key, value) => {
return this.setFeatureFlag(key, value);
Expand Down Expand Up @@ -211,10 +217,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 +499,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

0 comments on commit 1d47a88

Please sign in to comment.