Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Decouple the data deletion controller #24870

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,10 +102,10 @@ export default class MetaMetricsDataDeletionController extends BaseController<
MetaMetricsDataDeletionState,
MetaMetricsDataDeletionControllerMessenger
> {
private metaMetricsId;

#dataDeletionService: DataDeletionService;

#getMetaMetricsId: () => string

/**
* Creates a MetaMetricsDataDeletionController instance.
*
Expand All @@ -121,12 +119,12 @@ export default class MetaMetricsDataDeletionController extends BaseController<
dataDeletionService,
messenger,
state,
metaMetricsStore,
getMetaMetricsId,
}: {
dataDeletionService: DataDeletionService;
messenger: MetaMetricsDataDeletionControllerMessenger;
state?: MetaMetricsDataDeletionState;
metaMetricsStore: ObservableStore<MetaMetricsControllerState>;
getMetaMetricsId: () => string;
}) {
// Call the constructor of BaseControllerV2
super({
Expand All @@ -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;
}

Expand All @@ -154,13 +152,14 @@ export default class MetaMetricsDataDeletionController extends BaseController<
*
*/
async createMetaMetricsDataDeletionTask(): Promise<void> {
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;
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ export default class MetamaskController extends EventEmitter {
dataDeletionService,
messenger: metaMetricsDataDeletionMessenger,
state: initState.metaMetricsDataDeletionController,
metaMetricsStore: this.metaMetricsController.store,
getMetaMetricsId: () => this.metaMetricsController.getMetaMetricsId(),
Gudahtt marked this conversation as resolved.
Show resolved Hide resolved
});

const gasFeeMessenger = this.controllerMessenger.getRestricted({
Expand Down