Skip to content

Commit b0a310d

Browse files
committed
refactor: revert ui/components/app/srp-quiz-modal/SRPQuiz/SRPQuiz.tsx to not touch multichain
1 parent 66acd3c commit b0a310d

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

ui/components/app/srp-quiz-modal/SRPQuiz/SRPQuiz.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports, import/no-commonjs */
22
import React, { useCallback, useContext, useEffect, useState } from 'react';
3-
import { useNavigate } from 'react-router-dom-v5-compat';
3+
import { useHistory } from 'react-router-dom';
44
import { useSelector } from 'react-redux';
55
import {
66
MetaMetricsEventCategory,
@@ -72,7 +72,7 @@ export default function SRPQuiz(props: SRPQuizProps): JSX.Element {
7272
const [stage, setStage] = useState<QuizStage>(QuizStage.introduction);
7373

7474
const trackEvent = useContext(MetaMetricsContext);
75-
const navigate = useNavigate();
75+
const history = useHistory();
7676
const t = useI18nContext();
7777
const hdEntropyIndex = useSelector(getHDEntropyIndex);
7878

@@ -237,7 +237,7 @@ export default function SRPQuiz(props: SRPQuizProps): JSX.Element {
237237
route = `${REVEAL_SEED_ROUTE}/${props.keyringId}`;
238238
}
239239

240-
navigate(route);
240+
history.push(route);
241241
if (props.closeAfterCompleting) {
242242
props.onClose();
243243
}

ui/components/multichain-accounts/multichain-srp-backup/multichain-srp-backup.test.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { screen, fireEvent, waitFor } from '@testing-library/react';
3-
import { renderWithProvider } from '../../../../test/lib/render-helpers-navigate';
3+
import { renderWithProvider } from '../../../../test/lib/render-helpers';
44
import mockState from '../../../../test/data/mock-state.json';
55
import configureStore from '../../../store/store';
66
import { ONBOARDING_REVIEW_SRP_ROUTE } from '../../../helpers/constants/routes';
@@ -9,14 +9,6 @@ import { MultichainSrpBackup } from './multichain-srp-backup';
99
const srpBackupRowTestId = 'multichain-srp-backup';
1010
const srpQuizHeaderTestId = 'srp-quiz-header';
1111

12-
const mockUseNavigate = jest.fn();
13-
jest.mock('react-router-dom-v5-compat', () => {
14-
return {
15-
...jest.requireActual('react-router-dom-v5-compat'),
16-
useNavigate: () => mockUseNavigate,
17-
};
18-
});
19-
2012
describe('MultichainSrpBackup', () => {
2113
const renderComponent = (props = {}) => {
2214
const store = configureStore({
@@ -58,28 +50,30 @@ describe('MultichainSrpBackup', () => {
5850
});
5951

6052
it('navigates to SRP review route when shouldShowBackupReminder is true', () => {
61-
renderComponent({ shouldShowBackupReminder: true });
53+
const { history } = renderComponent({ shouldShowBackupReminder: true });
54+
const mockHistoryPush = jest.spyOn(history, 'push');
6255

6356
fireEvent.click(screen.getByTestId(srpBackupRowTestId));
6457

65-
expect(mockUseNavigate).toHaveBeenCalledWith(
58+
expect(mockHistoryPush).toHaveBeenCalledWith(
6659
`${ONBOARDING_REVIEW_SRP_ROUTE}/?isFromReminder=true`,
6760
);
6861
});
6962

7063
it('opens SRP quiz modal when shouldShowBackupReminder is false', async () => {
71-
renderComponent({
64+
const { history } = renderComponent({
7265
shouldShowBackupReminder: false,
7366
keyringId: 'test-keyring-id',
7467
});
68+
const mockHistoryPush = jest.spyOn(history, 'push');
7569

7670
fireEvent.click(screen.getByTestId(srpBackupRowTestId));
7771

7872
await waitFor(() => {
7973
expect(screen.getByText('Security quiz')).toBeInTheDocument();
8074
});
8175

82-
expect(mockUseNavigate).not.toHaveBeenCalled();
76+
expect(mockHistoryPush).not.toHaveBeenCalled();
8377
});
8478

8579
it('closes SRP quiz modal when close button is clicked', async () => {

ui/components/multichain-accounts/multichain-srp-backup/multichain-srp-backup.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useState } from 'react';
2-
import { useNavigate } from 'react-router-dom-v5-compat';
2+
import { useHistory } from 'react-router-dom';
33
import classnames from 'classnames';
44
import { IconSize } from '@metamask/design-system-react';
55
import { Box, Icon, IconName, Text } from '../../component-library';
@@ -30,17 +30,17 @@ export const MultichainSrpBackup: React.FC<MultichainSrpBackupProps> = ({
3030
keyringId,
3131
}) => {
3232
const t = useI18nContext();
33-
const navigate = useNavigate();
33+
const history = useHistory();
3434
const [srpQuizModalVisible, setSrpQuizModalVisible] = useState(false);
3535

3636
const handleSrpBackupClick = useCallback(() => {
3737
if (shouldShowBackupReminder) {
3838
const backUpSRPRoute = `${ONBOARDING_REVIEW_SRP_ROUTE}/?isFromReminder=true`;
39-
navigate(backUpSRPRoute);
39+
history.push(backUpSRPRoute);
4040
} else {
4141
setSrpQuizModalVisible(true);
4242
}
43-
}, [shouldShowBackupReminder, navigate, setSrpQuizModalVisible]);
43+
}, [shouldShowBackupReminder, history, setSrpQuizModalVisible]);
4444

4545
const handleQuizModalClose = useCallback(() => {
4646
setSrpQuizModalVisible(false);

0 commit comments

Comments
 (0)