From e6ca33d5cc004c259e27fec259a7c6440235236b Mon Sep 17 00:00:00 2001 From: David Walsh Date: Fri, 15 Sep 2023 11:32:54 -0500 Subject: [PATCH] UX: Snaps: Only display Notification in Global Menu if enabled snap uses that permission --- .../multichain/global-menu/global-menu.js | 73 ++++++++++--------- ui/selectors/selectors.js | 10 +++ 2 files changed, 49 insertions(+), 34 deletions(-) diff --git a/ui/components/multichain/global-menu/global-menu.js b/ui/components/multichain/global-menu/global-menu.js index 6dfa89431045..7a619be8045a 100644 --- a/ui/components/multichain/global-menu/global-menu.js +++ b/ui/components/multichain/global-menu/global-menu.js @@ -44,6 +44,7 @@ import { getMetaMetricsId, ///: END:ONLY_INCLUDE_IN(build-mmi) getSelectedAddress, + getNotifySnaps, getUnapprovedTransactions, ///: BEGIN:ONLY_INCLUDE_IN(snaps) getUnreadNotificationsCount, @@ -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; @@ -167,40 +170,42 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => { )} { ///: BEGIN:ONLY_INCLUDE_IN(snaps) - <> - { - closeMenu(); - history.push(NOTIFICATIONS_ROUTE); - }} - > - {t('notifications')} - {unreadNotificationsCount > 0 && ( - - {unreadNotificationsCount > 99 - ? '99+' - : unreadNotificationsCount} - - )} - - + notifySnaps.length ? ( + <> + { + closeMenu(); + history.push(NOTIFICATIONS_ROUTE); + }} + > + {t('notifications')} + {unreadNotificationsCount > 0 && ( + + {unreadNotificationsCount > 99 + ? '99+' + : unreadNotificationsCount} + + )} + + + ) : null ///: END:ONLY_INCLUDE_IN(snaps) } { + return Object.values(snaps).filter( + ({ id }) => subjects[id]?.permissions.snap_notify, + ); + }, +); + export const getSnapsRouteObjects = createSelector(getSnaps, (snaps) => { return Object.values(snaps).map((snap) => { return {