From 94c10bee963e998922e026b50e27ba443af94605 Mon Sep 17 00:00:00 2001 From: MetaMask Bot Date: Fri, 16 Jun 2023 16:44:05 +0000 Subject: [PATCH 01/30] Version v10.33.0 --- CHANGELOG.md | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 +- 2 files changed, 151 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e628cdcbb..6da2d36c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,154 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [10.33.0] +### Uncategorized +- feat: add new linea mainnet network ([#19326](https://github.com/MetaMask/metamask-extension/pull/19326)) +- Feat/19274/ds popover update account list menu ([#19534](https://github.com/MetaMask/metamask-extension/pull/19534)) +- Updated contacts Title and copy changes in Send Flow ([#19618](https://github.com/MetaMask/metamask-extension/pull/19618)) +- Fix #19619 - Submit the account creation form when pressing enter ([#19620](https://github.com/MetaMask/metamask-extension/pull/19620)) +- Fix searchable item list height ([#19634](https://github.com/MetaMask/metamask-extension/pull/19634)) +- Master sync PR following v10.32.0 ([#19630](https://github.com/MetaMask/metamask-extension/pull/19630)) +- [FLASK] Update rate limits for `showInAppNotification` and `showNativeNotification` ([#19621](https://github.com/MetaMask/metamask-extension/pull/19621)) +- Merge branch 'develop' into master-sync +- [MMI] renames method for better understanding ([#19622](https://github.com/MetaMask/metamask-extension/pull/19622)) +- Extend `wallet_watchAsset` to support `ERC721` and `ERC1155` tokens ([#19454](https://github.com/MetaMask/metamask-extension/pull/19454)) +- Swaps UI update ([#19169](https://github.com/MetaMask/metamask-extension/pull/19169)) +- Enable e2e debug flag in CI ([#19588](https://github.com/MetaMask/metamask-extension/pull/19588)) +- devDeps: socketcluster-client@14.3.1->14.3.2 ([#19055](https://github.com/MetaMask/metamask-extension/pull/19055)) +- MMI start script and fixes a bug preventing it to run ([#19594](https://github.com/MetaMask/metamask-extension/pull/19594)) +- UX: Ensure 'Connect Hardware' route is functioning properly ([#19612](https://github.com/MetaMask/metamask-extension/pull/19612)) +- Fix unknown processing time not showing in warning color ([#19527](https://github.com/MetaMask/metamask-extension/pull/19527)) +- devDeps: bump and align devDependencies ([#19194](https://github.com/MetaMask/metamask-extension/pull/19194)) +- fix signature controller patch ([#19607](https://github.com/MetaMask/metamask-extension/pull/19607)) +- Fix #19437 - Prevent Connected Sites global menu item from being clicked during confirmation ([#19598](https://github.com/MetaMask/metamask-extension/pull/19598)) +- UX: Add portfolio button in overview ([#19601](https://github.com/MetaMask/metamask-extension/pull/19601)) +- Sync NetworkController lookupNetwork tests w/ core ([#19401](https://github.com/MetaMask/metamask-extension/pull/19401)) +- feature(19493): eliminate e2e flakyness for eth-sign ([#19606](https://github.com/MetaMask/metamask-extension/pull/19606)) +- fix: refactor linea goerli testnet implementation ([#19321](https://github.com/MetaMask/metamask-extension/pull/19321)) +- feature(19496): eliminate flow e2e flakyness in terms of asserting content for DOM ([#19600](https://github.com/MetaMask/metamask-extension/pull/19600)) +- Fix flakey tests in metamask controller tests ([#19312](https://github.com/MetaMask/metamask-extension/pull/19312)) +- Fix #19439 - Allow Account Picker during Send flow ([#19522](https://github.com/MetaMask/metamask-extension/pull/19522)) +- Adding deprecation tags to popover and old modals ([#19556](https://github.com/MetaMask/metamask-extension/pull/19556)) +- devDeps: degenerator@3.0.1->3.0.4 ([#19178](https://github.com/MetaMask/metamask-extension/pull/19178)) +- updated components with Multichain Prefix ([#19593](https://github.com/MetaMask/metamask-extension/pull/19593)) +- Sync NetworkController getEIP1559Compatibility tests w/ core ([#19419](https://github.com/MetaMask/metamask-extension/pull/19419)) +- Sync NetworkController setProviderType tests ([#19406](https://github.com/MetaMask/metamask-extension/pull/19406)) +- Sync rollbackToPreviousProvider tests w/ core ([#19428](https://github.com/MetaMask/metamask-extension/pull/19428)) +- Update message manager and signature controller ([#19370](https://github.com/MetaMask/metamask-extension/pull/19370)) +- Update lockfile ([#19583](https://github.com/MetaMask/metamask-extension/pull/19583)) +- UX Multichain: UI fixes for settings page ([#19574](https://github.com/MetaMask/metamask-extension/pull/19574)) +- UX Multichain: updated enums for multichain token list item ([#19575](https://github.com/MetaMask/metamask-extension/pull/19575)) +- Adding background/default to BorderColor enum to prevent propType error and updating tests ([#19571](https://github.com/MetaMask/metamask-extension/pull/19571)) +- UX: Multichain: Move Add Account and Import Account into Account Menu Popover ([#19346](https://github.com/MetaMask/metamask-extension/pull/19346)) +- Update `@metamask/gas-fee-controller` to v6 ([#19366](https://github.com/MetaMask/metamask-extension/pull/19366)) +- [FLASK] Bump RateLimitController to v3 ([#19578](https://github.com/MetaMask/metamask-extension/pull/19578)) +- Await approval request in transaction controller ([#19197](https://github.com/MetaMask/metamask-extension/pull/19197)) +- Upgrade assets-controllers to v9 ([#19472](https://github.com/MetaMask/metamask-extension/pull/19472)) +- Check Node (and Yarn) versions at install ([#19537](https://github.com/MetaMask/metamask-extension/pull/19537)) +- fix: update linea testnet rpc url ([#19294](https://github.com/MetaMask/metamask-extension/pull/19294)) +- UX Multichain: Updated header to use picker network in popup view ([#19514](https://github.com/MetaMask/metamask-extension/pull/19514)) +- [FLASK] Align update error state with Figma ([#19547](https://github.com/MetaMask/metamask-extension/pull/19547)) +- [FLASK] Fix usages of `getSnapName` ([#19546](https://github.com/MetaMask/metamask-extension/pull/19546)) +- [FLASK] Improve snaps connect flow ([#19461](https://github.com/MetaMask/metamask-extension/pull/19461)) +- feature(19463): fix send-eth flaky test and refactor ([#19531](https://github.com/MetaMask/metamask-extension/pull/19531)) +- [FLASK] Update Snaps privacy notice ([#19501](https://github.com/MetaMask/metamask-extension/pull/19501)) +- Add getEthQuery action to NetworkController ([#19420](https://github.com/MetaMask/metamask-extension/pull/19420)) +- Sync NetworkController setActiveNetwork tests w/ core ([#19405](https://github.com/MetaMask/metamask-extension/pull/19405)) +- Bump minimum Node version to 16.20.0 ([#19520](https://github.com/MetaMask/metamask-extension/pull/19520)) +- Sync removeNetworkConfiguration tests w/ core ([#19427](https://github.com/MetaMask/metamask-extension/pull/19427)) +- Sync NetworkController upsertNetworkConfiguration w/ core ([#19426](https://github.com/MetaMask/metamask-extension/pull/19426)) +- Deprecate JS version of Box in favor of TS version ([#19530](https://github.com/MetaMask/metamask-extension/pull/19530)) +- Make `eth_accounts` return all permitted accounts ([#18516](https://github.com/MetaMask/metamask-extension/pull/18516)) +- Adding `Box` component in TS to component-library ([#19363](https://github.com/MetaMask/metamask-extension/pull/19363)) +- added validTag string literal union ([#19258](https://github.com/MetaMask/metamask-extension/pull/19258)) +- update icons for add-network ([#19513](https://github.com/MetaMask/metamask-extension/pull/19513)) +- Send flow UI update ([#19465](https://github.com/MetaMask/metamask-extension/pull/19465)) +- Reduce e2e test flakiness ([#19507](https://github.com/MetaMask/metamask-extension/pull/19507)) +- Master sync follow v10.31.1 ([#19517](https://github.com/MetaMask/metamask-extension/pull/19517)) +- feat(17901): fix network, add-account and mv3 phishing warning issue ([#19462](https://github.com/MetaMask/metamask-extension/pull/19462)) +- issue-18714: Replaced deprecated constants with enum in EthSignModal and HoldToRevealModal Component ([#19499](https://github.com/MetaMask/metamask-extension/pull/19499)) +- Added the ability to navigate multiple SIWE notifications ([#18103](https://github.com/MetaMask/metamask-extension/pull/18103)) +- [FLASK] Update snap installation permission warning UI ([#19494](https://github.com/MetaMask/metamask-extension/pull/19494)) +- When gas fees suggested by dapp is too high, show warning color and icon ([#19088](https://github.com/MetaMask/metamask-extension/pull/19088)) +- [MMI] Improved code, fixed bugs and added more tests ([#19488](https://github.com/MetaMask/metamask-extension/pull/19488)) +- Update LavaMoat policies ([#19505](https://github.com/MetaMask/metamask-extension/pull/19505)) +- issue-18714: Replaced deprecated constants with enum in confirmation-warning-modal.js ([#19477](https://github.com/MetaMask/metamask-extension/pull/19477)) +- Creating story for `icon-border` ([#19467](https://github.com/MetaMask/metamask-extension/pull/19467)) +- Creating story for `account-mismatch-warning` ([#19460](https://github.com/MetaMask/metamask-extension/pull/19460)) +- Widen the number of test files that TS sees ([#19403](https://github.com/MetaMask/metamask-extension/pull/19403)) +- fix(e2e): flaky test-e2e-chrome on add-custom-network.spec.js ([#19487](https://github.com/MetaMask/metamask-extension/pull/19487)) +- [FLASK] Rework Snaps headers and footers ([#19442](https://github.com/MetaMask/metamask-extension/pull/19442)) +- Bump `fast-xml-parser` to fix audit issue ([#19489](https://github.com/MetaMask/metamask-extension/pull/19489)) +- Remove unwanted console.log in E2E test ([#19482](https://github.com/MetaMask/metamask-extension/pull/19482)) +- Feature/mmi 3009 confirm transaction base code fences ([#19335](https://github.com/MetaMask/metamask-extension/pull/19335)) +- Fix capitalization of MetaMask ([#19466](https://github.com/MetaMask/metamask-extension/pull/19466)) +- setActiveNetwork captures network config ID ([#19404](https://github.com/MetaMask/metamask-extension/pull/19404)) +- Creating story for `asset-list` ([#19450](https://github.com/MetaMask/metamask-extension/pull/19450)) +- UX: Multichain: Restore Flask support link and text ([#19198](https://github.com/MetaMask/metamask-extension/pull/19198)) +- Have mmi build being generated ([#19441](https://github.com/MetaMask/metamask-extension/pull/19441)) +- Using NetworkAccountBalanceHeader component on SIWE screen ([#19361](https://github.com/MetaMask/metamask-extension/pull/19361)) +- [FLASK] Update UI (for audit) (UI facelift) ([#19388](https://github.com/MetaMask/metamask-extension/pull/19388)) +- [FLASK] Limit notification count display to 99+ ([#19449](https://github.com/MetaMask/metamask-extension/pull/19449)) +- replacing depricated constants ([#19448](https://github.com/MetaMask/metamask-extension/pull/19448)) +- replacing depricated constants ([#19447](https://github.com/MetaMask/metamask-extension/pull/19447)) +- UX Multichain: Update settings title ([#19414](https://github.com/MetaMask/metamask-extension/pull/19414)) +- Handle watch asset accept and reject using ApprovalController only ([#18829](https://github.com/MetaMask/metamask-extension/pull/18829)) +- Revert "feature: Add legacy derivation path to Trezor (#19443)" ([#19443](https://github.com/MetaMask/metamask-extension/pull/19443)) +- feature: Add legacy derivation path to Trezor ([#19443](https://github.com/MetaMask/metamask-extension/pull/19443)) +- Replacing deprecated constants with enums ([#19242](https://github.com/MetaMask/metamask-extension/pull/19242)) +- Updating component-library readme storybook render ([#19359](https://github.com/MetaMask/metamask-extension/pull/19359)) +- Part of #18714: Replacing deprecated constants in `Avatar-Base` folder ([#19408](https://github.com/MetaMask/metamask-extension/pull/19408)) +- feature(17901): fix import UI error ([#19372](https://github.com/MetaMask/metamask-extension/pull/19372)) +- [FLASK] Update snap tweaks ([#19410](https://github.com/MetaMask/metamask-extension/pull/19410)) +- [FLASK] `snaps@0.34.0-flask.1` ([#19377](https://github.com/MetaMask/metamask-extension/pull/19377)) +- Remove MULTICHAIN flag for NFT badges ([#19416](https://github.com/MetaMask/metamask-extension/pull/19416)) +- Sync NetworkController initializeProvider tests w/ core ([#19297](https://github.com/MetaMask/metamask-extension/pull/19297)) +- Sync default value of networkDetails w/ core ([#19407](https://github.com/MetaMask/metamask-extension/pull/19407)) +- UX: Multichain: Make MetaFox logo more accessible ([#19395](https://github.com/MetaMask/metamask-extension/pull/19395)) +- [MMI] Added code fencing in libs folder ([#17929](https://github.com/MetaMask/metamask-extension/pull/17929)) +- Multichain NFT network badges ([#19029](https://github.com/MetaMask/metamask-extension/pull/19029)) +- Fix details when transferring NFT not added to wallet ([#19045](https://github.com/MetaMask/metamask-extension/pull/19045)) +- feature(on-ramp): update supported networks ([#19268](https://github.com/MetaMask/metamask-extension/pull/19268)) +- feature(17901): fix flaky tests in send-eth e2e ([#19397](https://github.com/MetaMask/metamask-extension/pull/19397)) +- accept approval request first ([#19409](https://github.com/MetaMask/metamask-extension/pull/19409)) +- Fix/storybook console cleanup ([#19244](https://github.com/MetaMask/metamask-extension/pull/19244)) +- Release MultiChain 0.5 ([#18903](https://github.com/MetaMask/metamask-extension/pull/18903)) +- Part of #18714: Replacing deprecated constants in `Avatar-Favicon` folder ([#19332](https://github.com/MetaMask/metamask-extension/pull/19332)) +- ConfirmTxPage: rm redundant unapprovedTxs const ([#19275](https://github.com/MetaMask/metamask-extension/pull/19275)) +- Replacing Deprecated Constants ([#19333](https://github.com/MetaMask/metamask-extension/pull/19333)) +- added deprecation message above SiteIcon ([#19256](https://github.com/MetaMask/metamask-extension/pull/19256)) +- ci: temporarily disable codecov status checks ([#19354](https://github.com/MetaMask/metamask-extension/pull/19354)) +- ConfirmApprove: fix space occurring after footer ([#19276](https://github.com/MetaMask/metamask-extension/pull/19276)) +- Clean ConfirmTransaction page related code ([#19208](https://github.com/MetaMask/metamask-extension/pull/19208)) +- deep clone signature tx in order to avoid state mutation bug on development ([#19179](https://github.com/MetaMask/metamask-extension/pull/19179)) +- Update `@metamask/approval-controller` to v3 ([#19365](https://github.com/MetaMask/metamask-extension/pull/19365)) +- Update `@metamask/notification-controller` to v3 ([#19364](https://github.com/MetaMask/metamask-extension/pull/19364)) +- Update `@metamask/address-book-controller` to v3 ([#19345](https://github.com/MetaMask/metamask-extension/pull/19345)) +- Update `@metamask/controller-utils` to v4 ([#19344](https://github.com/MetaMask/metamask-extension/pull/19344)) +- devDeps: yargs@7.1.1->7.1.2 ([#19057](https://github.com/MetaMask/metamask-extension/pull/19057)) +- devDeps: squirrelly@^8.0.8->^9.0.0 ([#19113](https://github.com/MetaMask/metamask-extension/pull/19113)) +- Update mv3 minimum version to chrome v88 ([#19358](https://github.com/MetaMask/metamask-extension/pull/19358)) +- Ensure custom provider configs have chain ID and RPC URL ([#19296](https://github.com/MetaMask/metamask-extension/pull/19296)) +- Update INFURA_NETWORKS in NC tests to ostensibly use dec #'s ([#19316](https://github.com/MetaMask/metamask-extension/pull/19316)) +- NetworkController tests: Sync withController helper ([#19313](https://github.com/MetaMask/metamask-extension/pull/19313)) +- NetworkController tests: Remove commented line ([#19315](https://github.com/MetaMask/metamask-extension/pull/19315)) +- Part of #18714: Replacing deprecated constants in `Modal-Header` folder ([#19339](https://github.com/MetaMask/metamask-extension/pull/19339)) +- Update `@metamask/announcement-controller` to v4 ([#19348](https://github.com/MetaMask/metamask-extension/pull/19348)) +- Update README.md ([#19350](https://github.com/MetaMask/metamask-extension/pull/19350)) +- NetworkController: Improve test for destroy ([#19314](https://github.com/MetaMask/metamask-extension/pull/19314)) +- Add getProviderConfig action to NetworkController ([#19317](https://github.com/MetaMask/metamask-extension/pull/19317)) +- Sync NetworkController constructor tests with core ([#19311](https://github.com/MetaMask/metamask-extension/pull/19311)) +- Update `@metamask/base-controller` to v3 ([#19343](https://github.com/MetaMask/metamask-extension/pull/19343)) +- [FLASK] Add Snaps privacy warning on snap install ([#18835](https://github.com/MetaMask/metamask-extension/pull/18835)) +- feature(17901): fix failing network error and remove duplicated e2e for mv3 ([#19292](https://github.com/MetaMask/metamask-extension/pull/19292)) +- feature(17901): fix address-book `Sends to an address book entry` e2e against MV3 build ([#19330](https://github.com/MetaMask/metamask-extension/pull/19330)) +- Revert "[MMI] Add confirm-transaction-base code fences (#18795)" ([#18795](https://github.com/MetaMask/metamask-extension/pull/18795)) +- updates values ([#19336](https://github.com/MetaMask/metamask-extension/pull/19336)) +- Changes to Popover folder ([#19245](https://github.com/MetaMask/metamask-extension/pull/19245)) +- [MMI] Add confirm-transaction-base code fences ([#18795](https://github.com/MetaMask/metamask-extension/pull/18795)) +- [MMI] adds mmi code fences to mm controller ([#18279](https://github.com/MetaMask/metamask-extension/pull/18279)) + ## [10.32.0] ### Added - Enable token detection for the Aurora network ([#19009](https://github.com/MetaMask/metamask-extension/pull/19009)) @@ -3779,7 +3927,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Uncategorized - Added the ability to restore accounts from seed words. -[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.32.0...HEAD +[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.33.0...HEAD +[10.33.0]: https://github.com/MetaMask/metamask-extension/compare/v10.32.0...v10.33.0 [10.32.0]: https://github.com/MetaMask/metamask-extension/compare/v10.31.1...v10.32.0 [10.31.1]: https://github.com/MetaMask/metamask-extension/compare/v10.31.0...v10.31.1 [10.31.0]: https://github.com/MetaMask/metamask-extension/compare/v10.30.4...v10.31.0 diff --git a/package.json b/package.json index 43e66d32a..adf1a8995 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "metamask-crx", - "version": "10.32.0", + "version": "10.33.0", "private": true, "repository": { "type": "git", From ac3053d16adc2e43e0f14406921b370bd41beeec Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Mon, 19 Jun 2023 16:26:24 -0230 Subject: [PATCH 02/30] Run yarn lavamoat:auto for v10.33.0 --- lavamoat/build-system/policy.json | 71 ++++--------------------------- 1 file changed, 8 insertions(+), 63 deletions(-) diff --git a/lavamoat/build-system/policy.json b/lavamoat/build-system/policy.json index 89e2820e1..9ee988092 100644 --- a/lavamoat/build-system/policy.json +++ b/lavamoat/build-system/policy.json @@ -980,7 +980,6 @@ "packages": { "@lavamoat/allow-scripts>@npmcli/run-script>node-gyp>npmlog>are-we-there-yet": true, "@lavamoat/allow-scripts>@npmcli/run-script>node-gyp>npmlog>gauge": true, - "@storybook/addon-mdx-gfm>@storybook/node-logger>npmlog>console-control-strings": true, "@storybook/react>@storybook/node-logger>npmlog>console-control-strings": true, "nyc>yargs>set-blocking": true } @@ -1009,9 +1008,6 @@ "@lavamoat/allow-scripts>@npmcli/run-script>node-gyp>npmlog>gauge>aproba": true, "@lavamoat/allow-scripts>@npmcli/run-script>node-gyp>npmlog>gauge>string-width": true, "@lavamoat/allow-scripts>@npmcli/run-script>node-gyp>npmlog>gauge>strip-ansi": true, - "@storybook/addon-mdx-gfm>@storybook/node-logger>npmlog>console-control-strings": true, - "@storybook/addon-mdx-gfm>@storybook/node-logger>npmlog>gauge>has-unicode": true, - "@storybook/addon-mdx-gfm>@storybook/node-logger>npmlog>gauge>wide-align": true, "@storybook/react>@storybook/node-logger>npmlog>console-control-strings": true, "@storybook/react>@storybook/node-logger>npmlog>gauge>has-unicode": true, "@storybook/react>@storybook/node-logger>npmlog>gauge>wide-align": true, @@ -1137,33 +1133,11 @@ "@metamask/jazzicon>color>color-convert>color-name": true } }, - "@sentry/cli>mkdirp": { - "builtin": { - "fs": true, - "path.dirname": true, - "path.resolve": true - } - }, "@storybook/addon-knobs>qs": { "packages": { "string.prototype.matchall>side-channel": true } }, - "@storybook/addon-mdx-gfm>@storybook/node-logger>npmlog>gauge>has-unicode": { - "builtin": { - "os.type": true - }, - "globals": { - "process.env.LANG": true, - "process.env.LC_ALL": true, - "process.env.LC_CTYPE": true - } - }, - "@storybook/addon-mdx-gfm>@storybook/node-logger>npmlog>gauge>wide-align": { - "packages": { - "yargs>string-width": true - } - }, "@storybook/core>@storybook/core-server>x-default-browser>default-browser-id>untildify>os-homedir": { "builtin": { "os.homedir": true @@ -4895,20 +4869,9 @@ }, "packages": { "@storybook/core>@storybook/core-server>x-default-browser>default-browser-id>untildify>os-homedir": true, - "gulp-watch>chokidar>fsevents>node-pre-gyp>nopt>osenv>os-homedir": true, "gulp-watch>chokidar>fsevents>node-pre-gyp>nopt>osenv>os-tmpdir": true } }, - "gulp-watch>chokidar>fsevents>node-pre-gyp>nopt>osenv>os-homedir": { - "builtin": { - "os.homedir": true - }, - "globals": { - "process.env": true, - "process.getuid": true, - "process.platform": true - } - }, "gulp-watch>chokidar>fsevents>node-pre-gyp>nopt>osenv>os-tmpdir": { "globals": { "process.env.SystemRoot": true, @@ -4930,34 +4893,9 @@ "setTimeout": true }, "packages": { - "gulp-watch>chokidar>fsevents>node-pre-gyp>rimraf>glob": true, "nyc>glob": true } }, - "gulp-watch>chokidar>fsevents>node-pre-gyp>rimraf>glob": { - "builtin": { - "assert": true, - "events.EventEmitter": true, - "fs": true, - "path.join": true, - "path.resolve": true, - "util": true - }, - "globals": { - "console.error": true, - "process.cwd": true, - "process.nextTick": true, - "process.platform": true - }, - "packages": { - "eslint>minimatch": true, - "gulp-watch>path-is-absolute": true, - "nyc>glob>fs.realpath": true, - "nyc>glob>inflight": true, - "pump>once": true, - "pumpify>inherits": true - } - }, "gulp-watch>chokidar>fsevents>node-pre-gyp>semver": { "globals": { "console": true, @@ -8246,7 +8184,14 @@ "path.dirname": true }, "packages": { - "@sentry/cli>mkdirp": true + "stylelint>file-entry-cache>flat-cache>write>mkdirp": true + } + }, + "stylelint>file-entry-cache>flat-cache>write>mkdirp": { + "builtin": { + "fs": true, + "path.dirname": true, + "path.resolve": true } }, "stylelint>global-modules": { From c76d91dfe7f3056e7c8dcebc69189b89cca53dd9 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 20 Jun 2023 12:30:49 -0230 Subject: [PATCH 03/30] Update changelog for v10.33.0 (#19664) * Update changelog for v10.33.0 * Update CHANGELOG.md Co-authored-by: Frederik Bolding * Update CHANGELOG.md Co-authored-by: Frederik Bolding * Update CHANGELOG.md Co-authored-by: Frederik Bolding * Update CHANGELOG.md Co-authored-by: Frederik Bolding --------- Co-authored-by: Frederik Bolding --- CHANGELOG.md | 186 ++++++++++++--------------------------------------- 1 file changed, 42 insertions(+), 144 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6da2d36c2..08b8b50db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,152 +7,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## [10.33.0] -### Uncategorized -- feat: add new linea mainnet network ([#19326](https://github.com/MetaMask/metamask-extension/pull/19326)) -- Feat/19274/ds popover update account list menu ([#19534](https://github.com/MetaMask/metamask-extension/pull/19534)) -- Updated contacts Title and copy changes in Send Flow ([#19618](https://github.com/MetaMask/metamask-extension/pull/19618)) -- Fix #19619 - Submit the account creation form when pressing enter ([#19620](https://github.com/MetaMask/metamask-extension/pull/19620)) -- Fix searchable item list height ([#19634](https://github.com/MetaMask/metamask-extension/pull/19634)) -- Master sync PR following v10.32.0 ([#19630](https://github.com/MetaMask/metamask-extension/pull/19630)) -- [FLASK] Update rate limits for `showInAppNotification` and `showNativeNotification` ([#19621](https://github.com/MetaMask/metamask-extension/pull/19621)) -- Merge branch 'develop' into master-sync -- [MMI] renames method for better understanding ([#19622](https://github.com/MetaMask/metamask-extension/pull/19622)) -- Extend `wallet_watchAsset` to support `ERC721` and `ERC1155` tokens ([#19454](https://github.com/MetaMask/metamask-extension/pull/19454)) -- Swaps UI update ([#19169](https://github.com/MetaMask/metamask-extension/pull/19169)) -- Enable e2e debug flag in CI ([#19588](https://github.com/MetaMask/metamask-extension/pull/19588)) -- devDeps: socketcluster-client@14.3.1->14.3.2 ([#19055](https://github.com/MetaMask/metamask-extension/pull/19055)) -- MMI start script and fixes a bug preventing it to run ([#19594](https://github.com/MetaMask/metamask-extension/pull/19594)) -- UX: Ensure 'Connect Hardware' route is functioning properly ([#19612](https://github.com/MetaMask/metamask-extension/pull/19612)) -- Fix unknown processing time not showing in warning color ([#19527](https://github.com/MetaMask/metamask-extension/pull/19527)) -- devDeps: bump and align devDependencies ([#19194](https://github.com/MetaMask/metamask-extension/pull/19194)) -- fix signature controller patch ([#19607](https://github.com/MetaMask/metamask-extension/pull/19607)) -- Fix #19437 - Prevent Connected Sites global menu item from being clicked during confirmation ([#19598](https://github.com/MetaMask/metamask-extension/pull/19598)) -- UX: Add portfolio button in overview ([#19601](https://github.com/MetaMask/metamask-extension/pull/19601)) -- Sync NetworkController lookupNetwork tests w/ core ([#19401](https://github.com/MetaMask/metamask-extension/pull/19401)) -- feature(19493): eliminate e2e flakyness for eth-sign ([#19606](https://github.com/MetaMask/metamask-extension/pull/19606)) -- fix: refactor linea goerli testnet implementation ([#19321](https://github.com/MetaMask/metamask-extension/pull/19321)) -- feature(19496): eliminate flow e2e flakyness in terms of asserting content for DOM ([#19600](https://github.com/MetaMask/metamask-extension/pull/19600)) -- Fix flakey tests in metamask controller tests ([#19312](https://github.com/MetaMask/metamask-extension/pull/19312)) -- Fix #19439 - Allow Account Picker during Send flow ([#19522](https://github.com/MetaMask/metamask-extension/pull/19522)) -- Adding deprecation tags to popover and old modals ([#19556](https://github.com/MetaMask/metamask-extension/pull/19556)) -- devDeps: degenerator@3.0.1->3.0.4 ([#19178](https://github.com/MetaMask/metamask-extension/pull/19178)) -- updated components with Multichain Prefix ([#19593](https://github.com/MetaMask/metamask-extension/pull/19593)) -- Sync NetworkController getEIP1559Compatibility tests w/ core ([#19419](https://github.com/MetaMask/metamask-extension/pull/19419)) -- Sync NetworkController setProviderType tests ([#19406](https://github.com/MetaMask/metamask-extension/pull/19406)) -- Sync rollbackToPreviousProvider tests w/ core ([#19428](https://github.com/MetaMask/metamask-extension/pull/19428)) -- Update message manager and signature controller ([#19370](https://github.com/MetaMask/metamask-extension/pull/19370)) -- Update lockfile ([#19583](https://github.com/MetaMask/metamask-extension/pull/19583)) -- UX Multichain: UI fixes for settings page ([#19574](https://github.com/MetaMask/metamask-extension/pull/19574)) -- UX Multichain: updated enums for multichain token list item ([#19575](https://github.com/MetaMask/metamask-extension/pull/19575)) -- Adding background/default to BorderColor enum to prevent propType error and updating tests ([#19571](https://github.com/MetaMask/metamask-extension/pull/19571)) -- UX: Multichain: Move Add Account and Import Account into Account Menu Popover ([#19346](https://github.com/MetaMask/metamask-extension/pull/19346)) -- Update `@metamask/gas-fee-controller` to v6 ([#19366](https://github.com/MetaMask/metamask-extension/pull/19366)) -- [FLASK] Bump RateLimitController to v3 ([#19578](https://github.com/MetaMask/metamask-extension/pull/19578)) -- Await approval request in transaction controller ([#19197](https://github.com/MetaMask/metamask-extension/pull/19197)) -- Upgrade assets-controllers to v9 ([#19472](https://github.com/MetaMask/metamask-extension/pull/19472)) -- Check Node (and Yarn) versions at install ([#19537](https://github.com/MetaMask/metamask-extension/pull/19537)) -- fix: update linea testnet rpc url ([#19294](https://github.com/MetaMask/metamask-extension/pull/19294)) -- UX Multichain: Updated header to use picker network in popup view ([#19514](https://github.com/MetaMask/metamask-extension/pull/19514)) -- [FLASK] Align update error state with Figma ([#19547](https://github.com/MetaMask/metamask-extension/pull/19547)) -- [FLASK] Fix usages of `getSnapName` ([#19546](https://github.com/MetaMask/metamask-extension/pull/19546)) -- [FLASK] Improve snaps connect flow ([#19461](https://github.com/MetaMask/metamask-extension/pull/19461)) -- feature(19463): fix send-eth flaky test and refactor ([#19531](https://github.com/MetaMask/metamask-extension/pull/19531)) -- [FLASK] Update Snaps privacy notice ([#19501](https://github.com/MetaMask/metamask-extension/pull/19501)) -- Add getEthQuery action to NetworkController ([#19420](https://github.com/MetaMask/metamask-extension/pull/19420)) -- Sync NetworkController setActiveNetwork tests w/ core ([#19405](https://github.com/MetaMask/metamask-extension/pull/19405)) -- Bump minimum Node version to 16.20.0 ([#19520](https://github.com/MetaMask/metamask-extension/pull/19520)) -- Sync removeNetworkConfiguration tests w/ core ([#19427](https://github.com/MetaMask/metamask-extension/pull/19427)) -- Sync NetworkController upsertNetworkConfiguration w/ core ([#19426](https://github.com/MetaMask/metamask-extension/pull/19426)) -- Deprecate JS version of Box in favor of TS version ([#19530](https://github.com/MetaMask/metamask-extension/pull/19530)) -- Make `eth_accounts` return all permitted accounts ([#18516](https://github.com/MetaMask/metamask-extension/pull/18516)) -- Adding `Box` component in TS to component-library ([#19363](https://github.com/MetaMask/metamask-extension/pull/19363)) -- added validTag string literal union ([#19258](https://github.com/MetaMask/metamask-extension/pull/19258)) -- update icons for add-network ([#19513](https://github.com/MetaMask/metamask-extension/pull/19513)) -- Send flow UI update ([#19465](https://github.com/MetaMask/metamask-extension/pull/19465)) -- Reduce e2e test flakiness ([#19507](https://github.com/MetaMask/metamask-extension/pull/19507)) -- Master sync follow v10.31.1 ([#19517](https://github.com/MetaMask/metamask-extension/pull/19517)) -- feat(17901): fix network, add-account and mv3 phishing warning issue ([#19462](https://github.com/MetaMask/metamask-extension/pull/19462)) -- issue-18714: Replaced deprecated constants with enum in EthSignModal and HoldToRevealModal Component ([#19499](https://github.com/MetaMask/metamask-extension/pull/19499)) +### Added +- UI Upgrade ([#18903](https://github.com/MetaMask/metamask-extension/pull/18903)) + - A completely new application header, which contains: + - A new network picker, which displays as only an avatar in the popup and as a full dropdown in full screen mode + - A new account picker + - A new connected icon which displays in popup mode + - A new global menu which contains controls that were formally in the account menu as well as account options menu + - A new token list + - A new token details popover - Added the ability to navigate multiple SIWE notifications ([#18103](https://github.com/MetaMask/metamask-extension/pull/18103)) -- [FLASK] Update snap installation permission warning UI ([#19494](https://github.com/MetaMask/metamask-extension/pull/19494)) -- When gas fees suggested by dapp is too high, show warning color and icon ([#19088](https://github.com/MetaMask/metamask-extension/pull/19088)) -- [MMI] Improved code, fixed bugs and added more tests ([#19488](https://github.com/MetaMask/metamask-extension/pull/19488)) -- Update LavaMoat policies ([#19505](https://github.com/MetaMask/metamask-extension/pull/19505)) -- issue-18714: Replaced deprecated constants with enum in confirmation-warning-modal.js ([#19477](https://github.com/MetaMask/metamask-extension/pull/19477)) -- Creating story for `icon-border` ([#19467](https://github.com/MetaMask/metamask-extension/pull/19467)) -- Creating story for `account-mismatch-warning` ([#19460](https://github.com/MetaMask/metamask-extension/pull/19460)) -- Widen the number of test files that TS sees ([#19403](https://github.com/MetaMask/metamask-extension/pull/19403)) -- fix(e2e): flaky test-e2e-chrome on add-custom-network.spec.js ([#19487](https://github.com/MetaMask/metamask-extension/pull/19487)) -- [FLASK] Rework Snaps headers and footers ([#19442](https://github.com/MetaMask/metamask-extension/pull/19442)) -- Bump `fast-xml-parser` to fix audit issue ([#19489](https://github.com/MetaMask/metamask-extension/pull/19489)) -- Remove unwanted console.log in E2E test ([#19482](https://github.com/MetaMask/metamask-extension/pull/19482)) -- Feature/mmi 3009 confirm transaction base code fences ([#19335](https://github.com/MetaMask/metamask-extension/pull/19335)) -- Fix capitalization of MetaMask ([#19466](https://github.com/MetaMask/metamask-extension/pull/19466)) -- setActiveNetwork captures network config ID ([#19404](https://github.com/MetaMask/metamask-extension/pull/19404)) -- Creating story for `asset-list` ([#19450](https://github.com/MetaMask/metamask-extension/pull/19450)) -- UX: Multichain: Restore Flask support link and text ([#19198](https://github.com/MetaMask/metamask-extension/pull/19198)) -- Have mmi build being generated ([#19441](https://github.com/MetaMask/metamask-extension/pull/19441)) -- Using NetworkAccountBalanceHeader component on SIWE screen ([#19361](https://github.com/MetaMask/metamask-extension/pull/19361)) -- [FLASK] Update UI (for audit) (UI facelift) ([#19388](https://github.com/MetaMask/metamask-extension/pull/19388)) -- [FLASK] Limit notification count display to 99+ ([#19449](https://github.com/MetaMask/metamask-extension/pull/19449)) -- replacing depricated constants ([#19448](https://github.com/MetaMask/metamask-extension/pull/19448)) -- replacing depricated constants ([#19447](https://github.com/MetaMask/metamask-extension/pull/19447)) -- UX Multichain: Update settings title ([#19414](https://github.com/MetaMask/metamask-extension/pull/19414)) -- Handle watch asset accept and reject using ApprovalController only ([#18829](https://github.com/MetaMask/metamask-extension/pull/18829)) -- Revert "feature: Add legacy derivation path to Trezor (#19443)" ([#19443](https://github.com/MetaMask/metamask-extension/pull/19443)) -- feature: Add legacy derivation path to Trezor ([#19443](https://github.com/MetaMask/metamask-extension/pull/19443)) -- Replacing deprecated constants with enums ([#19242](https://github.com/MetaMask/metamask-extension/pull/19242)) -- Updating component-library readme storybook render ([#19359](https://github.com/MetaMask/metamask-extension/pull/19359)) -- Part of #18714: Replacing deprecated constants in `Avatar-Base` folder ([#19408](https://github.com/MetaMask/metamask-extension/pull/19408)) -- feature(17901): fix import UI error ([#19372](https://github.com/MetaMask/metamask-extension/pull/19372)) -- [FLASK] Update snap tweaks ([#19410](https://github.com/MetaMask/metamask-extension/pull/19410)) -- [FLASK] `snaps@0.34.0-flask.1` ([#19377](https://github.com/MetaMask/metamask-extension/pull/19377)) -- Remove MULTICHAIN flag for NFT badges ([#19416](https://github.com/MetaMask/metamask-extension/pull/19416)) -- Sync NetworkController initializeProvider tests w/ core ([#19297](https://github.com/MetaMask/metamask-extension/pull/19297)) -- Sync default value of networkDetails w/ core ([#19407](https://github.com/MetaMask/metamask-extension/pull/19407)) -- UX: Multichain: Make MetaFox logo more accessible ([#19395](https://github.com/MetaMask/metamask-extension/pull/19395)) -- [MMI] Added code fencing in libs folder ([#17929](https://github.com/MetaMask/metamask-extension/pull/17929)) -- Multichain NFT network badges ([#19029](https://github.com/MetaMask/metamask-extension/pull/19029)) -- Fix details when transferring NFT not added to wallet ([#19045](https://github.com/MetaMask/metamask-extension/pull/19045)) -- feature(on-ramp): update supported networks ([#19268](https://github.com/MetaMask/metamask-extension/pull/19268)) -- feature(17901): fix flaky tests in send-eth e2e ([#19397](https://github.com/MetaMask/metamask-extension/pull/19397)) -- accept approval request first ([#19409](https://github.com/MetaMask/metamask-extension/pull/19409)) -- Fix/storybook console cleanup ([#19244](https://github.com/MetaMask/metamask-extension/pull/19244)) -- Release MultiChain 0.5 ([#18903](https://github.com/MetaMask/metamask-extension/pull/18903)) -- Part of #18714: Replacing deprecated constants in `Avatar-Favicon` folder ([#19332](https://github.com/MetaMask/metamask-extension/pull/19332)) -- ConfirmTxPage: rm redundant unapprovedTxs const ([#19275](https://github.com/MetaMask/metamask-extension/pull/19275)) -- Replacing Deprecated Constants ([#19333](https://github.com/MetaMask/metamask-extension/pull/19333)) -- added deprecation message above SiteIcon ([#19256](https://github.com/MetaMask/metamask-extension/pull/19256)) -- ci: temporarily disable codecov status checks ([#19354](https://github.com/MetaMask/metamask-extension/pull/19354)) -- ConfirmApprove: fix space occurring after footer ([#19276](https://github.com/MetaMask/metamask-extension/pull/19276)) -- Clean ConfirmTransaction page related code ([#19208](https://github.com/MetaMask/metamask-extension/pull/19208)) -- deep clone signature tx in order to avoid state mutation bug on development ([#19179](https://github.com/MetaMask/metamask-extension/pull/19179)) -- Update `@metamask/approval-controller` to v3 ([#19365](https://github.com/MetaMask/metamask-extension/pull/19365)) -- Update `@metamask/notification-controller` to v3 ([#19364](https://github.com/MetaMask/metamask-extension/pull/19364)) -- Update `@metamask/address-book-controller` to v3 ([#19345](https://github.com/MetaMask/metamask-extension/pull/19345)) -- Update `@metamask/controller-utils` to v4 ([#19344](https://github.com/MetaMask/metamask-extension/pull/19344)) -- devDeps: yargs@7.1.1->7.1.2 ([#19057](https://github.com/MetaMask/metamask-extension/pull/19057)) -- devDeps: squirrelly@^8.0.8->^9.0.0 ([#19113](https://github.com/MetaMask/metamask-extension/pull/19113)) -- Update mv3 minimum version to chrome v88 ([#19358](https://github.com/MetaMask/metamask-extension/pull/19358)) -- Ensure custom provider configs have chain ID and RPC URL ([#19296](https://github.com/MetaMask/metamask-extension/pull/19296)) -- Update INFURA_NETWORKS in NC tests to ostensibly use dec #'s ([#19316](https://github.com/MetaMask/metamask-extension/pull/19316)) -- NetworkController tests: Sync withController helper ([#19313](https://github.com/MetaMask/metamask-extension/pull/19313)) -- NetworkController tests: Remove commented line ([#19315](https://github.com/MetaMask/metamask-extension/pull/19315)) -- Part of #18714: Replacing deprecated constants in `Modal-Header` folder ([#19339](https://github.com/MetaMask/metamask-extension/pull/19339)) -- Update `@metamask/announcement-controller` to v4 ([#19348](https://github.com/MetaMask/metamask-extension/pull/19348)) -- Update README.md ([#19350](https://github.com/MetaMask/metamask-extension/pull/19350)) -- NetworkController: Improve test for destroy ([#19314](https://github.com/MetaMask/metamask-extension/pull/19314)) -- Add getProviderConfig action to NetworkController ([#19317](https://github.com/MetaMask/metamask-extension/pull/19317)) -- Sync NetworkController constructor tests with core ([#19311](https://github.com/MetaMask/metamask-extension/pull/19311)) -- Update `@metamask/base-controller` to v3 ([#19343](https://github.com/MetaMask/metamask-extension/pull/19343)) +- Add portfolio button in on home screen, under the balance([#19601](https://github.com/MetaMask/metamask-extension/pull/19601)) +- Add support for ERC721 and ERC1155 tokens to `wallet_watchAsset` API ([#19454](https://github.com/MetaMask/metamask-extension/pull/19454)) +- Add support for Cronos, Moonbeam, Moonriver, Aurora, Harmony and Palm to the 'Buy Crypto' feature ([#19268](https://github.com/MetaMask/metamask-extension/pull/19268)) - [FLASK] Add Snaps privacy warning on snap install ([#18835](https://github.com/MetaMask/metamask-extension/pull/18835)) -- feature(17901): fix failing network error and remove duplicated e2e for mv3 ([#19292](https://github.com/MetaMask/metamask-extension/pull/19292)) -- feature(17901): fix address-book `Sends to an address book entry` e2e against MV3 build ([#19330](https://github.com/MetaMask/metamask-extension/pull/19330)) -- Revert "[MMI] Add confirm-transaction-base code fences (#18795)" ([#18795](https://github.com/MetaMask/metamask-extension/pull/18795)) -- updates values ([#19336](https://github.com/MetaMask/metamask-extension/pull/19336)) -- Changes to Popover folder ([#19245](https://github.com/MetaMask/metamask-extension/pull/19245)) -- [MMI] Add confirm-transaction-base code fences ([#18795](https://github.com/MetaMask/metamask-extension/pull/18795)) -- [MMI] adds mmi code fences to mm controller ([#18279](https://github.com/MetaMask/metamask-extension/pull/18279)) + +### Changed +- Redesign swaps feature to be faster and easier to use ([#19169](https://github.com/MetaMask/metamask-extension/pull/19169)) +- Update linea testnet rpc url ([#19294](https://github.com/MetaMask/metamask-extension/pull/19294)) +- Make `eth_accounts` return all permitted accounts ([#18516](https://github.com/MetaMask/metamask-extension/pull/18516)) +- When gas fees suggested by dapp is too high, show warning color and icon ([#19088](https://github.com/MetaMask/metamask-extension/pull/19088)) +- Show balance and selected account in the header on the SIWE screen ([#19361](https://github.com/MetaMask/metamask-extension/pull/19361)) +- Submit the account creation form when pressing enter ([#19620](https://github.com/MetaMask/metamask-extension/pull/19620)) +- [FLASK] Rework Snaps headers and footers ([#19442](https://github.com/MetaMask/metamask-extension/pull/19442)) +- Send flow UI update ([#19465](https://github.com/MetaMask/metamask-extension/pull/19465)) + - Remove Recents + - Display a list of "Your accounts" if the user has more than one account + - Display "Contacts" in alphabetical order after the final user's account + - UI Updates in Contacts Page (AddressBook) in Settings Page +- [FLASK] Small UI improvements ([#19388](https://github.com/MetaMask/metamask-extension/pull/19388)) +- [FLASK] Limit notification count display to 99+ ([#19449](https://github.com/MetaMask/metamask-extension/pull/19449)) +- [FLASK] Update snap tweaks ([#19410](https://github.com/MetaMask/metamask-extension/pull/19410)) +- [FLASK] Add snap icon SVG validation ([#19377](https://github.com/MetaMask/metamask-extension/pull/19377)) +- [FLASK] Update rate limits for showInAppNotification and showNativeNotification ([#19621](https://github.com/MetaMask/metamask-extension/pull/19621)) +- [FLASK] Align update error state with Figma ([#19547](https://github.com/MetaMask/metamask-extension/pull/19547)) +- [FLASK] Update snap installation permission warning UI ([#19494](https://github.com/MetaMask/metamask-extension/pull/19494)) +- [FLASK] Improve snaps connect flow ([#19461](https://github.com/MetaMask/metamask-extension/pull/19461)) + +### Fixed +- Fix centering and spacing of icons in the Add Network screen ([#19513](https://github.com/MetaMask/metamask-extension/pull/19513)) +- Fix details when transferring NFT not added to wallet ([#19045](https://github.com/MetaMask/metamask-extension/pull/19045)) +- Fix capitalization of MetaMask in some translations ([#19466](https://github.com/MetaMask/metamask-extension/pull/19466)) +- Fix space occurring after footer on token approve screen ([#19276](https://github.com/MetaMask/metamask-extension/pull/19276)) +- Fix unknown processing time not showing in warning color on confirmation screens ([#19527](https://github.com/MetaMask/metamask-extension/pull/19527)) + ## [10.32.0] ### Added From 0f330e21e5051587159965bfb5ec8039c81fd855 Mon Sep 17 00:00:00 2001 From: Nidhi Kumari Date: Wed, 21 Jun 2023 19:32:25 +0530 Subject: [PATCH 04/30] added extra margin for unlocked state in full view in header (#19701) Co-authored-by: Danica Shen --- ui/pages/routes/routes.component.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ui/pages/routes/routes.component.js b/ui/pages/routes/routes.component.js index 97d03d0ca..60a9406fb 100644 --- a/ui/pages/routes/routes.component.js +++ b/ui/pages/routes/routes.component.js @@ -113,6 +113,7 @@ import { SEND_STAGES } from '../../ducks/send'; import DeprecatedTestNetworks from '../../components/ui/deprecated-test-networks/deprecated-test-networks'; import NewNetworkInfo from '../../components/ui/new-network-info/new-network-info'; import { ThemeType } from '../../../shared/constants/preferences'; +import { Box } from '../../components/component-library'; export default class Routes extends Component { static propTypes = { @@ -561,11 +562,14 @@ export default class Routes extends Component { {accountDetailsAddress ? ( ) : null} -
+ {isLoading ? : null} {!isLoading && isNetworkLoading ? : null} {this.renderRoutes()} -
+ {isUnlocked ? : null} ); From 5512e2921f5031df912b8f57633089c17dddcac1 Mon Sep 17 00:00:00 2001 From: Nidhi Kumari Date: Fri, 23 Jun 2023 17:28:41 +0530 Subject: [PATCH 05/30] removed portfolio link from wallet view (#19716) * removed portfolio link from wallet view * removed unused code * updated test * updated spec file * updated test --- test/e2e/tests/portfolio-site.spec.js | 4 +- .../app/wallet-overview/eth-overview.js | 44 +------------------ .../app/wallet-overview/eth-overview.test.js | 2 +- 3 files changed, 4 insertions(+), 46 deletions(-) diff --git a/test/e2e/tests/portfolio-site.spec.js b/test/e2e/tests/portfolio-site.spec.js index 2bdb413d5..93e0d0877 100644 --- a/test/e2e/tests/portfolio-site.spec.js +++ b/test/e2e/tests/portfolio-site.spec.js @@ -26,7 +26,7 @@ describe('Portfolio site', function () { await driver.press('#password', driver.Key.ENTER); // Click Portfolio site - await driver.clickElement('[data-testid="home__portfolio-site"]'); + await driver.clickElement('[data-testid="eth-overview-portfolio"]'); await driver.waitUntilXWindowHandles(2); const windowHandles = await driver.getAllWindowHandles(); await driver.switchToWindowWithTitle('E2E Test Dapp', windowHandles); @@ -34,7 +34,7 @@ describe('Portfolio site', function () { // Verify site assert.equal( await driver.getCurrentUrl(), - 'http://127.0.0.1:8080/?metamaskEntry=ext&metametricsId=null', + 'http://127.0.0.1:8080/?metamaskEntry=ext_portfolio_button&metametricsId=null', ); }, ); diff --git a/ui/components/app/wallet-overview/eth-overview.js b/ui/components/app/wallet-overview/eth-overview.js index 2d026a78c..0ee8147c5 100644 --- a/ui/components/app/wallet-overview/eth-overview.js +++ b/ui/components/app/wallet-overview/eth-overview.js @@ -36,7 +36,6 @@ import IconButton from '../../ui/icon-button'; import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { - MetaMetricsContextProp, MetaMetricsEventCategory, MetaMetricsEventName, MetaMetricsSwapsEventSource, @@ -44,12 +43,7 @@ import { import Spinner from '../../ui/spinner'; import { startNewDraftTransaction } from '../../../ducks/send'; import { AssetType } from '../../../../shared/constants/transaction'; -import { - ButtonIcon, - ButtonIconSize, - Icon, - IconName, -} from '../../component-library'; +import { Icon, IconName } from '../../component-library'; import { IconColor } from '../../../helpers/constants/design-system'; import useRamps from '../../../hooks/experiences/useRamps'; import { getPortfolioUrl } from '../../../helpers/utils/portfolio'; @@ -156,42 +150,6 @@ const EthOverview = ({ className }) => { {balanceIsCached ? ( * ) : null} - { - ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) - { - const portfolioUrl = getPortfolioUrl( - '', - 'ext', - metaMetricsId, - ); - global.platform.openTab({ - url: portfolioUrl, - }); - trackEvent( - { - category: MetaMetricsEventCategory.Home, - event: MetaMetricsEventName.PortfolioLinkClicked, - properties: { - url: portfolioUrl, - }, - }, - { - contextPropsIntoEventProperties: [ - MetaMetricsContextProp.PageTitle, - ], - }, - ); - }} - /> - ///: END:ONLY_INCLUDE_IN - } {showFiat && balance && ( { const store = configureMockStore([thunk])(mockStore); const ETH_OVERVIEW_BUY = 'eth-overview-buy'; const ETH_OVERVIEW_BRIDGE = 'eth-overview-bridge'; - const ETH_OVERVIEW_PORTFOLIO = 'home__portfolio-site'; + const ETH_OVERVIEW_PORTFOLIO = 'eth-overview-portfolio'; const ETH_OVERVIEW_PRIMARY_CURRENCY = 'eth-overview__primary-currency'; const ETH_OVERVIEW_SECONDARY_CURRENCY = 'eth-overview__secondary-currency'; From e8e6d7cd3575bd784996bae4f55d01719e7cdaba Mon Sep 17 00:00:00 2001 From: Nidhi Kumari Date: Mon, 26 Jun 2023 23:27:56 +0530 Subject: [PATCH 06/30] UX Multichain: fixed padding for edit screen (#19707) * fixed padding for edit screen * Use network picker for header trigger * Fix swaps display * updated snapshot --------- Co-authored-by: David Walsh --- .../app-header/__snapshots__/app-header.test.js.snap | 2 +- ui/components/multichain/app-header/app-header.js | 5 +++++ ui/pages/routes/routes.component.js | 5 +---- ui/pages/swaps/index.scss | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ui/components/multichain/app-header/__snapshots__/app-header.test.js.snap b/ui/components/multichain/app-header/__snapshots__/app-header.test.js.snap index 86163faaf..bb44e6a6f 100644 --- a/ui/components/multichain/app-header/__snapshots__/app-header.test.js.snap +++ b/ui/components/multichain/app-header/__snapshots__/app-header.test.js.snap @@ -200,7 +200,7 @@ exports[`App Header should match snapshot 1`] = `
{ }); }, [chainId, dispatch, trackEvent]); + // This is required to ensure send and confirmation screens + // look as desired + const headerBottomMargin = disableNetworkPicker ? 4 : 0; + return ( <> {isUnlocked && !popupStatus ? ( @@ -175,6 +179,7 @@ export const AppHeader = ({ location }) => { className={classnames('multichain-app-header', { 'multichain-app-header-shadow': !isUnlocked || popupStatus, })} + marginBottom={headerBottomMargin} alignItems={AlignItems.center} width={BlockSize.Full} backgroundColor={ diff --git a/ui/pages/routes/routes.component.js b/ui/pages/routes/routes.component.js index 60a9406fb..d958cfd8f 100644 --- a/ui/pages/routes/routes.component.js +++ b/ui/pages/routes/routes.component.js @@ -562,10 +562,7 @@ export default class Routes extends Component { {accountDetailsAddress ? ( ) : null} - + {isLoading ? : null} {!isLoading && isNetworkLoading ? : null} {this.renderRoutes()} diff --git a/ui/pages/swaps/index.scss b/ui/pages/swaps/index.scss index c4a5e2142..83d0cdc7c 100644 --- a/ui/pages/swaps/index.scss +++ b/ui/pages/swaps/index.scss @@ -57,8 +57,7 @@ background: var(--color-background-default); box-shadow: var(--shadow-size-xs) var(--color-shadow-default); border: 1px solid var(--color-border-muted); - border-top: 0; - border-radius: 0 0 8px 8px; + border-radius: 8px; height: 620px; } } From 53edffe2798018899337ea5c37efef889b10cc46 Mon Sep 17 00:00:00 2001 From: David Walsh Date: Mon, 26 Jun 2023 11:13:26 -0500 Subject: [PATCH 07/30] Fix #847 - Don't show account address on token pages (#19740) Co-authored-by: Nidhi Kumari --- .../app/wallet-overview/eth-overview.js | 8 +++----- .../app/wallet-overview/token-overview.js | 1 + .../app/wallet-overview/wallet-overview.js | 20 +++++++++++-------- ui/pages/asset/components/native-asset.js | 2 +- ui/pages/home/home.component.js | 3 ++- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ui/components/app/wallet-overview/eth-overview.js b/ui/components/app/wallet-overview/eth-overview.js index 0ee8147c5..9867ba5b9 100644 --- a/ui/components/app/wallet-overview/eth-overview.js +++ b/ui/components/app/wallet-overview/eth-overview.js @@ -49,7 +49,7 @@ import useRamps from '../../../hooks/experiences/useRamps'; import { getPortfolioUrl } from '../../../helpers/utils/portfolio'; import WalletOverview from './wallet-overview'; -const EthOverview = ({ className }) => { +const EthOverview = ({ className, showAddress }) => { const dispatch = useDispatch(); const t = useContext(I18nContext); const trackEvent = useContext(MetaMetricsContext); @@ -121,6 +121,7 @@ const EthOverview = ({ className }) => { return ( { EthOverview.propTypes = { className: PropTypes.string, -}; - -EthOverview.defaultProps = { - className: undefined, + showAddress: PropTypes.bool, }; export default EthOverview; diff --git a/ui/components/app/wallet-overview/token-overview.js b/ui/components/app/wallet-overview/token-overview.js index 7593ad72f..0820c946a 100644 --- a/ui/components/app/wallet-overview/token-overview.js +++ b/ui/components/app/wallet-overview/token-overview.js @@ -83,6 +83,7 @@ const TokenOverview = ({ className, token }) => { return (
diff --git a/ui/components/app/wallet-overview/wallet-overview.js b/ui/components/app/wallet-overview/wallet-overview.js index a56f8b8d8..f24957954 100644 --- a/ui/components/app/wallet-overview/wallet-overview.js +++ b/ui/components/app/wallet-overview/wallet-overview.js @@ -7,15 +7,22 @@ import { getSelectedIdentity } from '../../../selectors'; import { AddressCopyButton } from '../../multichain'; import Box from '../../ui/box/box'; -const WalletOverview = ({ balance, buttons, className }) => { +const WalletOverview = ({ + balance, + buttons, + className, + showAddress = false, +}) => { const selectedIdentity = useSelector(getSelectedIdentity); const checksummedAddress = toChecksumHexAddress(selectedIdentity?.address); return (
- - - + {showAddress ? ( + + + + ) : null} {balance}
{buttons}
@@ -27,10 +34,7 @@ WalletOverview.propTypes = { balance: PropTypes.element.isRequired, buttons: PropTypes.element.isRequired, className: PropTypes.string, -}; - -WalletOverview.defaultProps = { - className: undefined, + showAddress: PropTypes.bool, }; export default WalletOverview; diff --git a/ui/pages/asset/components/native-asset.js b/ui/pages/asset/components/native-asset.js index 0d5d6f98b..851b88b39 100644 --- a/ui/pages/asset/components/native-asset.js +++ b/ui/pages/asset/components/native-asset.js @@ -64,7 +64,7 @@ export default function NativeAsset({ nativeCurrency }) { /> } /> - + ); diff --git a/ui/pages/home/home.component.js b/ui/pages/home/home.component.js index 9263dff65..52d8b1be9 100644 --- a/ui/pages/home/home.component.js +++ b/ui/pages/home/home.component.js @@ -778,12 +778,13 @@ export default class Home extends PureComponent {
{ ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) - + ///: END:ONLY_INCLUDE_IN } { ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) From 3960fdfcf91b4e219b4b9b0ea3438a055f6769f3 Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Mon, 26 Jun 2023 09:12:13 -0500 Subject: [PATCH 08/30] Add `tokenId` type validation in `wallet_watchAsset` middleware (#19738) --- .../handlers/watch-asset.js | 17 ++++ .../handlers/watch-asset.test.js | 99 +++++++++++++++++++ package.json | 2 +- yarn.lock | 10 +- 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 app/scripts/lib/rpc-method-middleware/handlers/watch-asset.test.js diff --git a/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js b/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js index 8954a15f5..2f7fb5d7a 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.js @@ -1,3 +1,5 @@ +import { ERC1155, ERC721 } from '@metamask/controller-utils'; +import { ethErrors } from 'eth-rpc-errors'; import { MESSAGE_TYPE } from '../../../../../shared/constants/app'; const watchAsset = { @@ -39,6 +41,21 @@ async function watchAssetHandler( params: { options: asset, type }, origin, } = req; + + const { tokenId } = asset; + + if ( + [ERC721, ERC1155].includes(type) && + tokenId !== undefined && + typeof tokenId !== 'string' + ) { + return end( + ethErrors.rpc.invalidParams({ + message: `Expected parameter 'tokenId' to be type 'string'. Received type '${typeof tokenId}'`, + }), + ); + } + await handleWatchAssetRequest(asset, type, origin); res.result = true; return end(); diff --git a/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.test.js b/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.test.js new file mode 100644 index 000000000..5af3ad1bd --- /dev/null +++ b/app/scripts/lib/rpc-method-middleware/handlers/watch-asset.test.js @@ -0,0 +1,99 @@ +import { ERC20, ERC721 } from '@metamask/controller-utils'; +import { ethErrors } from 'eth-rpc-errors'; +import watchAssetHandler from './watch-asset'; + +describe('watchAssetHandler', () => { + let mockEnd; + let mockHandleWatchAssetRequest; + + beforeEach(() => { + mockEnd = jest.fn(); + mockHandleWatchAssetRequest = jest.fn(); + }); + + it('should handle valid input for type ERC721 correctly', async () => { + const req = { + params: { + options: { + address: '0x1234', + tokenId: 'testTokenId', + }, + type: ERC721, + }, + origin: 'testOrigin', + }; + + const res = { + result: false, + }; + + await watchAssetHandler.implementation(req, res, null, mockEnd, { + handleWatchAssetRequest: mockHandleWatchAssetRequest, + }); + + expect(mockHandleWatchAssetRequest).toHaveBeenCalledWith( + req.params.options, + req.params.type, + req.origin, + ); + expect(res.result).toStrictEqual(true); + expect(mockEnd).toHaveBeenCalledWith(); + }); + + it('should handle valid input for type ERC20 correctly', async () => { + const req = { + params: { + options: { + address: '0x1234', + symbol: 'TEST', + decimals: 18, + }, + type: ERC20, + }, + origin: 'testOrigin', + }; + + const res = { + result: false, + }; + + await watchAssetHandler.implementation(req, res, null, mockEnd, { + handleWatchAssetRequest: mockHandleWatchAssetRequest, + }); + + expect(mockHandleWatchAssetRequest).toHaveBeenCalledWith( + req.params.options, + req.params.type, + req.origin, + ); + expect(res.result).toStrictEqual(true); + expect(mockEnd).toHaveBeenCalledWith(); + }); + + it('should throw when type is ERC721 and tokenId type is invalid', async () => { + const req = { + params: { + options: { + address: '0x1234', + tokenId: 222, + }, + type: ERC721, + }, + origin: 'testOrigin', + }; + + const res = { + result: false, + }; + + await watchAssetHandler.implementation(req, res, null, mockEnd, { + handleWatchAssetRequest: mockHandleWatchAssetRequest, + }); + + expect(mockEnd).toHaveBeenCalledWith( + ethErrors.rpc.invalidParams({ + message: `Expected parameter 'tokenId' to be type 'string'. Received type 'number'`, + }), + ); + }); +}); diff --git a/package.json b/package.json index adf1a8995..fff0ea2f6 100644 --- a/package.json +++ b/package.json @@ -386,7 +386,7 @@ "@metamask/eslint-config-typescript": "^9.0.1", "@metamask/forwarder": "^1.1.0", "@metamask/phishing-warning": "^2.1.0", - "@metamask/test-dapp": "^7.0.0", + "@metamask/test-dapp": "^7.0.1", "@sentry/cli": "^1.58.0", "@storybook/addon-a11y": "^7.0.11", "@storybook/addon-actions": "^7.0.11", diff --git a/yarn.lock b/yarn.lock index 56345e62f..8f80b5875 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4931,10 +4931,10 @@ __metadata: languageName: node linkType: hard -"@metamask/test-dapp@npm:^7.0.0": - version: 7.0.0 - resolution: "@metamask/test-dapp@npm:7.0.0" - checksum: 4a03ed86a97c94eef8131c0951fb7bf7eb0c988c407ae8e5ed6a897da30d1c48adf3e1e51e45220df6e5d51c22736a06c732ac95ba5741223573cd660706876b +"@metamask/test-dapp@npm:^7.0.1": + version: 7.0.1 + resolution: "@metamask/test-dapp@npm:7.0.1" + checksum: cbd9f7d66c32ecdccc2039b9d60ef7c0a118ce22392f2eec2ffc0911d3314f75eb81fc9bc6cdf14efd34de5fffb013693344ca2a2e46aa0a8cc33a3a8d8b0fea languageName: node linkType: hard @@ -24367,7 +24367,7 @@ __metadata: "@metamask/snaps-utils-flask": "npm:@metamask/snaps-utils@0.34.0-flask.1" "@metamask/subject-metadata-controller": ^2.0.0 "@metamask/swappable-obj-proxy": ^2.1.0 - "@metamask/test-dapp": ^7.0.0 + "@metamask/test-dapp": ^7.0.1 "@metamask/utils": ^5.0.0 "@ngraveio/bc-ur": ^1.1.6 "@popperjs/core": ^2.4.0 From 28093b0c593400161a36c9b17e30e122810e57ad Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 26 Jun 2023 16:13:16 -0230 Subject: [PATCH 09/30] Fix fallback gas estimation (#19746) * Fix fallback gas estimation Our fallback gas estimation was failing due to a bug in the `@metamask/controller-utils` package. This was causing gas estimation to fail completely on certain networks (those not supported by our gas estimation APIs and non EIP-1559 compatibile), and it was causing the fallback gas estimation operation (in case our API was down) to fail across all networks. Fixes https://github.com/MetaMask/metamask-extension/issues/19735 * Add e2e tests E2E tests have been added to capture gas estimation. Cases are added for our API, for the fallback estimate, and for non-EIP-1559 estimates. As part of this work, the legacy gas API had to be disabled. This was being used in e2e tests but was dead code in production. It needed to be disabled to ensure the code under test was reachable. * Fix gas API referenced in e2e test * Update unit test snapshots --- app/scripts/metamask-controller.js | 7 +- package.json | 2 +- test/e2e/tests/gas-estimates.spec.js | 171 ++++++++++++++++++ .../confirm-gas-display.test.js.snap | 1 + .../confirm-gas-display.js | 8 +- .../confirm-legacy-gas-display.js | 9 +- .../app/gas-details-item/gas-details-item.js | 7 +- .../transaction-detail-item.component.js | 7 +- .../confirm-send-ether.test.js.snap | 1 + .../confirm-transaction-base.test.js.snap | 1 + .../send-content.component.test.js.snap | 1 + yarn.lock | 12 +- 12 files changed, 210 insertions(+), 17 deletions(-) create mode 100644 test/e2e/tests/gas-estimates.spec.js diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 7b6b049d1..1c848efae 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -535,13 +535,8 @@ export default class MetamaskController extends EventEmitter { ), getCurrentAccountEIP1559Compatibility: this.getCurrentAccountEIP1559Compatibility.bind(this), - legacyAPIEndpoint: `${gasApiBaseUrl}/networks//gasPrices`, EIP1559APIEndpoint: `${gasApiBaseUrl}/networks//suggestedGasFees`, - getCurrentNetworkLegacyGasAPICompatibility: () => { - const { chainId } = - this.networkController.store.getState().providerConfig; - return process.env.IN_TEST || chainId === CHAIN_IDS.MAINNET; - }, + getCurrentNetworkLegacyGasAPICompatibility: () => false, getChainId: () => this.networkController.store.getState().providerConfig.chainId, }); diff --git a/package.json b/package.json index fff0ea2f6..5cb4be44e 100644 --- a/package.json +++ b/package.json @@ -233,7 +233,7 @@ "@metamask/base-controller": "^3.0.0", "@metamask/browser-passworder": "^4.1.0", "@metamask/contract-metadata": "^2.3.1", - "@metamask/controller-utils": "^4.0.0", + "@metamask/controller-utils": "^4.0.1", "@metamask/design-tokens": "^1.9.0", "@metamask/desktop": "^0.3.0", "@metamask/eth-json-rpc-infura": "^8.1.0", diff --git a/test/e2e/tests/gas-estimates.spec.js b/test/e2e/tests/gas-estimates.spec.js new file mode 100644 index 000000000..a7d121f31 --- /dev/null +++ b/test/e2e/tests/gas-estimates.spec.js @@ -0,0 +1,171 @@ +const { + convertToHexValue, + withFixtures, + logInWithBalanceValidation, +} = require('../helpers'); +const FixtureBuilder = require('../fixture-builder'); + +describe('Gas estimates generated by MetaMask', function () { + const baseGanacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: convertToHexValue(25000000000000000000), + }, + ], + }; + const preLondonGanacheOptions = { + ...baseGanacheOptions, + hardfork: 'berlin', + }; + const postLondonGanacheOptions = { + ...baseGanacheOptions, + hardfork: 'london', + }; + + describe('Send on a network that is EIP-1559 compatible', function () { + it('show expected gas defaults', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions: postLondonGanacheOptions, + title: this.test.title, + }, + async ({ driver, ganacheServer }) => { + await driver.navigate(); + await logInWithBalanceValidation(driver, ganacheServer); + + await driver.clickElement('[data-testid="eth-overview-send"]'); + + await driver.fill( + 'input[placeholder="Enter public address (0x) or ENS name"]', + '0x2f318C334780961FB129D2a6c30D0763d9a5C970', + ); + + await driver.fill('.unit-input__input', '1'); + + // Check that the gas estimation is what we expect + await driver.findElement({ + cass: '[data-testid="confirm-gas-display"]', + text: '0.00043983', + }); + }, + ); + }); + + it('show expected gas defaults when API is down', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions: postLondonGanacheOptions, + testSpecificMock: (mockServer) => { + mockServer + .forGet( + 'https://gas-api.metaswap.codefi.network/networks/1337/suggestedGasFees', + ) + .thenCallback(() => { + return { + json: { + error: 'cannot get gas prices for chain id 1337', + }, + statusCode: 503, + }; + }); + }, + title: this.test.title, + }, + async ({ driver, ganacheServer }) => { + await driver.navigate(); + await logInWithBalanceValidation(driver, ganacheServer); + + await driver.clickElement('[data-testid="eth-overview-send"]'); + + await driver.fill( + 'input[placeholder="Enter public address (0x) or ENS name"]', + '0x2f318C334780961FB129D2a6c30D0763d9a5C970', + ); + + await driver.fill('.unit-input__input', '1'); + + // Check that the gas estimation is what we expect + await driver.findElement({ + cass: '[data-testid="confirm-gas-display"]', + text: '0.00043983', + }); + }, + ); + }); + + it('show expected gas defaults when the network is not supported', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions: postLondonGanacheOptions, + testSpecificMock: (mockServer) => { + mockServer + .forGet( + 'https://gas-api.metaswap.codefi.network/networks/1337/suggestedGasFees', + ) + .thenCallback(() => { + return { + statusCode: 422, + }; + }); + }, + title: this.test.title, + }, + async ({ driver, ganacheServer }) => { + await driver.navigate(); + await logInWithBalanceValidation(driver, ganacheServer); + + await driver.clickElement('[data-testid="eth-overview-send"]'); + + await driver.fill( + 'input[placeholder="Enter public address (0x) or ENS name"]', + '0x2f318C334780961FB129D2a6c30D0763d9a5C970', + ); + + await driver.fill('.unit-input__input', '1'); + + // Check that the gas estimation is what we expect + await driver.findElement({ + cass: '[data-testid="confirm-gas-display"]', + text: '0.00043983', + }); + }, + ); + }); + }); + + describe('Send on a network that is not EIP-1559 compatible', function () { + it('show expected gas defaults', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions: preLondonGanacheOptions, + title: this.test.title, + }, + async ({ driver, ganacheServer }) => { + await driver.navigate(); + await logInWithBalanceValidation(driver, ganacheServer); + + await driver.clickElement('[data-testid="eth-overview-send"]'); + + await driver.fill( + 'input[placeholder="Enter public address (0x) or ENS name"]', + '0x2f318C334780961FB129D2a6c30D0763d9a5C970', + ); + + await driver.fill('.unit-input__input', '1'); + + // Check that the gas estimation is what we expect + await driver.findElement({ + cass: '[data-testid="confirm-gas-display"]', + text: '0.000042', + }); + }, + ); + }); + }); +}); diff --git a/ui/components/app/confirm-gas-display/__snapshots__/confirm-gas-display.test.js.snap b/ui/components/app/confirm-gas-display/__snapshots__/confirm-gas-display.test.js.snap index a993864ba..edd5c141f 100644 --- a/ui/components/app/confirm-gas-display/__snapshots__/confirm-gas-display.test.js.snap +++ b/ui/components/app/confirm-gas-display/__snapshots__/confirm-gas-display.test.js.snap @@ -4,6 +4,7 @@ exports[`ConfirmGasDisplay should match snapshot 1`] = `
{ checkNetworkAndAccountSupports1559, ); const supportsEIP1559 = networkAndAccountSupports1559 && !isLegacyTxn; + const dataTestId = 'confirm-gas-display'; return supportsEIP1559 ? ( - + ) : ( - + ); }; diff --git a/ui/components/app/confirm-gas-display/confirm-legacy-gas-display/confirm-legacy-gas-display.js b/ui/components/app/confirm-gas-display/confirm-legacy-gas-display/confirm-legacy-gas-display.js index 124fbb0d9..15e0abfb6 100644 --- a/ui/components/app/confirm-gas-display/confirm-legacy-gas-display/confirm-legacy-gas-display.js +++ b/ui/components/app/confirm-gas-display/confirm-legacy-gas-display/confirm-legacy-gas-display.js @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { useI18nContext } from '../../../../hooks/useI18nContext'; @@ -31,7 +32,7 @@ import { Icon, IconName } from '../../../component-library'; const renderHeartBeatIfNotInTest = () => process.env.IN_TEST ? null : ; -const ConfirmLegacyGasDisplay = () => { +const ConfirmLegacyGasDisplay = ({ 'data-testid': dataTestId } = {}) => { const t = useI18nContext(); // state selectors @@ -55,6 +56,7 @@ const ConfirmLegacyGasDisplay = () => { return [ { return ( @@ -186,4 +189,8 @@ const ConfirmLegacyGasDisplay = () => { ); }; +ConfirmLegacyGasDisplay.propTypes = { + 'data-testid': PropTypes.string, +}; + export default ConfirmLegacyGasDisplay; diff --git a/ui/components/app/gas-details-item/gas-details-item.js b/ui/components/app/gas-details-item/gas-details-item.js index 10e8ca459..7d5afd287 100644 --- a/ui/components/app/gas-details-item/gas-details-item.js +++ b/ui/components/app/gas-details-item/gas-details-item.js @@ -24,7 +24,10 @@ import { useDraftTransactionWithTxParams } from '../../../hooks/useDraftTransact import { PriorityLevels } from '../../../../shared/constants/gas'; import GasDetailsItemTitle from './gas-details-item-title'; -const GasDetailsItem = ({ userAcknowledgedGasMissing = false }) => { +const GasDetailsItem = ({ + 'data-testid': dataTestId, + userAcknowledgedGasMissing = false, +}) => { const t = useI18nContext(); const draftTransaction = useSelector(getCurrentDraftTransaction); const transactionData = useDraftTransactionWithTxParams(); @@ -64,6 +67,7 @@ const GasDetailsItem = ({ userAcknowledgedGasMissing = false }) => { return ( } detailTitleColor={TextColor.textDefault} detailText={ @@ -137,6 +141,7 @@ const GasDetailsItem = ({ userAcknowledgedGasMissing = false }) => { }; GasDetailsItem.propTypes = { + 'data-testid': PropTypes.string, userAcknowledgedGasMissing: PropTypes.bool, }; diff --git a/ui/components/app/transaction-detail-item/transaction-detail-item.component.js b/ui/components/app/transaction-detail-item/transaction-detail-item.component.js index a90bad16a..ed1578b62 100644 --- a/ui/components/app/transaction-detail-item/transaction-detail-item.component.js +++ b/ui/components/app/transaction-detail-item/transaction-detail-item.component.js @@ -14,6 +14,7 @@ import { } from '../../../helpers/constants/design-system'; export default function TransactionDetailItem({ + 'data-testid': dataTestId, detailTitle = '', detailText, detailTitleColor = Color.textDefault, @@ -24,7 +25,7 @@ export default function TransactionDetailItem({ flexWidthValues = false, }) { return ( -
+
Date: Mon, 26 Jun 2023 12:54:32 -0500 Subject: [PATCH 10/30] UX: Ensure multichain native token name is always shown (#19705) * UX: Ensure multichain native token name is always shown * Fix lint --- ui/components/app/asset-list/asset-list.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ui/components/app/asset-list/asset-list.js b/ui/components/app/asset-list/asset-list.js index 1f072b95b..903c4857d 100644 --- a/ui/components/app/asset-list/asset-list.js +++ b/ui/components/app/asset-list/asset-list.js @@ -10,7 +10,6 @@ import { getNativeCurrencyImage, getDetectedTokensInCurrentNetwork, getIstokenDetectionInactiveOnNonMainnetSupportedNetwork, - getTokenList, } from '../../../selectors'; import { getNativeCurrency } from '../../../ducks/metamask/metamask'; import { useCurrencyDisplay } from '../../../hooks/useCurrencyDisplay'; @@ -62,19 +61,15 @@ const AssetList = ({ onClickAsset }) => { const primaryTokenImage = useSelector(getNativeCurrencyImage); const detectedTokens = useSelector(getDetectedTokensInCurrentNetwork) || []; - const istokenDetectionInactiveOnNonMainnetSupportedNetwork = useSelector( + const isTokenDetectionInactiveOnNonMainnetSupportedNetwork = useSelector( getIstokenDetectionInactiveOnNonMainnetSupportedNetwork, ); - const tokenList = useSelector(getTokenList); - const tokenData = Object.values(tokenList).find( - (token) => token.symbol === primaryCurrencyProperties.suffix, - ); - const title = tokenData?.name || primaryCurrencyProperties.suffix; + return ( <> onClickAsset(nativeCurrency)} - title={title} + title={nativeCurrency} primary={ primaryCurrencyProperties.value ?? secondaryCurrencyProperties.value } @@ -96,7 +91,7 @@ const AssetList = ({ onClickAsset }) => { }} /> {detectedTokens.length > 0 && - !istokenDetectionInactiveOnNonMainnetSupportedNetwork ? ( + !isTokenDetectionInactiveOnNonMainnetSupportedNetwork ? ( setShowDetectedTokens(true)} margin={4} From a9b3c8bfaf5c06a7786c09dcc141557fd929bffd Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Tue, 20 Jun 2023 18:57:14 +0200 Subject: [PATCH 11/30] Only show a Swaps notification on a supported chain (#19673) --- ui/selectors/selectors.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index c6b736878..675b52108 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -971,6 +971,7 @@ function getAllowedAnnouncementIds(state) { const currentlyUsingLedgerLive = getLedgerTransportType(state) === LedgerTransportTypes.live; const isFirefox = window.navigator.userAgent.includes('Firefox'); + const isSwapsChain = getIsSwapsChain(state); return { 1: false, @@ -993,7 +994,7 @@ function getAllowedAnnouncementIds(state) { 18: true, 19: true, 20: currentKeyringIsLedger && isFirefox, - 21: true, + 21: isSwapsChain, }; } From 425def40095267b88e3021295d73392b6f9c07a3 Mon Sep 17 00:00:00 2001 From: jiexi Date: Mon, 26 Jun 2023 11:27:03 -0700 Subject: [PATCH 12/30] Bump @metamask/providers to v11.1.0 (#19762) * Bump @metamask/providers to v11.1.0 --------- Co-authored-by: Alex --- package.json | 2 +- yarn.lock | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5cb4be44e..d7dac8e2b 100644 --- a/package.json +++ b/package.json @@ -255,7 +255,7 @@ "@metamask/permission-controller": "^4.0.0", "@metamask/phishing-controller": "^3.0.0", "@metamask/post-message-stream": "^6.0.0", - "@metamask/providers": "^10.2.1", + "@metamask/providers": "^11.1.0", "@metamask/rate-limit-controller": "^3.0.0", "@metamask/rpc-methods": "^0.32.2", "@metamask/rpc-methods-flask": "npm:@metamask/rpc-methods@0.34.0-flask.1", diff --git a/yarn.lock b/yarn.lock index 973fde720..645e9d28f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4582,6 +4582,25 @@ __metadata: languageName: node linkType: hard +"@metamask/providers@npm:^11.1.0": + version: 11.1.0 + resolution: "@metamask/providers@npm:11.1.0" + dependencies: + "@metamask/object-multiplex": ^1.1.0 + "@metamask/safe-event-emitter": ^3.0.0 + detect-browser: ^5.2.0 + eth-rpc-errors: ^4.0.2 + extension-port-stream: ^2.0.1 + fast-deep-equal: ^2.0.1 + is-stream: ^2.0.0 + json-rpc-engine: ^6.1.0 + json-rpc-middleware-stream: ^4.2.1 + pump: ^3.0.0 + webextension-polyfill: ^0.10.0 + checksum: fe62112c650d0bc2c012fcb48b6d18709866448d5ded289c85c96d683a263b63a9f60c171fb4bc2cdffc00a6c72b27343611680d72274b5778243f1366be7256 + languageName: node + linkType: hard + "@metamask/rate-limit-controller@npm:^3.0.0": version: 3.0.0 resolution: "@metamask/rate-limit-controller@npm:3.0.0" @@ -24352,7 +24371,7 @@ __metadata: "@metamask/phishing-controller": ^3.0.0 "@metamask/phishing-warning": ^2.1.0 "@metamask/post-message-stream": ^6.0.0 - "@metamask/providers": ^10.2.1 + "@metamask/providers": ^11.1.0 "@metamask/rate-limit-controller": ^3.0.0 "@metamask/rpc-methods": ^0.32.2 "@metamask/rpc-methods-flask": "npm:@metamask/rpc-methods@0.34.0-flask.1" From 3e9680c0d59fc0a78f94b350227a09b6bad16573 Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Wed, 28 Jun 2023 13:01:38 -0500 Subject: [PATCH 13/30] fix issue where non-standard NFT watchAsset requests result in notification with home screen view (#19788) --- ui/selectors/selectors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 675b52108..38722ac80 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -1,7 +1,7 @@ ///: BEGIN:ONLY_INCLUDE_IN(snaps) import { SubjectType } from '@metamask/subject-metadata-controller'; ///: END:ONLY_INCLUDE_IN -import { ApprovalType, ERC1155, ERC721 } from '@metamask/controller-utils'; +import { ApprovalType } from '@metamask/controller-utils'; import { createSelector, createSelectorCreator, @@ -574,7 +574,7 @@ export function getSuggestedNfts(state) { getUnapprovedConfirmations(state)?.filter(({ requestData, type }) => { return ( type === ApprovalType.WatchAsset && - [ERC721, ERC1155].includes(requestData?.asset?.standard) + requestData?.asset?.tokenId !== undefined ); }) || [] ); From 8ff54bcfc8e983a991e8f2858181d3355392561c Mon Sep 17 00:00:00 2001 From: Alex Donesky Date: Wed, 28 Jun 2023 12:59:54 -0500 Subject: [PATCH 14/30] Bump `@metamask/assets-controllers` one minor version to `v9.2.0` (#19807) * bump @metamask/assets-controllers one minor version to v9.2.0 * dedupe --- package.json | 2 +- yarn.lock | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index d7dac8e2b..9793ffcc5 100644 --- a/package.json +++ b/package.json @@ -229,7 +229,7 @@ "@metamask/address-book-controller": "^3.0.0", "@metamask/announcement-controller": "^4.0.0", "@metamask/approval-controller": "^3.1.0", - "@metamask/assets-controllers": "^9.0.0", + "@metamask/assets-controllers": "^9.2.0", "@metamask/base-controller": "^3.0.0", "@metamask/browser-passworder": "^4.1.0", "@metamask/contract-metadata": "^2.3.1", diff --git a/yarn.lock b/yarn.lock index 645e9d28f..66b7728c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3893,21 +3893,21 @@ __metadata: languageName: node linkType: hard -"@metamask/assets-controllers@npm:^9.0.0": - version: 9.0.0 - resolution: "@metamask/assets-controllers@npm:9.0.0" +"@metamask/assets-controllers@npm:^9.2.0": + version: 9.2.0 + resolution: "@metamask/assets-controllers@npm:9.2.0" dependencies: "@ethersproject/address": ^5.7.0 "@ethersproject/bignumber": ^5.7.0 "@ethersproject/contracts": ^5.7.0 "@ethersproject/providers": ^5.7.0 "@metamask/abi-utils": ^1.2.0 - "@metamask/approval-controller": ^3.1.0 + "@metamask/approval-controller": ^3.3.0 "@metamask/base-controller": ^3.0.0 "@metamask/contract-metadata": ^2.3.1 - "@metamask/controller-utils": ^4.0.0 + "@metamask/controller-utils": ^4.0.1 "@metamask/metamask-eth-abis": 3.0.0 - "@metamask/network-controller": ^10.0.0 + "@metamask/network-controller": ^10.2.0 "@metamask/preferences-controller": ^4.1.0 "@metamask/rpc-errors": ^5.1.1 "@metamask/utils": ^5.0.2 @@ -3922,10 +3922,10 @@ __metadata: single-call-balance-checker-abi: ^1.0.0 uuid: ^8.3.2 peerDependencies: - "@metamask/approval-controller": ^3.1.0 - "@metamask/network-controller": ^10.0.0 + "@metamask/approval-controller": ^3.3.0 + "@metamask/network-controller": ^10.2.0 "@metamask/preferences-controller": ^4.1.0 - checksum: 86f10c9f699f00b5e015fd16ec3f319240fe60251c1a74184a22ac525b32a0d111a156c615bfa9ca2df6695509ea0b13a73c61a3422c28663ca849cb2848c31f + checksum: 020e86dfc3dfa5eea927ada0b2f5a00642495589edbf5ab54f160e65e5e904502682f11ebebe10d892a091d05eb10306cf92d403a2ac8434048cd3e1f3df3f89 languageName: node linkType: hard @@ -4356,12 +4356,12 @@ __metadata: languageName: node linkType: hard -"@metamask/network-controller@npm:^10.0.0": - version: 10.0.0 - resolution: "@metamask/network-controller@npm:10.0.0" +"@metamask/network-controller@npm:^10.1.0, @metamask/network-controller@npm:^10.2.0": + version: 10.2.0 + resolution: "@metamask/network-controller@npm:10.2.0" dependencies: "@metamask/base-controller": ^3.0.0 - "@metamask/controller-utils": ^4.0.0 + "@metamask/controller-utils": ^4.0.1 "@metamask/eth-json-rpc-infura": ^8.0.0 "@metamask/eth-json-rpc-middleware": ^11.0.0 "@metamask/eth-json-rpc-provider": ^1.0.0 @@ -4375,7 +4375,7 @@ __metadata: immer: ^9.0.6 json-rpc-engine: ^6.1.0 uuid: ^8.3.2 - checksum: 4ffc32d81eeb108ad8b11c6dcd368f8aafb016a10fd0464bd9afd20261794911017f19898a474985ea3d8d3d1094b336cad7e9064e1621c662042224b6ca3725 + checksum: 6474125845d838564ef60105b5914369aa650a6769df5f3f2a471839f351d798984faa5e3184054a5bfb4ec738e2a50c6fbf31f9eceb9cea4c227651105295dc languageName: node linkType: hard @@ -24337,7 +24337,7 @@ __metadata: "@metamask/address-book-controller": ^3.0.0 "@metamask/announcement-controller": ^4.0.0 "@metamask/approval-controller": ^3.1.0 - "@metamask/assets-controllers": ^9.0.0 + "@metamask/assets-controllers": ^9.2.0 "@metamask/auto-changelog": ^2.1.0 "@metamask/base-controller": ^3.0.0 "@metamask/browser-passworder": ^4.1.0 From a7d9c9cc111951b153abc4725e2132b088489042 Mon Sep 17 00:00:00 2001 From: Nidhi Kumari Date: Wed, 28 Jun 2023 20:41:19 +0530 Subject: [PATCH 15/30] removed margin for popup view (#19804) --- ui/components/multichain/app-header/app-header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/components/multichain/app-header/app-header.js b/ui/components/multichain/app-header/app-header.js index e26141c4b..3b98c957d 100644 --- a/ui/components/multichain/app-header/app-header.js +++ b/ui/components/multichain/app-header/app-header.js @@ -151,7 +151,7 @@ export const AppHeader = ({ location }) => { // This is required to ensure send and confirmation screens // look as desired - const headerBottomMargin = disableNetworkPicker ? 4 : 0; + const headerBottomMargin = !popupStatus && disableNetworkPicker ? 4 : 0; return ( <> From 9cadb4ffe4c140866e8e96e024a40d1478b14aca Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 28 Jun 2023 18:59:06 -0230 Subject: [PATCH 16/30] Update yarn.lock following 8ff54bcfc8 --- yarn.lock | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 66b7728c7..5261ce9df 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4356,7 +4356,7 @@ __metadata: languageName: node linkType: hard -"@metamask/network-controller@npm:^10.1.0, @metamask/network-controller@npm:^10.2.0": +"@metamask/network-controller@npm:^10.2.0": version: 10.2.0 resolution: "@metamask/network-controller@npm:10.2.0" dependencies: @@ -35044,6 +35044,13 @@ __metadata: languageName: node linkType: hard +"webextension-polyfill@npm:^0.10.0": + version: 0.10.0 + resolution: "webextension-polyfill@npm:0.10.0" + checksum: 4a59036bda571360c2c0b2fb03fe1dc244f233946bcf9a6766f677956c40fd14d270aaa69cdba95e4ac521014afbe4008bfa5959d0ac39f91c990eb206587f91 + languageName: node + linkType: hard + "webextension-polyfill@npm:^0.7.0": version: 0.7.0 resolution: "webextension-polyfill@npm:0.7.0" From af2c87d77726413c953b32c56072571131b2cea5 Mon Sep 17 00:00:00 2001 From: Monte Lai Date: Thu, 29 Jun 2023 21:24:08 +0800 Subject: [PATCH 17/30] [FLASK] Add Snaps Keyring (#19710) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * flask - add restricted snap_manageAccounts * snap keyring: use local snap keyring instead of package * mvp snap-keyring * fixed the easier lint errors * fix missing permission text * add removal function * update snap keyring * update dep * update git link * update messages and remove snap keyring from lib * set snapprovider as soon as possible * chore: update snap keyring dependency * chore: pass SnapController to SnapKeyring constructor * chore: update deps and comment line (wip) * fix latest update for snaps and remove setController * update yarn lock * add routes * add messages * add message * add snap account detail page * add snap account card * add snap account page * update route * add background * use css grid * update snap text styling * fix lint * remove unused import * change manage link to go to snap * add types for react-router-dom * add link to settings * add breadcrumb to header * add popover * add prop types * add link to propTypes * fix icon in header and tag * update popover * update yarn.lock * add link to account list menu * update from deprecated * add add-snap-popup * use popoverheader * fix lint * update to use modal instead of popup * add install snap * remove export of DeferredPromise * change snap keyring to its own enum * update imports and fences * fix snapId and route * fix header and button for snapCard * hide app header on AddSnapAccountPage * update icon * match path to SnapAccountDetail * set getting started button to close modal * fix key prop warning * add By Metamask message * fix label * add fence to snapkeyringtype * update yarn.lock * refactor removeAccount and static snap list * update removeSnap * feat: remove associated accounts when snap is removed * add get snaps installed to snaps page * fix updateAvailable * add tests to ui components * update test * update scss * udpate config snap popup style * fixed https://www.notion.so/Show-pop-up-only-once-c6aa8494486a4ece8a5c5e35fea56ab5 * update accountListMenu click to open tab or push depending on environment * update yark.lock * remove unused uuid * update lock * update eth-snap-keyring * udpate install from snap page * update to install to use popup * use release versino of eth-snap-keyring * chore: bump snaps-utils version to `0.34.1-flask.1` * update configure snap * chore: update eth-snap-keyring * chore: update policies * fix: remove unused * fix: fix snap-account-detail-page test * fix: fix styles * chore: remove swappable-obj-proxy * fix: fix duplicate entry * fix: disable export private key for snaps account * feat: shuffle snap lists on every reload * fix: configure not popping up * refactor: snapsAddSnapAccountModalDismissal into action and selector * fix: E2BIG when running prettier * fix: lint default export or add-snap-account-modal * fix: lint, remove vendor prefix * fix: fix snapCreatedByMetamask to snapCreatedByMetaMask * Add `manageAccounts` RPC method (#19724) * Update dependencies * Remove snap-keyring-permissions * Update dependencies * Update dependencies * Update imports * removed portfolio link from wallet view (#19716) * removed portfolio link from wallet view * removed unused code * updated test * updated spec file * updated test * Validate LavaMoat policies on each PR (#19703) * Validate LavaMoat policies on each PR The LavaMoat policies are now validated on every PR. This makes it easier to validate policy changes, as they should always correspond with the changes made in the PR (unlike today, when they could be due to a change in platform or a previous PR). Closes #19680 * Update LavaMoat policies --------- Co-authored-by: MetaMask Bot * fix(action): add required permissions to remove labels (#19728) * Fix dependencies * signature approved metrics e2e test (#19628) * Update dependencies * Integrate Snow with LavaMoat scuttling protection (#17969) * Update lavamoat policies * Security Provider cleanup (#19694) * security-prov: isFlaggedSecurityProviderResponse * security-prov: create shared/modules/util * security prov: rn isFlagged -> isSuspcious - util fn returns true if response is not verified and flagged * security prov: add util test and support undefined param * security prov: reorg util fn - no logic changes * Update LavaMoat policies (#19744) Update LavaMoat policies to match what CI expects. * Replacing deprecated constants & creating stories (#19686) * Replacing deprecated constants & creating stories * updating snapshot * fix: fix imports * chore: update policy.json * fix: move SmartTransactionController out of snaps code fence * fix: yarn.lock dedupe * fix: lavamoat policy * fix: update test * fix: remove snapshot, the list of snaps are always randomized. * fix: resole snaps-controller to use flask --------- Co-authored-by: Nidhi Kumari Co-authored-by: Mark Stacey Co-authored-by: MetaMask Bot Co-authored-by: Gauthier Petetin Co-authored-by: Brad Decker Co-authored-by: weizman Co-authored-by: Ariella Vu <20778143+digiwand@users.noreply.github.com> Co-authored-by: Dhruv <79097544+dhruvv173@users.noreply.github.com> Co-authored-by: Monte Lai * Update LavaMoat policies * chore: fix webapp policy.json * feat: add snap label test * feat: test to disable export private key for snap accounts * feat: add snap account link test in account-list-menu * fix: add fence for setSnapsAddSnapAccountModalDismissed * fix: remove comments * fix: move routes into snaps fence * feat: use snap registry * fix: account snap identification * chore: add `keyring-snaps` feature flag * fix: remove unneeded spread * Disable warn logs in content-script (#19754) * Use Yarn caching in GitHub Actions (#19662) GitHub actions that install dependencies will now also cache those dependencies using the standard strategy for Yarn (which is to hash the lockfile). This matches the module template (see https://github.com/MetaMask/metamask-module-template/pull/145 for details). This should have no functional impact except that this action will run faster when dependencies are unchanged. * Fixing misspelling in 10.28.0 changelog notes (#19756) * Add `tokenId` type validation in `wallet_watchAsset` middleware (#19738) * Remove unused GitHub Action workflow (#19660) This GitHub action workflow was disabled, but was still running setup steps. It has now been removed entirely. We can re-introduce it again later once the problem that led to it being disabled has been fixed. The associated npm script and JavaScript module have been removed as well. * Fix #847 - Don't show account address on token pages (#19740) Co-authored-by: Nidhi Kumari * Deprecating FormField and fixing console error (#19739) * Deprecating FormField and fixing console error * Updating snapshots * updated linea image for token and badge (#19717) * updated linea image for token and badge * replaced hardcoded string with constant * UI updates for contacts Page (#19646) * updated contacts flow update * json file updates * updated contacts edit and view list * keep contacts tab selected * lint fix * replaced hardcoded strings with constant * updated padding in box * Replacing deprecated components and fixing prop errors (#19745) * Use `snaps@0.35.2-flask.1` and `snaps@1.0.0-prerelease.1` (#19734) * snaps@0.35.0-flask.1 * Update LavaMoat policies * Update stable snaps packages to 1.0.0-prerelease.1 * Update LavaMoat policies * Fix lint * snaps@0.35.2 * Exclude snap_manageAccounts * Code fencing * Revert removing endowment:keyring exclusion * Bump iframe URLs * UX: Ensure multichain native token name is always shown (#19705) * UX: Ensure multichain native token name is always shown * Fix lint * UX Multichain: fixed padding for edit screen (#19707) * fixed padding for edit screen * Use network picker for header trigger * Fix swaps display * updated snapshot --------- Co-authored-by: David Walsh * Bump @metamask/providers to v11.1.0 (#19762) * Bump @metamask/providers to v11.1.0 --------- Co-authored-by: Alex * Fix fallback gas estimation (#19746) * Fix fallback gas estimation Our fallback gas estimation was failing due to a bug in the `@metamask/controller-utils` package. This was causing gas estimation to fail completely on certain networks (those not supported by our gas estimation APIs and non EIP-1559 compatibile), and it was causing the fallback gas estimation operation (in case our API was down) to fail across all networks. Fixes https://github.com/MetaMask/metamask-extension/issues/19735 * Add e2e tests E2E tests have been added to capture gas estimation. Cases are added for our API, for the fallback estimate, and for non-EIP-1559 estimates. As part of this work, the legacy gas API had to be disabled. This was being used in e2e tests but was dead code in production. It needed to be disabled to ensure the code under test was reachable. * Fix gas API referenced in e2e test * Update unit test snapshots * Update Label component font weight from bold to medium (#19731) * Update Label component font weight from bold to medium * update snapshot * fix snapshots * fix snapshots 2 * Removeing deprecated constants for enums --------- Co-authored-by: georgewrmarshall * Part of #17670: Replace Typography with Text component in CancelSpeedupPopover (#18638) * create story * replace Typography with Text component * review changes * replace CSS with props styling * use `Button` from `component-library` * tooltip HTML refactor with `component-library` components * remove whitespace in story * strong tag support within Text component * addresses #18651 * taken from #18752 as suggested in https://github.com/MetaMask/metamask-extension/pull/18638#discussion_r1176334805 * replace `strong` with new `Text as="strong"` * remove unneccessary css from fa564e3f036f1439f9f220cca23595b508760614 * add text variant definition * Updating text variant of button * restrore proper spacing between elements * Quick fix for test * Adding key --------- Co-authored-by: georgewrmarshall Co-authored-by: Garrett Bear * Issue 17670 replace typography with text (#19433) * Replace Typograph with Text component in numeric-input-component.js * Replace Typography with Text component in signature-request-message.js * Replace Typography with Text component in signature-request.component.js * Replacing deprecating constants and fixing some signature story warnings * Updating snapshot * Fixing import --------- Co-authored-by: georgewrmarshall Co-authored-by: Garrett Bear * Part of #18714: Replacing deprecated constants in `confirm-subtitle` folder (#19699) * repalcing deprecated constants * resolve issue * lint fixes --------- Co-authored-by: georgewrmarshall * Part of #17670: Replace Typography with Text component in: callout.js (#18912) * Part of #17670: Replace Typography with Text component in: callout.js * Update ui/components/ui/callout/callout.js Co-authored-by: Danica Shen * Update callout.js * Updating snapshot and deprecating component * Updating snapshot and deprecating component --------- Co-authored-by: Danica Shen Co-authored-by: George Marshall Co-authored-by: Garrett Bear * [MMI] Added code fences in whats new popup (#19581) * added code fences in whats new popup * Improved code * Added missing prop * Update LavaMoat policies * updated functions by using an options object for the rendering functions in order to bypass possible typsecript issues --------- Co-authored-by: MetaMask Bot * Updated action list in token, NFTs and activity view (#19702) * updated ui for nft import button * updated no nft image found in the center * updated footer for all screens in tabs * removed no nft state from nft tab * updated snapshot * lint fix * fixed e2e tests * fixed prep build error * removed no nfts yet test * updated tabs * fixed prod error * updated no nft screen * changed button size to md * fix: change 'M' to '?' * fix: update fence to keyring-snaps * chore: rename folder * fix: typo * chore: remove logs * feat: add metamask developer constant * fix: sass keyring-snap path * chore: update yarn.lock * fix: remove alias * feat: add KEYRING_SNAPS_REGISTRY_URL env * fix: nested fence * feat: add snap manageAccount e2e (#19777) * feat: add snap manageAccount e2e * feat: update link * fix: lint * fix: get values of restrictedMethodPermissionBuilders * fix: add fence to perferences * fix: stop shuffle * fix: remove KEYRING_SNAPS_REGISTRY_URL from metamaskRc * fix: use permissions to determine account snaps * fix: remove shuffle * fix: add comments to fences in excluded snap permission. * chore: fix policy.json * fix: fix snap-account-detail test * fix: lint * fix: snap accoutn detail page test * Update LavaMoat policies * Update ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.test.tsx Co-authored-by: Maarten Zuidhoorn * Update ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.test.tsx Co-authored-by: Maarten Zuidhoorn * fix: remove fence from isAbleToExportAccount * chore: remove comment line * fix: dismiss snap modal * fix: try catch for scroll * fix: icon for manageAccount * fix: update `handleSnapRequest` to make `params` optional and add `id` * fix: lint for uuid * fix: remove arg in saveSnapKeyring * fix: add fence for uuidV4 * chore: bump dep * fix: permission_manageAccounts message and icon * chore: update registry link * chore: convert address to lowercase * fix: change icon * chore: bump eth-snap-keyring * chore: update webapp policy.json * Update ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.test.tsx Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com> * fix: update fences * fix: nested fence * Update app/_locales/en/messages.json Co-authored-by: Maarten Zuidhoorn * Update app/_locales/en/messages.json Co-authored-by: Maarten Zuidhoorn * Update app/_locales/en/messages.json Co-authored-by: Maarten Zuidhoorn * Update app/_locales/en/messages.json Co-authored-by: Maarten Zuidhoorn * Update ui/components/multichain/account-details/account-details-display.js Co-authored-by: Maarten Zuidhoorn * Update ui/pages/keyring-snaps/snap-account-detail-page/header.tsx Co-authored-by: Maarten Zuidhoorn * Update ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.tsx Co-authored-by: Maarten Zuidhoorn * fix: rename and added jsdoc * fix: add fence to snap label * fix: remove comment * fix: change pixel to int and remove unused class * fix: lint * fix: create two tests for main and flask restricted methods * fix: remove fence in test * fix: lint header * feat: allow `metamask.github.io` in manifest * fix: remove comment * fix: rename isAbleToExportAccount * chore: use a more restrictive registry URL * fix: change to && not || * fix: remove unused * fix: move keyring snaps URL to Flask's base manifest * fix: use fetch instead of fetchWithCache * fix: lint --------- Co-authored-by: kumavis Co-authored-by: Howard Braham Co-authored-by: Daniel Rocha <68558152+danroc@users.noreply.github.com> Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com> Co-authored-by: Nidhi Kumari Co-authored-by: Mark Stacey Co-authored-by: MetaMask Bot Co-authored-by: Gauthier Petetin Co-authored-by: Brad Decker Co-authored-by: weizman Co-authored-by: Ariella Vu <20778143+digiwand@users.noreply.github.com> Co-authored-by: Dhruv <79097544+dhruvv173@users.noreply.github.com> Co-authored-by: ryanml Co-authored-by: Alex Donesky Co-authored-by: David Walsh Co-authored-by: George Marshall Co-authored-by: Frederik Bolding Co-authored-by: jiexi Co-authored-by: jainex Co-authored-by: Matthias Kretschmann Co-authored-by: Garrett Bear Co-authored-by: Ujwal Kumar Co-authored-by: rohit kerkar <129620973+rohiiittttt@users.noreply.github.com> Co-authored-by: Harsh Shukla <125105825+PrgrmrHarshShukla@users.noreply.github.com> Co-authored-by: Danica Shen Co-authored-by: Albert Olivé Co-authored-by: Maarten Zuidhoorn --- app/_locales/en/messages.json | 78 ++++++ app/images/add-snaps-image.svg | 218 ++++++++++++++++ app/images/snap-account-page.svg | 19 ++ .../permissions/snaps/snap-permissions.js | 2 +- app/scripts/controllers/preferences.js | 24 ++ app/scripts/metamask-controller.js | 62 ++++- builds.yml | 7 + lavamoat/browserify/beta/policy.json | 111 +++++--- lavamoat/browserify/desktop/policy.json | 166 +++++++++--- lavamoat/browserify/flask/policy.json | 166 +++++++++--- lavamoat/browserify/main/policy.json | 111 +++++--- lavamoat/browserify/mmi/policy.json | 111 +++++--- package.json | 5 +- shared/constants/app.ts | 6 + shared/constants/keyring.ts | 9 + shared/constants/permissions.test.js | 31 ++- shared/constants/permissions.ts | 3 + shared/constants/snaps/permissions.ts | 2 +- test/data/mock-state.json | 20 ++ test/e2e/snaps/enums.js | 2 + .../e2e/snaps/test-snap-manageAccount.spec.js | 113 +++++++++ .../app/account-menu/keyring-label.js | 61 +++++ .../configure-snap-popup.test.tsx | 68 +++++ .../configure-snap-popup.tsx | 99 ++++++++ .../app/configure-snap-popup/index.js | 1 + .../account-details-modal.component.js | 12 +- .../account-details-modal.test.js | 129 ++++++++++ .../account-details-display.js | 4 +- .../account-list-item/account-list-item.js | 4 + .../account-list-item.test.js | 13 + .../account-list-menu/account-list-menu.js | 27 ++ .../account-list-menu.test.js | 53 +++- ui/helpers/constants/routes.ts | 10 + ui/helpers/utils/permission.js | 9 + ui/helpers/utils/util.js | 10 + .../add-snap-account-modal.stories.tsx | 36 +++ .../add-snap-account-modal.tsx | 70 +++++ .../add-snap-account-modal/index.ts | 1 + ui/pages/keyring-snaps/add-snap-account.tsx | 38 +++ ui/pages/keyring-snaps/constants.ts | 1 + ui/pages/keyring-snaps/index.scss | 2 + ui/pages/keyring-snaps/index.ts | 1 + .../new-snap-account-page/index.ts | 2 + .../new-snap-account-page.scss | 32 +++ .../new-snap-account-page.test.tsx | 145 +++++++++++ .../new-snap-account-page.tsx | 134 ++++++++++ .../snap-account-detail-page.test.tsx.snap | 232 +++++++++++++++++ .../snap-account-detail-page/detail.tsx | 22 ++ .../snap-account-detail-page/header.tsx | 214 ++++++++++++++++ .../snap-account-detail-page/index.ts | 1 + .../snap-account-detail-page.scss | 24 ++ .../snap-account-detail-page.test.tsx | 239 ++++++++++++++++++ .../snap-account-detail-page.tsx | 147 +++++++++++ .../__snapshots__/snap-card.test.tsx.snap | 54 ++++ ui/pages/keyring-snaps/snap-card/index.ts | 1 + .../snap-card/snap-card.test.tsx | 75 ++++++ .../keyring-snaps/snap-card/snap-card.tsx | 139 ++++++++++ ui/pages/pages.scss | 1 + ui/pages/routes/routes.component.js | 14 + ui/selectors/selectors.js | 12 + ui/store/actions.ts | 67 ++++- yarn.lock | 89 +++++-- 62 files changed, 3323 insertions(+), 236 deletions(-) create mode 100644 app/images/add-snaps-image.svg create mode 100644 app/images/snap-account-page.svg create mode 100644 test/e2e/snaps/test-snap-manageAccount.spec.js create mode 100644 ui/components/app/account-menu/keyring-label.js create mode 100644 ui/components/app/configure-snap-popup/configure-snap-popup.test.tsx create mode 100644 ui/components/app/configure-snap-popup/configure-snap-popup.tsx create mode 100644 ui/components/app/configure-snap-popup/index.js create mode 100644 ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.stories.tsx create mode 100644 ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.tsx create mode 100644 ui/pages/keyring-snaps/add-snap-account-modal/index.ts create mode 100644 ui/pages/keyring-snaps/add-snap-account.tsx create mode 100644 ui/pages/keyring-snaps/constants.ts create mode 100644 ui/pages/keyring-snaps/index.scss create mode 100644 ui/pages/keyring-snaps/index.ts create mode 100644 ui/pages/keyring-snaps/new-snap-account-page/index.ts create mode 100644 ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.scss create mode 100644 ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.test.tsx create mode 100644 ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.tsx create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/detail.tsx create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/header.tsx create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/index.ts create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.scss create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.test.tsx create mode 100644 ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.tsx create mode 100644 ui/pages/keyring-snaps/snap-card/__snapshots__/snap-card.test.tsx.snap create mode 100644 ui/pages/keyring-snaps/snap-card/index.ts create mode 100644 ui/pages/keyring-snaps/snap-card/snap-card.test.tsx create mode 100644 ui/pages/keyring-snaps/snap-card/snap-card.tsx diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index 3405e0712..b187737be 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -271,6 +271,9 @@ "addNfts": { "message": "Add NFTs" }, + "addSnapAccountModalDescription": { + "message": "Discover options to keep your account secure with MetaMask Snaps" + }, "addSuggestedNFTs": { "message": "Add suggested NFTs" }, @@ -706,6 +709,21 @@ "complianceSettingsExplanation": { "message": "Change your settings or view reports by opening up Codefi Compliance or disconnect below." }, + "configureSnapPopupDescription": { + "message": "You're now leaving MetaMask to configure this snap." + }, + "configureSnapPopupInstallDescription": { + "message": "You're now leaving MetaMask to install this snap." + }, + "configureSnapPopupInstallTitle": { + "message": "Install snap" + }, + "configureSnapPopupLink": { + "message": "Click this link to continue:" + }, + "configureSnapPopupTitle": { + "message": "Configure snap" + }, "confirm": { "message": "Confirm" }, @@ -1701,6 +1719,9 @@ "general": { "message": "General" }, + "getStarted": { + "message": "Get started" + }, "globalTitle": { "message": "Global menu" }, @@ -3126,6 +3147,10 @@ "message": "Allow the snap to run indefinitely while, for example, processing large amounts of data.", "description": "An extended description for the `endowment:long-running` permission" }, + "permission_manageAccounts": { + "message": "Add and control Ethereum accounts", + "description": "The description for `snap_manageAccounts` permission" + }, "permission_manageBip32Keys": { "message": "Control your accounts and assets under $1 ($2).", "description": "The description for the `snap_getBip32Entropy` permission. $1 is a derivation path, e.g. 'm/44'/0'/0''. $2 is the elliptic curve name, e.g. 'secp256k1'." @@ -3739,6 +3764,9 @@ "message": "Set a spending cap for your $1", "description": "$1 is a token symbol" }, + "settingAddSnapAccount": { + "message": "Add snap account" + }, "settings": { "message": "Settings" }, @@ -3843,6 +3871,9 @@ "smartSwapsSubDescription": { "message": "* Smart Swaps will attempt to submit your transaction privately, multiple times. If all attempts fail, the transaction will be broadcast publicly to ensure your Swap successfully goes through." }, + "snapConfigure": { + "message": "Configure" + }, "snapConnectionWarning": { "message": "$1 wants to connect to $2. Only continue if you trust this website.", "description": "$2 is the snap and $1 is the dapp requesting connection to the snap." @@ -3851,6 +3882,47 @@ "message": "This content is coming from $1", "description": "This is shown when a snap shows transaction insight information in the confirmation UI. $1 is a link to the snap's settings page with the link text being the name of the snap." }, + "snapCreateAccountSubtitle": { + "message": "Choose how to secure your new account using MetaMask Snaps." + }, + "snapCreateAccountTitle": { + "message": "Create a $1 account", + "description": "Title of the Create Snap Account Page, $1 is the text using a different color" + }, + "snapCreateAccountTitle2": { + "message": "snap", + "description": "$1 of the snapCreateAccountTitle" + }, + "snapCreatedByMetaMask": { + "message": "By MetaMask" + }, + "snapDetailAudits": { + "message": "Audit" + }, + "snapDetailDeveloper": { + "message": "Developer" + }, + "snapDetailLastUpdated": { + "message": "Updated" + }, + "snapDetailManageSnap": { + "message": "Manage snap" + }, + "snapDetailTags": { + "message": "Tags" + }, + "snapDetailVersion": { + "message": "Version" + }, + "snapDetailWebsite": { + "message": "Website" + }, + "snapDetailsCreateASnapAccount": { + "message": "Create a Snap Account" + }, + "snapDetailsInstalled": { + "message": "Installed" + }, "snapError": { "message": "Snap Error: '$1'. Error Code: '$2'", "description": "This is shown when a snap encounters an error. $1 is the error message from the snap, and $2 is the error code." @@ -3892,6 +3964,9 @@ "message": "Installation failed", "description": "Error title used when snap installation fails." }, + "snapIsAudited": { + "message": "Audited" + }, "snapResultError": { "message": "Error" }, @@ -3904,6 +3979,9 @@ "snapUpdate": { "message": "Update snap" }, + "snapUpdateAvailable": { + "message": "Update available" + }, "snapUpdateErrorDescription": { "message": "$1 couldn’t be updated.", "description": "Error description used when snap update fails. $1 is the snap name." diff --git a/app/images/add-snaps-image.svg b/app/images/add-snaps-image.svg new file mode 100644 index 000000000..7a59fef9e --- /dev/null +++ b/app/images/add-snaps-image.svg @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/images/snap-account-page.svg b/app/images/snap-account-page.svg new file mode 100644 index 000000000..f0df8e6b1 --- /dev/null +++ b/app/images/snap-account-page.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/app/scripts/controllers/permissions/snaps/snap-permissions.js b/app/scripts/controllers/permissions/snaps/snap-permissions.js index cfada9365..4788608d0 100644 --- a/app/scripts/controllers/permissions/snaps/snap-permissions.js +++ b/app/scripts/controllers/permissions/snaps/snap-permissions.js @@ -1,8 +1,8 @@ -import { endowmentPermissionBuilders } from '@metamask/snaps-controllers'; import { restrictedMethodPermissionBuilders, selectHooks, } from '@metamask/rpc-methods'; +import { endowmentPermissionBuilders } from '@metamask/snaps-controllers'; import { ExcludedSnapEndowments, ExcludedSnapPermissions, diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 85b2ccc43..052f218a3 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -4,6 +4,9 @@ import { IPFS_DEFAULT_GATEWAY_URL } from '../../../shared/constants/network'; import { LedgerTransportTypes } from '../../../shared/constants/hardware-wallets'; import { ThemeType } from '../../../shared/constants/preferences'; import { shouldShowLineaMainnet } from '../../../shared/modules/network.utils'; +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +import { KEYRING_SNAPS_REGISTRY_URL } from '../../../shared/constants/app'; +///: END:ONLY_INCLUDE_IN export default class PreferencesController { /** @@ -65,8 +68,12 @@ export default class PreferencesController { ledgerTransportType: window.navigator.hid ? LedgerTransportTypes.webhid : LedgerTransportTypes.u2f, + snapRegistryList: {}, transactionSecurityCheckEnabled: false, theme: ThemeType.os, + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + snapsAddSnapAccountModalDismissed: false, + ///: END:ONLY_INCLUDE_IN isLineaMainnetReleased: false, ...opts.initState, }; @@ -511,6 +518,23 @@ export default class PreferencesController { return this.store.getState().disabledRpcMethodPreferences; } + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + setSnapsAddSnapAccountModalDismissed(value) { + this.store.updateState({ snapsAddSnapAccountModalDismissed: value }); + } + + async updateSnapRegistry() { + let snapRegistry; + try { + snapRegistry = await fetch(KEYRING_SNAPS_REGISTRY_URL); + } catch (error) { + console.error(`Failed to fetch registry: `, error); + snapRegistry = {}; + } + this.store.updateState({ snapRegistryList: snapRegistry }); + } + ///: END:ONLY_INCLUDE_IN + // // PRIVATE METHODS // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b71dbbe7d..c60ed5fc6 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -49,13 +49,12 @@ import { SubjectMetadataController, SubjectType, } from '@metamask/subject-metadata-controller'; +import SmartTransactionsController from '@metamask/smart-transactions-controller'; ///: BEGIN:ONLY_INCLUDE_IN(snaps) import { encrypt, decrypt } from '@metamask/browser-passworder'; import { RateLimitController } from '@metamask/rate-limit-controller'; import { NotificationController } from '@metamask/notification-controller'; -///: END:ONLY_INCLUDE_IN -import SmartTransactionsController from '@metamask/smart-transactions-controller'; -///: BEGIN:ONLY_INCLUDE_IN(snaps) + import { CronjobController, JsonSnapsRegistry, @@ -63,6 +62,9 @@ import { IframeExecutionService, } from '@metamask/snaps-controllers'; ///: END:ONLY_INCLUDE_IN +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +import { SnapKeyring } from '@metamask/eth-snap-keyring'; +///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) import { @@ -772,6 +774,16 @@ export default class MetamaskController extends EventEmitter { ///: END:ONLY_INCLUDE_IN } + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + additionalKeyrings.push( + (() => { + const builder = () => new SnapKeyring(this.snapController); + builder.type = SnapKeyring.type; + return builder; + })(), + ); + ///: END:ONLY_INCLUDE_IN + this.keyringController = new KeyringController({ keyringBuilders: additionalKeyrings, initState: initState.KeyringController, @@ -1679,7 +1691,28 @@ export default class MetamaskController extends EventEmitter { }); } + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + /** + * Initialize the snap keyring if it is not present. + */ + async getSnapKeyring() { + if (!this.snapKeyring) { + let [snapKeyring] = this.keyringController.getKeyringsByType( + KeyringType.snap, + ); + if (!snapKeyring) { + snapKeyring = await this.keyringController.addNewKeyring( + KeyringType.snap, + ); + } + this.snapKeyring = snapKeyring; + } + return this.snapKeyring; + } + ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(snaps) + /** * Constructor helper for getting Snap permission specifications. */ @@ -1735,6 +1768,16 @@ export default class MetamaskController extends EventEmitter { this.controllerMessenger, 'SnapController:updateSnapState', ), + ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + getSnapKeyring: this.getSnapKeyring.bind(this), + saveSnapKeyring: async () => { + await this.keyringController.persistAllKeyrings(); + await this.keyringController._updateMemStoreKeyrings(); + await this.keyringController.fullUpdate(); + }, + ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(snaps) }), }; } @@ -2167,6 +2210,13 @@ export default class MetamaskController extends EventEmitter { preferencesController.setTransactionSecurityCheckEnabled.bind( preferencesController, ), + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + setSnapsAddSnapAccountModalDismissed: + preferencesController.setSnapsAddSnapAccountModalDismissed.bind( + preferencesController, + ), + ///: END:ONLY_INCLUDE_IN + // AssetsContractController getTokenStandardAndDetails: this.getTokenStandardAndDetails.bind(this), @@ -2408,6 +2458,11 @@ export default class MetamaskController extends EventEmitter { dismissNotifications: this.dismissNotifications.bind(this), markNotificationsAsRead: this.markNotificationsAsRead.bind(this), ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + updateSnapRegistry: this.preferencesController.updateSnapRegistry.bind( + preferencesController, + ), + ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(desktop) // Desktop getDesktopEnabled: this.desktopController.getDesktopEnabled.bind( @@ -2771,6 +2826,7 @@ export default class MetamaskController extends EventEmitter { // set new identities this.preferencesController.setAddresses(accounts); this.selectFirstIdentity(); + return vault; } finally { releaseLock(); diff --git a/builds.yml b/builds.yml index ca31ff44d..019da9378 100644 --- a/builds.yml +++ b/builds.yml @@ -46,6 +46,7 @@ buildTypes: - snaps - desktop - build-flask + - keyring-snaps env: - INFURA_FLASK_PROJECT_ID - SEGMENT_FLASK_WRITE_KEY @@ -64,6 +65,7 @@ buildTypes: - snaps - desktop - build-flask + - keyring-snaps env: - INFURA_FLASK_PROJECT_ID - SEGMENT_FLASK_WRITE_KEY @@ -138,6 +140,11 @@ features: - src: ./app/build-types/flask/images/ dest: images - ./{app,shared,ui}/**/flask/** + keyring-snaps: + env: + - KEYRING_SNAPS_REGISTRY_URL: https://metamask.github.io/keyring-snaps-registry/prod/registry.json + assets: + - ./{app,shared,ui}/**/keyring-snaps/** # Env variables that are required for all types of builds # diff --git a/lavamoat/browserify/beta/policy.json b/lavamoat/browserify/beta/policy.json index 06df25223..f3373a420 100644 --- a/lavamoat/browserify/beta/policy.json +++ b/lavamoat/browserify/beta/policy.json @@ -933,7 +933,7 @@ "@metamask/eth-json-rpc-middleware>@metamask/utils": true, "@metamask/eth-json-rpc-middleware>pify": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "eth-rpc-errors": true, "json-rpc-engine": true, "vinyl>clone": true @@ -955,9 +955,9 @@ "packages": { "@metamask/browser-passworder": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>obs-store": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, "browserify>events": true } }, @@ -968,7 +968,7 @@ "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/scure-bip39": true, "browserify>buffer": true } @@ -1010,11 +1010,44 @@ "crypto": true } }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "browserify>buffer": true, "browserify>events": true, "ethereumjs-wallet>randombytes": true @@ -1107,6 +1140,39 @@ "ganache>secp256k1>elliptic": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-token-tracker": { "globals": { "console.warn": true @@ -1234,42 +1300,9 @@ "browserify>events": true } }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": true, - "bn.js": true, - "browserify>buffer": true, - "eth-sig-util>tweetnacl": true, - "eth-sig-util>tweetnacl-util": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": { - "globals": { - "TextDecoder": true, - "crypto": true - }, - "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { - "globals": { - "TextEncoder": true, - "crypto": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": { - "packages": { - "browserify>buffer": true, - "ethjs>ethjs-util>is-hex-prefixed": true, - "ethjs>ethjs-util>strip-hex-prefix": true - } - }, "@metamask/eth-trezor-keyring>@trezor/connect-plugin-ethereum": { "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true } }, "@metamask/eth-trezor-keyring>@trezor/connect-web": { @@ -1612,7 +1645,7 @@ "setTimeout": true }, "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>@metamask/utils": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>eth-json-rpc-middleware>pify": true, "@metamask/safe-event-emitter": true, diff --git a/lavamoat/browserify/desktop/policy.json b/lavamoat/browserify/desktop/policy.json index 99706027e..aa3b955d2 100644 --- a/lavamoat/browserify/desktop/policy.json +++ b/lavamoat/browserify/desktop/policy.json @@ -1004,7 +1004,7 @@ "@metamask/eth-json-rpc-middleware>@metamask/utils": true, "@metamask/eth-json-rpc-middleware>pify": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "eth-rpc-errors": true, "json-rpc-engine": true, "vinyl>clone": true @@ -1026,9 +1026,9 @@ "packages": { "@metamask/browser-passworder": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>obs-store": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, "browserify>events": true } }, @@ -1039,7 +1039,7 @@ "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/scure-bip39": true, "browserify>buffer": true } @@ -1081,11 +1081,44 @@ "crypto": true } }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "browserify>buffer": true, "browserify>events": true, "ethereumjs-wallet>randombytes": true @@ -1178,6 +1211,94 @@ "ganache>secp256k1>elliptic": true } }, + "@metamask/eth-snap-keyring": { + "globals": { + "console.error": true, + "console.warn": true + }, + "packages": { + "@ethereumjs/tx": true, + "@metamask/eth-snap-keyring>@metamask/keyring-api": true, + "@metamask/eth-snap-keyring>@metamask/utils": true, + "@metamask/eth-snap-keyring>uuid": true, + "browserify>events": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, + "@metamask/eth-snap-keyring>@metamask/keyring-api": { + "packages": { + "@metamask/eth-snap-keyring>@metamask/keyring-api>@metamask/utils": true, + "@metamask/eth-snap-keyring>@metamask/keyring-api>uuid": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>@metamask/keyring-api>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "browserify>buffer": true, + "nock>debug": true, + "semver": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>@metamask/keyring-api>uuid": { + "globals": { + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "browserify>buffer": true, + "nock>debug": true, + "semver": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>uuid": { + "globals": { + "crypto": true + } + }, "@metamask/eth-token-tracker": { "globals": { "console.warn": true @@ -1305,42 +1426,9 @@ "browserify>events": true } }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": true, - "bn.js": true, - "browserify>buffer": true, - "eth-sig-util>tweetnacl": true, - "eth-sig-util>tweetnacl-util": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": { - "globals": { - "TextDecoder": true, - "crypto": true - }, - "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { - "globals": { - "TextEncoder": true, - "crypto": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": { - "packages": { - "browserify>buffer": true, - "ethjs>ethjs-util>is-hex-prefixed": true, - "ethjs>ethjs-util>strip-hex-prefix": true - } - }, "@metamask/eth-trezor-keyring>@trezor/connect-plugin-ethereum": { "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true } }, "@metamask/eth-trezor-keyring>@trezor/connect-web": { @@ -1683,7 +1771,7 @@ "setTimeout": true }, "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>@metamask/utils": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>eth-json-rpc-middleware>pify": true, "@metamask/safe-event-emitter": true, diff --git a/lavamoat/browserify/flask/policy.json b/lavamoat/browserify/flask/policy.json index 99706027e..aa3b955d2 100644 --- a/lavamoat/browserify/flask/policy.json +++ b/lavamoat/browserify/flask/policy.json @@ -1004,7 +1004,7 @@ "@metamask/eth-json-rpc-middleware>@metamask/utils": true, "@metamask/eth-json-rpc-middleware>pify": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "eth-rpc-errors": true, "json-rpc-engine": true, "vinyl>clone": true @@ -1026,9 +1026,9 @@ "packages": { "@metamask/browser-passworder": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>obs-store": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, "browserify>events": true } }, @@ -1039,7 +1039,7 @@ "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/scure-bip39": true, "browserify>buffer": true } @@ -1081,11 +1081,44 @@ "crypto": true } }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "browserify>buffer": true, "browserify>events": true, "ethereumjs-wallet>randombytes": true @@ -1178,6 +1211,94 @@ "ganache>secp256k1>elliptic": true } }, + "@metamask/eth-snap-keyring": { + "globals": { + "console.error": true, + "console.warn": true + }, + "packages": { + "@ethereumjs/tx": true, + "@metamask/eth-snap-keyring>@metamask/keyring-api": true, + "@metamask/eth-snap-keyring>@metamask/utils": true, + "@metamask/eth-snap-keyring>uuid": true, + "browserify>events": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, + "@metamask/eth-snap-keyring>@metamask/keyring-api": { + "packages": { + "@metamask/eth-snap-keyring>@metamask/keyring-api>@metamask/utils": true, + "@metamask/eth-snap-keyring>@metamask/keyring-api>uuid": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>@metamask/keyring-api>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "browserify>buffer": true, + "nock>debug": true, + "semver": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>@metamask/keyring-api>uuid": { + "globals": { + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/utils": { + "globals": { + "TextDecoder": true, + "TextEncoder": true + }, + "packages": { + "browserify>buffer": true, + "nock>debug": true, + "semver": true, + "superstruct": true + } + }, + "@metamask/eth-snap-keyring>uuid": { + "globals": { + "crypto": true + } + }, "@metamask/eth-token-tracker": { "globals": { "console.warn": true @@ -1305,42 +1426,9 @@ "browserify>events": true } }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": true, - "bn.js": true, - "browserify>buffer": true, - "eth-sig-util>tweetnacl": true, - "eth-sig-util>tweetnacl-util": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": { - "globals": { - "TextDecoder": true, - "crypto": true - }, - "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { - "globals": { - "TextEncoder": true, - "crypto": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": { - "packages": { - "browserify>buffer": true, - "ethjs>ethjs-util>is-hex-prefixed": true, - "ethjs>ethjs-util>strip-hex-prefix": true - } - }, "@metamask/eth-trezor-keyring>@trezor/connect-plugin-ethereum": { "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true } }, "@metamask/eth-trezor-keyring>@trezor/connect-web": { @@ -1683,7 +1771,7 @@ "setTimeout": true }, "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>@metamask/utils": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>eth-json-rpc-middleware>pify": true, "@metamask/safe-event-emitter": true, diff --git a/lavamoat/browserify/main/policy.json b/lavamoat/browserify/main/policy.json index 06df25223..f3373a420 100644 --- a/lavamoat/browserify/main/policy.json +++ b/lavamoat/browserify/main/policy.json @@ -933,7 +933,7 @@ "@metamask/eth-json-rpc-middleware>@metamask/utils": true, "@metamask/eth-json-rpc-middleware>pify": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "eth-rpc-errors": true, "json-rpc-engine": true, "vinyl>clone": true @@ -955,9 +955,9 @@ "packages": { "@metamask/browser-passworder": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>obs-store": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, "browserify>events": true } }, @@ -968,7 +968,7 @@ "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/scure-bip39": true, "browserify>buffer": true } @@ -1010,11 +1010,44 @@ "crypto": true } }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "browserify>buffer": true, "browserify>events": true, "ethereumjs-wallet>randombytes": true @@ -1107,6 +1140,39 @@ "ganache>secp256k1>elliptic": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-token-tracker": { "globals": { "console.warn": true @@ -1234,42 +1300,9 @@ "browserify>events": true } }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": true, - "bn.js": true, - "browserify>buffer": true, - "eth-sig-util>tweetnacl": true, - "eth-sig-util>tweetnacl-util": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": { - "globals": { - "TextDecoder": true, - "crypto": true - }, - "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { - "globals": { - "TextEncoder": true, - "crypto": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": { - "packages": { - "browserify>buffer": true, - "ethjs>ethjs-util>is-hex-prefixed": true, - "ethjs>ethjs-util>strip-hex-prefix": true - } - }, "@metamask/eth-trezor-keyring>@trezor/connect-plugin-ethereum": { "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true } }, "@metamask/eth-trezor-keyring>@trezor/connect-web": { @@ -1612,7 +1645,7 @@ "setTimeout": true }, "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>@metamask/utils": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>eth-json-rpc-middleware>pify": true, "@metamask/safe-event-emitter": true, diff --git a/lavamoat/browserify/mmi/policy.json b/lavamoat/browserify/mmi/policy.json index 8b3e07fcc..a097c6d55 100644 --- a/lavamoat/browserify/mmi/policy.json +++ b/lavamoat/browserify/mmi/policy.json @@ -1154,7 +1154,7 @@ "@metamask/eth-json-rpc-middleware>@metamask/utils": true, "@metamask/eth-json-rpc-middleware>pify": true, "@metamask/eth-json-rpc-middleware>safe-stable-stringify": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "eth-rpc-errors": true, "json-rpc-engine": true, "vinyl>clone": true @@ -1176,9 +1176,9 @@ "packages": { "@metamask/browser-passworder": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": true, "@metamask/eth-keyring-controller>obs-store": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, "browserify>events": true } }, @@ -1189,7 +1189,7 @@ "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-hd-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/scure-bip39": true, "browserify>buffer": true } @@ -1231,11 +1231,44 @@ "crypto": true } }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-keyring-controller>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring": { "packages": { "@ethereumjs/tx>@ethereumjs/util": true, "@metamask/eth-keyring-controller>@metamask/eth-simple-keyring>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "browserify>buffer": true, "browserify>events": true, "ethereumjs-wallet>randombytes": true @@ -1328,6 +1361,39 @@ "ganache>secp256k1>elliptic": true } }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": { + "packages": { + "@ethereumjs/tx>@ethereumjs/util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": true, + "bn.js": true, + "browserify>buffer": true, + "eth-sig-util>tweetnacl": true, + "eth-sig-util>tweetnacl-util": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography": { + "globals": { + "TextDecoder": true, + "crypto": true + }, + "packages": { + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { + "globals": { + "TextEncoder": true, + "crypto": true + } + }, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util>ethjs-util": { + "packages": { + "browserify>buffer": true, + "ethjs>ethjs-util>is-hex-prefixed": true, + "ethjs>ethjs-util>strip-hex-prefix": true + } + }, "@metamask/eth-token-tracker": { "globals": { "console.warn": true @@ -1455,42 +1521,9 @@ "browserify>events": true } }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": { - "packages": { - "@ethereumjs/tx>@ethereumjs/util": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": true, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": true, - "bn.js": true, - "browserify>buffer": true, - "eth-sig-util>tweetnacl": true, - "eth-sig-util>tweetnacl-util": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography": { - "globals": { - "TextDecoder": true, - "crypto": true - }, - "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethereum-cryptography>@noble/hashes": { - "globals": { - "TextEncoder": true, - "crypto": true - } - }, - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util>ethjs-util": { - "packages": { - "browserify>buffer": true, - "ethjs>ethjs-util>is-hex-prefixed": true, - "ethjs>ethjs-util>strip-hex-prefix": true - } - }, "@metamask/eth-trezor-keyring>@trezor/connect-plugin-ethereum": { "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true } }, "@metamask/eth-trezor-keyring>@trezor/connect-web": { @@ -1833,7 +1866,7 @@ "setTimeout": true }, "packages": { - "@metamask/eth-trezor-keyring>@metamask/eth-sig-util": true, + "@metamask/eth-snap-keyring>@metamask/eth-sig-util": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>@metamask/utils": true, "@metamask/network-controller>@metamask/eth-json-rpc-infura>eth-json-rpc-middleware>pify": true, "@metamask/safe-event-emitter": true, diff --git a/package.json b/package.json index ae531d703..3d6f2789a 100644 --- a/package.json +++ b/package.json @@ -51,8 +51,8 @@ "sentry:publish": "node ./development/sentry-publish.js", "lint": "yarn lint:prettier && yarn lint:eslint && yarn lint:tsc && yarn lint:styles", "lint:fix": "yarn lint:prettier:fix && yarn lint:eslint:fix && yarn lint:styles:fix", - "lint:prettier": "prettier --check -- **/*.json", - "lint:prettier:fix": "prettier --write -- **/*.json", + "lint:prettier": "prettier --check -- '**/*.json'", + "lint:prettier:fix": "prettier --write -- '**/*.json'", "lint:changed": "./development/get-changed-file-names.sh | grep --regexp='[.]js$' | tr '\\n' '\\0' | xargs -0 eslint", "lint:changed:fix": "./development/get-changed-file-names.sh | grep --regexp='[.]js$' | tr '\\n' '\\0' | xargs -0 eslint --fix", "lint:changelog": "auto-changelog validate", @@ -235,6 +235,7 @@ "@metamask/eth-json-rpc-middleware": "^11.0.0", "@metamask/eth-keyring-controller": "^10.0.1", "@metamask/eth-ledger-bridge-keyring": "^0.15.0", + "@metamask/eth-snap-keyring": "^0.1.3", "@metamask/eth-token-tracker": "^4.0.0", "@metamask/eth-trezor-keyring": "^1.0.0", "@metamask/etherscan-link": "^2.2.0", diff --git a/shared/constants/app.ts b/shared/constants/app.ts index 3b99fa5e7..04cf708ba 100644 --- a/shared/constants/app.ts +++ b/shared/constants/app.ts @@ -63,6 +63,12 @@ export const MESSAGE_TYPE = { ///: END:ONLY_INCLUDE_IN } as const; +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +// eslint-disable-next-line prefer-destructuring +export const KEYRING_SNAPS_REGISTRY_URL = + process.env.KEYRING_SNAPS_REGISTRY_URL; +///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(snaps) export const SNAP_DIALOG_TYPES = { [DialogType.Alert]: MESSAGE_TYPE.SNAP_DIALOG_ALERT, diff --git a/shared/constants/keyring.ts b/shared/constants/keyring.ts index f285fa468..091317c27 100644 --- a/shared/constants/keyring.ts +++ b/shared/constants/keyring.ts @@ -8,10 +8,19 @@ export enum InternalKeyringType { imported = 'Simple Key Pair', } +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +export enum SnapKeyringType { + snap = 'Snap Keyring', +} +///: END:ONLY_INCLUDE_IN + /** * All keyrings supported by MetaMask. */ export const KeyringType = { ...HardwareKeyringType, ...InternalKeyringType, + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + ...SnapKeyringType, + ///: END:ONLY_INCLUDE_IN }; diff --git a/shared/constants/permissions.test.js b/shared/constants/permissions.test.js index 031c41c0a..94f6388ef 100644 --- a/shared/constants/permissions.test.js +++ b/shared/constants/permissions.test.js @@ -24,7 +24,13 @@ describe('EndowmentPermissions', () => { describe('RestrictedMethods', () => { it('has the expected permission keys', () => { - expect(Object.keys(RestrictedMethods).sort()).toStrictEqual( + // this is done because we there is a difference between flask and stable permissions + // the code fence in `shared/constants/snaps/permissions.ts` is not supported in jest + const mainBuildRestrictedMethodPermissions = Object.keys(RestrictedMethods) + .filter((key) => key !== 'snap_manageAccounts') + .sort(); + + expect(mainBuildRestrictedMethodPermissions).toStrictEqual( [ 'eth_accounts', ...Object.keys(restrictedMethodPermissionBuilders).filter( @@ -35,3 +41,26 @@ describe('RestrictedMethods', () => { ); }); }); + +// Kept here because code fences are not supported in jest. +// rpc methods flask has more restricted endowment permission builders +jest.mock('@metamask/rpc-methods', () => + jest.requireActual('@metamask/rpc-methods-flask'), +); + +describe('Flask Restricted Methods', () => { + it('has the expected flask permission keys', () => { + const flaskExcludedSnapPermissions = Object.keys( + ExcludedSnapPermissions, + ).filter((key) => key !== 'snap_manageAccounts'); + + expect(Object.keys(RestrictedMethods).sort()).toStrictEqual( + [ + 'eth_accounts', + ...Object.keys(restrictedMethodPermissionBuilders).filter( + (targetName) => !flaskExcludedSnapPermissions.includes(targetName), + ), + ].sort(), + ); + }); +}); diff --git a/shared/constants/permissions.ts b/shared/constants/permissions.ts index 3380327b2..1d0c60ac1 100644 --- a/shared/constants/permissions.ts +++ b/shared/constants/permissions.ts @@ -14,6 +14,9 @@ export const RestrictedMethods = Object.freeze({ snap_getEntropy: 'snap_getEntropy', wallet_snap: 'wallet_snap', ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + snap_manageAccounts: 'snap_manageAccounts', + ///: END:ONLY_INCLUDE_IN } as const); ///: BEGIN:ONLY_INCLUDE_IN(snaps) diff --git a/shared/constants/snaps/permissions.ts b/shared/constants/snaps/permissions.ts index c77d4a3c4..360c4a379 100644 --- a/shared/constants/snaps/permissions.ts +++ b/shared/constants/snaps/permissions.ts @@ -13,7 +13,7 @@ export const EndowmentPermissions = Object.freeze({ // Methods / permissions in external packages that we are temporarily excluding. export const ExcludedSnapPermissions = Object.freeze({ // TODO: Enable in Flask - ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-flask) + ///: BEGIN:ONLY_INCLUDE_IN(build-main) snap_manageAccounts: 'This permission is still in development and therefore not available.', ///: END:ONLY_INCLUDE_IN diff --git a/test/data/mock-state.json b/test/data/mock-state.json index dc9b7e3e0..07153cf85 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -139,6 +139,10 @@ { "type": "Simple Key Pair", "accounts": ["0xeb9e64b93097bc15f01f13eae97015c57ab64823"] + }, + { + "type": "Snap Keyring", + "accounts": ["0xb552685e3d2790efd64a175b00d51f02cdafee5d"] } ], "identities": { @@ -172,6 +176,22 @@ "subjectType": "snap" } }, + "snapRegistryList": { + "a51ea3a8-f1b0-4613-9440-b80e2236713b": { + "id": "a51ea3a8-f1b0-4613-9440-b80e2236713b", + "snapId": "npm:@metamask/snap-simple-keyring", + "iconUrl": "", + "snapTitle": "Metamask Simple Keyring", + "snapSlug": "Secure your account with MetaMask Mobile", + "snapDescription": "A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap.", + "tags": ["EOA"], + "developer": "Metamask", + "website": "https://www.consensys.net/", + "auditUrls": ["auditUrl1", "auditUrl2"], + "version": "1.0.0", + "lastUpdated": "April 20, 2023" + } + }, "notifications": { "test": { "id": "test", diff --git a/test/e2e/snaps/enums.js b/test/e2e/snaps/enums.js index 1e5558cf2..d19c74967 100644 --- a/test/e2e/snaps/enums.js +++ b/test/e2e/snaps/enums.js @@ -1,3 +1,5 @@ module.exports = { TEST_SNAPS_WEBSITE_URL: 'https://metamask.github.io/test-snaps/5.5.0/', + TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL: + 'https://metamask.github.io/snap-simple-keyring/latest/', }; diff --git a/test/e2e/snaps/test-snap-manageAccount.spec.js b/test/e2e/snaps/test-snap-manageAccount.spec.js new file mode 100644 index 000000000..9ba5dce54 --- /dev/null +++ b/test/e2e/snaps/test-snap-manageAccount.spec.js @@ -0,0 +1,113 @@ +const { strict: assert } = require('assert'); +const { withFixtures } = require('../helpers'); +const FixtureBuilder = require('../fixture-builder'); +const { TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL } = require('./enums'); + +describe('Test Snap Account', function () { + it('can create a new snap account', async function () { + const ganacheOptions = { + accounts: [ + { + secretKey: + '0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC', + balance: 25000000000000000000, + }, + ], + }; + await withFixtures( + { + fixtures: new FixtureBuilder().build(), + ganacheOptions, + failOnConsoleError: false, + title: this.test.title, + }, + async ({ driver }) => { + await driver.navigate(); + + // enter pw into extension + await driver.fill('#password', 'correct horse battery staple'); + await driver.press('#password', driver.Key.ENTER); + + // navigate to test snaps page and connect + await driver.openNewPage(TEST_SNAPS_SIMPLE_KEYRING_WEBSITE_URL); + await driver.delay(1000); + const connectButton = await driver.findElement('#connectButton'); + await driver.scrollToElement(connectButton); + await driver.delay(1000); + await driver.clickElement('#connectButton'); + await driver.delay(500); + + // switch to metamask extension and click connect + const windowHandles = await driver.waitUntilXWindowHandles( + 3, + 1000, + 10000, + ); + await driver.switchToWindowWithTitle( + 'MetaMask Notification', + windowHandles, + ); + await driver.clickElement({ + text: 'Connect', + tag: 'button', + }); + + try { + await driver.clickElement('[data-testid="snap-install-scroll"]'); + } catch (_) { + console.log('Missing scroll'); + } + + await driver.waitForSelector({ text: 'Install' }); + + await driver.clickElement({ + text: 'Install', + tag: 'button', + }); + + await driver.waitForSelector({ text: 'OK' }); + + await driver.clickElement({ + text: 'OK', + tag: 'button', + }); + + await driver.switchToWindowWithTitle( + 'SSK - Snap Simple Keyring', + windowHandles, + ); + + // check the dapp connection status + await driver.waitForSelector({ + css: '#snapConnected', + text: 'Connected', + }); + + // create new account on dapp + await driver.clickElement({ + text: 'Create Account', + tag: 'div', + }); + + // create name for account + await driver.fill("[placeholder='Name']", 'snap account'); + + await driver.clickElement({ + text: 'Execute', + tag: 'button', + }); + + await driver.delay(1000); + + // switch to metamask extension + await driver.switchToWindowWithTitle('MetaMask', windowHandles); + + // click on accounts + await driver.clickElement('[data-testid="account-menu-icon"]'); + + const label = await driver.findElement('.mm-tag'); + assert.strictEqual(await label.getText(), 'Snaps'); + }, + ); + }); +}); diff --git a/ui/components/app/account-menu/keyring-label.js b/ui/components/app/account-menu/keyring-label.js new file mode 100644 index 000000000..7abc718d1 --- /dev/null +++ b/ui/components/app/account-menu/keyring-label.js @@ -0,0 +1,61 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { HardwareKeyringNames } from '../../../../shared/constants/hardware-wallets'; +import { KeyringType } from '../../../../shared/constants/keyring'; + +export default function KeyringLabel({ keyring }) { + const t = useI18nContext(); + let label = null; + + // Keyring value might take a while to get a value + if (!keyring) { + return null; + } + const { type } = keyring; + + switch (type) { + case KeyringType.qr: + label = HardwareKeyringNames.qr; + break; + case KeyringType.imported: + label = t('imported'); + break; + case KeyringType.trezor: + label = HardwareKeyringNames.trezor; + break; + case KeyringType.ledger: + label = HardwareKeyringNames.ledger; + break; + case KeyringType.lattice: + label = HardwareKeyringNames.lattice; + break; + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + case KeyringType.snap: + label = t('snaps'); + break; + ///: END:ONLY_INCLUDE_IN + default: + label = null; + } + + ///: BEGIN:ONLY_INCLUDE_IN(mmi) + if (type.startsWith('Custody') && /JSONRPC/u.test(type)) { + label = type.split(' - ')[1]; + return null; + } + ///: END:ONLY_INCLUDE_IN + + if (label === null) { + return label; + } + + return ( + <>{label ?
{label}
: null} + ); +} + +KeyringLabel.propTypes = { + keyring: PropTypes.object, +}; diff --git a/ui/components/app/configure-snap-popup/configure-snap-popup.test.tsx b/ui/components/app/configure-snap-popup/configure-snap-popup.test.tsx new file mode 100644 index 000000000..6a4ac9f8d --- /dev/null +++ b/ui/components/app/configure-snap-popup/configure-snap-popup.test.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import { fireEvent } from '@testing-library/react'; +import configureMockStore from 'redux-mock-store'; +import { renderWithProvider } from '../../../../test/lib/render-helpers'; +import messages from '../../../../app/_locales/en/messages.json'; +import mockState from '../../../../test/data/mock-state.json'; +import ConfigureSnapPopup, { + ConfigureSnapPopupType, +} from './configure-snap-popup'; + +const mockOnClose = jest.fn(); +const mockStore = configureMockStore([])(mockState); +describe('ConfigureSnapPopup', () => { + global.platform = { openTab: jest.fn() }; + + it('should show configure popup title and description', async () => { + const { getByText } = renderWithProvider( + , + mockStore, + ); + expect( + getByText(messages.configureSnapPopupTitle.message), + ).toBeInTheDocument(); + expect( + getByText(messages.configureSnapPopupDescription.message), + ).toBeInTheDocument(); + }); + + it('should show install popup title and description', async () => { + const { getByText } = renderWithProvider( + , + mockStore, + ); + expect( + getByText(messages.configureSnapPopupInstallTitle.message), + ).toBeInTheDocument(); + expect( + getByText(messages.configureSnapPopupInstallDescription.message), + ).toBeInTheDocument(); + }); + + it('should open link on click of link', async () => { + const { getByText } = renderWithProvider( + , + mockStore, + ); + const link = getByText('mockLink'); + await fireEvent.click(link); + expect(global.platform.openTab).toHaveBeenCalledWith({ + url: 'mockLink', + }); + }); +}); diff --git a/ui/components/app/configure-snap-popup/configure-snap-popup.tsx b/ui/components/app/configure-snap-popup/configure-snap-popup.tsx new file mode 100644 index 000000000..d62edd27c --- /dev/null +++ b/ui/components/app/configure-snap-popup/configure-snap-popup.tsx @@ -0,0 +1,99 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { + BUTTON_VARIANT, + Button, + Text, + Box, + Modal, + ModalOverlay, + ModalContent, + ModalHeader, +} from '../../component-library'; +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { + AlignItems, + Display, + FlexDirection, + JustifyContent, + TextAlign, + TextVariant, +} from '../../../helpers/constants/design-system'; + +export enum ConfigureSnapPopupType { + CONFIGURE = 'configure', + INSTALL = 'install', +} + +export default function ConfigureSnapPopup({ + type, + isOpen, + onClose, + link, +}: { + type: ConfigureSnapPopupType; + isOpen: boolean; + onClose: () => void; + link: string; +}) { + const t = useI18nContext(); + + return ( + + + + + {type === ConfigureSnapPopupType.CONFIGURE + ? t('configureSnapPopupTitle') + : t('configureSnapPopupInstallTitle')} + + + + + {type === ConfigureSnapPopupType.CONFIGURE + ? t('configureSnapPopupDescription') + : t('configureSnapPopupInstallDescription')} + + + {t('configureSnapPopupLink')} + + + + + + ); +} + +ConfigureSnapPopup.propTypes = { + type: PropTypes.oneOf([ + ConfigureSnapPopupType.CONFIGURE, + ConfigureSnapPopupType.INSTALL, + ]).isRequired, + isOpen: PropTypes.bool.isRequired, + onClose: PropTypes.func.isRequired, + link: PropTypes.string.isRequired, +}; diff --git a/ui/components/app/configure-snap-popup/index.js b/ui/components/app/configure-snap-popup/index.js new file mode 100644 index 000000000..60684ebc0 --- /dev/null +++ b/ui/components/app/configure-snap-popup/index.js @@ -0,0 +1 @@ +export { default, ConfigureSnapPopupType } from './configure-snap-popup'; diff --git a/ui/components/app/modals/account-details-modal/account-details-modal.component.js b/ui/components/app/modals/account-details-modal/account-details-modal.component.js index f35a8153b..1a759713b 100644 --- a/ui/components/app/modals/account-details-modal/account-details-modal.component.js +++ b/ui/components/app/modals/account-details-modal/account-details-modal.component.js @@ -6,8 +6,10 @@ import AccountModalContainer from '../account-modal-container'; import QrView from '../../../ui/qr-code'; import EditableLabel from '../../../ui/editable-label'; import Button from '../../../ui/button'; -import { getURLHostName } from '../../../../helpers/utils/util'; -import { isHardwareKeyring } from '../../../../helpers/utils/hardware'; +import { + getURLHostName, + isAbleToExportAccount, +} from '../../../../helpers/utils/util'; ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) import CustodyLabels from '../../../institutional/custody-labels/custody-labels'; import { toChecksumHexAddress } from '../../../../../shared/modules/hexstring-utils'; @@ -65,11 +67,7 @@ export default class AccountDetailsModal extends Component { return kr.accounts.includes(address); }); - let exportPrivateKeyFeatureEnabled = true; - // This feature is disabled for hardware wallets - if (isHardwareKeyring(keyring?.type)) { - exportPrivateKeyFeatureEnabled = false; - } + let exportPrivateKeyFeatureEnabled = isAbleToExportAccount(keyring?.type); ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) if (keyring?.type?.search('Custody') !== -1) { diff --git a/ui/components/app/modals/account-details-modal/account-details-modal.test.js b/ui/components/app/modals/account-details-modal/account-details-modal.test.js index 7b85c27bb..259da80ca 100644 --- a/ui/components/app/modals/account-details-modal/account-details-modal.test.js +++ b/ui/components/app/modals/account-details-modal/account-details-modal.test.js @@ -103,4 +103,133 @@ describe('Account Details Modal', () => { expect(queryByText(/block.explorer/u)).toBeInTheDocument(); }); + + it('does not display export private key if the keyring is snaps', () => { + const mockStateWithSnapKeyring = { + appState: { + networkDropdownOpen: false, + gasIsLoading: false, + isLoading: false, + modal: { + open: false, + modalState: { + name: null, + props: {}, + }, + previousModalState: { + name: null, + }, + }, + warning: null, + customTokenAmount: '10', + }, + history: { + mostRecentOverviewPage: '/mostRecentOverviewPage', + }, + metamask: { + providerConfig: { + type: 'rpc', + chainId: '0x5', + ticker: 'ETH', + id: 'testNetworkConfigurationId', + }, + keyrings: [ + { + type: 'Snap Keyring', + accounts: [ + '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', + '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b', + ], + }, + { + type: 'Ledger Hardware', + accounts: ['0xc42edfcc21ed14dda456aa0756c153f7985d8813'], + }, + { + type: 'Simple Key Pair', + accounts: ['0xeb9e64b93097bc15f01f13eae97015c57ab64823'], + }, + ], + identities: { + '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': { + address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', + name: 'Test Account', + }, + '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': { + address: '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b', + name: 'Test Account 2', + }, + '0xc42edfcc21ed14dda456aa0756c153f7985d8813': { + address: '0xc42edfcc21ed14dda456aa0756c153f7985d8813', + name: 'Test Ledger 1', + }, + '0xeb9e64b93097bc15f01f13eae97015c57ab64823': { + name: 'Test Account 3', + address: '0xeb9e64b93097bc15f01f13eae97015c57ab64823', + }, + }, + networkDetails: { + EIPS: { + 1559: true, + }, + }, + frequentRpcListDetail: [], + subjectMetadata: { + 'npm:@metamask/test-snap-bip44': { + name: '@metamask/test-snap-bip44', + version: '1.2.3', + subjectType: 'snap', + }, + }, + notifications: { + test: { + id: 'test', + origin: 'local:http://localhost:8086/', + createdDate: 1652967897732, + readDate: null, + message: 'Hello, http://localhost:8086!', + }, + test2: { + id: 'test2', + origin: 'local:http://localhost:8086/', + createdDate: 1652967897732, + readDate: 1652967897732, + message: 'Hello, http://localhost:8086!', + }, + }, + cachedBalances: {}, + incomingTransactions: {}, + selectedAddress: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', + accounts: { + '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': { + balance: '0x346ba7725f412cbfdb', + address: '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc', + }, + '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b': { + address: '0xec1adf982415d2ef5ec55899b9bfb8bc0f29251b', + balance: '0x0', + }, + '0xc42edfcc21ed14dda456aa0756c153f7985d8813': { + address: '0xc42edfcc21ed14dda456aa0756c153f7985d8813', + balance: '0x0', + }, + '0xeb9e64b93097bc15f01f13eae97015c57ab64823': { + address: '0xeb9e64b93097bc15f01f13eae97015c57ab64823', + balance: '0x0', + }, + }, + }, + }; + const mockStoreWithSnapKeyring = configureMockState([thunk])( + mockStateWithSnapKeyring, + ); + const { queryByText } = renderWithProvider( + , + mockStoreWithSnapKeyring, + ); + + const exportPrivateKeyButton = queryByText(exportPrivateKey.message); + + expect(exportPrivateKeyButton).not.toBeInTheDocument(); + }); }); diff --git a/ui/components/multichain/account-details/account-details-display.js b/ui/components/multichain/account-details/account-details-display.js index 210670fbb..dfceec94d 100644 --- a/ui/components/multichain/account-details/account-details-display.js +++ b/ui/components/multichain/account-details/account-details-display.js @@ -11,7 +11,7 @@ import { getHardwareWalletType, getMetaMaskKeyrings, } from '../../../selectors'; -import { isHardwareKeyring } from '../../../helpers/utils/hardware'; +import { isAbleToExportAccount } from '../../../helpers/utils/util'; import { BUTTON_SECONDARY_SIZES, ButtonSecondary, @@ -43,7 +43,7 @@ export const AccountDetailsDisplay = ({ const keyrings = useSelector(getMetaMaskKeyrings); const keyring = keyrings.find((kr) => kr.accounts.includes(address)); - const exportPrivateKeyFeatureEnabled = !isHardwareKeyring(keyring?.type); + const exportPrivateKeyFeatureEnabled = isAbleToExportAccount(keyring?.type); const chainId = useSelector(getCurrentChainId); const deviceName = useSelector(getHardwareWalletType); diff --git a/ui/components/multichain/account-list-item/account-list-item.js b/ui/components/multichain/account-list-item/account-list-item.js index 4871b4c28..5066578fd 100644 --- a/ui/components/multichain/account-list-item/account-list-item.js +++ b/ui/components/multichain/account-list-item/account-list-item.js @@ -60,6 +60,10 @@ function getLabel(keyring = {}, t) { return HardwareKeyringNames.ledger; case KeyringType.lattice: return HardwareKeyringNames.lattice; + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + case KeyringType.snap: + return t('snaps'); + ///: END:ONLY_INCLUDE_IN default: return null; } diff --git a/ui/components/multichain/account-list-item/account-list-item.test.js b/ui/components/multichain/account-list-item/account-list-item.test.js index 6b4a60e6a..3cd9cf3c3 100644 --- a/ui/components/multichain/account-list-item/account-list-item.test.js +++ b/ui/components/multichain/account-list-item/account-list-item.test.js @@ -102,4 +102,17 @@ describe('AccountListItem', () => { expect(getByAltText(`${connectedAvatarName} logo`)).toBeInTheDocument(); }); + + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + it('renders the snap label for snap accounts', () => { + const { getByText } = render({ + identity: { + address: '0xb552685e3d2790eFd64a175B00D51F02cdaFEe5D', + name: 'Snap Account', + }, + }); + + expect(getByText('Snaps')).toBeInTheDocument(); + }); + ///: END:ONLY_INCLUDE_IN }); diff --git a/ui/components/multichain/account-list-menu/account-list-menu.js b/ui/components/multichain/account-list-menu/account-list-menu.js index a53c1c255..ff0f6b236 100644 --- a/ui/components/multichain/account-list-menu/account-list-menu.js +++ b/ui/components/multichain/account-list-menu/account-list-menu.js @@ -33,6 +33,9 @@ import { } from '../../../../shared/constants/metametrics'; import { CONNECT_HARDWARE_ROUTE, + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + ADD_SNAP_ACCOUNT_ROUTE, + ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) CUSTODY_ACCOUNT_ROUTE, ///: END:ONLY_INCLUDE_IN @@ -247,6 +250,30 @@ export const AccountListMenu = ({ onClose }) => { {t('hardwareWallet')} + { + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + <> + + { + dispatch(toggleAccountMenu()); + getEnvironmentType() === ENVIRONMENT_TYPE_POPUP + ? global.platform.openExtensionInBrowser( + ADD_SNAP_ACCOUNT_ROUTE, + null, + true, + ) + : history.push(ADD_SNAP_ACCOUNT_ROUTE); + }} + > + {t('settingAddSnapAccount')} + + + + ///: END:ONLY_INCLUDE_IN + } { ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) diff --git a/ui/components/multichain/account-list-menu/account-list-menu.test.js b/ui/components/multichain/account-list-menu/account-list-menu.test.js index 8e4637f93..b1c789b2f 100644 --- a/ui/components/multichain/account-list-menu/account-list-menu.test.js +++ b/ui/components/multichain/account-list-menu/account-list-menu.test.js @@ -1,12 +1,33 @@ /* eslint-disable jest/require-top-level-describe */ import React from 'react'; import reactRouterDom from 'react-router-dom'; -import { fireEvent, renderWithProvider } from '../../../../test/jest'; +import { fireEvent, renderWithProvider, waitFor } from '../../../../test/jest'; import configureStore from '../../../store/store'; import mockState from '../../../../test/data/mock-state.json'; -import { CONNECT_HARDWARE_ROUTE } from '../../../helpers/constants/routes'; +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +import messages from '../../../../app/_locales/en/messages.json'; +import { + CONNECT_HARDWARE_ROUTE, + ADD_SNAP_ACCOUNT_ROUTE, +} from '../../../helpers/constants/routes'; +///: END:ONLY_INCLUDE_IN import { AccountListMenu } from '.'; +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +const mockToggleAccountMenu = jest.fn(); +const mockGetEnvironmentType = jest.fn(); + +jest.mock('../../../store/actions.ts', () => ({ + ...jest.requireActual('../../../store/actions.ts'), + toggleAccountMenu: () => mockToggleAccountMenu, +})); + +jest.mock('../../../../app/scripts/lib/util', () => ({ + ...jest.requireActual('../../../../app/scripts/lib/util'), + getEnvironmentType: () => mockGetEnvironmentType, +})); +///: END:ONLY_INCLUDE_IN + const render = (props = { onClose: () => jest.fn() }) => { const store = configureStore({ activeTab: { @@ -137,4 +158,32 @@ describe('AccountListMenu', () => { const searchBox = document.querySelector('input[type=search]'); expect(searchBox).toBeInTheDocument(); }); + + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + it('renders the add snap account button', async () => { + const { getByText } = render(); + const addSnapAccountButton = getByText( + messages.settingAddSnapAccount.message, + ); + expect(addSnapAccountButton).toBeInTheDocument(); + + fireEvent.click(addSnapAccountButton); + + await waitFor(() => { + expect(mockToggleAccountMenu).toHaveBeenCalled(); + }); + }); + + it('pushes history when clicking add snap account from extended view', async () => { + const { getByText } = render(); + mockGetEnvironmentType.mockReturnValueOnce('fullscreen'); + const addSnapAccountButton = getByText( + messages.settingAddSnapAccount.message, + ); + fireEvent.click(addSnapAccountButton); + await waitFor(() => { + expect(historyPushMock).toHaveBeenCalledWith(ADD_SNAP_ACCOUNT_ROUTE); + }); + }); + ///: END:ONLY_INCLUDE_IN }); diff --git a/ui/helpers/constants/routes.ts b/ui/helpers/constants/routes.ts index 974af5edc..3e2e4e1b1 100644 --- a/ui/helpers/constants/routes.ts +++ b/ui/helpers/constants/routes.ts @@ -50,6 +50,9 @@ const CONNECT_SNAP_UPDATE_ROUTE = '/snap-update'; const CONNECT_SNAP_RESULT_ROUTE = '/snap-install-result'; const NOTIFICATIONS_ROUTE = '/notifications'; ///: END:ONLY_INCLUDE_IN +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +const ADD_SNAP_ACCOUNT_ROUTE = '/add-snap-account'; +///: END:ONLY_INCLUDE_IN const CONNECTED_ROUTE = '/connected'; const CONNECTED_ACCOUNTS_ROUTE = '/connected/accounts'; const SWAPS_ROUTE = '/swaps'; @@ -132,6 +135,10 @@ const PATH_NAME_MAP = { [CONFIRM_IMPORT_TOKEN_ROUTE]: 'Confirm Import Token Page', [CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE]: 'Confirm Add Suggested Token Page', [NEW_ACCOUNT_ROUTE]: 'New Account Page', + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + [ADD_SNAP_ACCOUNT_ROUTE]: 'Add Snap Account List Page', + [`${ADD_SNAP_ACCOUNT_ROUTE}/:snapId`]: `Add Snap Account Page`, + ///: END:ONLY_INCLUDE_IN [CONFIRM_ADD_SUGGESTED_NFT_ROUTE]: 'Confirm Add Suggested NFT Page', [CONNECT_HARDWARE_ROUTE]: 'Connect Hardware Wallet Page', ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) @@ -249,6 +256,9 @@ export { CONNECT_SNAP_RESULT_ROUTE, NOTIFICATIONS_ROUTE, ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + ADD_SNAP_ACCOUNT_ROUTE, + ///: END:ONLY_INCLUDE_IN CONNECTED_ROUTE, CONNECTED_ACCOUNTS_ROUTE, PATH_NAME_MAP, diff --git a/ui/helpers/utils/permission.js b/ui/helpers/utils/permission.js index c43f79a51..34e01ee7b 100644 --- a/ui/helpers/utils/permission.js +++ b/ui/helpers/utils/permission.js @@ -255,6 +255,7 @@ export const PERMISSION_DESCRIPTIONS = deepFreeze({ leftIcon: IconName.SecurityKey, weight: 3, }), + [RestrictedMethods.snap_manageState]: ({ t }) => ({ label: t('permission_manageState'), description: t('permission_manageStateDescription'), @@ -389,6 +390,14 @@ export const PERMISSION_DESCRIPTIONS = deepFreeze({ return results; }, ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + [RestrictedMethods.snap_manageAccounts]: ({ t }) => ({ + label: t('permission_manageAccounts'), + leftIcon: getLeftIcon(IconName.UserCircleAdd), + rightIcon: null, + weight: 3, + }), + ///: END:ONLY_INCLUDE_IN [UNKNOWN_PERMISSION]: ({ t, permissionName }) => ({ label: t('permission_unknown', [permissionName ?? 'undefined']), leftIcon: getLeftIcon(IconName.Question), diff --git a/ui/helpers/utils/util.js b/ui/helpers/utils/util.js index 5f0030ed3..20ba3656b 100644 --- a/ui/helpers/utils/util.js +++ b/ui/helpers/utils/util.js @@ -621,3 +621,13 @@ export const getNetworkNameFromProviderType = (providerName) => { } return providerName; }; + +/** + * Checks if the given keyring type is able to export an account. + * + * @param keyringType - The type of the keyring. + * @returns {boolean} `false` if the keyring type includes 'Hardware' or 'Snap', `true` otherwise. + */ +export const isAbleToExportAccount = (keyringType = '') => { + return !keyringType.includes('Hardware') && !keyringType.includes('Snap'); +}; diff --git a/ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.stories.tsx b/ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.stories.tsx new file mode 100644 index 000000000..2f5ef9f72 --- /dev/null +++ b/ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.stories.tsx @@ -0,0 +1,36 @@ +import { useArgs } from '@storybook/client-api'; +import { StoryFn } from '@storybook/react'; +import React from 'react'; +import { BUTTON_VARIANT, Button } from '../../../components/component-library'; +import AddSnapAccountModal from '.'; + +const AddSnapAccountModalStory = { + title: 'Components/App/AddSnapAccountModal', + component: AddSnapAccountModal, + argTypes: {}, +}; + +export const DefaultStory: StoryFn = () => { + const [{ isShowingModal }, updateArgs] = useArgs(); + + return ( + <> + + {isShowingModal && ( + updateArgs({ isShowingModal: false })} + /> + )} + + ); +}; + +DefaultStory.storyName = 'Default'; + +export default AddSnapAccountModalStory; diff --git a/ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.tsx b/ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.tsx new file mode 100644 index 000000000..374f17b46 --- /dev/null +++ b/ui/pages/keyring-snaps/add-snap-account-modal/add-snap-account-modal.tsx @@ -0,0 +1,70 @@ +import React from 'react'; +import { + BUTTON_VARIANT, + Box, + Button, + Modal, + ModalContent, + ModalHeader, + ModalOverlay, + Text, +} from '../../../components/component-library'; +import { + AlignItems, + Display, + FlexDirection, + JustifyContent, + TextAlign, + TextVariant, +} from '../../../helpers/constants/design-system'; +import { useI18nContext } from '../../../hooks/useI18nContext'; + +export default function AddSnapAccountModal({ + onClose, + isOpen, +}: { + isOpen: boolean; + onClose: () => void; +}) { + const t = useI18nContext(); + + return ( + + + + + {t('settingAddSnapAccount')} + + + + + + + {t('addSnapAccountModalDescription')} + + + + + + ); +} diff --git a/ui/pages/keyring-snaps/add-snap-account-modal/index.ts b/ui/pages/keyring-snaps/add-snap-account-modal/index.ts new file mode 100644 index 000000000..285965e91 --- /dev/null +++ b/ui/pages/keyring-snaps/add-snap-account-modal/index.ts @@ -0,0 +1 @@ +export { default } from './add-snap-account-modal'; diff --git a/ui/pages/keyring-snaps/add-snap-account.tsx b/ui/pages/keyring-snaps/add-snap-account.tsx new file mode 100644 index 000000000..023892a04 --- /dev/null +++ b/ui/pages/keyring-snaps/add-snap-account.tsx @@ -0,0 +1,38 @@ +import React from 'react'; +import { Route, Switch } from 'react-router-dom'; +import { ADD_SNAP_ACCOUNT_ROUTE } from '../../helpers/constants/routes'; +import { + BackgroundColor, + Display, + JustifyContent, +} from '../../helpers/constants/design-system'; +import { Box } from '../../components/component-library'; +import NewSnapAccountPage from './new-snap-account-page'; +import SnapAccountDetailPage from './snap-account-detail-page'; + +export default function AddSnapAccountPage() { + return ( + + + <> + + + + + + ); +} diff --git a/ui/pages/keyring-snaps/constants.ts b/ui/pages/keyring-snaps/constants.ts new file mode 100644 index 000000000..29fbf55bc --- /dev/null +++ b/ui/pages/keyring-snaps/constants.ts @@ -0,0 +1 @@ +export const METAMASK_DEVELOPER = 'metamask'; diff --git a/ui/pages/keyring-snaps/index.scss b/ui/pages/keyring-snaps/index.scss new file mode 100644 index 000000000..8762f63fd --- /dev/null +++ b/ui/pages/keyring-snaps/index.scss @@ -0,0 +1,2 @@ +@import "./snap-account-detail-page/snap-account-detail-page"; +@import "./new-snap-account-page/new-snap-account-page"; diff --git a/ui/pages/keyring-snaps/index.ts b/ui/pages/keyring-snaps/index.ts new file mode 100644 index 000000000..ef43f8bf5 --- /dev/null +++ b/ui/pages/keyring-snaps/index.ts @@ -0,0 +1 @@ +export { default } from './add-snap-account'; diff --git a/ui/pages/keyring-snaps/new-snap-account-page/index.ts b/ui/pages/keyring-snaps/new-snap-account-page/index.ts new file mode 100644 index 000000000..4bb5e161e --- /dev/null +++ b/ui/pages/keyring-snaps/new-snap-account-page/index.ts @@ -0,0 +1,2 @@ +export { default } from './new-snap-account-page'; +export type { SnapCardProps, SnapDetails } from './new-snap-account-page'; diff --git a/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.scss b/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.scss new file mode 100644 index 000000000..9ae038d23 --- /dev/null +++ b/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.scss @@ -0,0 +1,32 @@ +.snap-account-page { + $width-screen-sm-min: 85vw; + $width-screen-md-min: 80vw; + $width-screen-lg-min: 62vw; + + @include screen-sm-min { + width: $width-screen-sm-min; + } + + @include screen-md-min { + width: $width-screen-md-min; + } + + @include screen-lg-min { + width: $width-screen-lg-min; + } + + background-image: url('images/snap-account-page.svg'); + background-size: 100% auto; + background-repeat: no-repeat; + background-position: bottom; +} + +.snap-account-cards { + grid-template-columns: repeat(3, 1fr); +} + +.snap-account-color-text { + background-image: linear-gradient(0.45deg, #f6851b, #43aefc); + background-clip: text; + color: transparent; +} diff --git a/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.test.tsx b/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.test.tsx new file mode 100644 index 000000000..8935d62df --- /dev/null +++ b/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.test.tsx @@ -0,0 +1,145 @@ +import { fireEvent, waitFor } from '@testing-library/react'; +import React from 'react'; +import configureMockStore from 'redux-mock-store'; +import messages from '../../../../app/_locales/en/messages.json'; +import { renderWithProvider } from '../../../../test/lib/render-helpers'; +import NewSnapAccountPage from '.'; + +const mockHistoryPush = jest.fn(); + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useHistory: () => ({ + push: mockHistoryPush, + }), +})); + +const mockState = { + metamask: { + snapRegistryList: { + 'a51ea3a8-f1b0-4613-9440-b80e2236713b': { + id: 'a51ea3a8-f1b0-4613-9440-b80e2236713b', + snapId: 'npm:@metamask/snap-simple-keyring', + iconUrl: '', + snapTitle: 'Metamask Simple Keyring', + snapSlug: 'Secure your account with MetaMask Mobile', + snapDescription: + 'A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap.', + tags: ['EOA'], + developer: 'Metamask', + website: 'https://www.consensys.net/', + auditUrls: ['auditUrl1', 'auditUrl2'], + version: '1.0.0', + lastUpdated: 'April 20, 2023', + }, + }, + snaps: { + 'npm:@metamask/snap-simple-keyring': { + id: 'npm:@metamask/snap-simple-keyring', + origin: 'npm:@metamask/snap-simple-keyring', + version: '5.1.2', + iconUrl: null, + initialPermissions: { + 'endowment:manageAccount': {}, + }, + manifest: { + description: 'An example keymanagement snap', + proposedName: 'Example Key Management Test Snap', + repository: { + type: 'git', + url: 'https://github.com/MetaMask/snap-simple-keyring.git', + }, + source: { + location: { + npm: { + filePath: 'dist/bundle.js', + packageName: '@metamask/test-snap-account', + registry: 'https://registry.npmjs.org', + }, + }, + shasum: 'L1k+dT9Q+y3KfIqzaH09MpDZVPS9ZowEh9w01ZMTWMU=', + }, + version: '0.0.1', + }, + versionHistory: [ + { + date: 1680686075921, + origin: 'https://metamask.github.io', + version: '0.0.1', + }, + ], + }, + }, + }, +}; + +const renderComponent = (props = {}) => { + const mockStore = configureMockStore([])(mockState); + return renderWithProvider(, mockStore); +}; + +describe('NewSnapAccountPage', () => { + it('should render the popup', async () => { + const { getByText } = renderComponent(); + const popupTitle = getByText(messages.settingAddSnapAccount.message); + expect(popupTitle).toBeInTheDocument(); + + const closeButton = getByText(messages.getStarted.message); + await fireEvent.click(closeButton); + await waitFor(() => { + expect(popupTitle).not.toBeInTheDocument(); + }); + }); + + it('should render the texts', async () => { + const { getByText } = renderComponent(); + expect( + getByText(messages.settingAddSnapAccount.message), + ).toBeInTheDocument(); + expect( + getByText(messages.addSnapAccountModalDescription.message), + ).toBeInTheDocument(); + }); + + it('should render all the keymanagement snaps', async () => { + const { getAllByTestId } = renderComponent(); + const keyManagementSnaps = getAllByTestId('key-management-snap'); + expect(keyManagementSnaps.length).toBe( + Object.values(mockState.metamask.snapRegistryList).length, + ); + }); + + it('should go to snap detail page on click of snap carot', async () => { + const { getAllByTestId } = renderComponent(); + const iconCarot = getAllByTestId('to-snap-detail')[0]; + + await fireEvent.click(iconCarot); + + await waitFor(() => { + expect(mockHistoryPush).toHaveBeenCalled(); + }); + }); + + it('should show configure button after clicking', async () => { + const { getByTestId, getByText } = renderComponent(); + const configureButton = getByTestId('configure-snap-button'); + + await fireEvent.click(configureButton); + await waitFor(() => { + const configureSnapTitleInPopup = getByText( + messages.configureSnapPopupTitle.message, + ); + expect(configureSnapTitleInPopup).toBeInTheDocument(); + }); + + const closeButton = getByText(messages.getStarted.message); + await fireEvent.click(closeButton); + + await waitFor(() => { + const configureSnapTitleInPopup = getByText( + messages.configureSnapPopupTitle.message, + ); + expect(configureSnapTitleInPopup).toBeInTheDocument(); + }); + }); +}); diff --git a/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.tsx b/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.tsx new file mode 100644 index 000000000..2ec9aea8c --- /dev/null +++ b/ui/pages/keyring-snaps/new-snap-account-page/new-snap-account-page.tsx @@ -0,0 +1,134 @@ +import { Snap } from '@metamask/snaps-utils'; +import React, { useState, useEffect } from 'react'; +import { shallowEqual, useSelector } from 'react-redux'; +import { useHistory } from 'react-router-dom'; +import { Box, Text } from '../../../components/component-library'; +import { + AlignItems, + Display, + FlexDirection, + FlexWrap, + JustifyContent, + TextColor, + TextVariant, +} from '../../../helpers/constants/design-system'; +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { + getSnaps, + getsnapsAddSnapAccountModalDismissed, + getSnapRegistry, +} from '../../../selectors'; +import { + setSnapsAddSnapAccountModalDismissed, + updateSnapRegistry, +} from '../../../store/actions'; +import AddSnapAccountModal from '../add-snap-account-modal'; +import SnapCard from '../snap-card/snap-card'; + +export interface SnapDetails { + id: string; + snapId: string; + iconUrl: string; + snapTitle: string; + snapSlug: string; + snapDescription: string; + tags: string[]; + developer: string; + website: string; + auditUrls: string[]; + version: string; + lastUpdated: string; +} + +export interface SnapCardProps extends SnapDetails { + isInstalled: boolean; + updateAvailable: boolean; +} + +export default function NewSnapAccountPage() { + const t = useI18nContext(); + const history = useHistory(); + const [showPopup, setShowPopup] = useState(true); + const installedSnaps: Record = useSelector(getSnaps); + const snapRegistryList: Record = useSelector( + getSnapRegistry, + shallowEqual, + ); + useEffect(() => { + updateSnapRegistry().catch((err) => + console.log(`Failed to fetch snap list: ${err}`), + ); + }, []); + + const hidePopup = async () => { + setShowPopup(false); + await setSnapsAddSnapAccountModalDismissed(); + }; + + const snapsAddSnapAccountModalDismissed = useSelector( + getsnapsAddSnapAccountModalDismissed, + ); + + return ( + + { + await hidePopup(); + }} + isOpen={showPopup && !snapsAddSnapAccountModalDismissed} + /> + + + {t('snapCreateAccountTitle', [ + + {t('snapCreateAccountTitle2')} + , + ])} + + + {t('snapCreateAccountSubtitle')} + + + + {Object.values(snapRegistryList).map( + (snap: SnapDetails, index: number) => { + const foundSnap = Object.values(installedSnaps).find( + (installedSnap) => installedSnap.id === snap.snapId, + ); + + const isInstalled = Boolean(foundSnap); + + return ( + { + history.push(`/add-snap-account/${snap.id}`); + }} + /> + ); + }, + )} + + + ); +} diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap b/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap new file mode 100644 index 000000000..86dad4839 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/__snapshots__/snap-account-detail-page.test.tsx.snap @@ -0,0 +1,232 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SnapAccountDetails should take a snapshot 1`] = ` +
+
+
+
+ + +

+ Metamask Simple Keyring +

+
+
+
+

+ Metamask Simple Keyring +

+
+
+ +
+
+
+
+ +
+
+

+

+ + +

+ By MetaMask +

+
+

+
+
+

+

+ + +

+ Audited +

+
+

+
+
+
+
+
+

+ Secure your account with MetaMask Mobile +

+

+ A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap. +

+
+
+
+

+ Tags +

+
+

+ EOA +

+
+
+
+

+ Developer +

+

+ Metamask +

+
+
+

+ Website +

+ https://www.consensys.net/ +
+
+

+ Audit +

+

+ + auditUrl1 + +

+

+ + auditUrl2 + +

+
+
+

+ Version +

+

+ 1.0.0 +

+
+
+

+ Updated +

+

+ April 20, 2023 +

+
+
+
+
+
+`; diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/detail.tsx b/ui/pages/keyring-snaps/snap-account-detail-page/detail.tsx new file mode 100644 index 000000000..7e47b59ad --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/detail.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { Box, Text } from '../../../components/component-library'; +import { + FlexDirection, + TextVariant, +} from '../../../helpers/constants/design-system'; + +const Detail = ({ + title, + children, +}: React.PropsWithChildren<{ title: string }>) => { + return ( + + + {title} + + {children} + + ); +}; + +export default Detail; diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/header.tsx b/ui/pages/keyring-snaps/snap-account-detail-page/header.tsx new file mode 100644 index 000000000..ff44b01d4 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/header.tsx @@ -0,0 +1,214 @@ +import React, { useState } from 'react'; +import ConfigureSnapPopup, { + ConfigureSnapPopupType, +} from '../../../components/app/configure-snap-popup/configure-snap-popup'; +import { + BUTTON_VARIANT, + Box, + Button, + Icon, + IconName, + Tag, + Text, +} from '../../../components/component-library'; +import { + AlignItems, + BackgroundColor, + BorderColor, + Display, + FlexDirection, + JustifyContent, + TextColor, + TextVariant, +} from '../../../helpers/constants/design-system'; +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { SnapCardProps } from '../new-snap-account-page/new-snap-account-page'; +import { METAMASK_DEVELOPER } from '../constants'; + +export const SnapDetailHeader = ({ + updateAvailable, + snapTitle, + isInstalled, + iconUrl, + developer, + auditUrls, + website, +}: Pick< + SnapCardProps, + | 'updateAvailable' + | 'snapTitle' + | 'isInstalled' + | 'iconUrl' + | 'developer' + | 'auditUrls' + | 'website' +>) => { + const t = useI18nContext(); + const [showConfigPopover, setShowConfigPopover] = useState(false); + const [showConfigPopoverType, setShowConfigPopoverType] = + useState(ConfigureSnapPopupType.INSTALL); + + return ( + <> + + + + + {snapTitle} + + + + + {snapTitle} + + {isInstalled && ( + + )} + + + {isInstalled && updateAvailable && ( + + )} + {isInstalled && ( + + )} + {!isInstalled && ( + + )} + + + + + + + {developer.toLowerCase() === METAMASK_DEVELOPER && ( + + {' '} + + {t('snapCreatedByMetaMask')} + + + } + labelProps={{ + color: TextColor.infoDefault, + }} + className="" + marginRight={1} + /> + )} + {auditUrls.length > 0 && ( + + {' '} + + {t('snapIsAudited')} + + + } + labelProps={{ + color: TextColor.infoDefault, + }} + /> + )} +
+ + setShowConfigPopover(false)} + link={website} + /> + + ); +}; diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/index.ts b/ui/pages/keyring-snaps/snap-account-detail-page/index.ts new file mode 100644 index 000000000..56caa6c61 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/index.ts @@ -0,0 +1 @@ +export { default } from './snap-account-detail-page'; diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.scss b/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.scss new file mode 100644 index 000000000..8d8854ec8 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.scss @@ -0,0 +1,24 @@ + +.snap-details-page { + $width-screen-sm-min: 85vw; + $width-screen-md-min: 80vw; + $width-screen-lg-min: 62vw; + + @include screen-sm-min { + width: $width-screen-sm-min; + } + + @include screen-md-min { + width: $width-screen-md-min; + } + + @include screen-lg-min { + width: $width-screen-lg-min; + } + + + .snap-detail-icon { + width: 16px; + height: 16px; + } +} diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.test.tsx b/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.test.tsx new file mode 100644 index 000000000..d50aa90bc --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.test.tsx @@ -0,0 +1,239 @@ +import { fireEvent, waitFor } from '@testing-library/react'; +import React from 'react'; +import configureMockStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import messages from '../../../../app/_locales/en/messages.json'; +import mockState from '../../../../test/data/mock-state.json'; +import { renderWithProvider } from '../../../../test/lib/render-helpers'; +import SnapAccountDetailPage from '.'; + +const snap = { + id: 'a51ea3a8-f1b0-4613-9440-b80e2236713b', + snapId: 'npm:@metamask/snap-simple-keyring', + iconUrl: '', + snapTitle: 'Metamask Simple Keyring', + snapSlug: 'Secure your account with MetaMask Mobile', + snapDescription: + 'A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap.', + tags: ['EOA'], + developer: 'Metamask', + website: 'https://www.consensys.net/', + auditUrls: ['auditUrl1', 'auditUrl2'], + version: '1.0.0', + lastUpdated: 'April 20, 2023', +}; + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useHistory: () => ({ + push: jest.fn(), + }), + useParams: jest + .fn() + .mockReturnValue({ snapId: 'a51ea3a8-f1b0-4613-9440-b80e2236713b' }), +})); + +const renderComponent = (state, props = {}) => { + const mockStore = configureMockStore([thunk])(state); + return renderWithProvider( + , + mockStore, + `/add-snap-account/${snap.id}`, + ); +}; +describe('SnapAccountDetails', () => { + it('should take a snapshot', () => { + const { container } = renderComponent(mockState); + expect(container).toMatchSnapshot(); + }); + + it('should render the snap details', async () => { + const { getAllByText, getByText } = renderComponent(mockState); + + expect(getAllByText(snap.snapTitle).length).toBe(2); + expect(getByText(snap.snapSlug)).toBeInTheDocument(); + expect(getByText(snap.snapDescription)).toBeInTheDocument(); + snap.tags.forEach((tag) => { + expect(getByText(tag)).toBeInTheDocument(); + }); + + expect(getByText(snap.developer)).toBeInTheDocument(); + expect(getByText(snap.website)).toBeInTheDocument(); + + snap.auditUrls.forEach((auditUrl) => { + expect(getByText(auditUrl)).toBeInTheDocument(); + }); + + expect(getByText(snap.version)).toBeInTheDocument(); + expect(getByText(snap.lastUpdated)).toBeInTheDocument(); + }); + + it('it should render configure if snap is already installed', async () => { + const mockStateForConfig = { + metamask: { + snapRegistryList: { + 'a51ea3a8-f1b0-4613-9440-b80e2236713b': { + id: 'a51ea3a8-f1b0-4613-9440-b80e2236713b', + snapId: 'npm:@metamask/snap-simple-keyring', + iconUrl: '', + snapTitle: 'Metamask Simple Keyring', + snapSlug: 'Secure your account with MetaMask Mobile', + snapDescription: + 'A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap.', + tags: ['EOA'], + developer: 'Metamask', + website: 'https://www.consensys.net/', + auditUrls: ['auditUrl1', 'auditUrl2'], + version: '1.0.0', + lastUpdated: 'April 20, 2023', + }, + }, + snaps: { + 'npm:@metamask/snap-simple-keyring': { + id: 'npm:@metamask/snap-simple-keyring', + origin: 'npm:@metamask/snap-simple-keyring', + version: '1.0.0', + iconUrl: null, + initialPermissions: { + 'endowment:manageAccount': {}, + }, + manifest: { + description: 'An example keymanagement snap', + proposedName: 'Example Key Management Test Snap', + repository: { + type: 'git', + url: 'https://github.com/MetaMask/snap-simple-keyring.git', + }, + source: { + location: { + npm: { + filePath: 'dist/bundle.js', + packageName: '@metamask/test-snap-account', + registry: 'https://registry.npmjs.org', + }, + }, + shasum: 'L1k+dT9Q+y3KfIqzaH09MpDZVPS9ZowEh9w01ZMTWMU=', + }, + version: '0.0.1', + }, + versionHistory: [ + { + date: 1680686075921, + origin: 'https://metamask.github.io', + version: '0.0.1', + }, + ], + }, + }, + }, + }; + const { queryByText, getByText } = renderComponent(mockStateForConfig); + expect(queryByText(messages.snapInstall.message)).not.toBeInTheDocument(); + + expect( + queryByText(messages.snapUpdateAvailable.message), + ).not.toBeInTheDocument(); + + const configureButton = getByText(messages.snapConfigure.message); + expect(configureButton).toBeInTheDocument(); + }); + + it('it should render install if snap is not installed', async () => { + const { queryByText, getByText, getAllByText } = renderComponent(mockState); + expect( + queryByText(messages.snapUpdateAvailable.message), + ).not.toBeInTheDocument(); + + expect(queryByText(messages.snapConfigure.message)).not.toBeInTheDocument(); + + const installButton = getByText(messages.snapInstall.message); + expect(installButton).toBeInTheDocument(); + + fireEvent.click(installButton); + + // expect(mockInstallSnapFromSnapAccounts).toHaveBeenCalledTimes(1); + await waitFor(() => { + expect( + getAllByText(messages.configureSnapPopupInstallTitle.message).length, + ).toBe(2); + }); + }); + + it('it should render update if snap update is available', async () => { + const mockStateForConfig = { + metamask: { + snapRegistryList: { + 'a51ea3a8-f1b0-4613-9440-b80e2236713b': { + id: 'a51ea3a8-f1b0-4613-9440-b80e2236713b', + snapId: 'npm:@metamask/snap-simple-keyring', + iconUrl: '', + snapTitle: 'MetaMask Simple Keyring', + snapSlug: 'Secure your account with MetaMask Mobile', + snapDescription: + 'A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap.', + tags: ['EOA'], + developer: 'MetaMask', + website: 'https://www.consensys.net/', + auditUrls: ['auditUrl1', 'auditUrl2'], + version: '1.0.0', + lastUpdated: 'April 20, 2023', + }, + }, + snaps: { + 'npm:@metamask/snap-simple-keyring': { + id: 'npm:@metamask/snap-simple-keyring', + origin: 'npm:@metamask/snap-simple-keyring', + version: '0.0.0', + iconUrl: null, + initialPermissions: { + 'endowment:manageAccount': {}, + }, + manifest: { + description: 'An example keymanagement snap', + proposedName: 'Example Key Management Test Snap', + repository: { + type: 'git', + url: 'https://github.com/MetaMask/snap-simple-keyring.git', + }, + source: { + location: { + npm: { + filePath: 'dist/bundle.js', + packageName: '@metamask/test-snap-account', + registry: 'https://registry.npmjs.org', + }, + }, + shasum: 'L1k+dT9Q+y3KfIqzaH09MpDZVPS9ZowEh9w01ZMTWMU=', + }, + version: '0.0.1', + }, + versionHistory: [ + { + date: 1680686075921, + origin: 'https://metamask.github.io', + version: '0.0.1', + }, + ], + }, + }, + }, + }; + const { queryByText, getByText } = renderComponent(mockStateForConfig); + expect(queryByText(messages.snapInstall.message)).not.toBeInTheDocument(); + + expect( + queryByText(messages.snapUpdateAvailable.message), + ).toBeInTheDocument(); + + const configureButton = getByText(messages.snapConfigure.message); + expect(configureButton).toBeInTheDocument(); + + fireEvent.click(configureButton); + + await waitFor(() => { + expect( + getByText(messages.configureSnapPopupTitle.message), + ).toBeInTheDocument(); + }); + }); +}); diff --git a/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.tsx b/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.tsx new file mode 100644 index 000000000..711446ef4 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-account-detail-page/snap-account-detail-page.tsx @@ -0,0 +1,147 @@ +import React from 'react'; +import { useSelector } from 'react-redux'; +import { useHistory, useParams } from 'react-router-dom'; +import semver from 'semver'; +import { + BUTTON_VARIANT, + Box, + Button, + Tag, + Text, +} from '../../../components/component-library'; +import { + BlockSize, + Display, + FlexDirection, + TextColor, + TextVariant, +} from '../../../helpers/constants/design-system'; +import { + ADD_SNAP_ACCOUNT_ROUTE, + SNAPS_VIEW_ROUTE, +} from '../../../helpers/constants/routes'; +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { getSnapRegistry, getSnaps } from '../../../selectors'; +import { SnapDetails } from '../new-snap-account-page'; +import Detail from './detail'; +import { SnapDetailHeader } from './header'; + +interface RouteParams { + snapId: string; +} + +export default function SnapAccountDetailPage() { + const t = useI18nContext(); + const history = useHistory(); + + const { snapId } = useParams(); + const installedSnaps = useSelector(getSnaps); + const snapRegistryList: Record = + useSelector(getSnapRegistry); + const currentSnap = Object.values(snapRegistryList).find( + (snap) => snap.id === snapId, + ); + + if (!currentSnap) { + history.push(ADD_SNAP_ACCOUNT_ROUTE); + return null; + } + + const isInstalled = Boolean(installedSnaps[currentSnap.snapId]); + + const updateAvailable = + isInstalled && + semver.gt(currentSnap.version, installedSnaps[currentSnap.snapId].version); + + return ( + + + + + + {currentSnap.snapSlug} + + + {currentSnap.snapDescription} + + + + + {currentSnap.tags.map((tag, index) => { + return ( + + ); + })} + + + {currentSnap.developer} + + {currentSnap.website} + + {currentSnap.auditUrls.map((auditLink, index) => { + return ( + + + + ); + })} + + + {currentSnap.version} + + + {currentSnap.lastUpdated} + + {isInstalled && ( + + + + )} + + + + ); +} diff --git a/ui/pages/keyring-snaps/snap-card/__snapshots__/snap-card.test.tsx.snap b/ui/pages/keyring-snaps/snap-card/__snapshots__/snap-card.test.tsx.snap new file mode 100644 index 000000000..01cf8ff49 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-card/__snapshots__/snap-card.test.tsx.snap @@ -0,0 +1,54 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SnapCard should render 1`] = ` +
+
+
+
+
+

+ M +

+
+
+ +
+

+ Metamask Simple Keyring +

+

+ Secure your account with MetaMask Mobile +

+
+ +
+
+
+`; diff --git a/ui/pages/keyring-snaps/snap-card/index.ts b/ui/pages/keyring-snaps/snap-card/index.ts new file mode 100644 index 000000000..32ddd24ac --- /dev/null +++ b/ui/pages/keyring-snaps/snap-card/index.ts @@ -0,0 +1 @@ +export { default } from './snap-card'; diff --git a/ui/pages/keyring-snaps/snap-card/snap-card.test.tsx b/ui/pages/keyring-snaps/snap-card/snap-card.test.tsx new file mode 100644 index 000000000..9660d8cc0 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-card/snap-card.test.tsx @@ -0,0 +1,75 @@ +import { fireEvent, waitFor } from '@testing-library/react'; +import React from 'react'; +import configureMockStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; +import messages from '../../../../app/_locales/en/messages.json'; +import { renderWithProvider } from '../../../../test/lib/render-helpers'; +import SnapCard from './snap-card'; + +const mockHistoryPush = jest.fn(); + +jest.mock('react-router-dom', () => ({ + ...jest.requireActual('react-router-dom'), + useHistory: () => ({ + push: mockHistoryPush, + }), +})); + +const snap = { + id: 'a51ea3a8-f1b0-4613-9440-b80e2236713b', + snapId: 'npm:@metamask/snap-simple-keyring', + iconUrl: '', + snapTitle: 'Metamask Simple Keyring', + snapSlug: 'Secure your account with MetaMask Mobile', + snapDescription: + 'A simple private key is a randomly generated string of characters that is used to sign transactions. This private key is stored securely within this snap.', + tags: ['EOA'], + developer: 'Metamask', + website: 'https://www.consensys.net/', + auditUrls: ['auditUrl1', 'auditUrl2'], + version: '1.0.0', + lastUpdated: 'April 20, 2023', +}; + +const renderComponent = (props) => { + const mockStore = configureMockStore([thunk])({}); + return renderWithProvider(, mockStore); +}; +describe('SnapCard', () => { + it('should render', () => { + const { container } = renderComponent(snap); + expect(container).toMatchSnapshot(); + }); + + it('should show install button', async () => { + const { getByText } = renderComponent({ ...snap, isInstalled: false }); + expect(getByText(snap.snapTitle)).toBeInTheDocument(); + expect(getByText(snap.snapSlug)).toBeInTheDocument(); + const installButton = getByText(messages.install.message); + + expect(installButton).toBeInTheDocument(); + fireEvent.click(installButton); + await waitFor(() => { + expect(mockHistoryPush).toHaveBeenCalledWith( + `/add-snap-account/${snap.id}`, + ); + }); + }); + + it('should show configure button', async () => { + const { getByText } = renderComponent({ ...snap, isInstalled: true }); + expect(getByText(snap.snapTitle)).toBeInTheDocument(); + expect(getByText(snap.snapSlug)).toBeInTheDocument(); + const configureButton = getByText(messages.snapConfigure.message); + + expect(configureButton).toBeInTheDocument(); + fireEvent.click(configureButton); + + // shows popover + await waitFor(() => { + expect( + getByText(messages.configureSnapPopupTitle.message), + ).toBeInTheDocument(); + }); + }); +}); diff --git a/ui/pages/keyring-snaps/snap-card/snap-card.tsx b/ui/pages/keyring-snaps/snap-card/snap-card.tsx new file mode 100644 index 000000000..30277e626 --- /dev/null +++ b/ui/pages/keyring-snaps/snap-card/snap-card.tsx @@ -0,0 +1,139 @@ +import React, { useState } from 'react'; +import { useHistory } from 'react-router-dom'; +import ConfigureSnapPopup, { + ConfigureSnapPopupType, +} from '../../../components/app/configure-snap-popup'; +import { + BUTTON_VARIANT, + Box, + Button, + Icon, + IconName, + Text, +} from '../../../components/component-library'; +import { + AlignItems, + BackgroundColor, + BorderColor, + BorderRadius, + Color, + Display, + FlexDirection, + IconColor, + JustifyContent, + TextVariant, +} from '../../../helpers/constants/design-system'; +import { useI18nContext } from '../../../hooks/useI18nContext'; +import { SnapCardProps } from '../new-snap-account-page/new-snap-account-page'; + +export default function SnapCard({ + iconUrl, + snapTitle, + snapSlug, + isInstalled, + website, + id, + onClickFunc, +}: Pick< + SnapCardProps, + 'iconUrl' | 'snapTitle' | 'snapSlug' | 'isInstalled' | 'website' | 'id' +> & { onClickFunc: () => void }) { + const t = useI18nContext(); + const history = useHistory(); + const [showConfigPopover, setShowConfigPopover] = useState(false); + + return ( + + + + {iconUrl ? ( + + ) : ( + // This is the fallback icon based on the first letter of the snap name. + + {snapTitle ? snapTitle[0] : '?'} + + )} + + {isInstalled ? ( + + ) : ( + + )} + + + {snapTitle} + + + {snapSlug} + + + + + + setShowConfigPopover(false)} + link={website} + /> + + ); +} diff --git a/ui/pages/pages.scss b/ui/pages/pages.scss index ef23b24fc..f9795cb28 100644 --- a/ui/pages/pages.scss +++ b/ui/pages/pages.scss @@ -1,5 +1,6 @@ /** Please import your files in alphabetical order **/ @import 'add-nft/index'; +@import 'keyring-snaps/index'; @import 'import-token/index'; @import 'asset/asset'; @import 'confirm-import-token/index'; diff --git a/ui/pages/routes/routes.component.js b/ui/pages/routes/routes.component.js index d958cfd8f..3a29ff768 100644 --- a/ui/pages/routes/routes.component.js +++ b/ui/pages/routes/routes.component.js @@ -42,6 +42,9 @@ import TokenDetailsPage from '../token-details'; ///: BEGIN:ONLY_INCLUDE_IN(snaps) import Notifications from '../notifications'; ///: END:ONLY_INCLUDE_IN +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +import AddSnapAccountPage from '../keyring-snaps/add-snap-account'; +///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(desktop) import { registerOnDesktopDisconnect } from '../../hooks/desktopHooks'; import DesktopErrorPage from '../desktop-error'; @@ -90,6 +93,9 @@ import { ///: BEGIN:ONLY_INCLUDE_IN(snaps) NOTIFICATIONS_ROUTE, ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + ADD_SNAP_ACCOUNT_ROUTE, + ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(desktop) DESKTOP_PAIRING_ROUTE, DESKTOP_ERROR_ROUTE, @@ -335,6 +341,14 @@ export default class Routes extends Component { ///: END:ONLY_INCLUDE_IN } + { + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + + ///: END:ONLY_INCLUDE_IN + } { - return async (dispatch: MetaMaskReduxDispatch) => { - await submitRequestToBackground('removeSnap', [snapId]); - await forceUpdateMetamaskState(dispatch); + return async (dispatch: MetaMaskReduxDispatch, getState) => { + dispatch(showLoadingIndication()); + ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + const subjects = getPermissionSubjects(getState()) as { + [k: string]: { permissions: Record }; + }; + + const isAccountsSnap = + subjects[snapId]?.permissions?.snap_manageAccounts !== undefined; + + try { + ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) + if (isAccountsSnap) { + const accounts = (await handleSnapRequest({ + snapId, + origin: 'metamask', + handler: HandlerType.OnRpcRequest, + request: { + id: uuidV4(), + jsonrpc: '2.0', + method: 'keyring_listAccounts', + }, + })) as unknown as any[]; + for (const account of accounts) { + dispatch(removeAccount(account.address.toLowerCase())); + } + } + ///: END:ONLY_INCLUDE_IN + ///: BEGIN:ONLY_INCLUDE_IN(snaps) + + await submitRequestToBackground('removeSnap', [snapId]); + await forceUpdateMetamaskState(dispatch); + } catch (error) { + dispatch(displayWarning(error)); + throw error; + } finally { + dispatch(hideLoadingIndication()); + } }; } @@ -1135,9 +1181,10 @@ export async function handleSnapRequest(args: { origin: string; handler: string; request: { + id?: string; jsonrpc: '2.0'; method: string; - params: Record; + params?: Record; }; }): Promise { return submitRequestToBackground('handleSnapRequest', [args]); @@ -4343,3 +4390,15 @@ export function setSnapsInstallPrivacyWarningShownStatus(shown: boolean) { }; } ///: END:ONLY_INCLUDE_IN + +///: BEGIN:ONLY_INCLUDE_IN(keyring-snaps) +export async function setSnapsAddSnapAccountModalDismissed() { + await submitRequestToBackground('setSnapsAddSnapAccountModalDismissed', [ + true, + ]); +} + +export async function updateSnapRegistry() { + await submitRequestToBackground('updateSnapRegistry', []); +} +///: END:ONLY_INCLUDE_IN diff --git a/yarn.lock b/yarn.lock index 389c05c8c..8d44f4106 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4186,7 +4186,7 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-sig-util@npm:5.0.2, @metamask/eth-sig-util@npm:^5.0.0, @metamask/eth-sig-util@npm:^5.0.1, @metamask/eth-sig-util@npm:^5.0.2": +"@metamask/eth-sig-util@npm:5.0.2": version: 5.0.2 resolution: "@metamask/eth-sig-util@npm:5.0.2" dependencies: @@ -4200,6 +4200,20 @@ __metadata: languageName: node linkType: hard +"@metamask/eth-sig-util@npm:^5.0.0, @metamask/eth-sig-util@npm:^5.0.1, @metamask/eth-sig-util@npm:^5.0.2, @metamask/eth-sig-util@npm:^5.1.0": + version: 5.1.0 + resolution: "@metamask/eth-sig-util@npm:5.1.0" + dependencies: + "@ethereumjs/util": ^8.0.6 + bn.js: ^4.12.0 + ethereum-cryptography: ^2.0.0 + ethjs-util: ^0.1.6 + tweetnacl: ^1.0.3 + tweetnacl-util: ^0.15.1 + checksum: c639e3bf91625faeb0230a6314f0b2d05e8f5e2989542d3e0eed1d21b7b286e1860f68629870fd7e568c1a599b3993c4210403fb4c84a625fb1e75ef676eab4f + languageName: node + linkType: hard + "@metamask/eth-simple-keyring@npm:^5.0.0": version: 5.0.0 resolution: "@metamask/eth-simple-keyring@npm:5.0.0" @@ -4212,6 +4226,22 @@ __metadata: languageName: node linkType: hard +"@metamask/eth-snap-keyring@npm:^0.1.3": + version: 0.1.3 + resolution: "@metamask/eth-snap-keyring@npm:0.1.3" + dependencies: + "@ethereumjs/tx": ^4.1.2 + "@metamask/eth-sig-util": ^5.1.0 + "@metamask/keyring-api": ^0.1.3 + "@metamask/snaps-controllers": ^0.35.2-flask.1 + "@metamask/utils": ^6.1.0 + "@types/uuid": ^9.0.1 + superstruct: ^1.0.3 + uuid: ^9.0.0 + checksum: f77cb75fcbd05024693488c42d244f78e7ee87f3f295ac95971182a78f1399428acc5f10aaf6d6ba08fa28cc3519d4e644226ac7cdf22e77a8659f945d9686ce + languageName: node + linkType: hard + "@metamask/eth-token-tracker@npm:^4.0.0": version: 4.0.0 resolution: "@metamask/eth-token-tracker@npm:4.0.0" @@ -4300,6 +4330,21 @@ __metadata: languageName: node linkType: hard +"@metamask/keyring-api@npm:^0.1.3": + version: 0.1.3 + resolution: "@metamask/keyring-api@npm:0.1.3" + dependencies: + "@metamask/providers": ^11.0.0 + "@metamask/snaps-controllers": ^0.35.2-flask.1 + "@metamask/snaps-utils": ^0.35.2-flask.1 + "@metamask/utils": ^6.0.1 + "@types/uuid": ^9.0.1 + superstruct: ^1.0.3 + uuid: ^9.0.0 + checksum: 2307b5162dbb66d82f7d8ab8e9f1c3a0ef581b915702187b6b8fa5d8e8533838d0539d6f35853ef4f25096f13c9dbf4505fadff247b73f6d489d9c904015d21c + languageName: node + linkType: hard + "@metamask/logo@npm:^3.1.1": version: 3.1.1 resolution: "@metamask/logo@npm:3.1.1" @@ -4705,7 +4750,7 @@ __metadata: languageName: node linkType: hard -"@metamask/snaps-controllers-flask@npm:@metamask/snaps-controllers@0.35.2-flask.1": +"@metamask/snaps-controllers-flask@npm:@metamask/snaps-controllers@0.35.2-flask.1, @metamask/snaps-controllers@npm:^0.35.2-flask.1": version: 0.35.2-flask.1 resolution: "@metamask/snaps-controllers@npm:0.35.2-flask.1" dependencies: @@ -4952,7 +4997,7 @@ __metadata: languageName: node linkType: hard -"@metamask/utils@npm:^6.0.0, @metamask/utils@npm:^6.0.1": +"@metamask/utils@npm:^6.0.0, @metamask/utils@npm:^6.0.1, @metamask/utils@npm:^6.1.0": version: 6.1.0 resolution: "@metamask/utils@npm:6.1.0" dependencies: @@ -7925,17 +7970,17 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:>=13.7.0, @types/node@npm:^18.15.11": - version: 18.16.12 - resolution: "@types/node@npm:18.16.12" - checksum: 90b316c097a059534870bc8e358c7996d99e3bb4395c88a91b893b925ad34e32ff1177009ec6c16a6467266414dca64ec9613e9e6bb3f91b6de0ab629d3bb3b9 +"@types/node@npm:*, @types/node@npm:>=13.7.0": + version: 20.2.5 + resolution: "@types/node@npm:20.2.5" + checksum: 38ce7c7e9d76880dc632f71d71e0d5914fcda9d5e9a7095d6c339abda55ca4affb0f2a882aeb29398f8e09d2c5151f0b6586c81c8ccdfe529c34b1ea3337425e languageName: node linkType: hard "@types/node@npm:^16.0.0, @types/node@npm:^16.11.26, @types/node@npm:^16.7.10": - version: 16.18.31 - resolution: "@types/node@npm:16.18.31" - checksum: 1e0bbbdcfdb80ebb9c5544a58b9692964dca08175a9d2f787a1ed8c75c253d106d56cf7d94c5ba0b44e1627000d093d599f995aeb657f5edbf577e66565b017a + version: 16.18.34 + resolution: "@types/node@npm:16.18.34" + checksum: 35c0ffe09687578d002ceb7e706d0ba450546aeb3d2716f28691f2af0063bd274dbde0f741d087ea217f2a8db413eb700d22dfb4f08a67986ff801423bd7be8d languageName: node linkType: hard @@ -7946,6 +7991,13 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^18.15.11": + version: 18.16.16 + resolution: "@types/node@npm:18.16.16" + checksum: 0efad726dd1e0bef71c392c708fc5d78c5b39c46b0ac5186fee74de4ccb1b2e847b3fa468da67d62812f56569da721b15bf31bdc795e6c69b56c73a45079ed2d + languageName: node + linkType: hard + "@types/normalize-package-data@npm:^2.4.0": version: 2.4.0 resolution: "@types/normalize-package-data@npm:2.4.0" @@ -8229,10 +8281,10 @@ __metadata: languageName: node linkType: hard -"@types/uuid@npm:^9.0.0": - version: 9.0.1 - resolution: "@types/uuid@npm:9.0.1" - checksum: c472b8a77cbeded4bc529220b8611afa39bd64677f507838f8083d8aac8033b1f88cb9ddaa2f8589e0dcd2317291d0f6e1379f82d5ceebd6f74f3b4825288e00 +"@types/uuid@npm:^9.0.0, @types/uuid@npm:^9.0.1": + version: 9.0.2 + resolution: "@types/uuid@npm:9.0.2" + checksum: 1754bcf3444e1e3aeadd6e774fc328eb53bc956665e2e8fb6ec127aa8e1f43d9a224c3d22a9a6233dca8dd81a12dc7fed4d84b8876dd5ec82d40f574f7ff8b68 languageName: node linkType: hard @@ -10804,7 +10856,7 @@ __metadata: languageName: node linkType: hard -"bn.js@npm:^4.0.0, bn.js@npm:^4.1.0, bn.js@npm:^4.1.1, bn.js@npm:^4.11.0, bn.js@npm:^4.11.7, bn.js@npm:^4.11.8, bn.js@npm:^4.11.9": +"bn.js@npm:^4.0.0, bn.js@npm:^4.1.0, bn.js@npm:^4.1.1, bn.js@npm:^4.11.0, bn.js@npm:^4.11.7, bn.js@npm:^4.11.8, bn.js@npm:^4.11.9, bn.js@npm:^4.12.0": version: 4.12.0 resolution: "bn.js@npm:4.12.0" checksum: 39afb4f15f4ea537b55eaf1446c896af28ac948fdcf47171961475724d1bb65118cca49fa6e3d67706e4790955ec0e74de584e45c8f1ef89f46c812bee5b5a12 @@ -11745,9 +11797,9 @@ __metadata: linkType: hard "caniuse-lite@npm:^1.0.30001109, caniuse-lite@npm:^1.0.30001426, caniuse-lite@npm:^1.0.30001449": - version: 1.0.30001481 - resolution: "caniuse-lite@npm:1.0.30001481" - checksum: 8200a043c191b4fd4fe0beda37a58fd61869c895ab93f87bdd0420e5927453f48434d716ce9da8552ff6c3ecc4dcd1366354cda3a134f3cc844af741574a7cab + version: 1.0.30001497 + resolution: "caniuse-lite@npm:1.0.30001497" + checksum: 6721120f9a588c442a81cf32f911b4e97a88cb129c27bd2cb0fce6447ad058baa12affa1ee09c517f9e088c7ce74964154d032b6631f66d75dd37c6bc59a67f6 languageName: node linkType: hard @@ -24447,6 +24499,7 @@ __metadata: "@metamask/eth-json-rpc-middleware": ^11.0.0 "@metamask/eth-keyring-controller": ^10.0.1 "@metamask/eth-ledger-bridge-keyring": ^0.15.0 + "@metamask/eth-snap-keyring": ^0.1.3 "@metamask/eth-token-tracker": ^4.0.0 "@metamask/eth-trezor-keyring": ^1.0.0 "@metamask/etherscan-link": ^2.2.0 From 48465432d688042519c5fda44c9604b5d91b1e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20Regadas?= Date: Thu, 29 Jun 2023 15:42:37 +0100 Subject: [PATCH 18/30] [MMI] connect custodial with incorrect styles (#19820) * updates the custody-keyring package and sorts the order of custodians * updates the styles * snapshots update * lint * run dedupe * clean up --- package.json | 2 +- .../__snapshots__/custody.test.js.snap | 153 +++++++++--------- ui/pages/institutional/custody/custody.js | 140 ++++++++++------ yarn.lock | 62 +++---- 4 files changed, 197 insertions(+), 160 deletions(-) diff --git a/package.json b/package.json index 3d6f2789a..a0249594d 100644 --- a/package.json +++ b/package.json @@ -215,7 +215,7 @@ "@lavamoat/snow": "^1.5.0", "@material-ui/core": "^4.11.0", "@metamask-institutional/custody-controller": "0.2.6", - "@metamask-institutional/custody-keyring": "0.0.23", + "@metamask-institutional/custody-keyring": "^0.0.25", "@metamask-institutional/extension": "^0.1.3", "@metamask-institutional/institutional-features": "^1.1.8", "@metamask-institutional/portfolio-dashboard": "^1.1.3", diff --git a/ui/pages/institutional/custody/__snapshots__/custody.test.js.snap b/ui/pages/institutional/custody/__snapshots__/custody.test.js.snap index 6fbc42967..32385217b 100644 --- a/ui/pages/institutional/custody/__snapshots__/custody.test.js.snap +++ b/ui/pages/institutional/custody/__snapshots__/custody.test.js.snap @@ -2,13 +2,14 @@ exports[`CustodyPage renders CustodyPage 1`] = `
+ +
- -
-

- Custodial Accounts -

-
+
+

+ Custodial Accounts +

+
+ Please choose the custodian you want to connect in order to add or refresh a token. +
+
+
    - Please choose the custodian you want to connect in order to add or refresh a token. - -
    -
      -
      +

      - Saturn Custody -

      - Saturn Custody -

      -
      - + Saturn Custody +

      -
    -
    + +
+
-
+
`; exports[`CustodyPage renders CustodyPage 2`] = `
+ +
- -
-
- -

- Back -

-
-

+ +

-

-

-

-

-

- Enter your token or add a new token + Back

+

+
+

+

+

+

+ Enter your token or add a new token +

diff --git a/ui/pages/institutional/custody/custody.js b/ui/pages/institutional/custody/custody.js index 6c545411c..7ab0efb5f 100644 --- a/ui/pages/institutional/custody/custody.js +++ b/ui/pages/institutional/custody/custody.js @@ -73,7 +73,21 @@ const CustodyPage = () => { const custodianButtons = useMemo(() => { const custodianItems = []; - custodians.forEach((custodian) => { + + const sortedCustodians = custodians.sort(function (a, b) { + const nameA = a.name.toLowerCase(); + const nameB = b.name.toLowerCase(); + + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + return 0; + }); + + sortedCustodians.forEach((custodian) => { if ( (!custodian.production && process.env.METAMASK_ENVIRONMENT === 'production') || @@ -88,15 +102,16 @@ const CustodyPage = () => { custodianItems.push( - + {custodian.iconUrl && ( { }; return ( - + <> {connectError && ( {connectError} @@ -342,18 +357,30 @@ const CustodyPage = () => { {!accounts && !selectedCustodianType ? ( - history.push(DEFAULT_ROUTE)} + + alignItems={AlignItems.center} + marginBottom={4} + marginTop={4} + > + history.push(DEFAULT_ROUTE)} + display={Display.Flex} + /> + {t('back')} + {t('connectCustodialAccountTitle')} @@ -374,9 +401,13 @@ const CustodyPage = () => { {!accounts && selectedCustodianType && ( <> { ariaLabel={t('back')} iconName={IconName.ArrowLeft} size={IconSize.Sm} - color={Color.iconAlternative} + color={Color.iconDefault} onClick={() => cancelConnectCustodianToken()} display={[Display.Flex]} /> @@ -410,43 +441,46 @@ const CustodyPage = () => { {t('enterCustodianToken', [selectedCustodianDisplayName])} - - - setCurrentJwt(jwt)} - jwtInputText={t('pasteJWTToken')} - apiUrl={apiUrl} - urlInputText={t('custodyApiUrl', [selectedCustodianDisplayName])} - onUrlChange={(url) => setApiUrl(url)} - /> - - - + + + @@ -598,7 +632,7 @@ const CustodyPage = () => { )} - + ); }; diff --git a/yarn.lock b/yarn.lock index 8d44f4106..3279bfe14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3699,22 +3699,6 @@ __metadata: languageName: node linkType: hard -"@metamask-institutional/custody-keyring@npm:0.0.23": - version: 0.0.23 - resolution: "@metamask-institutional/custody-keyring@npm:0.0.23" - dependencies: - "@ethereumjs/tx": ^4.1.1 - "@ethereumjs/util": ^8.0.5 - "@metamask-institutional/configuration-client": ^1.0.6 - "@metamask-institutional/sdk": ^0.1.15 - "@metamask-institutional/types": ^1.0.2 - "@metamask/obs-store": ^8.0.0 - crypto: ^1.0.1 - lodash.clonedeep: ^4.5.0 - checksum: eae1003ddfd262526d28c23d6dbdfbc6d42879bb989c9bcf97416d3964aaa6ce202a0803c46256fb1afc1399592176ba2fdfcbd2043c4f1275f5079e067c3a78 - languageName: node - linkType: hard - "@metamask-institutional/custody-keyring@npm:^0.0.22": version: 0.0.22 resolution: "@metamask-institutional/custody-keyring@npm:0.0.22" @@ -3731,6 +3715,22 @@ __metadata: languageName: node linkType: hard +"@metamask-institutional/custody-keyring@npm:^0.0.25": + version: 0.0.25 + resolution: "@metamask-institutional/custody-keyring@npm:0.0.25" + dependencies: + "@ethereumjs/tx": ^4.1.1 + "@ethereumjs/util": ^8.0.5 + "@metamask-institutional/configuration-client": ^1.0.6 + "@metamask-institutional/sdk": ^0.1.18 + "@metamask-institutional/types": ^1.0.3 + "@metamask/obs-store": ^8.0.0 + crypto: ^1.0.1 + lodash.clonedeep: ^4.5.0 + checksum: 9e6405e69be3f96f686b611e7c0c513da70115f78a9731f0960a1480706f7498e4b69154ce9c78967e886558b0a6c06aaf23e89713408b3f74f175176fcd790c + languageName: node + linkType: hard + "@metamask-institutional/extension@npm:^0.1.3": version: 0.1.3 resolution: "@metamask-institutional/extension@npm:0.1.3" @@ -3773,24 +3773,24 @@ __metadata: languageName: node linkType: hard -"@metamask-institutional/sdk@npm:^0.1.14, @metamask-institutional/sdk@npm:^0.1.15, @metamask-institutional/sdk@npm:^0.1.16, @metamask-institutional/sdk@npm:^0.1.17": - version: 0.1.17 - resolution: "@metamask-institutional/sdk@npm:0.1.17" +"@metamask-institutional/sdk@npm:^0.1.14, @metamask-institutional/sdk@npm:^0.1.15, @metamask-institutional/sdk@npm:^0.1.16, @metamask-institutional/sdk@npm:^0.1.17, @metamask-institutional/sdk@npm:^0.1.18": + version: 0.1.18 + resolution: "@metamask-institutional/sdk@npm:0.1.18" dependencies: - "@metamask-institutional/simplecache": ^1.0.2 - "@metamask-institutional/types": ^1.0.2 + "@metamask-institutional/simplecache": ^1.1.0 + "@metamask-institutional/types": ^1.0.3 "@types/jsonwebtoken": ^9.0.1 "@types/node": ^18.15.11 bignumber.js: ^9.1.1 jsonwebtoken: ^9.0.0 - checksum: 82b3a8038fdf96983846fa884c867ec9497ac4a2a287d8bb2ce4ffde39b6127ce3af8d2adccab5cedf4ed6b1980488f3cc83347237c085f44ed3a0c004f8a183 + checksum: c9093f4d6495d35f540b25e6dae70ab69ee9c1ce6e18f6164e9aeae5194318a34dfb471791f4f83cec68059456740bd66a5e6368115431d1029a04524f500067 languageName: node linkType: hard -"@metamask-institutional/simplecache@npm:^1.0.2": - version: 1.0.2 - resolution: "@metamask-institutional/simplecache@npm:1.0.2" - checksum: 65444d49478e14956f884e5423992ad7069c9e8979cdc012db3f8f6f207147816b8f3b45be33007772a9628560b5f054ea52b0eb8a9ee25066abc199260d30b6 +"@metamask-institutional/simplecache@npm:^1.1.0": + version: 1.1.0 + resolution: "@metamask-institutional/simplecache@npm:1.1.0" + checksum: 6011c8cafe4f1ca4736a668cac764dfbb2759f887cfbc76c869491e28a4ed5a206bd0635474c31585852eb39e2b6d0081b778c0c55ec4003ed52abfe2e474ad3 languageName: node linkType: hard @@ -3808,10 +3808,10 @@ __metadata: languageName: node linkType: hard -"@metamask-institutional/types@npm:^1.0.1, @metamask-institutional/types@npm:^1.0.2": - version: 1.0.2 - resolution: "@metamask-institutional/types@npm:1.0.2" - checksum: 27bee2dc32a1a8869a2918863d60e4c59b350ad5fcf2d3fbc3fd52b9db2e2af33eb3af568726b72cb7accd7aba2639e9e707522989cc5db9ee8d8f1239f9d6f9 +"@metamask-institutional/types@npm:^1.0.1, @metamask-institutional/types@npm:^1.0.2, @metamask-institutional/types@npm:^1.0.3": + version: 1.0.3 + resolution: "@metamask-institutional/types@npm:1.0.3" + checksum: ce22762d43c8438104df32a91b115c6e99d5f17745fd0e747141730a91b0affd2d92cd1c7dabe34dad8cc59d6dccc70019aa07bd2039c3da68b9987ab7bcf81b languageName: node linkType: hard @@ -24473,7 +24473,7 @@ __metadata: "@lavamoat/snow": ^1.5.0 "@material-ui/core": ^4.11.0 "@metamask-institutional/custody-controller": 0.2.6 - "@metamask-institutional/custody-keyring": 0.0.23 + "@metamask-institutional/custody-keyring": ^0.0.25 "@metamask-institutional/extension": ^0.1.3 "@metamask-institutional/institutional-features": ^1.1.8 "@metamask-institutional/portfolio-dashboard": ^1.1.3 From a2dfe8d1135f483de157d22470cde783818546a7 Mon Sep 17 00:00:00 2001 From: Bernardo Garces Chapero Date: Thu, 29 Jun 2023 16:51:56 +0100 Subject: [PATCH 19/30] Approval flow for add & switch network (#19656) --- .../handlers/add-ethereum-chain.js | 26 ++++++++++++++++--- app/scripts/metamask-controller.js | 10 +++++++ package.json | 4 +-- ui/pages/confirmation/confirmation.js | 24 ++++++++++++++++- .../templates/add-ethereum-chain.test.js | 1 + .../templates/switch-ethereum-chain.test.js | 1 + ui/pages/home/home.component.js | 6 ++++- ui/pages/home/home.container.js | 2 ++ ui/pages/routes/routes.component.test.js | 1 + ui/selectors/approvals.test.ts | 23 +++++++++++++--- ui/selectors/approvals.ts | 9 ++++--- ui/store/actions.ts | 6 ++++- ui/store/store.ts | 1 + yarn.lock | 10 +++---- 14 files changed, 102 insertions(+), 22 deletions(-) diff --git a/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js b/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js index 03b3f5714..7c0c5af57 100644 --- a/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js +++ b/app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.js @@ -22,6 +22,8 @@ const addEthereumChain = { findNetworkConfigurationBy: true, setActiveNetwork: true, requestUserApproval: true, + startApprovalFlow: true, + endApprovalFlow: true, }, }; export default addEthereumChain; @@ -38,6 +40,8 @@ async function addEthereumChainHandler( findNetworkConfigurationBy, setActiveNetwork, requestUserApproval, + startApprovalFlow, + endApprovalFlow, }, ) { if (!req.params?.[0] || typeof req.params[0] !== 'object') { @@ -242,6 +246,9 @@ async function addEthereumChainHandler( ); } let networkConfigurationId; + + const { id: approvalFlowId } = await startApprovalFlow(); + try { await requestUserApproval({ origin, @@ -269,6 +276,7 @@ async function addEthereumChainHandler( // Once the network has been added, the requested is considered successful res.result = null; } catch (error) { + endApprovalFlow({ id: approvalFlowId }); return end(error); } @@ -285,14 +293,24 @@ async function addEthereumChainHandler( networkConfigurationId, }, }); - await setActiveNetwork(networkConfigurationId); } catch (error) { // For the purposes of this method, it does not matter if the user // declines to switch the selected network. However, other errors indicate // that something is wrong. - if (error.code !== errorCodes.provider.userRejectedRequest) { - return end(error); - } + return end( + error.code === errorCodes.provider.userRejectedRequest + ? undefined + : error, + ); + } finally { + endApprovalFlow({ id: approvalFlowId }); } + + try { + await setActiveNetwork(networkConfigurationId); + } catch (error) { + return end(error); + } + return end(); } diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index c60ed5fc6..e3a0a704a 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -3909,6 +3909,16 @@ export default class MetamaskController extends EventEmitter { this.approvalController.addAndShowApprovalRequest.bind( this.approvalController, ), + startApprovalFlow: this.approvalController.startFlow.bind( + this.approvalController, + ), + endApprovalFlow: this.approvalController.endFlow.bind( + this.approvalController, + ), + setApprovalFlowLoadingText: + this.approvalController.setFlowLoadingText.bind( + this.approvalController, + ), sendMetrics: this.metaMetricsController.trackEvent.bind( this.metaMetricsController, ), diff --git a/package.json b/package.json index a0249594d..df3cdf08e 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "resolutions": { "@babel/core": "patch:@babel/core@npm%3A7.21.5#./.yarn/patches/@babel-core-npm-7.21.5-c72c337956.patch", "@babel/runtime": "patch:@babel/runtime@npm%3A7.18.9#./.yarn/patches/@babel-runtime-npm-7.18.9-28ca6b5f61.patch", - "@metamask/approval-controller": "^3.0.0", + "@metamask/approval-controller": "^3.3.0", "@types/react": "^16.9.53", "analytics-node/axios": "^0.21.2", "ganache-core/lodash": "^4.17.21", @@ -224,7 +224,7 @@ "@metamask-institutional/transaction-update": "^0.1.21", "@metamask/address-book-controller": "^3.0.0", "@metamask/announcement-controller": "^4.0.0", - "@metamask/approval-controller": "^3.1.0", + "@metamask/approval-controller": "^3.3.0", "@metamask/assets-controllers": "^9.2.0", "@metamask/base-controller": "^3.0.0", "@metamask/browser-passworder": "^4.1.0", diff --git a/ui/pages/confirmation/confirmation.js b/ui/pages/confirmation/confirmation.js index 76a6a51e1..458d78941 100644 --- a/ui/pages/confirmation/confirmation.js +++ b/ui/pages/confirmation/confirmation.js @@ -32,11 +32,14 @@ import { ///: END:ONLY_INCLUDE_IN getUnapprovedTemplatedConfirmations, getUnapprovedTxCount, + getApprovalFlows, + getTotalUnapprovedCount, } from '../../selectors'; import NetworkDisplay from '../../components/app/network-display/network-display'; import Callout from '../../components/ui/callout'; import SiteOrigin from '../../components/ui/site-origin'; import { Icon, IconName } from '../../components/component-library'; +import Loading from '../../components/ui/loading-screen'; ///: BEGIN:ONLY_INCLUDE_IN(snaps) import SnapAuthorshipHeader from '../../components/app/snaps/snap-authorship-header'; import { getSnapName } from '../../helpers/utils/util'; @@ -176,6 +179,9 @@ export default function ConfirmationPage({ isEqual, ); const unapprovedTxsCount = useSelector(getUnapprovedTxCount); + const approvalFlows = useSelector(getApprovalFlows, isEqual); + const totalUnapprovedCount = useSelector(getTotalUnapprovedCount); + const [approvalFlowLoadingText, setApprovalFlowLoadingText] = useState(null); const [currentPendingConfirmation, setCurrentPendingConfirmation] = useState(0); const pendingConfirmation = pendingConfirmations[currentPendingConfirmation]; @@ -256,20 +262,36 @@ export default function ConfirmationPage({ // viewed index, reset the index. if ( pendingConfirmations.length === 0 && + (approvalFlows.length === 0 || totalUnapprovedCount !== 0) && redirectToHomeOnZeroConfirmations ) { history.push(DEFAULT_ROUTE); - } else if (pendingConfirmations.length <= currentPendingConfirmation) { + } else if ( + pendingConfirmations.length && + pendingConfirmations.length <= currentPendingConfirmation + ) { setCurrentPendingConfirmation(pendingConfirmations.length - 1); } }, [ pendingConfirmations, + approvalFlows, + totalUnapprovedCount, history, currentPendingConfirmation, redirectToHomeOnZeroConfirmations, ]); + useEffect(() => { + const childFlow = approvalFlows[approvalFlows.length - 1]; + + setApprovalFlowLoadingText(childFlow?.loadingText ?? null); + }, [approvalFlows]); + if (!pendingConfirmation) { + if (approvalFlows.length > 0) { + return ; + } + return null; } diff --git a/ui/pages/confirmation/templates/add-ethereum-chain.test.js b/ui/pages/confirmation/templates/add-ethereum-chain.test.js index f41d227a0..fbabd3940 100644 --- a/ui/pages/confirmation/templates/add-ethereum-chain.test.js +++ b/ui/pages/confirmation/templates/add-ethereum-chain.test.js @@ -33,6 +33,7 @@ const mockBaseStore = { pendingApprovals: { [mockApprovalId]: mockApproval, }, + approvalFlows: [{ id: mockApprovalId, loadingText: null }], subjectMetadata: {}, providerConfig: { type: 'rpc', diff --git a/ui/pages/confirmation/templates/switch-ethereum-chain.test.js b/ui/pages/confirmation/templates/switch-ethereum-chain.test.js index 077d0d2f0..4faee9c1f 100644 --- a/ui/pages/confirmation/templates/switch-ethereum-chain.test.js +++ b/ui/pages/confirmation/templates/switch-ethereum-chain.test.js @@ -33,6 +33,7 @@ const mockBaseStore = { pendingApprovals: { [mockApprovalId]: mockApproval, }, + approvalFlows: [], subjectMetadata: {}, providerConfig: { type: 'rpc', diff --git a/ui/pages/home/home.component.js b/ui/pages/home/home.component.js index cc4c44098..b0c838762 100644 --- a/ui/pages/home/home.component.js +++ b/ui/pages/home/home.component.js @@ -84,6 +84,7 @@ import FlaskHomeFooter from './flask/flask-home-footer.component'; function shouldCloseNotificationPopup({ isNotification, totalUnapprovedCount, + hasApprovalFlows, isSigningQRHardwareTransaction, ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) waitForConfirmDeepLinkDialog, @@ -93,6 +94,7 @@ function shouldCloseNotificationPopup({ let shouldCLose = isNotification && totalUnapprovedCount === 0 && + !hasApprovalFlows && !isSigningQRHardwareTransaction; ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) @@ -139,6 +141,7 @@ export default class Home extends PureComponent { originOfCurrentTab: PropTypes.string, disableWeb3ShimUsageAlert: PropTypes.func.isRequired, pendingConfirmations: PropTypes.arrayOf(PropTypes.object).isRequired, + hasApprovalFlows: PropTypes.bool.isRequired, infuraBlocked: PropTypes.bool.isRequired, showWhatsNewPopup: PropTypes.bool.isRequired, hideWhatsNewPopup: PropTypes.func.isRequired, @@ -287,6 +290,7 @@ export default class Home extends PureComponent { showAwaitingSwapScreen, swapsFetchParams, pendingConfirmations, + hasApprovalFlows, } = this.props; ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) @@ -307,7 +311,7 @@ export default class Home extends PureComponent { history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE); } else if (hasWatchNftPendingApprovals) { history.push(CONFIRM_ADD_SUGGESTED_NFT_ROUTE); - } else if (pendingConfirmations.length > 0) { + } else if (pendingConfirmations.length > 0 || hasApprovalFlows) { history.push(CONFIRMATION_V_NEXT_ROUTE); } ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) diff --git a/ui/pages/home/home.container.js b/ui/pages/home/home.container.js index 9ccfbbf90..1fe1a47f7 100644 --- a/ui/pages/home/home.container.js +++ b/ui/pages/home/home.container.js @@ -36,6 +36,7 @@ import { getRemoveNftMessage, getSuggestedTokens, getSuggestedNfts, + getApprovalFlows, } from '../../selectors'; import { @@ -137,6 +138,7 @@ const mapStateToProps = (state) => { selectedAddress, firstPermissionsRequestId, totalUnapprovedCount, + hasApprovalFlows: getApprovalFlows(state).length > 0, connectedStatusPopoverHasBeenShown, defaultHomeActiveTabName, firstTimeFlowType, diff --git a/ui/pages/routes/routes.component.test.js b/ui/pages/routes/routes.component.test.js index f4e4b0abd..259039536 100644 --- a/ui/pages/routes/routes.component.test.js +++ b/ui/pages/routes/routes.component.test.js @@ -106,6 +106,7 @@ describe('Routes Component', () => { swapsFeatureIsLive: true, }, pendingApprovals: {}, + approvalFlows: [], announcements: {}, }, send: { diff --git a/ui/selectors/approvals.test.ts b/ui/selectors/approvals.test.ts index 44923b416..e20261abb 100644 --- a/ui/selectors/approvals.test.ts +++ b/ui/selectors/approvals.test.ts @@ -1,5 +1,5 @@ import { ApprovalType } from '@metamask/controller-utils'; -import { hasPendingApprovals } from './approvals'; +import { getApprovalFlows, hasPendingApprovals } from './approvals'; describe('approval selectors', () => { const mockedState = { @@ -13,6 +13,7 @@ describe('approval selectors', () => { type: ApprovalType.WatchAsset, requestData: {}, requestState: null, + expectsResult: false, }, '2': { id: '2', @@ -21,13 +22,19 @@ describe('approval selectors', () => { type: ApprovalType.Transaction, requestData: {}, requestState: null, + expectsResult: false, }, }, - unapprovedTxs: { - '2': { + approvalFlows: [ + { + id: '1', + loadingText: 'loadingText1', + }, + { id: '2', + loadingText: 'loadingText2', }, - }, + ], }, }; @@ -47,4 +54,12 @@ describe('approval selectors', () => { expect(result).toBe(false); }); }); + + describe('getApprovalFlows', () => { + it('should return existing approval flows', () => { + const result = getApprovalFlows(mockedState); + + expect(result).toStrictEqual(mockedState.metamask.approvalFlows); + }); + }); }); diff --git a/ui/selectors/approvals.ts b/ui/selectors/approvals.ts index a424798c4..e619f274d 100644 --- a/ui/selectors/approvals.ts +++ b/ui/selectors/approvals.ts @@ -1,13 +1,10 @@ import { ApprovalControllerState } from '@metamask/approval-controller'; import { ApprovalType } from '@metamask/controller-utils'; -import { TransactionMeta } from '../../shared/constants/transaction'; type ApprovalsMetaMaskState = { metamask: { pendingApprovals: ApprovalControllerState['pendingApprovals']; - unapprovedTxs: { - [transactionId: string]: TransactionMeta; - }; + approvalFlows: ApprovalControllerState['approvalFlows']; }; }; @@ -46,3 +43,7 @@ export const getApprovalRequestsByType = ( return pendingApprovalRequests; }; + +export function getApprovalFlows(state: ApprovalsMetaMaskState) { + return state.metamask.approvalFlows; +} diff --git a/ui/store/actions.ts b/ui/store/actions.ts index d635a14d4..509127bf6 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -35,6 +35,7 @@ import { getPermittedAccountsForCurrentTab, getSelectedAddress, hasTransactionPendingApprovals, + getApprovalFlows, ///: BEGIN:ONLY_INCLUDE_IN(snaps) getNotifications, ///: END:ONLY_INCLUDE_IN @@ -2382,9 +2383,12 @@ export function closeCurrentNotificationWindow(): ThunkAction< AnyAction > { return (_, getState) => { + const state = getState(); + const approvalFlows = getApprovalFlows(state); if ( getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION && - !hasTransactionPendingApprovals(getState()) + !hasTransactionPendingApprovals(state) && + approvalFlows.length === 0 ) { closeNotificationPopup(); } diff --git a/ui/store/store.ts b/ui/store/store.ts index 35870f4a1..bd6e42427 100644 --- a/ui/store/store.ts +++ b/ui/store/store.ts @@ -69,6 +69,7 @@ interface TemporaryBackgroundState { networkId: string | null; networkStatus: NetworkStatus; pendingApprovals: ApprovalControllerState['pendingApprovals']; + approvalFlows: ApprovalControllerState['approvalFlows']; knownMethodData?: { [fourBytePrefix: string]: Record; }; diff --git a/yarn.lock b/yarn.lock index 3279bfe14..6c7da3567 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3857,16 +3857,16 @@ __metadata: languageName: node linkType: hard -"@metamask/approval-controller@npm:^3.0.0": - version: 3.1.0 - resolution: "@metamask/approval-controller@npm:3.1.0" +"@metamask/approval-controller@npm:^3.3.0": + version: 3.3.0 + resolution: "@metamask/approval-controller@npm:3.3.0" dependencies: "@metamask/base-controller": ^3.0.0 "@metamask/utils": ^5.0.2 eth-rpc-errors: ^4.0.2 immer: ^9.0.6 nanoid: ^3.1.31 - checksum: 2043e62e8815a600e839617b4df26515fc33f655e21562dc230cd6dbfc4677e955e1e45a5df8fbb2def2122b3578f6a632acb939f8175419febb1471d0c48ce0 + checksum: 1fa6111a897d6f4aa369fd1a669fb5e16558277019f9d6c61449aea0d7b2672a62c189e5b3d9e84ab6e4d5826932c78d2bdb0f05aafb184a4ff07903c46abf2c languageName: node linkType: hard @@ -24482,7 +24482,7 @@ __metadata: "@metamask-institutional/transaction-update": ^0.1.21 "@metamask/address-book-controller": ^3.0.0 "@metamask/announcement-controller": ^4.0.0 - "@metamask/approval-controller": ^3.1.0 + "@metamask/approval-controller": ^3.3.0 "@metamask/assets-controllers": ^9.2.0 "@metamask/auto-changelog": ^2.1.0 "@metamask/base-controller": ^3.0.0 From 12bd60ee791e008a944de26cf2bd999b733a2385 Mon Sep 17 00:00:00 2001 From: Brad Decker Date: Thu, 29 Jun 2023 11:01:54 -0500 Subject: [PATCH 20/30] wallet created metrics tests (#19791) Co-authored-by: Danica Shen --- test/e2e/helpers.js | 89 +++++++++++++++++++- test/e2e/metrics/signature-approved.spec.js | 23 +---- test/e2e/metrics/wallet-created.spec.js | 93 +++++++++++++++++++++ 3 files changed, 181 insertions(+), 24 deletions(-) create mode 100644 test/e2e/metrics/wallet-created.spec.js diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 42a8ba657..d6a4bb2ab 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -294,22 +294,52 @@ const completeImportSRPOnboardingFlowWordByWord = async ( await driver.clickElement('[data-testid="pin-extension-done"]'); }; -const completeCreateNewWalletOnboardingFlow = async (driver, password) => { +/** + * Begin the create new wallet flow on onboarding screen. + * + * @param {WebDriver} driver + */ +const onboardingBeginCreateNewWallet = async (driver) => { // agree to terms of use await driver.clickElement('[data-testid="onboarding-terms-checkbox"]'); // welcome await driver.clickElement('[data-testid="onboarding-create-wallet"]'); +}; +/** + * Choose either "I Agree" or "No Thanks" on the MetaMetrics onboarding screen + * + * @param {WebDriver} driver + * @param {boolean} optin - true to opt into metrics, default is false + */ +const onboardingChooseMetametricsOption = async (driver, optin = false) => { + const optionIdentifier = optin ? 'i-agree' : 'no-thanks'; // metrics - await driver.clickElement('[data-testid="metametrics-no-thanks"]'); + await driver.clickElement(`[data-testid="metametrics-${optionIdentifier}"]`); +}; +/** + * Set a password for MetaMask during onboarding + * + * @param {WebDriver} driver + * @param {string} password - Password to set + */ +const onboardingCreatePassword = async (driver, password) => { // create password await driver.fill('[data-testid="create-password-new"]', password); await driver.fill('[data-testid="create-password-confirm"]', password); await driver.clickElement('[data-testid="create-password-terms"]'); await driver.clickElement('[data-testid="create-password-wallet"]'); +}; +/** + * Choose to secure wallet, and then get recovery phrase and confirm the SRP + * during onboarding flow. + * + * @param {WebDriver} driver + */ +const onboardingRevealAndConfirmSRP = async (driver) => { // secure my wallet await driver.clickElement('[data-testid="secure-wallet-recommended"]'); @@ -336,16 +366,40 @@ const completeCreateNewWalletOnboardingFlow = async (driver, password) => { await driver.clickElement('[data-testid="confirm-recovery-phrase"]'); await driver.clickElement({ text: 'Confirm', tag: 'button' }); +}; +/** + * Complete the onboarding flow by confirming completion. Final step before the + * reminder to pin the extension. + * + * @param {WebDriver} driver + */ +const onboardingCompleteWalletCreation = async (driver) => { // complete await driver.findElement({ text: 'Wallet creation successful', tag: 'h2' }); await driver.clickElement('[data-testid="onboarding-complete-done"]'); +}; +/** + * Move through the steps of pinning extension after successful onboarding + * + * @param {WebDriver} driver + */ +const onboardingPinExtension = async (driver) => { // pin extension await driver.clickElement('[data-testid="pin-extension-next"]'); await driver.clickElement('[data-testid="pin-extension-done"]'); }; +const completeCreateNewWalletOnboardingFlow = async (driver, password) => { + await onboardingBeginCreateNewWallet(driver); + await onboardingChooseMetametricsOption(driver, false); + await onboardingCreatePassword(driver, password); + await onboardingRevealAndConfirmSRP(driver); + await onboardingCompleteWalletCreation(driver); + await onboardingPinExtension(driver); +}; + const importWrongSRPOnboardingFlow = async (driver, seedPhrase) => { // agree to terms of use await driver.clickElement('[data-testid="onboarding-terms-checkbox"]'); @@ -687,6 +741,30 @@ async function switchToNotificationWindow(driver) { await driver.switchToWindowWithTitle('MetaMask Notification', windowHandles); } +/** + * When mocking the segment server and returning an array of mocks from the + * mockServer method, this method will allow getting all of the seen requests + * for each mock in the array. + * + * @param {WebDriver} driver + * @param {import('mockttp').Mockttp} mockedEndpoints + * @returns {import('mockttp/dist/pluggable-admin').MockttpClientResponse[]} + */ +async function getEventPayloads(driver, mockedEndpoints) { + await driver.wait(async () => { + let isPending = true; + for (const mockedEndpoint of mockedEndpoints) { + isPending = await mockedEndpoint.isPending(); + } + return isPending === false; + }, 10000); + const mockedRequests = []; + for (const mockedEndpoint of mockedEndpoints) { + mockedRequests.push(...(await mockedEndpoint.getSeenRequests())); + } + return mockedRequests.map((req) => req.body.json.batch).flat(); +} + module.exports = { DAPP_URL, DAPP_ONE_URL, @@ -734,4 +812,11 @@ module.exports = { sleepSeconds, terminateServiceWorker, switchToNotificationWindow, + getEventPayloads, + onboardingBeginCreateNewWallet, + onboardingChooseMetametricsOption, + onboardingCreatePassword, + onboardingRevealAndConfirmSRP, + onboardingCompleteWalletCreation, + onboardingPinExtension, }; diff --git a/test/e2e/metrics/signature-approved.spec.js b/test/e2e/metrics/signature-approved.spec.js index 88a61131a..989656832 100644 --- a/test/e2e/metrics/signature-approved.spec.js +++ b/test/e2e/metrics/signature-approved.spec.js @@ -6,6 +6,7 @@ const { regularDelayMs, openDapp, unlockWallet, + getEventPayloads, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -76,28 +77,6 @@ async function clickSignOnSignatureConfirmation(driver) { await driver.getAllWindowHandles(); } -/** - * This method handles getting the mocked requests to the segment server - * - * @param {WebDriver} driver - * @param {import('mockttp').Mockttp} mockedEndpoints - * @returns {import('mockttp/dist/pluggable-admin').MockttpClientResponse[]} - */ -async function getEventPayloads(driver, mockedEndpoints) { - await driver.wait(async () => { - let isPending = true; - for (const mockedEndpoint of mockedEndpoints) { - isPending = await mockedEndpoint.isPending(); - } - return isPending === false; - }, 10000); - const mockedRequests = []; - for (const mockedEndpoint of mockedEndpoints) { - mockedRequests.push(...(await mockedEndpoint.getSeenRequests())); - } - return mockedRequests.map((req) => req.body.json.batch).flat(); -} - describe('Signature Approved Event', function () { it('Successfully tracked for signTypedData_v4', async function () { await withFixtures( diff --git a/test/e2e/metrics/wallet-created.spec.js b/test/e2e/metrics/wallet-created.spec.js new file mode 100644 index 000000000..8b04ee956 --- /dev/null +++ b/test/e2e/metrics/wallet-created.spec.js @@ -0,0 +1,93 @@ +const { strict: assert } = require('assert'); +const { + defaultGanacheOptions, + withFixtures, + WALLET_PASSWORD, + onboardingBeginCreateNewWallet, + onboardingChooseMetametricsOption, + onboardingCreatePassword, + onboardingRevealAndConfirmSRP, + onboardingCompleteWalletCreation, + onboardingPinExtension, + getEventPayloads, +} = require('../helpers'); +const FixtureBuilder = require('../fixture-builder'); + +/** + * mocks the segment api multiple times for specific payloads that we expect to + * see when these tests are run. In this case we are looking for + * 'Permissions Requested' and 'Permissions Received'. Do not use the constants + * from the metrics constants files, because if these change we want a strong + * indicator to our data team that the shape of data will change. + * + * @param {import('mockttp').Mockttp} mockServer + * @returns {Promise[]} + */ +async function mockSegment(mockServer) { + return [ + await mockServer + .forPost('https://api.segment.io/v1/batch') + .withJsonBodyIncluding({ + batch: [{ type: 'track', event: 'Wallet Setup Selected' }], + }) + .thenCallback(() => { + return { + statusCode: 200, + }; + }), + await mockServer + .forPost('https://api.segment.io/v1/batch') + .withJsonBodyIncluding({ + batch: [{ type: 'track', event: 'Wallet Created' }], + }) + .thenCallback(() => { + return { + statusCode: 200, + }; + }), + ]; +} + +describe('Wallet Created Event', function () { + it('Successfully tracked when onboarding', async function () { + await withFixtures( + { + fixtures: new FixtureBuilder({ onboarding: true }) + .withMetaMetricsController({ + metaMetricsId: 'fake-metrics-id', + participateInMetaMetrics: true, + }) + .build(), + defaultGanacheOptions, + title: this.test.title, + testSpecificMock: mockSegment, + }, + async ({ driver, mockedEndpoint: mockedEndpoints }) => { + await driver.navigate(); + + await onboardingBeginCreateNewWallet(driver); + await onboardingChooseMetametricsOption(driver, true); + await onboardingCreatePassword(driver, WALLET_PASSWORD); + await onboardingRevealAndConfirmSRP(driver); + await onboardingCompleteWalletCreation(driver); + await onboardingPinExtension(driver); + + const events = await getEventPayloads(driver, mockedEndpoints); + assert.deepStrictEqual(events[0].properties, { + account_type: 'metamask', + category: 'Onboarding', + locale: 'en', + chain_id: '0x539', + environment_type: 'fullscreen', + }); + assert.deepStrictEqual(events[1].properties, { + method: 'create', + category: 'Onboarding', + locale: 'en', + chain_id: '0x539', + environment_type: 'fullscreen', + }); + }, + ); + }); +}); From 6bb5e6941dd05188aa6900245ca385fabdc52ef6 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 29 Jun 2023 13:51:58 -0230 Subject: [PATCH 21/30] Disable the opensea provider and NFT feature What's New notifications (#19828) --- ui/selectors/selectors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 2a0fab346..04517c7e0 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -991,8 +991,8 @@ function getAllowedAnnouncementIds(state) { 15: false, 16: false, 17: false, - 18: true, - 19: true, + 18: false, + 19: false, 20: currentKeyringIsLedger && isFirefox, 21: isSwapsChain, }; From 2bf6f1bb377e8331915b598f7be611f1e474d8d0 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 29 Jun 2023 13:51:58 -0230 Subject: [PATCH 22/30] Disable the opensea provider and NFT feature What's New notifications (#19828) --- ui/selectors/selectors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/selectors/selectors.js b/ui/selectors/selectors.js index 38722ac80..f5d12d814 100644 --- a/ui/selectors/selectors.js +++ b/ui/selectors/selectors.js @@ -991,8 +991,8 @@ function getAllowedAnnouncementIds(state) { 15: false, 16: false, 17: false, - 18: true, - 19: true, + 18: false, + 19: false, 20: currentKeyringIsLedger && isFirefox, 21: isSwapsChain, }; From 59980f1b2714b2050284634b819495ef565f6e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Oliv=C3=A9?= Date: Fri, 30 Jun 2023 12:41:28 +0200 Subject: [PATCH 23/30] Fixing connect custody flow (#19802) * Fixing connect custody flow * Finished fixing mmi connect flow * Fixed test * updated snapshot * Finished fixing tests --- app/scripts/metamask-controller.js | 43 ++++-- .../confirm-add-custodian-token.js | 129 +++++++++--------- .../__snapshots__/custody.test.js.snap | 127 +++-------------- ui/pages/institutional/custody/custody.js | 82 +++++------ .../institutional/custody/custody.test.js | 26 ++-- .../institution-background.test.js | 1 - .../institutional/institution-background.ts | 46 ++++--- 7 files changed, 186 insertions(+), 268 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index e3a0a704a..7c40d960a 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2368,19 +2368,38 @@ export default class MetamaskController extends EventEmitter { ...getPermissionBackgroundApiMethods(permissionController), ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) - connectCustodyAddresses: - this.mmiController.connectCustodyAddresses.bind(this), - getCustodianAccounts: this.mmiController.getCustodianAccounts.bind(this), + connectCustodyAddresses: this.mmiController.connectCustodyAddresses.bind( + this.mmiController, + ), + getCustodianAccounts: this.mmiController.getCustodianAccounts.bind( + this.mmiController, + ), getCustodianAccountsByAddress: - this.mmiController.getCustodianAccountsByAddress.bind(this), + this.mmiController.getCustodianAccountsByAddress.bind( + this.mmiController, + ), getCustodianTransactionDeepLink: - this.mmiController.getCustodianTransactionDeepLink.bind(this), + this.mmiController.getCustodianTransactionDeepLink.bind( + this.mmiController, + ), getCustodianConfirmDeepLink: - this.mmiController.getCustodianConfirmDeepLink.bind(this), + this.mmiController.getCustodianConfirmDeepLink.bind(this.mmiController), getCustodianSignMessageDeepLink: - this.mmiController.getCustodianSignMessageDeepLink.bind(this), - getCustodianToken: this.mmiController.getCustodianToken.bind(this), - getCustodianJWTList: this.mmiController.getCustodianJWTList.bind(this), + this.mmiController.getCustodianSignMessageDeepLink.bind( + this.mmiController, + ), + getCustodianToken: this.mmiController.getCustodianToken.bind( + this.mmiController, + ), + getCustodianJWTList: this.mmiController.getCustodianJWTList.bind( + this.mmiController, + ), + getAllCustodianAccountsWithToken: + this.mmiController.getAllCustodianAccountsWithToken.bind( + this.mmiController, + ), + setCustodianNewRefreshToken: + this.mmiController.setCustodianNewRefreshToken.bind(this.mmiController), setWaitForConfirmDeepLinkDialog: this.custodyController.setWaitForConfirmDeepLinkDialog.bind( this.custodyController, @@ -2393,8 +2412,6 @@ export default class MetamaskController extends EventEmitter { this.custodyController.getCustodianConnectRequest.bind( this.custodyController, ), - getAllCustodianAccountsWithToken: - this.mmiController.getAllCustodianAccountsWithToken.bind(this), getMmiConfiguration: this.mmiConfigurationController.getConfiguration.bind( this.mmiConfigurationController, @@ -2415,12 +2432,10 @@ export default class MetamaskController extends EventEmitter { this.institutionalFeaturesController.syncReportsInProgress.bind( this.institutionalFeaturesController, ), - removeConnectInstitutionalFeature: this.institutionalFeaturesController.removeConnectInstitutionalFeature.bind( this.institutionalFeaturesController, ), - getComplianceHistoricalReportsByAddress: this.institutionalFeaturesController.getComplianceHistoricalReportsByAddress.bind( this.institutionalFeaturesController, @@ -2429,8 +2444,6 @@ export default class MetamaskController extends EventEmitter { this.institutionalFeaturesController.removeAddTokenConnectRequest.bind( this.institutionalFeaturesController, ), - setCustodianNewRefreshToken: - this.mmiController.setCustodianNewRefreshToken.bind(this), ///: END:ONLY_INCLUDE_IN ///: BEGIN:ONLY_INCLUDE_IN(snaps) diff --git a/ui/pages/institutional/confirm-add-custodian-token/confirm-add-custodian-token.js b/ui/pages/institutional/confirm-add-custodian-token/confirm-add-custodian-token.js index 15c879463..e353f2285 100644 --- a/ui/pages/institutional/confirm-add-custodian-token/confirm-add-custodian-token.js +++ b/ui/pages/institutional/confirm-add-custodian-token/confirm-add-custodian-token.js @@ -5,10 +5,10 @@ import PulseLoader from '../../../components/ui/pulse-loader'; import { CUSTODY_ACCOUNT_ROUTE } from '../../../helpers/constants/routes'; import { AlignItems, - DISPLAY, + Display, TextColor, - TEXT_ALIGN, - FLEX_DIRECTION, + TextAlign, + FlexDirection, } from '../../../helpers/constants/design-system'; import { BUILT_IN_NETWORKS } from '../../../../shared/constants/network'; import { I18nContext } from '../../../contexts/i18n'; @@ -23,8 +23,12 @@ import { Button, BUTTON_SIZES, BUTTON_VARIANT, + Box, } from '../../../components/component-library'; -import Box from '../../../components/ui/box'; +import { + complianceActivated, + getInstitutionalConnectRequests, +} from '../../../ducks/institutional/institutional'; const ConfirmAddCustodianToken = () => { const t = useContext(I18nContext); @@ -34,59 +38,12 @@ const ConfirmAddCustodianToken = () => { const mmiActions = mmiActionsFactory(); const mostRecentOverviewPage = useSelector(getMostRecentOverviewPage); - const connectRequests = useSelector( - (state) => state.metamask.institutionalFeatures?.connectRequests, - ); - const complianceActivated = useSelector((state) => - Boolean(state.metamask.institutionalFeatures?.complianceProjectId), - ); + const connectRequests = useSelector(getInstitutionalConnectRequests); + const isComplianceActivated = useSelector(complianceActivated); const [showMore, setShowMore] = useState(false); const [isLoading, setIsLoading] = useState(false); const [connectError, setConnectError] = useState(''); - const handleConnectError = (e) => { - let errorMessage = e.message; - - if (!errorMessage) { - errorMessage = 'Connection error'; - } - - setConnectError(errorMessage); - setIsLoading(false); - }; - - const renderSelectedToken = () => { - const connectRequest = connectRequests ? connectRequests[0] : undefined; - - return ( - - - {showMore && connectRequest?.token - ? connectRequest?.token - : `...${connectRequest?.token.slice(-9)}`} - - {!showMore && ( - - { - setShowMore(true); - }} - > - {t('showMore')} - - - )} - - ); - }; - const connectRequest = connectRequests ? connectRequests[0] : undefined; if (!connectRequest) { @@ -148,7 +105,31 @@ const ConfirmAddCustodianToken = () => { marginLeft={4} className="add_custodian_token_confirm__token" > - {renderSelectedToken()} + + + {showMore && connectRequest?.token + ? connectRequest?.token + : `...${connectRequest?.token.slice(-9)}`} + + {!showMore && ( + + { + setShowMore(true); + }} + > + {t('showMore')} + + + )} + {connectRequest.apiUrl && ( @@ -168,9 +149,9 @@ const ConfirmAddCustodianToken = () => { )} - {!complianceActivated && ( + {!isComplianceActivated && ( - + {connectError} @@ -180,19 +161,19 @@ const ConfirmAddCustodianToken = () => { {isLoading ? ( ) : ( - + -

- Back -

-
-

-
-

-

-

-

- Enter your token or add a new token -

-
-
-
-
-

- Paste or drop your token here: -

- -
-
-
-

- API URL -

-
- -
-
-
-
- - -
-
-
`; diff --git a/ui/pages/institutional/custody/custody.js b/ui/pages/institutional/custody/custody.js index 7ab0efb5f..1257e1c57 100644 --- a/ui/pages/institutional/custody/custody.js +++ b/ui/pages/institutional/custody/custody.js @@ -44,6 +44,7 @@ import { getCurrentChainId } from '../../../selectors'; import { getMMIConfiguration } from '../../../selectors/institutional/selectors'; import CustodyAccountList from '../connect-custody/account-list'; import JwtUrlForm from '../../../components/institutional/jwt-url-form'; +import PulseLoader from '../../../components/ui/pulse-loader/pulse-loader'; const CustodyPage = () => { const t = useI18nContext(); @@ -55,6 +56,7 @@ const CustodyPage = () => { const currentChainId = useSelector(getCurrentChainId); const { custodians } = useSelector(getMMIConfiguration); + const [loading, setLoading] = useState(true); const [selectedAccounts, setSelectedAccounts] = useState({}); const [selectedCustodianName, setSelectedCustodianName] = useState(''); const [selectedCustodianImage, setSelectedCustodianImage] = useState(null); @@ -200,12 +202,12 @@ const CustodyPage = () => { ); const getCustodianAccounts = useCallback( - async (token, custody, getNonImportedAccounts) => { + async (token, getNonImportedAccounts) => { return await dispatch( mmiActions.getCustodianAccounts( token, apiUrl, - custody || selectedCustodianType, + selectedCustodianType, getNonImportedAccounts, ), ); @@ -218,12 +220,8 @@ const CustodyPage = () => { // If you have one JWT already, but no dropdown yet, currentJwt is null! const jwt = currentJwt || jwtList[0]; setConnectError(''); - const accountsValue = await getCustodianAccounts( - jwt, - apiUrl, - selectedCustodianType, - true, - ); + const accountsValue = await getCustodianAccounts(jwt, true); + setAccounts(accountsValue); trackEvent({ category: 'MMI', @@ -245,15 +243,16 @@ const CustodyPage = () => { handleConnectError, jwtList, selectedCustodianName, - selectedCustodianType, trackEvent, ]); useEffect(() => { + setLoading(true); const fetchConnectRequest = async () => { const connectRequestValue = await dispatch( mmiActions.getCustodianConnectRequest(), ); + setChainId(parseInt(currentChainId, 16)); // check if it's empty object @@ -266,15 +265,22 @@ const CustodyPage = () => { setSelectedCustodianType(connectRequestValue.custodianType); setSelectedCustodianName(connectRequestValue.custodianName); setApiUrl(connectRequestValue.apiUrl); - connect(); } }; - // call the function - fetchConnectRequest() - // make sure to catch any error - .catch(console.error); - }, [dispatch, connect, currentChainId, mmiActions]); + const handleFetchConnectRequest = async () => { + try { + await fetchConnectRequest(); + setLoading(false); + } catch (error) { + console.error(error); + setLoading(false); + } + }; + + handleFetchConnectRequest(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); useEffect(() => { const handleNetworkChange = async () => { @@ -282,14 +288,7 @@ const CustodyPage = () => { const jwt = currentJwt || jwtList[0]; if (jwt && jwt.length) { - setAccounts( - await getCustodianAccounts( - jwt, - apiUrl, - selectedCustodianType, - true, - ), - ); + setAccounts(await getCustodianAccounts(jwt, true)); } } }; @@ -341,6 +340,10 @@ const CustodyPage = () => { } }; + if (loading) { + return ; + } + return ( <> {connectError && ( @@ -348,7 +351,6 @@ const CustodyPage = () => { {connectError} )} - {selectError && ( {selectError} @@ -397,7 +399,6 @@ const CustodyPage = () => { ) : null} - {!accounts && selectedCustodianType && ( <> { )} - {accounts && accounts.length > 0 && ( <> { selectedAccounts={selectedAccounts} onAddAccounts={async () => { try { + const selectedCustodian = custodians.find( + (custodian) => custodian.name === selectedCustodianName, + ); + await dispatch( mmiActions.connectCustodyAddresses( selectedCustodianType, @@ -548,17 +552,7 @@ const CustodyPage = () => { selectedAccounts, ), ); - const selectedCustodian = custodians.find( - (custodian) => custodian.name === selectedCustodianName, - ); - history.push({ - pathname: CUSTODY_ACCOUNT_DONE_ROUTE, - state: { - imgSrc: selectedCustodian.iconUrl, - title: t('custodianAccountAddedTitle'), - description: t('custodianAccountAddedDesc'), - }, - }); + trackEvent({ category: 'MMI', event: 'Custodial accounts connected', @@ -568,6 +562,15 @@ const CustodyPage = () => { chainId, }, }); + + history.push({ + pathname: CUSTODY_ACCOUNT_DONE_ROUTE, + state: { + imgSrc: selectedCustodian.iconUrl, + title: t('custodianAccountAddedTitle'), + description: t('custodianAccountAddedDesc'), + }, + }); } catch (e) { setSelectError(e.message); } @@ -598,7 +601,6 @@ const CustodyPage = () => { /> )} - {accounts && accounts.length === 0 && ( { marginBottom={2} fontWeight={FontWeight.Bold} color={TextColor.textDefault} - variant={TextVariant.bodySm} + variant={TextVariant.bodyLgMedium} > {t('allCustodianAccountsConnectedTitle')} - + {t('allCustodianAccountsConnectedSubtitle')} diff --git a/ui/pages/institutional/custody/custody.test.js b/ui/pages/institutional/custody/custody.test.js index f944d33aa..22612a456 100644 --- a/ui/pages/institutional/custody/custody.test.js +++ b/ui/pages/institutional/custody/custody.test.js @@ -1,6 +1,6 @@ import React from 'react'; import configureMockStore from 'redux-mock-store'; -import { fireEvent, waitFor, screen } from '@testing-library/react'; +import { fireEvent, waitFor, screen, act } from '@testing-library/react'; import thunk from 'redux-thunk'; import { renderWithProvider } from '../../../../test/lib/render-helpers'; import CustodyPage from '.'; @@ -16,8 +16,8 @@ const mockedGetCustodianConnectRequest = jest.fn().mockReturnValue({ custodian: 'saturn', token: 'token', apiUrl: 'url', - custodianType: 'JSON-RPC', - custodianName: 'Saturn', + custodianType: undefined, + custodianName: 'saturn', }); jest.mock('../../../store/institutional/institution-background', () => ({ @@ -85,29 +85,19 @@ describe('CustodyPage', function () { }); }); - it('calls getCustodianJwtList on custody select when connect btn is click', async () => { - const { getByTestId } = renderWithProvider(, store); - - const custodyBtn = getByTestId('custody-connect-button'); - await waitFor(() => { - fireEvent.click(custodyBtn); + it('calls getCustodianJwtList on custody select when connect btn is click and clicks connect button and shows the jwt form', async () => { + act(() => { + renderWithProvider(, store); }); await waitFor(() => { - expect(mockedGetCustodianJWTList).toHaveBeenCalled(); - }); - }); - - it('clicks connect button and shows the jwt form', async () => { - const { getByTestId } = renderWithProvider(, store); - const custodyBtn = getByTestId('custody-connect-button'); - - await waitFor(() => { + const custodyBtn = screen.getByTestId('custody-connect-button'); fireEvent.click(custodyBtn); }); await waitFor(() => { expect(screen.getByTestId('jwt-form-connect-button')).toBeInTheDocument(); + expect(mockedGetCustodianJWTList).toHaveBeenCalled(); }); }); }); diff --git a/ui/store/institutional/institution-background.test.js b/ui/store/institutional/institution-background.test.js index 878ea24ce..7d9f0869f 100644 --- a/ui/store/institutional/institution-background.test.js +++ b/ui/store/institutional/institution-background.test.js @@ -117,7 +117,6 @@ describe('Institution Actions', () => { 'newApiUrl', ); connectCustodyAddresses(jest.fn()); - setWaitForConfirmDeepLinkDialog(jest.fn()); expect(connectCustodyAddresses).toBeDefined(); expect(setWaitForConfirmDeepLinkDialog).toBeDefined(); }); diff --git a/ui/store/institutional/institution-background.ts b/ui/store/institutional/institution-background.ts index 22b0c0818..5a6156e29 100644 --- a/ui/store/institutional/institution-background.ts +++ b/ui/store/institutional/institution-background.ts @@ -91,14 +91,17 @@ export function mmiActionsFactory() { }; } - function createAction(name: string, payload: any) { - return () => { - callBackgroundMethod(name, [payload], (err) => { - if (isErrorWithMessage(err)) { - throw new Error(err.message); + function createAction(name: string, payload: any): Promise { + return new Promise((resolve, reject) => { + callBackgroundMethod(name, [payload], (error) => { + if (error) { + reject(error); + return; } + + resolve(); }); - }; + }); } return { @@ -190,18 +193,27 @@ export function mmiActionsFactory() { createAction('syncReportsInProgress', { address, historicalReports }), removeConnectInstitutionalFeature: (origin: string, projectId: string) => createAction('removeConnectInstitutionalFeature', { origin, projectId }), - removeAddTokenConnectRequest: ( - origin: string, - apiUrl: string, - token: string, - ) => + removeAddTokenConnectRequest: ({ + origin, + apiUrl, + token, + }: { + origin: string; + apiUrl: string; + token: string; + }) => createAction('removeAddTokenConnectRequest', { origin, apiUrl, token }), - setCustodianConnectRequest: ( - token: string, - apiUrl: string, - custodianType: string, - custodianName: string, - ) => + setCustodianConnectRequest: ({ + token, + apiUrl, + custodianType, + custodianName, + }: { + token: string; + apiUrl: string; + custodianType: string; + custodianName: string; + }) => createAsyncAction('setCustodianConnectRequest', [ { token, apiUrl, custodianType, custodianName }, ]), From 5545e5e5818b0e9be532eacea778ffff52b40eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Oliv=C3=A9?= Date: Fri, 30 Jun 2023 14:03:47 +0200 Subject: [PATCH 24/30] Added code fence to remove backup notice (#19840) --- ui/pages/home/home.component.js | 37 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/ui/pages/home/home.component.js b/ui/pages/home/home.component.js index b0c838762..602ce34cd 100644 --- a/ui/pages/home/home.component.js +++ b/ui/pages/home/home.component.js @@ -474,7 +474,6 @@ export default class Home extends PureComponent { } /> ) : null} - {removeNftMessage === 'success' ? ( ) : null} - {shouldShowSeedPhraseReminder ? ( - { - const backUpSRPRoute = `${ONBOARDING_SECURE_YOUR_WALLET_ROUTE}/?isFromReminder=true`; - if (isPopup) { - global.platform.openExtensionInBrowser(backUpSRPRoute); - } else { - history.push(backUpSRPRoute); - } - }} - infoText={t('backupApprovalInfo')} - key="home-backupApprovalNotice" - /> - ) : null} + { + ///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask) + shouldShowSeedPhraseReminder ? ( + { + const backUpSRPRoute = `${ONBOARDING_SECURE_YOUR_WALLET_ROUTE}/?isFromReminder=true`; + if (isPopup) { + global.platform.openExtensionInBrowser(backUpSRPRoute); + } else { + history.push(backUpSRPRoute); + } + }} + infoText={t('backupApprovalInfo')} + key="home-backupApprovalNotice" + /> + ) : null + ///: END:ONLY_INCLUDE_IN + } {infuraBlocked && this.state.canShowBlockageNotification ? ( Date: Fri, 30 Jun 2023 15:22:07 +0300 Subject: [PATCH 25/30] fix: skip snow usage for MV3 test build (#19827) * try fix * fix lint for app-init.js * fix lint for use-snow.js * remove comment in app-init.js --------- Co-authored-by: Danica Shen --- app/scripts/app-init.js | 8 ++++++++ app/scripts/use-snow.js | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/scripts/app-init.js b/app/scripts/app-init.js index 450c59597..f4cc97b83 100644 --- a/app/scripts/app-init.js +++ b/app/scripts/app-init.js @@ -60,6 +60,14 @@ function importAllScripts() { loadFile('./globalthis.js'); loadFile('./sentry-install.js'); + // eslint-disable-next-line no-undef + const isWorker = !self.document; + if (!isWorker) { + loadFile('./snow.js'); + } + + loadFile('./use-snow.js'); + // Always apply LavaMoat in e2e test builds, so that we can capture initialization stats if (testMode || applyLavaMoat) { loadFile('./runtime-lavamoat.js'); diff --git a/app/scripts/use-snow.js b/app/scripts/use-snow.js index 868db4e36..87d00be3d 100644 --- a/app/scripts/use-snow.js +++ b/app/scripts/use-snow.js @@ -8,14 +8,22 @@ Changing this code must be done cautiously to avoid breaking the app! // eslint-disable-next-line import/unambiguous (function () { const log = console.log.bind(console); + // eslint-disable-next-line no-undef + const isWorker = !self.document; const msg = 'Snow detected a new realm creation attempt in MetaMask. Performing scuttling on new realm.'; - Object.defineProperty(window.top, 'SCUTTLER', { + // eslint-disable-next-line no-undef + Object.defineProperty(self, 'SCUTTLER', { value: (realm, scuttle) => { - window.top.SNOW((win) => { - log(msg, win); - scuttle(win); - }, realm); + if (isWorker) { + scuttle(realm); + } else { + // eslint-disable-next-line no-undef + self.SNOW((win) => { + log(msg, win); + scuttle(win); + }, realm); + } }, }); })(); From 17c596473578b6a09d0bb553c80f9f13bc96dfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Oliv=C3=A9?= Date: Fri, 30 Jun 2023 15:19:59 +0200 Subject: [PATCH 26/30] =?UTF-8?q?[MMI]=C2=A0Removed=20institutional=20port?= =?UTF-8?q?folio=20dashboard=20(#19842)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Removed institutional portfolio dashboard * Fixed eslint * Removed unused key --- app/_locales/en/messages.json | 3 -- .../multichain/global-menu/global-menu.js | 48 ++++--------------- 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index b187737be..5d9b0ba06 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -673,9 +673,6 @@ "coingecko": { "message": "CoinGecko" }, - "compliance": { - "message": "Compliance" - }, "complianceActivatedDesc": { "message": "You can now use compliance in MetaMask Institutional. Receiving AML/CFT analysis within the confirmation screen on all the addresses you interact with." }, diff --git a/ui/components/multichain/global-menu/global-menu.js b/ui/components/multichain/global-menu/global-menu.js index 6d813aa72..50ff45780 100644 --- a/ui/components/multichain/global-menu/global-menu.js +++ b/ui/components/multichain/global-menu/global-menu.js @@ -9,9 +9,6 @@ import { ///: BEGIN:ONLY_INCLUDE_IN(snaps) NOTIFICATIONS_ROUTE, ///: END:ONLY_INCLUDE_IN(snaps) - ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) - COMPLIANCE_FEATURE_ROUTE, - ///: END:ONLY_INCLUDE_IN } from '../../../helpers/constants/routes'; import { lockMetamask } from '../../../store/actions'; import { useI18nContext } from '../../../hooks/useI18nContext'; @@ -23,12 +20,7 @@ import { } from '../../component-library'; import { Menu, MenuItem } from '../../ui/menu'; import { getEnvironmentType } from '../../../../app/scripts/lib/util'; -import { - ENVIRONMENT_TYPE_FULLSCREEN, - ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) - ENVIRONMENT_TYPE_POPUP, - ///: END:ONLY_INCLUDE_IN -} from '../../../../shared/constants/app'; +import { ENVIRONMENT_TYPE_FULLSCREEN } from '../../../../shared/constants/app'; import { SUPPORT_LINK } from '../../../../shared/lib/ui-utils'; ///: BEGIN:ONLY_INCLUDE_IN(build-beta,build-flask) import { SUPPORT_REQUEST_LINK } from '../../../helpers/constants/common'; @@ -114,44 +106,22 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => { { ///: BEGIN:ONLY_INCLUDE_IN(build-mmi) - <> - {mmiPortfolioEnabled && ( - { - trackEvent({ - category: MetaMetricsEventCategory.Navigation, - event: MetaMetricsEventName.UserClickedPortfolioButton, - }); - window.open(mmiPortfolioUrl, '_blank'); - closeMenu(); - }} - data-testid="global-menu-mmi-portfolio" - > - {t('portfolioDashboard')} - - )} - + mmiPortfolioEnabled && ( { trackEvent({ category: MetaMetricsEventCategory.Navigation, - event: MetaMetricsEventName.UserClickedCompliance, + event: MetaMetricsEventName.UserClickedPortfolioButton, }); - if (getEnvironmentType() === ENVIRONMENT_TYPE_POPUP) { - global.platform.openExtensionInBrowser( - COMPLIANCE_FEATURE_ROUTE, - ); - } else { - history.push(COMPLIANCE_FEATURE_ROUTE); - } + window.open(mmiPortfolioUrl, '_blank'); + closeMenu(); }} - data-testid="global-menu-mmi-compliance" + data-testid="global-menu-mmi-portfolio" > - {t('compliance')} + {t('portfolioDashboard')} - + ) ///: END:ONLY_INCLUDE_IN } From 7c7b5fe3aa09107205948876e3ad20a995083471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Oliv=C3=A9?= Date: Fri, 30 Jun 2023 15:53:55 +0200 Subject: [PATCH 27/30] =?UTF-8?q?[MMI]=C2=A0Added=20custom=20title=20for?= =?UTF-8?q?=20institutional=20(#19844)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added custom title for institutional * passing prop isMMI to notification view --- app/notification.html | 3 +++ development/build/scripts.js | 1 + 2 files changed, 4 insertions(+) diff --git a/app/notification.html b/app/notification.html index 209a642a3..766aef2ba 100644 --- a/app/notification.html +++ b/app/notification.html @@ -4,6 +4,9 @@ MetaMask Notification + {{@if(it.isMMI)}} + MetaMask Institutional + {{/if}}