Skip to content

Commit fa97321

Browse files
feat: ✨ show a notification item in the settings page (#26843)
<!-- 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** This PR introduces the `Notifications` option within the `settings page`. Clicking on this option will render the user to the `notifications/settings` page. Specifically: 1. If basic functionalities are not active, the option disappears from the menu 2. If notifications are not active, the user will still be redirected to the `notifications/settings page`, where they can enable them 3. If notifications are active, the user will access the `notifications/settings` page, where they can select their options [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26843?quickstart=1) ## **Related issues** N/A ## **Manual testing steps** 1. Go to the settings page. 2. Find the `Notifications` option 3. Verify that the `Notifications` option links to the `notifications/settings` page 4. Verify that the `Notifications` option is hidden if basic functionalities are off ## **Screenshots/Recordings** ### **Before** <img width="1624" alt="Screenshot 2024-10-23 at 16 26 12" src="https://github.com/user-attachments/assets/c260ca28-536d-413b-862b-79deda5e70bb"> ### **After** <img width="1624" alt="Screenshot 2024-10-23 at 16 41 30" src="https://github.com/user-attachments/assets/99fb68d6-ace1-4ddd-a863-7b4e2e125074"> ## **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/develop/.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/develop/.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.
1 parent 266da07 commit fa97321

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

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

Lines changed: 10 additions & 2 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 } from 'react-router-dom';
3+
import { useHistory, useLocation } from 'react-router-dom';
44
import type { InternalAccount } from '@metamask/keyring-api';
55
import { useI18nContext } from '../../hooks/useI18nContext';
66
import { NOTIFICATIONS_ROUTE } from '../../helpers/constants/routes';
@@ -47,6 +47,7 @@ type AccountType = InternalAccount & {
4747

4848
export default function NotificationsSettings() {
4949
const history = useHistory();
50+
const location = useLocation();
5051
const t = useI18nContext();
5152

5253
// Selectors
@@ -74,6 +75,9 @@ export default function NotificationsSettings() {
7475
await accountSettingsProps.update(accountAddresses);
7576
};
7677

78+
// Previous page
79+
const previousPage = location.state?.fromPage;
80+
7781
return (
7882
<NotificationsPage>
7983
<Header
@@ -82,7 +86,11 @@ export default function NotificationsSettings() {
8286
ariaLabel="Back"
8387
iconName={IconName.ArrowLeft}
8488
size={ButtonIconSize.Sm}
85-
onClick={() => history.push(NOTIFICATIONS_ROUTE)}
89+
onClick={() =>
90+
previousPage
91+
? history.push(previousPage)
92+
: history.push(NOTIFICATIONS_ROUTE)
93+
}
8694
/>
8795
}
8896
endAccessory={null}

ui/pages/settings/settings.component.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ADD_NETWORK_ROUTE,
2121
ADD_POPULAR_CUSTOM_NETWORK,
2222
DEFAULT_ROUTE,
23+
NOTIFICATIONS_SETTINGS_ROUTE,
2324
} from '../../helpers/constants/routes';
2425

2526
import { getSettingsRoutes } from '../../helpers/utils/settings-search';
@@ -69,6 +70,7 @@ class SettingsPage extends PureComponent {
6970
mostRecentOverviewPage: PropTypes.string.isRequired,
7071
pathnameI18nKey: PropTypes.string,
7172
toggleNetworkMenu: PropTypes.func.isRequired,
73+
useExternalServices: PropTypes.bool,
7274
};
7375

7476
static contextTypes = {
@@ -290,7 +292,7 @@ class SettingsPage extends PureComponent {
290292
}
291293

292294
renderTabs() {
293-
const { history, currentPath } = this.props;
295+
const { history, currentPath, useExternalServices } = this.props;
294296
const { t } = this.context;
295297

296298
const tabs = [
@@ -326,6 +328,14 @@ class SettingsPage extends PureComponent {
326328
},
327329
];
328330

331+
if (useExternalServices) {
332+
tabs.splice(4, 0, {
333+
content: t('notifications'),
334+
icon: <Icon name={IconName.Notification} />,
335+
key: NOTIFICATIONS_SETTINGS_ROUTE,
336+
});
337+
}
338+
329339
if (process.env.ENABLE_SETTINGS_PAGE_DEV_OPTIONS) {
330340
tabs.splice(-1, 0, {
331341
content: t('developerOptions'),
@@ -349,7 +359,12 @@ class SettingsPage extends PureComponent {
349359
}
350360
return matchPath(currentPath, { exact: true, path: key });
351361
}}
352-
onSelect={(key) => history.push(key)}
362+
onSelect={(key) =>
363+
history.push({
364+
pathname: key,
365+
state: { fromPage: currentPath },
366+
})
367+
}
353368
/>
354369
);
355370
}

ui/pages/settings/settings.container.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { compose } from 'redux';
22
import { connect } from 'react-redux';
33
import { withRouter } from 'react-router-dom';
4-
import { getAddressBookEntryOrAccountName } from '../../selectors';
4+
import {
5+
getAddressBookEntryOrAccountName,
6+
getUseExternalServices,
7+
} from '../../selectors';
58
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
69
// TODO: Remove restricted import
710
// eslint-disable-next-line import/no-restricted-paths
@@ -96,6 +99,7 @@ const mapStateToProps = (state, ownProps) => {
9699
? pathNameTail
97100
: '',
98101
);
102+
const useExternalServices = getUseExternalServices(state);
99103

100104
return {
101105
addNewNetwork,
@@ -109,6 +113,7 @@ const mapStateToProps = (state, ownProps) => {
109113
isPopup,
110114
mostRecentOverviewPage: getMostRecentOverviewPage(state),
111115
pathnameI18nKey,
116+
useExternalServices,
112117
};
113118
};
114119

0 commit comments

Comments
 (0)