Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
Browse files Browse the repository at this point in the history
… NOTIFY-668-extension-qa-handle-reinitialising-of-push-notifications
  • Loading branch information
Prithpal-Sooriya committed May 23, 2024
2 parents fbfdbba + caac664 commit 46bc896
Show file tree
Hide file tree
Showing 13 changed files with 207 additions and 143 deletions.
4 changes: 0 additions & 4 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion ui/components/app/snaps/snap-avatar/snap-avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const SnapAvatar = ({
avatarSize = IconSize.Lg,
borderWidth = 2,
className,
badgeBackgroundColor = BackgroundColor.backgroundAlternative,
}) => {
const subjectMetadata = useSelector((state) =>
getTargetSubjectMetadata(state, snapId),
Expand All @@ -53,7 +54,7 @@ const SnapAvatar = ({
iconName={IconName.Snaps}
size={badgeSize}
backgroundColor={IconColor.infoDefault}
borderColor={BackgroundColor.backgroundAlternative}
borderColor={badgeBackgroundColor}
borderWidth={borderWidth}
iconProps={{
color: IconColor.infoInverse,
Expand Down Expand Up @@ -98,6 +99,10 @@ SnapAvatar.propTypes = {
badgeSize: PropTypes.string,
avatarSize: PropTypes.string,
borderWidth: PropTypes.number,
/**
* The color of the badge background
*/
badgeBackgroundColor: PropTypes.string,
/**
* The className of the SnapAvatar
*/
Expand Down
2 changes: 1 addition & 1 deletion ui/components/multichain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export { ConnectedStatus } from './connected-status';
export { NotificationListItem } from './notification-list-item';
export { NotificationListItemIcon } from './notification-list-item-icon';
export { NotificationListItemText } from './notification-list-item-text';
export { NotificationListSnapButton } from './notification-list-snap-button';
export { NotificationDetail } from './notification-detail';
export { NotificationDetailAddress } from './notification-detail-address';
export { NotificationDetailAsset } from './notification-detail-asset';
Expand All @@ -43,6 +42,7 @@ export { NotificationsPage } from './notifications-page';
export { NotificationsSettingsBox } from './notifications-settings-box';
export { NotificationsSettingsType } from './notifications-settings-type';
export { NotificationsSettingsAccount } from './notifications-settings-account';
export { NotificationListItemSnap } from './notification-list-item-snap';
export { NotificationsTagCounter } from './notifications-tag-counter';
export { Toast, ToastContainer } from './toast';
export { PermissionDetailsModal } from './permission-details-modal';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { NotificationListItemSnap } from './notification-list-item-snap';
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import React from 'react';

import { Box, Icon, IconName, Text, IconSize } from '../../component-library';
import {
AlignItems,
BlockSize,
BackgroundColor,
Display,
FlexDirection,
FontWeight,
JustifyContent,
IconColor,
TextColor,
TextVariant,
TextAlign,
} from '../../../helpers/constants/design-system';
import type { NotificationListItemTextProps } from '../notification-list-item-text/notification-list-item-text';
import { NotificationListItemText } from '../notification-list-item-text';
import { formatMenuItemDate } from '../../../helpers/utils/notification.util';
import { SnapUIMarkdown } from '../../app/snaps/snap-ui-markdown';
import SnapAvatar from '../../app/snaps/snap-avatar';

export type NotificationListItemSnapProps = {
id: string;
isRead: boolean;
title: NotificationListItemTextProps;
snapMessage: string;
createdAt: Date;
handleSnapClick?: () => void;
handleSnapButton?: () => void;
};

/**
* `NotificationListItem` is a component that displays a single notification item.
*
* @param props - The properties object.
* @param props.isRead - Indicates whether the notification has been read.
* @param props.title - The title of the notification.
* @param props.createdAt - The date of the notification.
* @param props.id - The id of the notification.
* @param props.handleSnapClick - The function to call when the notification is clicked.
* @param props.handleSnapButton - The function to call when the snap button is clicked.
* @param props.snapMessage - The snap message to display on the notification.
* @returns Returns a notification list item component.
*/
export const NotificationListItemSnap = ({
id,
isRead,
title,
snapMessage,
createdAt,
handleSnapClick,
handleSnapButton,
}: NotificationListItemSnapProps) => {
const handleClick = () => {
handleSnapClick?.();
};

const handleButtonClick = () => {
handleSnapButton?.();
};

return (
<Box
className={`notification-list-item ${
isRead ? '' : 'notification-list-item--unread'
}`}
display={Display.Flex}
flexDirection={FlexDirection.Column}
justifyContent={JustifyContent.spaceBetween}
alignItems={AlignItems.flexStart}
width={BlockSize.Full}
paddingBottom={3}
paddingRight={5}
paddingLeft={5}
paddingTop={3}
key={id}
onClick={handleClick}
style={{ cursor: 'pointer' }}
>
<Box
display={Display.Flex}
justifyContent={JustifyContent.spaceBetween}
flexDirection={FlexDirection.Row}
alignItems={AlignItems.flexStart}
width={BlockSize.Full}
backgroundColor={BackgroundColor.transparent}
gap={4}
height={BlockSize.Full}
style={{ paddingLeft: '6px', paddingRight: '6px', paddingTop: '2px' }}
>
{!isRead && (
<Box
display={Display.Block}
className="notification-list-item__unread-dot__wrapper--snap"
>
<Icon
name={IconName.FullCircle}
color={IconColor.primaryDefault}
className="notification-list-item__unread-dot__dot"
data-testid="unread-dot"
/>
</Box>
)}

<Box height={BlockSize.Full} className="notification-list-item__icon">
<SnapAvatar
snapId="npm:@metamask/notification-example-snap"
badgeBackgroundColor={BackgroundColor.backgroundDefault}
avatarSize={IconSize.Md}
/>
</Box>

<Box
display={Display.Flex}
gap={4}
height={BlockSize.Full}
alignItems={AlignItems.flexStart}
width={BlockSize.Full}
>
<Box
display={Display.Block}
flexDirection={FlexDirection.Column}
alignItems={AlignItems.flexStart}
textAlign={TextAlign.Left}
width={BlockSize.Full}
>
<Box
display={Display.Flex}
flexDirection={FlexDirection.Row}
alignItems={AlignItems.flexStart}
justifyContent={JustifyContent.spaceBetween}
>
{/* Notification Title */}
<Box onClick={handleButtonClick}>
<NotificationListItemText
{...title}
color={TextColor.primaryDefault}
/>
</Box>

{/* Date */}
<Text
color={TextColor.textMuted}
variant={TextVariant.bodySm}
fontWeight={FontWeight.Normal}
as="p"
>
{formatMenuItemDate(createdAt)}
</Text>
</Box>

{/* Snap Message */}
<Box
color={TextColor.textDefault}
className="snap-notifications__item__details__message"
>
<SnapUIMarkdown markdown>{snapMessage}</SnapUIMarkdown>
</Box>
</Box>
</Box>
</Box>
</Box>
);
};
8 changes: 7 additions & 1 deletion ui/components/multichain/notification-list-item/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
.notification-list-item__unread-dot__wrapper {
position: absolute;
top: 24px;
left: 9px;
left: 11px;
}

.notification-list-item__unread-dot__wrapper--snap {
position: absolute;
top: 22px;
left: 11px;
}

.notification-list-item__unread-dot__dot {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type { NotificationListItemIconProps } from '../notification-list-item-ic
import type { NotificationListItemTextProps } from '../notification-list-item-text/notification-list-item-text';
import { NotificationListItemIcon } from '../notification-list-item-icon';
import { NotificationListItemText } from '../notification-list-item-text';
import { NotificationListSnapButton } from '../notification-list-snap-button';
import { formatMenuItemDate } from '../../../helpers/utils/notification.util';

export type NotificationListItemProps = {
Expand All @@ -30,10 +29,6 @@ export type NotificationListItemProps = {
createdAt: Date;
amount?: string;
onClick?: () => void;
snapButton?: {
text: string;
onClick: () => void;
};
};

/**
Expand All @@ -48,7 +43,6 @@ export type NotificationListItemProps = {
* @param props.amount - The amount associated with the notification, if applicable.
* @param props.id - The id of the notification.
* @param props.onClick - The function to call when the notification is clicked.
* @param props.snapButton - The snap button to display on the notification.
* @returns Returns a notification list item component.
*/
export const NotificationListItem = ({
Expand All @@ -60,7 +54,6 @@ export const NotificationListItem = ({
createdAt,
amount,
onClick,
snapButton,
}: NotificationListItemProps) => {
const handleClick = () => {
onClick?.();
Expand Down Expand Up @@ -122,6 +115,7 @@ export const NotificationListItem = ({
flexDirection={FlexDirection.Column}
alignItems={AlignItems.flexStart}
textAlign={TextAlign.Left}
width={BlockSize.Full}
>
{/* Notification Title */}
<NotificationListItemText
Expand Down Expand Up @@ -160,13 +154,7 @@ export const NotificationListItem = ({
</Text>
)}
</Box>
{/* Snap Button */}
</Box>
{snapButton && (
<Box width={BlockSize.Full} paddingTop={4}>
<NotificationListSnapButton {...snapButton} />
</Box>
)}
</Box>
);
};

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 46bc896

Please sign in to comment.