refactor(analytics): migrate Batch 2-12: metamask-assets#26298
Conversation
|
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. |
…2-12_metamask-assets
…uilder in token-related components
…sk-assets' of github.com:MetaMask/metamask-mobile into refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets
…2-12_metamask-assets
…sk-assets' of github.com:MetaMask/metamask-mobile into refactor/MCWP-297_analytics_migration_batch_2-12_metamask-assets
…2-12_metamask-assets
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
The new Affected components include:
Since this is a refactoring that doesn't change any business logic or UI behavior, the risk is low. However, selecting SmokeWalletPlatform provides coverage for:
This tag covers the main areas affected by the analytics hook migration without over-testing for what is essentially a code organization change. All unit tests have been updated to mock the new hook, indicating the changes are well-tested at the unit level. Performance Test Selection: |
| import DeFiPositionsListItem from './DeFiPositionsListItem'; | ||
| import { backgroundState } from '../../../util/test/initial-root-state'; | ||
| import { MetaMetricsEvents } from '../../hooks/useMetrics'; | ||
| import { MetaMetricsEvents } from '../../../core/Analytics'; |
There was a problem hiding this comment.
Test still uses deprecated MetricsEventBuilder instead of AnalyticsEventBuilder
Low Severity
This is the only test file in the migrated batch that still imports and uses MetricsEventBuilder from ../../../core/Analytics/MetricsEventBuilder — both in the mock factory (line 21–27) and in the test assertion (line 186). Every other migrated test file in this PR either uses AnalyticsEventBuilder or pure jest.fn() mocks. This creates an unnecessary dependency on the deprecated module in a file that's otherwise fully migrated to the new analytics system.
Additional Locations (1)
|





Description
Phase 2 analytics migration (Batch 2-12): migrate metamask-assets's asset components, token lists, collectible modals, DeFi positions, and token details from
useMetrics/withMetricsAwarenessto the new analytics system (useAnalytics/withAnalyticsAwareness).Reason: Deprecate MetaMetrics in favour of the shared analytics utility and AnalyticsController.
Changes: 20 source files + 16 test files migrated. React components now use
useAnalyticsfromapp/components/hooks/useAnalytics/useAnalyticsinstead ofuseMetrics; class components usewithAnalyticsAwarenessinstead ofwithMetricsAwareness(or removed the HOC when unused).MetaMetricsEventsimports moved fromhooks/useMetricstocore/Analytics. Test mocks updated to mockuseAnalyticsinstead ofuseMetrics.Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/MCWP-297 (Batch 2-12)
Manual testing steps
Screenshots/Recordings
N/A – analytics migration, no UI change.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Low Risk
Mostly mechanical analytics-hook/HOC and type import migrations with no functional UI or state-flow changes beyond event plumbing; risk is limited to missing/incorrect analytics injection causing lost tracking or test failures.
Overview
Migrates assets-related UI flows (custom token import, token list, asset/collectible detail modals, DeFi positions, and asset actions) from legacy
useMetrics/withMetricsAwarenessto the new analytics API (useAnalytics/withAnalyticsAwareness), updating call sites to use the new injectedanalyticsprop/hook methods.Updates supporting utilities (
goToAddEvmToken,removeEvmToken) to useAnalyticsEventBuildertypes and movesMetaMetricsEventsimports tocore/Analytics. Adjusts a large set of unit tests to mockuseAnalyticsinstead ofuseMetrics, and removes the metrics HOC wrapper fromViews/Assetwhere it’s no longer needed.Written by Cursor Bugbot for commit c1807bf. This will update automatically on new commits. Configure here.