From 4a72bf86f82d2349149dfc5f3df79113fbb125cf Mon Sep 17 00:00:00 2001 From: Matteo Scurati Date: Sat, 15 Jun 2024 07:00:07 +0200 Subject: [PATCH] fix: :bug: fix for the logic for using tabs --- 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} + > + + + )}