Skip to content

Commit 7e03b4d

Browse files
fix: logic for using notifications tabs (#25350)
## **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.
1 parent e70e44f commit 7e03b4d

File tree

2 files changed

+51
-46
lines changed

2 files changed

+51
-46
lines changed

ui/pages/notifications/notifications.test.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Provider } from 'react-redux';
44
import { MemoryRouter } from 'react-router-dom';
55
import configureStore from 'redux-mock-store';
66
import thunk from 'redux-thunk';
7+
import mockState from '../../../test/data/mock-state.json';
78
import Notifications from './notifications';
89

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

3334
const initialState = {
3435
metamask: {
36+
...mockState.metamask,
3537
theme: 'light',
3638
isMetamaskNotificationsEnabled: true,
3739
isFeatureAnnouncementsEnabled: true,

ui/pages/notifications/notifications.tsx

+49-46
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import { NotificationsPage } from '../../components/multichain';
1717
import { Content, Header } from '../../components/multichain/pages/page';
1818
import { useMetamaskNotificationsContext } from '../../contexts/metamask-notifications/metamask-notifications';
19-
import { getNotifications } from '../../selectors';
19+
import { getNotifications, getNotifySnaps } from '../../selectors';
2020
import {
2121
selectIsFeatureAnnouncementsEnabled,
2222
selectIsMetamaskNotificationsEnabled,
@@ -142,17 +142,15 @@ const filterNotifications = (
142142
}
143143

144144
if (activeTab === TAB_KEYS.WALLET) {
145-
return notifications.filter((notification) =>
146-
TRIGGER_TYPES_WALLET_SET.has(notification.type),
145+
return notifications.filter(
146+
(notification) =>
147+
TRIGGER_TYPES_WALLET_SET.has(notification.type) ||
148+
notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,
147149
);
148150
}
149151

150152
if (activeTab === TAB_KEYS.WEB3) {
151-
return notifications.filter(
152-
(notification) =>
153-
notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT ||
154-
notification.type === 'SNAP',
155-
);
153+
return notifications.filter((notification) => notification.type === 'SNAP');
156154
}
157155

158156
return notifications;
@@ -172,6 +170,9 @@ export default function Notifications() {
172170
[activeTab, combinedNotifications],
173171
);
174172

173+
let hasNotifySnaps = false;
174+
hasNotifySnaps = useSelector(getNotifySnaps).length > 0;
175+
175176
return (
176177
<NotificationsPage>
177178
{/* Back and Settings Buttons */}
@@ -202,44 +203,46 @@ export default function Notifications() {
202203
>
203204
{t('notifications')}
204205
</Header>
205-
<Content paddingLeft={0} paddingRight={0}>
206-
<Tabs
207-
defaultActiveTabKey={activeTab}
208-
onTabClick={(tab) => setActiveTab(tab)}
209-
tabsClassName="notifications__tabs"
210-
>
211-
<Tab
212-
activeClassName="notifications__tab--active"
213-
className="notifications__tab"
214-
data-testid={TAB_KEYS.ALL}
215-
name={t('all')}
216-
tabKey={TAB_KEYS.ALL}
217-
/>
218-
<Tab
219-
activeClassName="notifications__tab--active"
220-
className="notifications__tab"
221-
data-testid={TAB_KEYS.WALLET}
222-
name={
223-
<Box
224-
display={Display.Flex}
225-
justifyContent={JustifyContent.center}
226-
alignItems={AlignItems.center}
227-
gap={2}
228-
>
229-
{t('wallet')}
230-
<NewFeatureTag />
231-
</Box>
232-
}
233-
tabKey={TAB_KEYS.WALLET}
234-
></Tab>
235-
<Tab
236-
activeClassName="notifications__tab--active"
237-
className="notifications__tab"
238-
data-testid={TAB_KEYS.WEB3}
239-
name={t('web3')}
240-
tabKey={TAB_KEYS.WEB3}
241-
/>
242-
</Tabs>
206+
<Content paddingLeft={0} paddingRight={0} paddingTop={0}>
207+
{hasNotifySnaps && (
208+
<Tabs
209+
defaultActiveTabKey={activeTab}
210+
onTabClick={(tab) => setActiveTab(tab)}
211+
tabsClassName="notifications__tabs"
212+
>
213+
<Tab
214+
activeClassName="notifications__tab--active"
215+
className="notifications__tab"
216+
data-testid={TAB_KEYS.ALL}
217+
name={t('all')}
218+
tabKey={TAB_KEYS.ALL}
219+
/>
220+
<Tab
221+
activeClassName="notifications__tab--active"
222+
className="notifications__tab"
223+
data-testid={TAB_KEYS.WALLET}
224+
name={
225+
<Box
226+
display={Display.Flex}
227+
justifyContent={JustifyContent.center}
228+
alignItems={AlignItems.center}
229+
gap={2}
230+
>
231+
{t('wallet')}
232+
<NewFeatureTag />
233+
</Box>
234+
}
235+
tabKey={TAB_KEYS.WALLET}
236+
></Tab>
237+
<Tab
238+
activeClassName="notifications__tab--active"
239+
className="notifications__tab"
240+
data-testid={TAB_KEYS.WEB3}
241+
name={t('web3')}
242+
tabKey={TAB_KEYS.WEB3}
243+
/>
244+
</Tabs>
245+
)}
243246
<NotificationsList
244247
activeTab={activeTab}
245248
notifications={filteredNotifications}

0 commit comments

Comments
 (0)