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

feat: Integrate JSX into snap notifications #27407

Open
wants to merge 92 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
2968d94
make adjustments to show notification call
hmalik88 Sep 12, 2024
39f7d1b
Bump Snaps packages
Mrtenz Sep 24, 2024
652a6c3
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Sep 25, 2024
bdd1935
Bump dependencies again
Mrtenz Sep 27, 2024
0e30d3a
update notification controller, update raw snap notification type
hmalik88 Sep 30, 2024
4597ba1
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Sep 30, 2024
5689fe5
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Sep 30, 2024
3d5a9c4
add snap notification modal
hmalik88 Sep 30, 2024
1dfa869
Merge branch 'develop' into mrtenz/bump-snaps-packages
hmalik88 Sep 30, 2024
306d898
feat(snaps): Connect `getCurrencyRate` hook to `multichainRateControl…
GuillaumeRx Oct 2, 2024
f375215
feat: Integrate MetaMask links into Snaps `Link` component (#27377)
hmalik88 Oct 4, 2024
a6b6016
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 4, 2024
8377776
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 4, 2024
aad36db
integrate snaps expanded view into notification system
hmalik88 Oct 8, 2024
bd96aef
update yarn lock
hmalik88 Oct 8, 2024
f1e5e52
update lavamoat policies
hmalik88 Oct 8, 2024
f26bbb4
lint fixes
hmalik88 Oct 8, 2024
e60733e
another lint fix
hmalik88 Oct 8, 2024
8e96b0e
more lint fixes
hmalik88 Oct 8, 2024
ea99b02
fix type issues
hmalik88 Oct 8, 2024
f7168be
fix export
hmalik88 Oct 8, 2024
be72bb6
possible fix
hmalik88 Oct 8, 2024
c74c866
use literal instead of enum
hmalik88 Oct 8, 2024
2f49777
update notification detail button test
hmalik88 Oct 8, 2024
48f2567
fix notification detail block explorer button test
hmalik88 Oct 8, 2024
391663e
update snap-utils
hmalik88 Oct 8, 2024
174295b
dedupe
hmalik88 Oct 8, 2024
e31f656
Merge branch 'develop' into mrtenz/bump-snaps-packages
hmalik88 Oct 8, 2024
e14230f
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 8, 2024
6d03046
update yarn.lock
hmalik88 Oct 8, 2024
d50fdc2
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 8, 2024
cbfc9e4
update yarn.lock
hmalik88 Oct 8, 2024
d16283f
dedupe
hmalik88 Oct 8, 2024
0fb7067
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 8, 2024
6fc9fc7
regenerate lock file
hmalik88 Oct 8, 2024
6a0038a
update policy
hmalik88 Oct 8, 2024
43fc317
update policy
hmalik88 Oct 8, 2024
27f06b2
possible fix
hmalik88 Oct 8, 2024
7de27e9
revert changes
hmalik88 Oct 8, 2024
090d973
update policy final time?
hmalik88 Oct 8, 2024
4e994b4
Bump dependencies again again
Mrtenz Oct 9, 2024
350fde4
Bump execution environment URL
Mrtenz Oct 9, 2024
426140d
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 9, 2024
dbe384e
changes per PR comments
hmalik88 Oct 9, 2024
a7b0b4c
regenerate yarn.lock
hmalik88 Oct 9, 2024
5b34018
make change per comment
hmalik88 Oct 10, 2024
ddef404
fix
hmalik88 Oct 10, 2024
29b116b
lint fix
hmalik88 Oct 10, 2024
ec9a418
possible import fix
hmalik88 Oct 10, 2024
4573c85
another possible fix
hmalik88 Oct 10, 2024
76ccce6
Fix circular dependency issues
FrederikBolding Oct 11, 2024
afe7809
Fix another circular dependency
FrederikBolding Oct 11, 2024
7c18e47
Merge branch 'develop' into mrtenz/bump-snaps-packages
Mrtenz Oct 11, 2024
fbe1ca7
feat(snaps): Add `size` prop to `Heading` (#27721)
GuillaumeRx Oct 11, 2024
7de9c14
lint fix
hmalik88 Oct 11, 2024
3b6141e
import fix
hmalik88 Oct 11, 2024
74aa414
another fix
hmalik88 Oct 11, 2024
bc47345
Merge branch 'mrtenz/bump-snaps-packages' into hm/integrate-jsx-notif…
hmalik88 Oct 11, 2024
0ff9ab2
add missing section
hmalik88 Oct 11, 2024
efed42e
lint fix
hmalik88 Oct 11, 2024
75174e2
lint fix
hmalik88 Oct 11, 2024
ea3cac7
fix undefined error
hmalik88 Oct 13, 2024
67c23d3
fix bug and make style changes
hmalik88 Oct 14, 2024
cc5a9e2
fix styling
hmalik88 Oct 15, 2024
c5a2982
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Oct 23, 2024
6ca3c8a
regenerate yarn lock
hmalik88 Oct 24, 2024
f9dcbf2
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Nov 13, 2024
ffc2c9e
Revert "Merge branch 'develop' into hm/integrate-jsx-notifications"
hmalik88 Nov 13, 2024
73f32b9
Revert "Revert "Merge branch 'develop' into hm/integrate-jsx-notifica…
hmalik88 Nov 13, 2024
05e8d0e
undo
hmalik88 Nov 27, 2024
a5dc289
fix
hmalik88 Nov 27, 2024
73e0ba5
Revert "undo"
hmalik88 Nov 27, 2024
14ce024
fix yarn lock
hmalik88 Nov 27, 2024
6290f92
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Nov 27, 2024
14d6ab0
lint fix
hmalik88 Nov 27, 2024
4091c0a
fix read action in notification list item
hmalik88 Nov 27, 2024
374f5fd
remove extra hook
hmalik88 Nov 27, 2024
1b9b48e
fix notification-details
hmalik88 Nov 27, 2024
e844105
lint fix
hmalik88 Nov 27, 2024
f05912d
revert change to actions
hmalik88 Nov 27, 2024
fbf0de6
update components
hmalik88 Nov 28, 2024
bad7f15
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Nov 28, 2024
fe6cb7e
lint fix
hmalik88 Nov 28, 2024
b55f393
lint fix
hmalik88 Nov 28, 2024
ecdf8ea
another lint fix
hmalik88 Nov 28, 2024
2194a13
fixes
hmalik88 Nov 29, 2024
566f4c3
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Nov 29, 2024
9de4276
fix storybook
hmalik88 Nov 29, 2024
a650335
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Nov 29, 2024
1365918
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Nov 29, 2024
b7f667b
update logic to delete notification on detail view dismount
hmalik88 Dec 1, 2024
a81ea0f
Merge branch 'develop' into hm/integrate-jsx-notifications
hmalik88 Dec 1, 2024
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
23 changes: 19 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1461,12 +1461,19 @@ export default class MetamaskController extends EventEmitter {
},
showInAppNotification: {
method: (origin, args) => {
const { message } = args;
const { message, title, footerLink, interfaceId } = args;

const detailedView = {
title,
...(footerLink ? { footerLink } : {}),
interfaceId,
};

const notification = {
data: {
message,
origin,
...(interfaceId ? { detailedView } : {}),
},
type: TRIGGER_TYPES.SNAP,
readDate: null,
Expand Down Expand Up @@ -2866,14 +2873,22 @@ export default class MetamaskController extends EventEmitter {
origin,
args.message,
),
showInAppNotification: (origin, args) =>
showInAppNotification: (origin, args) => {
const { message, title, footerLink } = args;
const notificationArgs = {
interfaceId: args.content,
message,
title,
footerLink,
};
this.controllerMessenger.call(
'RateLimitController:call',
origin,
'showInAppNotification',
origin,
args,
),
notificationArgs,
);
},
updateSnapState: this.controllerMessenger.call.bind(
this.controllerMessenger,
'SnapController:updateSnapState',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
TextVariant,
} from '../../../helpers/constants/design-system';
import Tooltip from '../../ui/tooltip';
import { AvatarGroup } from '../../multichain';
import { AvatarGroup } from '../../multichain/avatar-group';
import { AvatarType } from '../../multichain/avatar-group/avatar-group.types';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { formatDate } from '../../../helpers/utils/util';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from '../../../store/actions';
import { TextVariant } from '../../../helpers/constants/design-system';
import { formatAccountType } from '../../../helpers/utils/metrics';
import { AccountDetailsMenuItem, ViewExplorerMenuItem } from '..';
import { AccountDetailsMenuItem, ViewExplorerMenuItem } from '../menu-items';

const METRICS_LOCATION = 'Account Options';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useSelector } from 'react-redux';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { shortenAddress } from '../../../helpers/utils/util';

import { AccountListItemMenu, AvatarGroup } from '..';
import { AccountListItemMenu } from '../account-list-item-menu';
import { AvatarGroup } from '../avatar-group';
import { ConnectedAccountsMenu } from '../connected-accounts-menu';
import {
AvatarAccount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,9 @@ import {
import { ModalContent } from '../../component-library/modal-content/deprecated';
import { ModalHeader } from '../../component-library/modal-header';
import { TextFieldSearch } from '../../component-library/text-field-search/deprecated';
import {
AccountListItem,
AccountListItemMenuTypes,
CreateEthAccount,
ImportAccount,
} from '..';
import { AccountListItem } from '../account-list-item';
import { AccountListItemMenuTypes } from '../account-list-item/account-list-item.types';

import {
AlignItems,
BlockSize,
Expand Down Expand Up @@ -130,6 +127,8 @@ import {
ACCOUNT_OVERVIEW_TAB_KEY_TO_TRACE_NAME_MAP,
AccountOverviewTabKey,
} from '../../../../shared/constants/app-state';
import { CreateEthAccount } from '../create-eth-account';
import { ImportAccount } from '../import-account';
///: BEGIN:ONLY_INCLUDE_IF(solana)
import {
SOLANA_WALLET_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import {
IconSize,
Text,
} from '../../component-library';
import { AccountListItem } from '../account-list-item';
import { AccountListItemMenuTypes } from '..';
import {
AccountListItem,
AccountListItemMenuTypes,
} from '../account-list-item';
import { mergeAccounts } from './account-list-menu';

export const HiddenAccountList = ({ onClose }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
setAccountLabel,
getNextAvailableAccountName as getNextAvailableAccountNameFromController,
} from '../../../store/actions';
import { CreateAccount } from '..';
import { CreateAccount } from '../create-account';
GuillaumeRx marked this conversation as resolved.
Show resolved Hide resolved

export const CreateEthAccount = ({ onActionComplete }) => {
const dispatch = useDispatch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ const mockNotification = {
type: 'ERC20_RECEIVED',
};

jest.mock('react-router-dom', () => {
const original = jest.requireActual('react-router-dom');
return {
...original,
useHistory: () => ({
push: jest.fn(),
}),
};
});

describe('NotificationDetailBlockExplorerButton', () => {
it('renders correctly with a valid block explorer URL', () => {
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const { TRIGGER_TYPES } = NotificationServicesController.Constants;

type Notification = NotificationServicesController.Types.INotification;

jest.mock('react-router-dom', () => {
const original = jest.requireActual('react-router-dom');
return {
...original,
useHistory: () => ({
push: jest.fn(),
}),
};
});

describe('NotificationDetailButton', () => {
const defaultProps = {
variant: ButtonVariant.Primary,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useContext } from 'react';
import { NotificationServicesController } from '@metamask/notification-services-controller';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
MetaMetricsEventCategory,
Expand All @@ -12,8 +11,9 @@ import {
IconName,
} from '../../component-library';
import { BlockSize } from '../../../helpers/constants/design-system';

type Notification = NotificationServicesController.Types.INotification;
import { TRIGGER_TYPES } from '../../../pages/notifications/notification-components';
import useSnapNavigation from '../../../hooks/snaps/useSnapNavigation';
import { type Notification } from '../../../pages/notifications/notification-components/types/notifications/notifications';

type NotificationDetailButtonProps = {
notification: Notification;
Expand All @@ -35,6 +35,16 @@ export const NotificationDetailButton = ({
endIconName = true,
}: NotificationDetailButtonProps) => {
const trackEvent = useContext(MetaMetricsContext);
const { navigate } = useSnapNavigation();
const isMetaMaskUrl = href.startsWith('metamask:');

// this logic can be expanded once this detail button is used outside of the current use cases
const getClickedItem = () => {
if (notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT) {
return 'block_explorer';
}
return isExternal ? 'external_link' : 'internal_link';
};

const onClick = () => {
trackEvent({
Expand All @@ -46,17 +56,21 @@ export const NotificationDetailButton = ({
...('chain_id' in notification && {
chain_id: notification.chain_id,
}),
clicked_item: 'block_explorer',
clicked_item: getClickedItem(),
},
});

if (notification.type === TRIGGER_TYPES.SNAP && isMetaMaskUrl) {
navigate(href);
}
};

return (
<Button
key={id}
href={href}
href={!isMetaMaskUrl && href ? href : undefined}
variant={variant}
externalLink={isExternal}
externalLink={!isMetaMaskUrl}
size={ButtonSize.Lg}
width={BlockSize.Full}
endIconName={endIconName ? IconName.Arrow2UpRight : undefined}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React, { createContext, useContext, useEffect, useMemo } from 'react';
import { useSelector } from 'react-redux';
import type { NotificationServicesController } from '@metamask/notification-services-controller';
import { useListNotifications } from '../../hooks/metamask-notifications/useNotifications';
import { useAccountSyncingEffect } from '../../hooks/metamask-notifications/useProfileSyncing';
import { selectIsProfileSyncingEnabled } from '../../selectors/metamask-notifications/profile-syncing';
import { selectIsMetamaskNotificationsEnabled } from '../../selectors/metamask-notifications/metamask-notifications';
import { getUseExternalServices } from '../../selectors';
import { getIsUnlocked } from '../../ducks/metamask/metamask';

type Notification = NotificationServicesController.Types.INotification;
import { type Notification } from '../../pages/notifications/notification-components/types/notifications/notifications';

type MetamaskNotificationsContextType = {
listNotifications: () => void;
Expand Down
7 changes: 2 additions & 5 deletions ui/hooks/metamask-notifications/useNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { useState, useCallback } from 'react';
import { useDispatch } from 'react-redux';
import type { InternalAccount } from '@metamask/keyring-api';
import type { NotificationServicesController } from '@metamask/notification-services-controller';
import log from 'loglevel';

import { type MarkAsReadNotificationsParam } from '@metamask/notification-services-controller/notification-services';
import {
createOnChainTriggers,
fetchAndUpdateMetamaskNotifications,
markMetamaskNotificationsAsRead,
enableMetamaskNotifications,
disableMetamaskNotifications,
} from '../../store/actions';

type Notification = NotificationServicesController.Types.INotification;
type MarkAsReadNotificationsParam =
NotificationServicesController.Types.MarkAsReadNotificationsParam;
import { type Notification } from '../../pages/notifications/notification-components/types/notifications/notifications';

// Define KeyringType interface
type KeyringType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import { Text } from '../../../../components/component-library';
import { useI18nContext } from '../../../../hooks/useI18nContext';
import { SnapAccountCard } from '../../../remove-snap-account';
import { SnapAccountCard } from '../../../remove-snap-account/snap-account-card';

const SnapAccountSuccessMessage = ({
message,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';
import type { NotificationServicesController } from '@metamask/notification-services-controller';
import { Box } from '../../../components/component-library';
import {
Display,
FlexDirection,
} from '../../../helpers/constants/design-system';
import type { NotificationComponent } from '../../notifications/notification-components/types/notifications/notifications';

type Notification = NotificationServicesController.Types.INotification;
import {
Notification,
NotificationComponentType,
type NotificationComponent,
} from '../../notifications/notification-components/types/notifications/notifications';

type NotificationDetailsBodyProps = {
body: NotificationComponent['details']['body'];
Expand All @@ -24,13 +25,13 @@ export const NotificationDetailsBody = ({
flexDirection={FlexDirection.Column}
padding={0}
>
{body.type === 'body_feature_announcement' && (
{body.type === NotificationComponentType.AnnouncementBody && (
<>
<body.Image notification={notification} />
<body.Description notification={notification} />
</>
)}
{body.type === 'body_onchain_notification' && (
{body.type === NotificationComponentType.OnChainBody && (
<>
{body.Image && <body.Image notification={notification} />}
{body.From && <body.From notification={notification} />}
Expand All @@ -47,6 +48,9 @@ export const NotificationDetailsBody = ({
{body.NetworkFee && <body.NetworkFee notification={notification} />}
</>
)}
{body.type === NotificationComponentType.SnapBody && (
<body.Content notification={notification} />
)}
</Box>
);
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import React from 'react';
import type { NotificationServicesController } from '@metamask/notification-services-controller';
import { Box } from '../../../components/component-library';
import {
BlockSize,
Display,
FlexDirection,
JustifyContent,
} from '../../../helpers/constants/design-system';
import type { NotificationComponent } from '../../notifications/notification-components/types/notifications/notifications';

type Notification = NotificationServicesController.Types.INotification;
import {
Notification,
NotificationComponentType,
type NotificationComponent,
} from '../../notifications/notification-components/types/notifications/notifications';

type NotificationDetailsFooterProps = {
footer: NotificationComponent['footer'];
Expand All @@ -29,21 +30,14 @@ export const NotificationDetailsFooter = ({
padding={4}
gap={4}
>
{footer.type === 'footer_onchain_notification' && (
<>
<footer.ScanLink notification={notification} />
</>
{footer.type === NotificationComponentType.OnChainFooter && (
<footer.ScanLink notification={notification} />
)}
{footer.type === NotificationComponentType.AnnouncementFooter && (
<footer.ExtensionLink notification={notification} />
)}
{footer.type === 'footer_feature_announcement' && (
<Box
display={Display.Flex}
gap={4}
flexDirection={FlexDirection.Row}
width={BlockSize.Full}
>
<footer.ExternalLink notification={notification} />
<footer.ExtensionLink notification={notification} />
</Box>
{footer.type === NotificationComponentType.SnapFooter && (
<footer.Link notification={notification} />
)}
</Box>
);
Expand Down
Loading
Loading