From 755ecedf27e2a796d169ba2d906fafc2025cde77 Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Tue, 18 Jun 2024 15:11:15 +0200 Subject: [PATCH] v12.0.0 fix: logic for using notifications tabs (#25382) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **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** ### **Before** ### **After** ## **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. ## **Description** [![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** ### **Before** ### **After** ## **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. --- ui/pages/notifications/notifications.test.tsx | 2 + ui/pages/notifications/notifications.tsx | 95 ++++++++++--------- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/ui/pages/notifications/notifications.test.tsx b/ui/pages/notifications/notifications.test.tsx index 61f793775f34..fc7675a85dea 100644 --- a/ui/pages/notifications/notifications.test.tsx +++ b/ui/pages/notifications/notifications.test.tsx @@ -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(); @@ -32,6 +33,7 @@ jest.mock('../../store/actions', () => ({ const initialState = { metamask: { + ...mockState.metamask, theme: 'light', isMetamaskNotificationsEnabled: true, isFeatureAnnouncementsEnabled: true, diff --git a/ui/pages/notifications/notifications.tsx b/ui/pages/notifications/notifications.tsx index 138011fe5124..5b5d89e6645a 100644 --- a/ui/pages/notifications/notifications.tsx +++ b/ui/pages/notifications/notifications.tsx @@ -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, @@ -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; @@ -172,6 +170,9 @@ export default function Notifications() { [activeTab, combinedNotifications], ); + let hasNotifySnaps = false; + hasNotifySnaps = useSelector(getNotifySnaps).length > 0; + return ( {/* Back and Settings Buttons */} @@ -202,44 +203,46 @@ export default function Notifications() { > {t('notifications')} - - setActiveTab(tab)} - tabsClassName="notifications__tabs" - > - - - {t('wallet')} - - - } - tabKey={TAB_KEYS.WALLET} - > - - + + {hasNotifySnaps && ( + setActiveTab(tab)} + tabsClassName="notifications__tabs" + > + + + {t('wallet')} + + + } + tabKey={TAB_KEYS.WALLET} + > + + + )}