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 64 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 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
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
34 changes: 28 additions & 6 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1406,11 +1406,11 @@ export default class MetamaskController extends EventEmitter {
rateLimitTimeout: 300000,
},
showInAppNotification: {
method: (origin, message) => {
method: (origin, notificationData) => {
this.controllerMessenger.call(
'NotificationController:show',
origin,
message,
notificationData,
);

return null;
Expand Down Expand Up @@ -1467,6 +1467,7 @@ export default class MetamaskController extends EventEmitter {
`${this.phishingController.name}:testOrigin`,
`${this.approvalController.name}:hasRequest`,
`${this.approvalController.name}:acceptRequest`,
`${this.snapController.name}:get`,
],
});

Expand Down Expand Up @@ -2757,14 +2758,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.message,
),
notificationArgs,
);
},
updateSnapState: this.controllerMessenger.call.bind(
this.controllerMessenger,
'SnapController:updateSnapState',
Expand All @@ -2791,7 +2800,7 @@ export default class MetamaskController extends EventEmitter {

return this.controllerMessenger.call(
'PhishingController:testOrigin',
sender.url,
sender,
FrederikBolding marked this conversation as resolved.
Show resolved Hide resolved
).result;
},
createInterface: this.controllerMessenger.call.bind(
Expand Down Expand Up @@ -5958,6 +5967,19 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger,
'SnapController:getAll',
),
getCurrencyRate: (currency) => {
const rate = this.multichainRatesController.state.rates[currency];
const { fiatCurrency } = this.multichainRatesController.state;

if (!rate) {
return undefined;
}

return {
...rate,
currency: fiatCurrency,
};
},
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
hasPermission: this.permissionController.hasPermission.bind(
this.permissionController,
Expand Down
8 changes: 4 additions & 4 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ buildTypes:
- SEGMENT_WRITE_KEY_REF: SEGMENT_PROD_WRITE_KEY
- ALLOW_LOCAL_SNAPS: false
- REQUIRE_SNAPS_ALLOWLIST: true
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.7.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.9.1/index.html
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
# Main build uses the default browser manifest
manifestOverrides: false
Expand All @@ -46,7 +46,7 @@ buildTypes:
- SEGMENT_WRITE_KEY_REF: SEGMENT_BETA_WRITE_KEY
- ALLOW_LOCAL_SNAPS: false
- REQUIRE_SNAPS_ALLOWLIST: true
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.7.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.9.1/index.html
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
# Modifies how the version is displayed.
# eg. instead of 10.25.0 -> 10.25.0-beta.2
Expand All @@ -67,7 +67,7 @@ buildTypes:
- SEGMENT_FLASK_WRITE_KEY
- ALLOW_LOCAL_SNAPS: true
- REQUIRE_SNAPS_ALLOWLIST: false
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.7.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.9.1/index.html
- SUPPORT_LINK: https://support.metamask.io/
- SUPPORT_REQUEST_LINK: https://support.metamask.io/
- INFURA_ENV_KEY_REF: INFURA_FLASK_PROJECT_ID
Expand All @@ -90,7 +90,7 @@ buildTypes:
- SEGMENT_WRITE_KEY_REF: SEGMENT_MMI_WRITE_KEY
- ALLOW_LOCAL_SNAPS: false
- REQUIRE_SNAPS_ALLOWLIST: true
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.7.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.9.1/index.html
- MMI_CONFIGURATION_SERVICE_URL: https://configuration.metamask-institutional.io/v2/configuration/default
- SUPPORT_LINK: https://support.metamask-institutional.io
- SUPPORT_REQUEST_LINK: https://support.metamask-institutional.io
Expand Down
29 changes: 3 additions & 26 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1633,32 +1633,9 @@
},
"@metamask/notification-controller": {
"packages": {
"@metamask/notification-controller>@metamask/base-controller": true,
"@metamask/notification-controller>@metamask/utils": true,
"@metamask/notification-controller>nanoid": true
}
},
"@metamask/notification-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
"@metamask/base-controller": true,
"@metamask/notification-controller>nanoid": true,
"@metamask/utils": true
}
},
"@metamask/notification-controller>nanoid": {
Expand Down
29 changes: 3 additions & 26 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1633,32 +1633,9 @@
},
"@metamask/notification-controller": {
"packages": {
"@metamask/notification-controller>@metamask/base-controller": true,
"@metamask/notification-controller>@metamask/utils": true,
"@metamask/notification-controller>nanoid": true
}
},
"@metamask/notification-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
"@metamask/base-controller": true,
"@metamask/notification-controller>nanoid": true,
"@metamask/utils": true
}
},
"@metamask/notification-controller>nanoid": {
Expand Down
29 changes: 3 additions & 26 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1633,32 +1633,9 @@
},
"@metamask/notification-controller": {
"packages": {
"@metamask/notification-controller>@metamask/base-controller": true,
"@metamask/notification-controller>@metamask/utils": true,
"@metamask/notification-controller>nanoid": true
}
},
"@metamask/notification-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
"@metamask/base-controller": true,
"@metamask/notification-controller>nanoid": true,
"@metamask/utils": true
}
},
"@metamask/notification-controller>nanoid": {
Expand Down
29 changes: 3 additions & 26 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1725,32 +1725,9 @@
},
"@metamask/notification-controller": {
"packages": {
"@metamask/notification-controller>@metamask/base-controller": true,
"@metamask/notification-controller>@metamask/utils": true,
"@metamask/notification-controller>nanoid": true
}
},
"@metamask/notification-controller>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/notification-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@metamask/utils>@scure/base": true,
"@metamask/utils>pony-cause": true,
"@noble/hashes": true,
"browserify>buffer": true,
"nock>debug": true,
"semver": true
"@metamask/base-controller": true,
"@metamask/notification-controller>nanoid": true,
"@metamask/utils": true
}
},
"@metamask/notification-controller>nanoid": {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"semver@7.3.8": "^7.5.4",
"@trezor/schema-utils@npm:1.0.2": "patch:@trezor/schema-utils@npm%3A1.0.2#~/.yarn/patches/@trezor-schema-utils-npm-1.0.2-7dd48689b2.patch",
"lavamoat-core@npm:^15.1.1": "patch:lavamoat-core@npm%3A15.1.1#~/.yarn/patches/lavamoat-core-npm-15.1.1-51fbe39988.patch",
"@metamask/snaps-sdk": "^6.5.1",
"@metamask/snaps-sdk": "^6.8.0",
"@swc/types@0.1.5": "^0.1.6",
"@babel/runtime@npm:^7.7.6": "patch:@babel/runtime@npm%3A7.24.0#~/.yarn/patches/@babel-runtime-npm-7.24.0-7eb1dd11a2.patch",
"@babel/runtime@npm:^7.9.2": "patch:@babel/runtime@npm%3A7.24.0#~/.yarn/patches/@babel-runtime-npm-7.24.0-7eb1dd11a2.patch",
Expand Down Expand Up @@ -334,7 +334,7 @@
"@metamask/metamask-eth-abis": "^3.1.1",
"@metamask/name-controller": "^8.0.0",
"@metamask/network-controller": "patch:@metamask/network-controller@npm%3A21.0.0#~/.yarn/patches/@metamask-network-controller-npm-21.0.0-559aa8e395.patch",
"@metamask/notification-controller": "^6.0.0",
"@metamask/notification-controller": "^7.0.0",
"@metamask/notification-services-controller": "^0.7.0",
"@metamask/object-multiplex": "^2.0.0",
"@metamask/obs-store": "^9.0.0",
Expand All @@ -354,12 +354,12 @@
"@metamask/selected-network-controller": "^18.0.1",
"@metamask/signature-controller": "^19.1.0",
"@metamask/smart-transactions-controller": "^13.0.0",
"@metamask/snaps-controllers": "^9.7.0",
"@metamask/snaps-execution-environments": "^6.7.2",
"@metamask/snaps-rpc-methods": "^11.1.1",
"@metamask/snaps-sdk": "^6.5.1",
"@metamask/snaps-utils": "^8.1.1",
"@metamask/transaction-controller": "^37.2.0",
"@metamask/snaps-controllers": "^9.11.0",
"@metamask/snaps-execution-environments": "^6.9.1",
"@metamask/snaps-rpc-methods": "^11.4.0",
"@metamask/snaps-sdk": "^6.8.0",
"@metamask/snaps-utils": "^8.4.0",
"@metamask/transaction-controller": "^37.0.0",
"@metamask/user-operation-controller": "^13.0.0",
"@metamask/utils": "^9.3.0",
"@ngraveio/bc-ur": "^1.1.12",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/snaps/enums.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/2.13.1/',
TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/snaps/test-snaps/2.15.1',
};
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
23 changes: 22 additions & 1 deletion ui/components/app/snaps/snap-ui-link/snap-ui-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,39 @@ import {
IconSize,
} from '../../../component-library';
import SnapLinkWarning from '../snap-link-warning';
import useSnapNavigation from '../../../../hooks/snaps/useSnapNavigation';

export const SnapUILink = ({ href, children }) => {
const [isOpen, setIsOpen] = useState(false);

const isMetaMaskUrl = href.startsWith('metamask:');
const { navigate } = useSnapNavigation();

const handleLinkClick = () => {
setIsOpen(true);
if (isMetaMaskUrl) {
navigate(href);
} else {
setIsOpen(true);
}
};

const handleModalClose = () => {
setIsOpen(false);
};

if (isMetaMaskUrl) {
return (
<ButtonLink
as="a"
size={ButtonLinkSize.Inherit}
className="snap-ui-link"
onClick={handleLinkClick}
>
{children}
</ButtonLink>
);
}

return (
<>
<SnapLinkWarning isOpen={isOpen} onClose={handleModalClose} url={href} />
Expand Down
13 changes: 12 additions & 1 deletion ui/components/app/snaps/snap-ui-renderer/components/heading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@ import {
} from '../../../../../helpers/constants/design-system';
import { UIComponentFactory } from './types';

export const generateSize = (size: HeadingElement['props']['size']) => {
switch (size) {
case 'md':
return TextVariant.headingMd;
case 'lg':
return TextVariant.headingLg;
default:
return TextVariant.headingSm;
}
};

export const heading: UIComponentFactory<HeadingElement> = ({ element }) => ({
element: 'Text',
children: element.props.children,
props: {
variant: TextVariant.headingSm,
variant: generateSize(element.props.size),
overflowWrap: OverflowWrap.Anywhere,
},
});
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
Loading