diff --git a/app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts b/app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts index 27abd4566e38..6be4e285e230 100644 --- a/app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts +++ b/app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts @@ -2,8 +2,6 @@ import { BaseController, RestrictedControllerMessenger, } from '@metamask/base-controller'; -import { ObservableStore } from '@metamask/obs-store'; -import { MetaMetricsControllerState } from '../metametrics'; import type { DataDeletionService } from '../../services/data-deletion-service'; // Unique name for the controller @@ -104,10 +102,10 @@ export default class MetaMetricsDataDeletionController extends BaseController< MetaMetricsDataDeletionState, MetaMetricsDataDeletionControllerMessenger > { - private metaMetricsId; - #dataDeletionService: DataDeletionService; + #getMetaMetricsId: () => string + /** * Creates a MetaMetricsDataDeletionController instance. * @@ -121,12 +119,12 @@ export default class MetaMetricsDataDeletionController extends BaseController< dataDeletionService, messenger, state, - metaMetricsStore, + getMetaMetricsId, }: { dataDeletionService: DataDeletionService; messenger: MetaMetricsDataDeletionControllerMessenger; state?: MetaMetricsDataDeletionState; - metaMetricsStore: ObservableStore; + getMetaMetricsId: () => string; }) { // Call the constructor of BaseControllerV2 super({ @@ -135,7 +133,7 @@ export default class MetaMetricsDataDeletionController extends BaseController< name: controllerName, state: { ...defaultState, ...state }, }); - this.metaMetricsId = metaMetricsStore.getState().metaMetricsId; + this.#getMetaMetricsId = getMetaMetricsId; this.#dataDeletionService = dataDeletionService; } @@ -154,13 +152,14 @@ export default class MetaMetricsDataDeletionController extends BaseController< * */ async createMetaMetricsDataDeletionTask(): Promise { - if (!this.metaMetricsId) { + const metaMetricsId = this.#getMetaMetricsId(); + if (!metaMetricsId) { throw new Error('MetaMetrics ID not found'); } const { data } = await this.#dataDeletionService.createDataDeletionRegulationTask( - this.metaMetricsId, + metaMetricsId, ); this.update((state) => { state.metaMetricsDataDeletionId = data?.regulateId; diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 34851f07228a..44cd293a7509 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -758,7 +758,7 @@ export default class MetamaskController extends EventEmitter { dataDeletionService, messenger: metaMetricsDataDeletionMessenger, state: initState.metaMetricsDataDeletionController, - metaMetricsStore: this.metaMetricsController.store, + getMetaMetricsId: () => this.metaMetricsController.getMetaMetricsId(), }); const gasFeeMessenger = this.controllerMessenger.getRestricted({