Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ show a notification item in the settings page #26843

Merged
merged 11 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ui/pages/notifications-settings/notifications-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { useHistory, useLocation } from 'react-router-dom';
import type { InternalAccount } from '@metamask/keyring-api';
import { useI18nContext } from '../../hooks/useI18nContext';
import { NOTIFICATIONS_ROUTE } from '../../helpers/constants/routes';
Expand Down Expand Up @@ -47,6 +47,7 @@ type AccountType = InternalAccount & {

export default function NotificationsSettings() {
const history = useHistory();
const location = useLocation();
const t = useI18nContext();

// Selectors
Expand Down Expand Up @@ -74,6 +75,9 @@ export default function NotificationsSettings() {
await accountSettingsProps.update(accountAddresses);
};

// Previous page
const previousPage = location.state?.fromPage;

return (
<NotificationsPage>
<Header
Expand All @@ -82,7 +86,11 @@ export default function NotificationsSettings() {
ariaLabel="Back"
iconName={IconName.ArrowLeft}
size={ButtonIconSize.Sm}
onClick={() => history.push(NOTIFICATIONS_ROUTE)}
onClick={() =>
previousPage
? history.push(previousPage)
: history.push(NOTIFICATIONS_ROUTE)
}
/>
}
endAccessory={null}
Expand Down
19 changes: 17 additions & 2 deletions ui/pages/settings/settings.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ADD_NETWORK_ROUTE,
ADD_POPULAR_CUSTOM_NETWORK,
DEFAULT_ROUTE,
NOTIFICATIONS_SETTINGS_ROUTE,
} from '../../helpers/constants/routes';

import { getSettingsRoutes } from '../../helpers/utils/settings-search';
Expand Down Expand Up @@ -69,6 +70,7 @@ class SettingsPage extends PureComponent {
mostRecentOverviewPage: PropTypes.string.isRequired,
pathnameI18nKey: PropTypes.string,
toggleNetworkMenu: PropTypes.func.isRequired,
useExternalServices: PropTypes.bool,
};

static contextTypes = {
Expand Down Expand Up @@ -290,7 +292,7 @@ class SettingsPage extends PureComponent {
}

renderTabs() {
const { history, currentPath } = this.props;
const { history, currentPath, useExternalServices } = this.props;
const { t } = this.context;

const tabs = [
Expand Down Expand Up @@ -326,6 +328,14 @@ class SettingsPage extends PureComponent {
},
];

if (useExternalServices) {
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
tabs.splice(4, 0, {
content: t('notifications'),
icon: <Icon name={IconName.Notification} />,
key: NOTIFICATIONS_SETTINGS_ROUTE,
Prithpal-Sooriya marked this conversation as resolved.
Show resolved Hide resolved
});
}

if (process.env.ENABLE_SETTINGS_PAGE_DEV_OPTIONS) {
tabs.splice(-1, 0, {
content: t('developerOptions'),
Expand All @@ -349,7 +359,12 @@ class SettingsPage extends PureComponent {
}
return matchPath(currentPath, { exact: true, path: key });
}}
onSelect={(key) => history.push(key)}
onSelect={(key) =>
history.push({
pathname: key,
state: { fromPage: currentPath },
})
}
/>
);
}
Expand Down
7 changes: 6 additions & 1 deletion ui/pages/settings/settings.container.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { compose } from 'redux';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { getAddressBookEntryOrAccountName } from '../../selectors';
import {
getAddressBookEntryOrAccountName,
getUseExternalServices,
} from '../../selectors';
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
Expand Down Expand Up @@ -96,6 +99,7 @@ const mapStateToProps = (state, ownProps) => {
? pathNameTail
: '',
);
const useExternalServices = getUseExternalServices(state);

return {
addNewNetwork,
Expand All @@ -109,6 +113,7 @@ const mapStateToProps = (state, ownProps) => {
isPopup,
mostRecentOverviewPage: getMostRecentOverviewPage(state),
pathnameI18nKey,
useExternalServices,
};
};

Expand Down