refactor: move analytics data deletion out of MetaMetrics (1/4 mobile-platform)#26022
Conversation
Extract data-deletion logic from MetaMetrics into a dedicated analyticsDataDeletion util and useAnalyticsDataDeletion hook. Remove configure() and deletion methods from MetaMetrics class.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
- Introduced a test case to verify that the function returns `hasCollectedDataSinceDeletionRequest` as false when data is recorded but no regulation ID exists. - Added another test case to ensure a valid status object is returned when storage read throws an error. - Updated the `checkDataDeleteStatus` function to handle errors during cache loading gracefully, logging the error without interrupting the flow.
- Updated the `setItem` method in `analyticsDataDeletion.ts` to safely handle potential null values by using optional chaining. - Adjusted the mock implementation of `setItem` in `testSetup.js` to remove the resolved value, aligning with the actual implementation.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
The changes are primarily internal refactoring with no user-facing behavior changes. The analytics data deletion functionality is used in Settings > Security & Privacy and wallet deletion flows. All changes have comprehensive unit test coverage. Selected SmokeWalletPlatform because:
The risk is medium because while this is a refactoring, it touches core infrastructure (Analytics, Authentication, Sagas) that could have subtle effects if something was missed. However, the comprehensive unit tests and the fact that the API surface remains the same provides confidence. Performance Test Selection: |
|



Description
Part 1/4 of #25767 — Code owner: mobile-platform
This PR extracts analytics data-deletion logic from the
MetaMetricssingleton into a dedicatedanalyticsDataDeletionutility anduseAnalyticsDataDeletionReact hook.Why? The
MetaMetricsclass accumulated responsibilities beyond its core analytics purpose (tracking, flushing, identity). Data deletion (Segment regulation API calls, status polling, StorageWrapper caching) is a distinct concern that belongs in its own module.What changed:
app/util/analytics/analyticsDataDeletion.ts— pure-function utility owning all deletion state and API calls (previously inMetaMetrics).app/components/hooks/useAnalyticsDataDeletion/— React hook exposingcreateDataDeletionTask,checkDataDeleteStatus,getDeleteRegulationCreationDate,getDeleteRegulationId,isDataRecorded.useMetricsanduseAnalyticshooks — delegate deletion methods to the new utility instead of callingMetaMetricsinstance methods.MetaMetrics.ts— removedconfigure(), all 6 deletion methods, and related private state. Interface updated accordingly.Authentication.ts— callscreateDataDeletionTaskfrom the utility instead of viaMetaMetrics.sagas/index.ts— removedMetaMetrics.configure()call fromstartAppServices.Changelog
CHANGELOG entry: null
Related issues
Fixes: #25767
Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-297
Manual testing steps
Screenshots/Recordings
N/A — no UI changes, internal refactor only.
Before
N/A
After
Scenario: user requests data deletion from Settings
No changes
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches analytics privacy/data-deletion behavior, including Segment API requests and persisted state/caching, and changes app startup/auth flows that previously invoked
MetaMetrics.configureand deletion methods.Overview
Extracts analytics data-deletion out of
MetaMetrics. Adds a newutil/analytics/analyticsDataDeletionmodule (with in-memory caching +fetchcalls to Segment regulations endpoints and persistence viaStorageWrapper) and a newuseAnalyticsDataDeletionhook that exposes the same six deletion/recording helpers.Updates callers to stop depending on
MetaMetricsfor deletion/config.useAnalytics/useMetricsnow delegate deletion/status +updateDataRecordingFlagto the new util,Authentication.deleteUsertriggers deletion via the util,startAppServicesno longer callsMetaMetrics.configure, andMetaMetrics/IMetaMetricsare stripped ofconfigure+ all data-deletion state/methods. Tests are updated and expanded to cover the new util/hook and the updated integrations.Written by Cursor Bugbot for commit b7f50a2. This will update automatically on new commits. Configure here.