Skip to content

Commit 66acd3c

Browse files
committed
refactor: fix lint and remove migration for home page since it is blocked by navigateToConfirmation
1 parent e49a2b7 commit 66acd3c

File tree

5 files changed

+34
-40
lines changed

5 files changed

+34
-40
lines changed

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

Lines changed: 13 additions & 7 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';
3+
import { renderWithProvider } from '../../../../test/lib/render-helpers-navigate';
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,6 +9,14 @@ 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+
1220
describe('MultichainSrpBackup', () => {
1321
const renderComponent = (props = {}) => {
1422
const store = configureStore({
@@ -50,30 +58,28 @@ describe('MultichainSrpBackup', () => {
5058
});
5159

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

5663
fireEvent.click(screen.getByTestId(srpBackupRowTestId));
5764

58-
expect(mockHistoryPush).toHaveBeenCalledWith(
65+
expect(mockUseNavigate).toHaveBeenCalledWith(
5966
`${ONBOARDING_REVIEW_SRP_ROUTE}/?isFromReminder=true`,
6067
);
6168
});
6269

6370
it('opens SRP quiz modal when shouldShowBackupReminder is false', async () => {
64-
const { history } = renderComponent({
71+
renderComponent({
6572
shouldShowBackupReminder: false,
6673
keyringId: 'test-keyring-id',
6774
});
68-
const mockHistoryPush = jest.spyOn(history, 'push');
6975

7076
fireEvent.click(screen.getByTestId(srpBackupRowTestId));
7177

7278
await waitFor(() => {
7379
expect(screen.getByText('Security quiz')).toBeInTheDocument();
7480
});
7581

76-
expect(mockHistoryPush).not.toHaveBeenCalled();
82+
expect(mockUseNavigate).not.toHaveBeenCalled();
7783
});
7884

7985
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 { useHistory } from 'react-router-dom';
2+
import { useNavigate } from 'react-router-dom-v5-compat';
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 history = useHistory();
33+
const navigate = useNavigate();
3434
const [srpQuizModalVisible, setSrpQuizModalVisible] = useState(false);
3535

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

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

ui/pages/home/home.component.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
3-
import { Route } from 'react-router-dom';
4-
import { Navigate } from 'react-router-dom-v5-compat';
3+
import { Redirect, Route } from 'react-router-dom';
54
import { Text, TextVariant, TextColor } from '@metamask/design-system-react';
65
import { COHORT_NAMES } from '@metamask/subscription-controller';
76
import {
@@ -65,11 +64,10 @@ import {
6564
SUPPORT_LINK,
6665
///: END:ONLY_INCLUDE_IF
6766
} from '../../../shared/lib/ui-utils';
68-
import { AccountOverview } from '../../components/multichain';
67+
import { AccountOverview } from '../../components/multichain/account-overview';
6968
import { setEditedNetwork } from '../../store/actions';
7069
import { navigateToConfirmation } from '../confirmations/hooks/useConfirmationNavigation';
7170
import PasswordOutdatedModal from '../../components/app/password-outdated-modal';
72-
import ConnectionsRemovedModal from '../../components/app/connections-removed-modal';
7371
import ShieldEntryModal from '../../components/app/shield-entry-modal';
7472
///: BEGIN:ONLY_INCLUDE_IF(build-beta)
7573
import BetaHomeFooter from './beta/beta-home-footer.component';
@@ -100,7 +98,7 @@ export default class Home extends PureComponent {
10098
};
10199

102100
static propTypes = {
103-
navigate: PropTypes.func,
101+
history: PropTypes.object,
104102
forgottenPassword: PropTypes.bool,
105103
setConnectedStatusPopoverHasBeenShown: PropTypes.func,
106104
shouldShowSeedPhraseReminder: PropTypes.bool.isRequired,
@@ -170,7 +168,6 @@ export default class Home extends PureComponent {
170168
setAccountDetailsAddress: PropTypes.func,
171169
isSeedlessPasswordOutdated: PropTypes.bool,
172170
isPrimarySeedPhraseBackedUp: PropTypes.bool,
173-
showConnectionsRemovedModal: PropTypes.bool,
174171
showShieldEntryModal: PropTypes.bool,
175172
isSocialLoginFlow: PropTypes.bool,
176173
lookupSelectedNetworks: PropTypes.func.isRequired,
@@ -224,7 +221,7 @@ export default class Home extends PureComponent {
224221

225222
checkStatusAndNavigate() {
226223
const {
227-
navigate,
224+
history,
228225
isNotification,
229226
haveSwapsQuotes,
230227
haveBridgeQuotes,
@@ -242,25 +239,25 @@ export default class Home extends PureComponent {
242239

243240
const canRedirect = !isNotification && !stayOnHomePage;
244241
if (canRedirect && showAwaitingSwapScreen) {
245-
navigate(AWAITING_SWAP_ROUTE);
242+
history.push(AWAITING_SWAP_ROUTE);
246243
} else if (canRedirect && (haveSwapsQuotes || swapsFetchParams)) {
247-
navigate(PREPARE_SWAP_ROUTE);
244+
history.push(PREPARE_SWAP_ROUTE);
248245
} else if (canRedirect && haveBridgeQuotes) {
249-
navigate(CROSS_CHAIN_SWAP_ROUTE + PREPARE_SWAP_ROUTE);
246+
history.push(CROSS_CHAIN_SWAP_ROUTE + PREPARE_SWAP_ROUTE);
250247
} else if (pendingApprovals.length || hasApprovalFlows) {
251248
navigateToConfirmation(
252249
pendingApprovals?.[0]?.id,
253250
pendingApprovals,
254251
hasApprovalFlows,
255-
navigate,
252+
history,
256253
);
257254
}
258255
}
259256

260257
checkRedirectAfterDefaultPage() {
261258
const {
262259
redirectAfterDefaultPage,
263-
navigate,
260+
history,
264261
clearRedirectAfterDefaultPage,
265262
setAccountDetailsAddress,
266263
} = this.props;
@@ -274,7 +271,7 @@ export default class Home extends PureComponent {
274271
setAccountDetailsAddress(redirectAfterDefaultPage.address);
275272
}
276273

277-
navigate(redirectAfterDefaultPage.path);
274+
history.push(redirectAfterDefaultPage.path);
278275
clearRedirectAfterDefaultPage();
279276
}
280277
}
@@ -398,7 +395,7 @@ export default class Home extends PureComponent {
398395
const { t } = this.context;
399396

400397
const {
401-
navigate,
398+
history,
402399
shouldShowSeedPhraseReminder,
403400
isPopup,
404401
shouldShowWeb3ShimUsageNotification,
@@ -661,7 +658,7 @@ export default class Home extends PureComponent {
661658
if (isPopup) {
662659
global.platform.openExtensionInBrowser(backUpSRPRoute);
663660
} else {
664-
navigate(backUpSRPRoute);
661+
history.push(backUpSRPRoute);
665662
}
666663
}}
667664
infoText={t('backupApprovalInfo')}
@@ -867,13 +864,12 @@ export default class Home extends PureComponent {
867864
showUpdateModal,
868865
isSeedlessPasswordOutdated,
869866
isPrimarySeedPhraseBackedUp,
870-
showConnectionsRemovedModal,
871867
showShieldEntryModal,
872868
isSocialLoginFlow,
873869
} = this.props;
874870

875871
if (forgottenPassword) {
876-
return <Navigate to={RESTORE_VAULT_ROUTE} replace />;
872+
return <Redirect to={{ pathname: RESTORE_VAULT_ROUTE }} />;
877873
} else if (this.state.notificationClosing || this.state.redirecting) {
878874
return null;
879875
}
@@ -935,7 +931,6 @@ export default class Home extends PureComponent {
935931
{showTermsOfUse ? (
936932
<TermsOfUsePopup onAccept={this.onAcceptTermsOfUse} />
937933
) : null}
938-
{showConnectionsRemovedModal && <ConnectionsRemovedModal />}
939934
{showShieldEntryModal && <ShieldEntryModal />}
940935
{isPopup && !connectedStatusPopoverHasBeenShown
941936
? this.renderPopover()

ui/pages/home/home.container.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { compose } from 'redux';
33
import { connect } from 'react-redux';
4+
import { withRouter } from 'react-router-dom';
45
import { useNavState } from '../../contexts/navigation-state';
56
import { useShieldSubscriptionContext } from '../../contexts/shield/shield-subscription';
67
import {
@@ -27,7 +28,6 @@ import {
2728
getEditedNetwork,
2829
selectPendingApprovalsForNavigation,
2930
getShowUpdateModal,
30-
getShowConnectionsRemovedModal,
3131
getIsSocialLoginFlow,
3232
getShowShieldEntryModal,
3333
getPendingShieldCohort,
@@ -88,7 +88,6 @@ import {
8888
clearRedirectAfterDefaultPage,
8989
} from '../../ducks/history/history';
9090

91-
import withRouterHooks from '../../helpers/higher-order-components/with-router-hooks/with-router-hooks';
9291
import Home from './home.component';
9392

9493
const mapStateToProps = (state) => {
@@ -192,7 +191,6 @@ const mapStateToProps = (state) => {
192191
redirectAfterDefaultPage,
193192
isSeedlessPasswordOutdated: getIsSeedlessPasswordOutdated(state),
194193
isPrimarySeedPhraseBackedUp: getIsPrimarySeedPhraseBackedUp(state),
195-
showConnectionsRemovedModal: getShowConnectionsRemovedModal(state),
196194
showShieldEntryModal: getShowShieldEntryModal(state),
197195
isSocialLoginFlow: getIsSocialLoginFlow(state),
198196
pendingShieldCohort: getPendingShieldCohort(state),
@@ -277,6 +275,6 @@ const HomeWithRouter = ({ match: _match, ...props }) => {
277275
};
278276

279277
export default compose(
280-
withRouterHooks,
278+
withRouter,
281279
connect(mapStateToProps, mapDispatchToProps),
282280
)(HomeWithRouter);

ui/pages/routes/routes.component.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,14 +1051,9 @@ export default function Routes() {
10511051
<RouteWithLayout
10521052
authenticated
10531053
path={DEFAULT_ROUTE}
1054+
component={Home}
10541055
layout={RootLayout}
1055-
>
1056-
{createV5CompatRoute(Home, {
1057-
wrapper: AuthenticatedV5Compat,
1058-
includeNavigate: true,
1059-
includeLocation: true,
1060-
})}
1061-
</RouteWithLayout>
1056+
/>
10621057
</Switch>
10631058
</Suspense>
10641059
);

0 commit comments

Comments
 (0)