Skip to content

Commit 283f6b5

Browse files
feat(deposit): pass email to OTP view (#16113)
<!-- 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** Small data refactor for the deposit flow. Email has been moved from the deposit context into local state and is passed now as a route param to the OTP view. <!-- 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? --> ## **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** - [ ] 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). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] 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. --------- Co-authored-by: AxelGes <[email protected]>
1 parent 827ea02 commit 283f6b5

File tree

7 files changed

+19
-43
lines changed

7 files changed

+19
-43
lines changed

app/components/UI/Ramp/Deposit/Views/EnterEmail/EnterEmail.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe('EnterEmail Component', () => {
105105
fireEvent.press(screen.getByRole('button', { name: 'Send email' }));
106106
await waitFor(() => {
107107
expect(mockNavigate).toHaveBeenCalledWith(Routes.DEPOSIT.OTP_CODE, {
108+
108109
quote: mockQuote,
109110
});
110111
});

app/components/UI/Ramp/Deposit/Views/EnterEmail/EnterEmail.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { getDepositNavbarOptions } from '../../../../Navbar';
2323
import { useDepositSdkMethod } from '../../hooks/useDepositSdkMethod';
2424
import { createOtpCodeNavDetails } from '../OtpCode/OtpCode';
2525
import { validateEmail } from '../../utils';
26-
import { useDepositSDK } from '../../sdk';
2726
import DepositProgressBar from '../../components/DepositProgressBar/DepositProgressBar';
2827
import { BuyQuote } from '@consensys/native-ramps-sdk';
2928

@@ -36,7 +35,7 @@ export const createEnterEmailNavDetails =
3635

3736
const EnterEmail = () => {
3837
const navigation = useNavigation();
39-
const { email, setEmail } = useDepositSDK();
38+
const [email, setEmail] = useState('');
4039
const [validationError, setValidationError] = useState(false);
4140
const { quote } = useParams<EnterEmailParams>();
4241

@@ -66,7 +65,7 @@ const EnterEmail = () => {
6665
await submitEmail();
6766

6867
if (!error) {
69-
navigation.navigate(...createOtpCodeNavDetails({ quote }));
68+
navigation.navigate(...createOtpCodeNavDetails({ quote, email }));
7069
}
7170
} else {
7271
setValidationError(true);

app/components/UI/Ramp/Deposit/Views/OtpCode/OtpCode.test.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ const mockQuote: MockQuote = {
2727
jest.mock('../../sdk', () => ({
2828
...jest.requireActual('../../sdk'),
2929
useDepositSDK: jest.fn().mockReturnValue({
30-
email: EMAIL,
31-
setEmail: jest.fn(),
3230
sdk: {},
3331
sdkError: null,
3432
providerApiKey: 'mock-api-key',
@@ -70,7 +68,7 @@ jest.mock('@react-navigation/native', () => {
7068
),
7169
}),
7270
useRoute: () => ({
73-
params: { quote: mockQuote },
71+
params: { email: EMAIL, quote: mockQuote },
7472
}),
7573
};
7674
});
@@ -123,17 +121,16 @@ describe('OtpCode Component', () => {
123121
ttl: 1000,
124122
userId: 'mock-user-id',
125123
} as NativeTransakAccessToken;
124+
126125
const mockSubmitCode = jest.fn().mockResolvedValue(mockResponse);
127126
const mockSetAuthToken = jest.fn().mockResolvedValue(undefined);
128127

129128
mockUseDepositSdkMethodValues = [
130-
{ ...mockUseDepositSdkMethodInitialState, data: mockResponse },
129+
{ ...mockUseDepositSdkMethodInitialState, data: null },
131130
mockSubmitCode,
132131
];
133132

134133
jest.mocked(useDepositSDK).mockReturnValue({
135-
email: EMAIL,
136-
setEmail: jest.fn(),
137134
sdk: {
138135
setAccessToken: jest.fn(),
139136
getAccessToken: jest.fn(),
@@ -154,7 +151,6 @@ describe('OtpCode Component', () => {
154151
const { getByTestId } = render(OtpCode);
155152

156153
const codeInput = getByTestId('otp-code-input');
157-
158154
fireEvent.changeText(codeInput, '123456');
159155

160156
fireEvent.press(
@@ -163,8 +159,16 @@ describe('OtpCode Component', () => {
163159
}),
164160
);
165161

162+
expect(mockSubmitCode).toHaveBeenCalled();
163+
164+
mockUseDepositSdkMethodValues[0] = {
165+
...mockUseDepositSdkMethodValues[0],
166+
data: mockResponse,
167+
};
168+
169+
render(OtpCode);
170+
166171
await waitFor(() => {
167-
expect(mockSubmitCode).toHaveBeenCalled();
168172
expect(mockSetAuthToken).toHaveBeenCalledWith(mockResponse);
169173
expect(mockNavigate).toHaveBeenCalledWith(
170174
Routes.DEPOSIT.VERIFY_IDENTITY,

app/components/UI/Ramp/Deposit/Views/OtpCode/OtpCode.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { BuyQuote } from '@consensys/native-ramps-sdk';
2727

2828
export interface OtpCodeParams {
2929
quote: BuyQuote;
30+
email: string;
3031
}
3132

3233
export const createOtpCodeNavDetails = createNavigationDetails<OtpCodeParams>(
@@ -38,8 +39,8 @@ const CELL_COUNT = 6;
3839
const OtpCode = () => {
3940
const navigation = useNavigation();
4041
const { styles, theme } = useStyles(styleSheet, {});
41-
const { email, setAuthToken } = useDepositSDK();
42-
const { quote } = useParams<OtpCodeParams>();
42+
const { setAuthToken } = useDepositSDK();
43+
const { quote, email } = useParams<OtpCodeParams>();
4344

4445
useEffect(() => {
4546
navigation.setOptions(

app/components/UI/Ramp/Deposit/hooks/useKycPolling.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ describe('useKycPolling', () => {
4848
sdkError: undefined,
4949
providerApiKey: 'test-key',
5050
providerFrontendAuth: 'test-auth',
51-
52-
setEmail: jest.fn(),
5351
isAuthenticated: true,
5452
authToken: { id: 'test-token' } as NativeTransakAccessToken,
5553
setAuthToken: jest.fn(),

app/components/UI/Ramp/Deposit/sdk/index.test.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,7 @@ describe('Deposit SDK Context', () => {
274274
});
275275
});
276276

277-
describe('Email and Authentication', () => {
278-
it('manages email state correctly', () => {
279-
let contextValue: ReturnType<typeof useDepositSDK> | undefined;
280-
const TestComponent = () => {
281-
contextValue = useDepositSDK();
282-
return null;
283-
};
284-
285-
renderWithProvider(
286-
<DepositSDKProvider>
287-
<TestComponent />
288-
</DepositSDKProvider>,
289-
{ state: mockedState },
290-
);
291-
292-
act(() => {
293-
contextValue?.setEmail('[email protected]');
294-
});
295-
296-
expect(contextValue?.email).toBe('[email protected]');
297-
});
298-
277+
describe('Authentication', () => {
299278
it('handles authentication state correctly', async () => {
300279
let contextValue: ReturnType<typeof useDepositSDK> | undefined;
301280
const TestComponent = () => {

app/components/UI/Ramp/Deposit/sdk/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export interface DepositSDK {
2828
sdkError?: Error;
2929
providerApiKey: string | null;
3030
providerFrontendAuth: string | null;
31-
email: string;
32-
setEmail: (email: string) => void;
3331
isAuthenticated: boolean;
3432
authToken?: NativeTransakAccessToken;
3533
setAuthToken: (token: NativeTransakAccessToken) => Promise<boolean>;
@@ -60,7 +58,6 @@ export const DepositSDKProvider = ({
6058
const providerFrontendAuth = useSelector(selectDepositProviderFrontendAuth);
6159
const [sdk, setSdk] = useState<NativeRampsSdk>();
6260
const [sdkError, setSdkError] = useState<Error>();
63-
const [email, setEmail] = useState<string>('');
6461
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(false);
6562
const [authToken, setAuthToken] = useState<NativeTransakAccessToken>();
6663

@@ -141,8 +138,6 @@ export const DepositSDKProvider = ({
141138
sdkError,
142139
providerApiKey,
143140
providerFrontendAuth,
144-
email,
145-
setEmail,
146141
isAuthenticated,
147142
authToken,
148143
setAuthToken: setAuthTokenCallback,
@@ -154,7 +149,6 @@ export const DepositSDKProvider = ({
154149
sdkError,
155150
providerApiKey,
156151
providerFrontendAuth,
157-
email,
158152
isAuthenticated,
159153
authToken,
160154
setAuthTokenCallback,

0 commit comments

Comments
 (0)