Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: Snaps: Only display Notification in Global Menu if enabled snap uses that permission #20913

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 41 additions & 34 deletions ui/components/multichain/global-menu/global-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
getSelectedAddress,
getUnapprovedTransactions,
///: BEGIN:ONLY_INCLUDE_IN(snaps)
getNotifySnaps,
getUnreadNotificationsCount,
///: END:ONLY_INCLUDE_IN
} from '../../../selectors';
Expand All @@ -72,6 +73,10 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => {
const address = useSelector(getSelectedAddress);
const unapprovedTransactons = useSelector(getUnapprovedTransactions);

///: BEGIN:ONLY_INCLUDE_IN(snaps)
const notifySnaps = useSelector(getNotifySnaps);
///: END:ONLY_INCLUDE_IN

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

Expand Down Expand Up @@ -167,40 +172,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 @@ -956,6 +956,16 @@ export const getInsightSnaps = createDeepEqualSelector(
},
);

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't seen destructuring in the filter callbackFn args before. Nice

);
},
);

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