Skip to content

Commit

Permalink
UX: Snaps: Only display Notification in Global Menu if enabled snap u…
Browse files Browse the repository at this point in the history
…ses that permission
  • Loading branch information
darkwing committed Sep 15, 2023
1 parent f315a2b commit e6ca33d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
73 changes: 39 additions & 34 deletions ui/components/multichain/global-menu/global-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getMetaMetricsId,
///: END:ONLY_INCLUDE_IN(build-mmi)
getSelectedAddress,
getNotifySnaps,
getUnapprovedTransactions,
///: BEGIN:ONLY_INCLUDE_IN(snaps)
getUnreadNotificationsCount,
Expand Down Expand Up @@ -72,6 +73,8 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => {
const address = useSelector(getSelectedAddress);
const unapprovedTransactons = useSelector(getUnapprovedTransactions);

const notifySnaps = useSelector(getNotifySnaps);

const hasUnapprovedTransactions =
Object.keys(unapprovedTransactons).length > 0;

Expand Down Expand Up @@ -167,40 +170,42 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => {
)}
{
///: BEGIN:ONLY_INCLUDE_IN(snaps)
<>
<MenuItem
iconName={IconName.Notification}
onClick={() => {
closeMenu();
history.push(NOTIFICATIONS_ROUTE);
}}
>
{t('notifications')}
{unreadNotificationsCount > 0 && (
<Text
as="span"
display={Display.InlineBlock}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
backgroundColor={BackgroundColor.primaryDefault}
color={TextColor.primaryInverse}
padding={[0, 1, 0, 1]}
variant={TextVariant.bodyXs}
textAlign={TextAlign.Center}
data-testid="global-menu-notification-count"
style={{
borderRadius: '16px',
minWidth: '24px',
}}
marginInlineStart={2}
>
{unreadNotificationsCount > 99
? '99+'
: unreadNotificationsCount}
</Text>
)}
</MenuItem>
</>
notifySnaps.length ? (
<>
<MenuItem
iconName={IconName.Notification}
onClick={() => {
closeMenu();
history.push(NOTIFICATIONS_ROUTE);
}}
>
{t('notifications')}
{unreadNotificationsCount > 0 && (
<Text
as="span"
display={Display.InlineBlock}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
backgroundColor={BackgroundColor.primaryDefault}
color={TextColor.primaryInverse}
padding={[0, 1, 0, 1]}
variant={TextVariant.bodyXs}
textAlign={TextAlign.Center}
data-testid="global-menu-notification-count"
style={{
borderRadius: '16px',
minWidth: '24px',
}}
marginInlineStart={2}
>
{unreadNotificationsCount > 99
? '99+'
: unreadNotificationsCount}
</Text>
)}
</MenuItem>
</>
) : null
///: END:ONLY_INCLUDE_IN(snaps)
}
<MenuItem
Expand Down
10 changes: 10 additions & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,16 @@ export const getInsightSnaps = createDeepEqualSelector(
},
);

export const getNotifySnaps = createDeepEqualSelector(
getEnabledSnaps,
getPermissionSubjects,
(snaps, subjects) => {
return Object.values(snaps).filter(
({ id }) => subjects[id]?.permissions.snap_notify,
);
},
);

export const getSnapsRouteObjects = createSelector(getSnaps, (snaps) => {
return Object.values(snaps).map((snap) => {
return {
Expand Down

0 comments on commit e6ca33d

Please sign in to comment.