Skip to content

Commit ba8fa85

Browse files
refactor(analytics): migrate Batch 1-5: rewards (MetaMask#25647)
## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> This PR migrates the `EndOfSeasonClaimBottomSheet` component from the legacy `useMetrics` hook to the new `useAnalytics` hook as part of the analytics migration effort (MCWP-297 batch 1-5 for rewards). - update both the component implementation and its test. ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: [MCWP-297](https://consensyssoftware.atlassian.net/browse/MCWP-297) ## **Manual testing steps** ```gherkin Feature: Rewards claim analytics tracking Scenario: user claims a reward Given user has a claimable reward available And the user opted-in for analytics When user opens the rewards claim bottom sheet And user successfully claims a reward Then "Rewards Reward Viewed" and "Rewards Reward Claimed" events are tracked ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** NA ### **After** NA ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. [MCWP-297]: https://consensyssoftware.atlassian.net/browse/MCWP-297?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Low risk refactor limited to swapping the analytics hook used by `EndOfSeasonClaimBottomSheet`; behavior should remain the same aside from how events are dispatched. > > **Overview** > Migrates `EndOfSeasonClaimBottomSheet` analytics tracking from legacy `useMetrics` to the new `useAnalytics` hook while keeping event constants (`MetaMetricsEvents`) sourced from `useMetrics`. > > Updates the associated Jest test to mock `useAnalytics` instead of `useMetrics`, preserving coverage for the "reward viewed" and "reward claimed" tracking. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ff90e39. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 62ba62f commit ba8fa85

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

app/components/UI/Rewards/components/EndOfSeasonClaimBottomSheet/EndOfSeasonClaimBottomSheet.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ jest.mock('@react-navigation/native', () => ({
4141
}),
4242
}));
4343

44-
// Mock useMetrics
44+
// Mock useAnalytics
4545
const mockTrackEvent = jest.fn();
4646
const mockCreateEventBuilder = jest.fn(() => ({
4747
addProperties: jest.fn().mockReturnThis(),
4848
build: jest.fn().mockReturnValue({}),
4949
}));
50-
jest.mock('../../../../hooks/useMetrics', () => ({
51-
useMetrics: () => ({
50+
jest.mock('../../../../hooks/useAnalytics/useAnalytics', () => ({
51+
useAnalytics: () => ({
5252
trackEvent: mockTrackEvent,
5353
createEventBuilder: mockCreateEventBuilder,
5454
}),
55+
}));
56+
57+
// Mock MetaMetricsEvents (still imported from useMetrics)
58+
jest.mock('../../../../hooks/useMetrics', () => ({
5559
MetaMetricsEvents: {
5660
REWARDS_REWARD_VIEWED: 'REWARDS_REWARD_VIEWED',
5761
REWARDS_REWARD_CLAIMED: 'REWARDS_REWARD_CLAIMED',

app/components/UI/Rewards/components/EndOfSeasonClaimBottomSheet/EndOfSeasonClaimBottomSheet.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import BottomSheet, {
99
BottomSheetRef,
1010
} from '../../../../../component-library/components/BottomSheets/BottomSheet';
1111
import useRewardsToast from '../../hooks/useRewardsToast';
12-
import { MetaMetricsEvents, useMetrics } from '../../../../hooks/useMetrics';
12+
import { MetaMetricsEvents } from '../../../../hooks/useMetrics';
13+
import { useAnalytics } from '../../../../hooks/useAnalytics/useAnalytics';
1314
import { useNavigation } from '@react-navigation/native';
1415
import { strings } from '../../../../../../locales/i18n';
1516
import { TouchableOpacity } from 'react-native';
@@ -94,7 +95,7 @@ const EndOfSeasonClaimBottomSheet = ({
9495
const tw = useTailwind();
9596
const { showToast: showRewardsToast, RewardsToastOptions } =
9697
useRewardsToast();
97-
const { trackEvent, createEventBuilder } = useMetrics();
98+
const { trackEvent, createEventBuilder } = useAnalytics();
9899
const { claimReward, isClaimingReward } = useClaimReward();
99100
const { lineaTokenReward } = useLineaSeasonOneTokenReward();
100101
const {

0 commit comments

Comments
 (0)