Skip to content

Commit

Permalink
addressing review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
NiranjanaBinoy committed Jul 4, 2024
1 parent b28c3ac commit 6770475
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
RestrictedControllerMessenger,
} from '@metamask/base-controller';
import type { DataDeletionService } from '../../services/data-deletion-service';
import { DeleteRegulationStatus } from '../../../../shared/constants/metametrics';

// Unique name for the controller
const controllerName = 'MetaMetricsDataDeletionController';
Expand All @@ -17,39 +18,20 @@ const controllerName = 'MetaMetricsDataDeletionController';
type PublicInterface<Interface> = Pick<Interface, keyof Interface>;

/**
* @type DataDeleteDate
* Timestamp at which regulation response is returned.
*/
export type DataDeleteDate = number;
/**
* @type DataDeleteDate
* Regulation Id retuned while creating a delete regulation.
*/
export type DataDeleteRegulationId = string;

/**
* The status on which to filter the returned regulations.
* Mentioned here: https://docs.segmentapis.com/tag/Deletion-and-Suppression#operation/listRegulationsFromSource
*
* @type DeleteRegulationStatus
*/
export enum DeleteRegulationStatus {
FAILED = 'FAILED',
FINISHED = 'FINISHED',
INITIALIZED = 'INITIALIZED',
INVALID = 'INVALID',
NOT_SUPPORTED = 'NOT_SUPPORTED',
PARTIAL_SUCCESS = 'PARTIAL_SUCCESS',
RUNNING = 'RUNNING',
UNKNOWN = 'UNKNOWN',
}
/**
* @type MetaMetricsDataDeletionState
* MetaMetricsDataDeletionController controller state
* @property metaMetricsDataDeletionId - Regulation Id retuned while creating a delete regulation.
* @property metaMetricsDataDeletionDate - Date at which the most recent regulation is created/requested for.
* @property metaMetricsDataDeletionStatus - Status of the current delete regulation.
* @property hasMetaMetricsDataRecorded - optional variable which records whether data was collected after last deletion
* metaMetricsDataDeletionId - Regulation Id retuned while creating a delete regulation.
* metaMetricsDataDeletionDate - Date at which the most recent regulation is created/requested for.
* metaMetricsDataDeletionStatus - Status of the current delete regulation.
* hasMetaMetricsDataRecorded - optional variable which records whether data was collected after last deletion
*/
export type MetaMetricsDataDeletionState = {
metaMetricsDataDeletionId: DataDeleteRegulationId;
Expand Down Expand Up @@ -147,7 +129,7 @@ export class MetaMetricsDataDeletionController extends BaseController<
}: {
dataDeletionService: PublicInterface<DataDeletionService>;
messenger: MetaMetricsDataDeletionControllerMessenger;
state?: MetaMetricsDataDeletionState;
state?: Partial<MetaMetricsDataDeletionState>;
getMetaMetricsId: () => string | null;
}) {
// Call the constructor of BaseControllerV2
Expand All @@ -159,6 +141,28 @@ export class MetaMetricsDataDeletionController extends BaseController<
});
this.#getMetaMetricsId = getMetaMetricsId;
this.#dataDeletionService = dataDeletionService;
this.#registerMessageHandlers();
}

/**
* Constructor helper for registering this controller's messaging system
* actions.
*/
#registerMessageHandlers(): void {
this.messagingSystem.registerActionHandler(
`${controllerName}:createMetaMetricsDataDeletionTask`,
this.createMetaMetricsDataDeletionTask.bind(this),
);

this.messagingSystem.registerActionHandler(
`${controllerName}:updateDataDeletionTaskStatus`,
this.updateDataDeletionTaskStatus.bind(this),
);

this.messagingSystem.registerActionHandler(
`${controllerName}:setHasMetaMetricsDataRecorded`,
this.setHasMetaMetricsDataRecorded.bind(this),
);
}

/**
Expand Down Expand Up @@ -192,16 +196,14 @@ export class MetaMetricsDataDeletionController extends BaseController<
throw new Error('Delete Regulation id not found');
}

const { data } =
await this.#dataDeletionService.fetchDeletionRegulationStatus(
deleteRegulationId,
);
const {
data: { regulation },
} = await this.#dataDeletionService.fetchDeletionRegulationStatus(
deleteRegulationId,
);

const regulation = data?.regulation;
this.update((state) => {
state.metaMetricsDataDeletionStatus =
regulation.overallStatus as DeleteRegulationStatus;

state.metaMetricsDataDeletionStatus = regulation.overallStatus;
return state;
});
}
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/services/data-deletion-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CircuitState,
} from 'cockatiel';
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
import { DeleteRegulationStatus } from '../../../shared/constants/metametrics';

const DEFAULT_ANALYTICS_DATA_DELETION_SOURCE_ID =
process.env.ANALYTICS_DATA_DELETION_SOURCE_ID ?? 'test';
Expand All @@ -18,17 +19,15 @@ const DEFAULT_ANALYTICS_DATA_DELETION_ENDPOINT =
'https://metametrics.metamask.test';

/**
* @type RegulationId
* Response from API after the delete regulation creation.
*/
export type RegulationId = { data: Record<string, string> };

/**
* @type CurrentRegulationStatus
* Response from API after the status check of current delete regulation.
*/
export type CurrentRegulationStatus = {
data: Record<string, Record<string, string>>;
data: { regulation: { overallStatus: DeleteRegulationStatus } };
};

/**
Expand Down
15 changes: 15 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,3 +851,18 @@ export enum MetaMetricsEventUiCustomization {
export enum MetaMetricsContextProp {
PageTitle = 'location',
}

/**
* The status on which to filter the returned regulations.
* Mentioned here: https://docs.segmentapis.com/tag/Deletion-and-Suppression#operation/listRegulationsFromSource
*/
export enum DeleteRegulationStatus {
failed = 'FAILED',
finished = 'FINISHED',
initialized = 'INITIALIZED',
invalid = 'INVALID',
notSupported = 'NOT_SUPPORTED',
partialSuccess = 'PARTIAL_SUCCESS',
running = 'RUNNING',
unknown = 'UNKNOWN',
}

0 comments on commit 6770475

Please sign in to comment.