Skip to content

Commit

Permalink
v12.0.0 fix: logic for using notifications tabs (#25382)
Browse files Browse the repository at this point in the history
## **Description**

This PR introduces two small fixes:
- If there are no snaps with notifications, the tabs for filtering
results are not displayed on the notifications page.
- Feature announcements are included in the onChain tab and not in the
Web3 tab.

[![Open in GitHub

Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25350?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page... 2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **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.


<!--
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**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25382?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] 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.
  • Loading branch information
matteoscurati authored Jun 18, 2024
1 parent 19c3eb4 commit 755eced
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 46 deletions.
2 changes: 2 additions & 0 deletions ui/pages/notifications/notifications.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import mockState from '../../../test/data/mock-state.json';
import Notifications from './notifications';

const mockDispatch = jest.fn();
Expand Down Expand Up @@ -32,6 +33,7 @@ jest.mock('../../store/actions', () => ({

const initialState = {
metamask: {
...mockState.metamask,
theme: 'light',
isMetamaskNotificationsEnabled: true,
isFeatureAnnouncementsEnabled: true,
Expand Down
95 changes: 49 additions & 46 deletions ui/pages/notifications/notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { NotificationsPage } from '../../components/multichain';
import { Content, Header } from '../../components/multichain/pages/page';
import { useMetamaskNotificationsContext } from '../../contexts/metamask-notifications/metamask-notifications';
import { getNotifications } from '../../selectors';
import { getNotifications, getNotifySnaps } from '../../selectors';
import {
selectIsFeatureAnnouncementsEnabled,
selectIsMetamaskNotificationsEnabled,
Expand Down Expand Up @@ -142,17 +142,15 @@ const filterNotifications = (
}

if (activeTab === TAB_KEYS.WALLET) {
return notifications.filter((notification) =>
TRIGGER_TYPES_WALLET_SET.has(notification.type),
return notifications.filter(
(notification) =>
TRIGGER_TYPES_WALLET_SET.has(notification.type) ||
notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,
);
}

if (activeTab === TAB_KEYS.WEB3) {
return notifications.filter(
(notification) =>
notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT ||
notification.type === 'SNAP',
);
return notifications.filter((notification) => notification.type === 'SNAP');
}

return notifications;
Expand All @@ -172,6 +170,9 @@ export default function Notifications() {
[activeTab, combinedNotifications],
);

let hasNotifySnaps = false;
hasNotifySnaps = useSelector(getNotifySnaps).length > 0;

return (
<NotificationsPage>
{/* Back and Settings Buttons */}
Expand Down Expand Up @@ -202,44 +203,46 @@ export default function Notifications() {
>
{t('notifications')}
</Header>
<Content paddingLeft={0} paddingRight={0}>
<Tabs
defaultActiveTabKey={activeTab}
onTabClick={(tab) => setActiveTab(tab)}
tabsClassName="notifications__tabs"
>
<Tab
activeClassName="notifications__tab--active"
className="notifications__tab"
data-testid={TAB_KEYS.ALL}
name={t('all')}
tabKey={TAB_KEYS.ALL}
/>
<Tab
activeClassName="notifications__tab--active"
className="notifications__tab"
data-testid={TAB_KEYS.WALLET}
name={
<Box
display={Display.Flex}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
gap={2}
>
{t('wallet')}
<NewFeatureTag />
</Box>
}
tabKey={TAB_KEYS.WALLET}
></Tab>
<Tab
activeClassName="notifications__tab--active"
className="notifications__tab"
data-testid={TAB_KEYS.WEB3}
name={t('web3')}
tabKey={TAB_KEYS.WEB3}
/>
</Tabs>
<Content paddingLeft={0} paddingRight={0} paddingTop={0}>
{hasNotifySnaps && (
<Tabs
defaultActiveTabKey={activeTab}
onTabClick={(tab) => setActiveTab(tab)}
tabsClassName="notifications__tabs"
>
<Tab
activeClassName="notifications__tab--active"
className="notifications__tab"
data-testid={TAB_KEYS.ALL}
name={t('all')}
tabKey={TAB_KEYS.ALL}
/>
<Tab
activeClassName="notifications__tab--active"
className="notifications__tab"
data-testid={TAB_KEYS.WALLET}
name={
<Box
display={Display.Flex}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
gap={2}
>
{t('wallet')}
<NewFeatureTag />
</Box>
}
tabKey={TAB_KEYS.WALLET}
></Tab>
<Tab
activeClassName="notifications__tab--active"
className="notifications__tab"
data-testid={TAB_KEYS.WEB3}
name={t('web3')}
tabKey={TAB_KEYS.WEB3}
/>
</Tabs>
)}
<NotificationsList
activeTab={activeTab}
notifications={filteredNotifications}
Expand Down

0 comments on commit 755eced

Please sign in to comment.