Skip to content

Commit 9829447

Browse files
authored
Merge branch 'main' into feat/trezor-erc721-e2e
2 parents 45b4b55 + e6defa6 commit 9829447

File tree

19 files changed

+74
-103
lines changed

19 files changed

+74
-103
lines changed

ui/hooks/snaps/useSnapNavigation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { useHistory } from 'react-router-dom';
1+
import { useNavigate } from 'react-router-dom-v5-compat';
22
import { parseMetaMaskUrl } from '@metamask/snaps-utils';
33
import { getSnapRoute } from '../../helpers/utils/util';
44

55
const useSnapNavigation = () => {
6-
const history = useHistory();
7-
const navigate = (url: string) => {
6+
const navigate = useNavigate();
7+
const useSnapNavigate = (url: string) => {
88
let path;
99
const linkData = parseMetaMaskUrl(url);
1010
if (linkData.snapId) {
1111
path = getSnapRoute(linkData.snapId);
1212
} else {
1313
path = linkData.path;
1414
}
15-
history.push(path);
15+
navigate(path);
1616
};
1717
return {
18-
navigate,
18+
useSnapNavigate,
1919
};
2020
};
2121

ui/pages/confirmations/components/confirm/info/batch/transaction-account-details/transaction-account-details.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ export default Story;
4040

4141
export const DefaultStory = () => <TransactionAccountDetails />;
4242

43-
DefaultStory.storyName = 'Default';
43+
DefaultStory.storyName = 'Default';

ui/pages/multichain-accounts/address-qr-code/address-qr-code.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ export const SolanaAddressQR = {
218218
<AddressQRCode />
219219
</StoryWrapper>
220220
),
221-
};
221+
};

ui/pages/multichain-accounts/base-account-details/base-account-details.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,4 @@ export const SolanaAccount = {
217217
/>
218218
</StoryWrapper>
219219
),
220-
};
220+
};

ui/pages/multichain-accounts/wallet-details/wallet-details.component.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ const meta: Meta<typeof WalletDetails> = {
5555
export default meta;
5656
type Story = StoryObj<typeof WalletDetails>;
5757

58-
export const Default: Story = {};
58+
export const Default: Story = {};

ui/pages/notification-details/notification-details.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback, useEffect } from 'react';
22
import { useSelector } from 'react-redux';
3-
import { useHistory, useLocation } from 'react-router-dom';
3+
import { useNavigate, useLocation } from 'react-router-dom-v5-compat';
44
import { TRIGGER_TYPES } from '@metamask/notification-services-controller/notification-services';
55
import { Box } from '../../components/component-library';
66
import {
@@ -26,11 +26,11 @@ import { NotificationDetailsBody } from './notification-details-body/notificatio
2626
import { NotificationDetailsFooter } from './notification-details-footer/notification-details-footer';
2727

2828
function useModalNavigation() {
29-
const history = useHistory();
29+
const navigate = useNavigate();
3030

3131
const redirectToNotifications = useCallback(() => {
32-
history.push(NOTIFICATIONS_ROUTE);
33-
}, [history]);
32+
navigate(NOTIFICATIONS_ROUTE);
33+
}, [navigate]);
3434

3535
return {
3636
redirectToNotifications,

ui/pages/notifications-settings/notifications-settings.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useMemo, useState } from 'react';
22
import { useSelector } from 'react-redux';
3-
import { useHistory, useLocation } from 'react-router-dom';
3+
import { useNavigate, useLocation } from 'react-router-dom-v5-compat';
44
import { useI18nContext } from '../../hooks/useI18nContext';
55
import { NOTIFICATIONS_ROUTE } from '../../helpers/constants/routes';
66
import {
@@ -57,7 +57,7 @@ function useNotificationAccounts() {
5757
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
5858
// eslint-disable-next-line @typescript-eslint/naming-convention
5959
export default function NotificationsSettings() {
60-
const history = useHistory();
60+
const navigate = useNavigate();
6161
const location = useLocation();
6262
const t = useI18nContext();
6363

@@ -99,8 +99,8 @@ export default function NotificationsSettings() {
9999
size={ButtonIconSize.Sm}
100100
onClick={() =>
101101
previousPage
102-
? history.push(previousPage)
103-
: history.push(NOTIFICATIONS_ROUTE)
102+
? navigate(previousPage)
103+
: navigate(NOTIFICATIONS_ROUTE)
104104
}
105105
/>
106106
}

ui/pages/notifications/notification-components/snap/snap-footer-button.test.tsx

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ import React from 'react';
22
import { processNotification } from '@metamask/notification-services-controller/notification-services';
33
import { fireEvent, waitFor } from '@testing-library/react';
44
import { createMockSnapNotification } from '@metamask/notification-services-controller/notification-services/mocks';
5-
import * as SnapNavigation from '../../../../hooks/snaps/useSnapNavigation';
65
import { renderWithProvider } from '../../../../../test/lib/render-helpers';
76
import { SnapFooterButton } from './snap-footer-button';
87
import { DetailedViewData, SnapNotification } from './types';
98

9+
const mockUseNavigate = jest.fn();
10+
11+
jest.mock('react-router-dom-v5-compat', () => {
12+
return {
13+
...jest.requireActual('react-router-dom-v5-compat'),
14+
useNavigate: () => mockUseNavigate,
15+
};
16+
});
17+
1018
// Type Util for testing
1119

1220
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
@@ -15,17 +23,11 @@ type MockVar = any;
1523

1624
describe('SnapFooterButton', () => {
1725
const arrangeMocks = () => {
18-
const mockNavigate = jest.fn();
19-
const mockUseSnapNavigation = jest
20-
.spyOn(SnapNavigation, 'default')
21-
.mockReturnValue({ navigate: mockNavigate });
2226
const notification = processNotification(
2327
createMockSnapNotification(),
2428
) as SnapNotification;
2529

2630
return {
27-
mockNavigate,
28-
mockUseSnapNavigation,
2931
notification,
3032
};
3133
};
@@ -44,7 +46,7 @@ describe('SnapFooterButton', () => {
4446
expect(container).toBeEmptyDOMElement();
4547
});
4648

47-
it('renders the NotificationDetailButton', () => {
49+
it('renders the NotificationDetailButton and navigates to home page when clicked', () => {
4850
const { notification } = arrangeMocks();
4951
(notification.data as DetailedViewData).detailedView.footerLink = {
5052
text: 'Go Home',
@@ -56,21 +58,8 @@ describe('SnapFooterButton', () => {
5658
);
5759
const button = getByText('Go Home');
5860
expect(button).toBeInTheDocument();
59-
});
60-
61-
it('navigates when internal link is clicked', () => {
62-
const { notification, mockNavigate } = arrangeMocks();
63-
(notification.data as DetailedViewData).detailedView.footerLink = {
64-
text: 'Go Home',
65-
href: 'metamask://client/',
66-
};
67-
68-
const { getByText } = renderWithProvider(
69-
<SnapFooterButton notification={notification} />,
70-
);
71-
const button = getByText('Go Home');
7261
fireEvent.click(button);
73-
expect(mockNavigate).toHaveBeenCalledWith('metamask://client/');
62+
expect(mockUseNavigate).toHaveBeenCalledWith('/');
7463
});
7564

7665
it('opens SnapLinkWarning when external link is clicked', async () => {

ui/pages/notifications/notification-components/snap/snap-footer-button.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { DetailedViewData, SnapNotification } from './types';
1212

1313
export const SnapFooterButton = (props: { notification: SnapNotification }) => {
1414
const trackEvent = useContext(MetaMetricsContext);
15-
const { navigate } = useSnapNavigation();
15+
const { useSnapNavigate } = useSnapNavigation();
1616
const [isOpen, setIsOpen] = useState(false);
1717
const data = props.notification.data as DetailedViewData;
1818
const footer = data?.detailedView?.footerLink;
@@ -44,10 +44,15 @@ export const SnapFooterButton = (props: { notification: SnapNotification }) => {
4444
if (isExternal) {
4545
setIsOpen(true);
4646
} else {
47-
navigate(href);
47+
useSnapNavigate(href);
4848
}
4949
},
50-
[navigate, props.notification.id, props.notification.type, trackEvent],
50+
[
51+
useSnapNavigate,
52+
props.notification.id,
53+
props.notification.type,
54+
trackEvent,
55+
],
5156
);
5257

5358
if (!footer) {

ui/pages/notifications/notification-components/snap/snap.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { useSelector } from 'react-redux';
3-
import { useHistory } from 'react-router-dom';
3+
import { useNavigate } from 'react-router-dom-v5-compat';
44
import { TRIGGER_TYPES } from '@metamask/notification-services-controller/notification-services';
55
import {
66
NotificationDetailTitle,
@@ -32,7 +32,7 @@ import { SnapFooterButton } from './snap-footer-button';
3232
export const components: NotificationComponent<SnapNotification> = {
3333
guardFn: isOfTypeNodeGuard([TRIGGER_TYPES.SNAP]),
3434
item: ({ notification, onClick }) => {
35-
const history = useHistory();
35+
const navigate = useNavigate();
3636
const snapsMetadata = useSelector(getSnapsMetadata);
3737
const snapsNameGetter = getSnapName(snapsMetadata);
3838
const { markNotificationAsRead } = useMarkNotificationAsRead();
@@ -48,7 +48,7 @@ export const components: NotificationComponent<SnapNotification> = {
4848
]);
4949
}
5050

51-
history.push(getSnapRoute(notification.data.origin));
51+
navigate(getSnapRoute(notification.data.origin));
5252
};
5353

5454
return (

0 commit comments

Comments
 (0)