Skip to content

Commit d5f1dbb

Browse files
authored
feat: rewards onboarding components (#37919)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** https://consensyssoftware.atlassian.net/browse/RWDS-268 Part 6 of #36827 introduces new rewards onboarding components <!-- 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? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/37919?quickstart=1) ## **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: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] 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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Implements the Rewards onboarding flow (modal with steps, error toast/banner, referral opt‑in) with full tests and new locale strings. > > - **UI/Flow**: > - Add `Rewards` onboarding modal `ui/components/app/rewards/onboarding/OnboardingModal.tsx` with steps `OnboardingIntroStep`, `OnboardingStep1`, `OnboardingStep2`, `OnboardingStep3`, `OnboardingStep4` and `ProgressIndicator`. > - New error surfaces: `RewardsErrorBanner` and `RewardsErrorToast`. > - **Logic**: > - Intro step handles geo eligibility, hardware wallet checks, and candidate subscription ID states (`pending/retry/error`) with retry actions; advances through steps; persists modal‑shown flag. > - Step 4 supports referral code validation UI and opt‑in action; legal links via constants in `onboarding/constants.ts`. > - **i18n**: > - Add/enhance Rewards onboarding and error strings in `app/_locales/en/messages.json` and `app/_locales/en_GB/messages.json`. > - **Tests**: > - Comprehensive tests for modal, steps 1–4, error banner/toast, and progress indicator. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 978bad2. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 45c4dff commit d5f1dbb

21 files changed

+3089
-0
lines changed

app/_locales/en/messages.json

Lines changed: 102 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/_locales/en_GB/messages.json

Lines changed: 102 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import React, { Ref } from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import { ButtonProps } from '@metamask/design-system-react';
4+
import RewardsErrorBanner from './RewardsErrorBanner';
5+
6+
// Partially mock the design-system Button to expose `isLoading` for assertions,
7+
// while keeping other components unchanged.
8+
jest.mock('@metamask/design-system-react', () => {
9+
const actual = jest.requireActual('@metamask/design-system-react');
10+
const ReactLib = jest.requireActual('react');
11+
12+
const MockButton = ReactLib.forwardRef(
13+
(
14+
{ children, isLoading, onClick, ...rest }: ButtonProps,
15+
ref: Ref<HTMLButtonElement>,
16+
) => (
17+
<button
18+
{...rest}
19+
// Provide a stable attribute to assert loading state
20+
data-loading={isLoading ? 'true' : 'false'}
21+
ref={ref}
22+
onClick={onClick}
23+
>
24+
{children}
25+
</button>
26+
),
27+
);
28+
29+
return {
30+
...actual,
31+
Button: MockButton,
32+
};
33+
});
34+
35+
describe('RewardsErrorBanner', () => {
36+
afterEach(() => {
37+
jest.clearAllMocks();
38+
});
39+
40+
it('renders title and description', () => {
41+
render(
42+
<RewardsErrorBanner
43+
title="Error Title"
44+
description="Something went wrong"
45+
/>,
46+
);
47+
48+
expect(screen.getByTestId('rewards-error-banner')).toBeInTheDocument();
49+
expect(screen.getByText('Error Title')).toBeInTheDocument();
50+
expect(screen.getByText('Something went wrong')).toBeInTheDocument();
51+
});
52+
53+
it('does not render action buttons when no handlers provided', () => {
54+
render(<RewardsErrorBanner title="T" description="D" />);
55+
// No buttons should be present if both onDismiss and onConfirm are undefined
56+
expect(screen.queryByRole('button')).not.toBeInTheDocument();
57+
});
58+
59+
it('renders Dismiss button and calls onDismiss when clicked', () => {
60+
const onDismiss = jest.fn();
61+
render(
62+
<RewardsErrorBanner title="T" description="D" onDismiss={onDismiss} />,
63+
);
64+
65+
const dismissButton = screen.getByRole('button', { name: 'Dismiss' });
66+
expect(dismissButton).toBeInTheDocument();
67+
68+
fireEvent.click(dismissButton);
69+
expect(onDismiss).toHaveBeenCalledTimes(1);
70+
});
71+
72+
it('renders Confirm button with default label and calls onConfirm', () => {
73+
const onConfirm = jest.fn();
74+
render(
75+
<RewardsErrorBanner title="T" description="D" onConfirm={onConfirm} />,
76+
);
77+
78+
const confirmButton = screen.getByRole('button', { name: 'Confirm' });
79+
expect(confirmButton).toBeInTheDocument();
80+
81+
fireEvent.click(confirmButton);
82+
expect(onConfirm).toHaveBeenCalledTimes(1);
83+
});
84+
85+
it('renders Confirm button with custom label when provided', () => {
86+
const onConfirm = jest.fn();
87+
render(
88+
<RewardsErrorBanner
89+
title="T"
90+
description="D"
91+
onConfirm={onConfirm}
92+
confirmButtonLabel="Proceed"
93+
/>,
94+
);
95+
96+
const confirmButton = screen.getByRole('button', { name: 'Proceed' });
97+
expect(confirmButton).toBeInTheDocument();
98+
});
99+
100+
it('sets loading state on Confirm button when onConfirmLoading is true', () => {
101+
const onConfirm = jest.fn();
102+
render(
103+
<RewardsErrorBanner
104+
title="T"
105+
description="D"
106+
onConfirm={onConfirm}
107+
onConfirmLoading
108+
/>,
109+
);
110+
111+
const confirmButton = screen.getByRole('button', { name: 'Confirm' });
112+
expect(confirmButton).toBeInTheDocument();
113+
// Assert the mocked Button exposes loading state via data-loading
114+
expect(confirmButton).toHaveAttribute('data-loading', 'true');
115+
});
116+
});

0 commit comments

Comments
 (0)