Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: update accounts deps + peer deps #30011

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/dist/assetsUtil.cjs b/dist/assetsUtil.cjs
index 017fb94055b64f99c75f8d54b763a501bdd03e97..34396ba143e3ebcb04fa2c80f7a35d1abd06710e 100644
--- a/dist/assetsUtil.cjs
+++ b/dist/assetsUtil.cjs
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
+function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
exports.getKeyByValue = exports.fetchTokenContractExchangeRates = exports.reduceInBatchesSerially = exports.divideIntoBatches = exports.ethersBigNumberToBN = exports.addUrlProtocolPrefix = exports.getFormattedIpfsUrl = exports.getIpfsCIDv1AndPath = exports.removeIpfsProtocolPrefix = exports.isTokenListSupportedForNetwork = exports.isTokenDetectionSupportedForNetwork = exports.SupportedStakedBalanceNetworks = exports.SupportedTokenDetectionNetworks = exports.formatIconUrlWithProxy = exports.formatAggregatorNames = exports.hasNewCollectionFields = exports.compareNftMetadata = exports.TOKEN_PRICES_BATCH_SIZE = void 0;
const controller_utils_1 = require("@metamask/controller-utils");
const utils_1 = require("@metamask/utils");
@@ -233,7 +234,7 @@ async function getIpfsCIDv1AndPath(ipfsUrl) {
const index = url.indexOf('/');
const cid = index !== -1 ? url.substring(0, index) : url;
const path = index !== -1 ? url.substring(index) : undefined;
- const { CID } = await import("multiformats");
+ const { CID } = _interopRequireWildcard(require("multiformats"));
// We want to ensure that the CID is v1 (https://docs.ipfs.io/concepts/content-addressing/#identifier-formats)
// because most cid v0s appear to be incompatible with IPFS subdomains
return {
6 changes: 3 additions & 3 deletions app/scripts/controllers/alert-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/
import { ControllerMessenger } from '@metamask/base-controller';
import { EthAccountType } from '@metamask/keyring-api';
import { EthAccountType, EthScope } from '@metamask/keyring-api';
import {
AlertController,
AllowedActions,
Expand Down Expand Up @@ -163,8 +163,8 @@ describe('AlertController', () => {
address: '0x1234567',
options: {},
methods: [],
scopes: ['eip155'],
type: 'eip155:eoa',
scopes: [EthScope.Eoa],
type: EthAccountType.Eoa,
metadata: {
name: '',
keyring: {
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/controllers/mmi-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ describe('MMIController', function () {
'KeyringController:stateChange',
'KeyringController:persistAllKeyrings',
'AccountsController:selectedAccountChange',
'SnapKeyring:accountAssetListUpdated',
'SnapKeyring:accountBalancesUpdated',
'SnapKeyring:accountTransactionsUpdated',
],
allowedActions: [
'AccountsController:setCurrentAccount',
Expand Down
11 changes: 11 additions & 0 deletions app/scripts/controllers/preferences-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { AccountsController } from '@metamask/accounts-controller';
import { KeyringControllerStateChangeEvent } from '@metamask/keyring-controller';
import { SnapControllerStateChangeEvent } from '@metamask/snaps-controllers';
import { Hex } from '@metamask/utils';
import {
SnapKeyringAccountAssetListUpdatedEvent,
SnapKeyringAccountBalancesUpdatedEvent,
SnapKeyringAccountTransactionsUpdatedEvent,
} from '@metamask/eth-snap-keyring';
import { CHAIN_IDS } from '../../../shared/constants/network';
import { mockNetworkState } from '../../../test/stub/networks';
import { ThemeType } from '../../../shared/constants/preferences';
Expand Down Expand Up @@ -44,6 +49,9 @@ const setupController = ({
| AllowedEvents
| KeyringControllerStateChangeEvent
| SnapControllerStateChangeEvent
| SnapKeyringAccountAssetListUpdatedEvent
| SnapKeyringAccountBalancesUpdatedEvent
| SnapKeyringAccountTransactionsUpdatedEvent
>();
const preferencesControllerMessenger: PreferencesControllerMessenger =
controllerMessenger.getRestricted({
Expand Down Expand Up @@ -74,6 +82,9 @@ const setupController = ({
allowedEvents: [
'KeyringController:stateChange',
'SnapController:stateChange',
'SnapKeyring:accountAssetListUpdated',
'SnapKeyring:accountBalancesUpdated',
'SnapKeyring:accountTransactionsUpdated',
],
allowedActions: [],
});
Expand Down
8 changes: 3 additions & 5 deletions app/scripts/lib/snap-keyring/snap-keyring.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ControllerMessenger } from '@metamask/base-controller';
import { EthAccountType } from '@metamask/keyring-api';
import { EthAccountType, EthScope } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { SNAP_MANAGE_ACCOUNTS_CONFIRMATION_TYPES } from '../../../../shared/constants/app';
import {
Expand All @@ -24,7 +24,6 @@ const mockShowError = jest.fn();
const mockGetAccounts = jest.fn();
const mockSnapId = 'snapId';
const mockSnapName = 'mock-snap';
const mockSnapController = jest.fn();
const mockPersisKeyringHelper = jest.fn();
const mockSetSelectedAccount = jest.fn();
const mockSetAccountName = jest.fn();
Expand All @@ -40,7 +39,7 @@ const mockAccount = {
id: '3afa663e-0600-4d93-868a-61c2e553013b',
address,
methods: [],
scopes: ['eip155'],
scopes: [EthScope.Eoa],
options: {},
};
const mockInternalAccount = {
Expand Down Expand Up @@ -68,7 +67,7 @@ const createControllerMessenger = ({
SnapKeyringBuilderAllowActions,
never
>().getRestricted({
name: 'SnapKeyringBuilder',
name: 'SnapKeyring',
allowedActions: [
'ApprovalController:addRequest',
'ApprovalController:acceptRequest',
Expand Down Expand Up @@ -137,7 +136,6 @@ const createSnapKeyringBuilder = ({
} = {}) => {
return snapKeyringBuilder(
createControllerMessenger(),
mockSnapController,
mockPersisKeyringHelper,
mockRemoveAccountHelper,
mockTrackEvent,
Expand Down
5 changes: 1 addition & 4 deletions app/scripts/lib/snap-keyring/snap-keyring.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SnapKeyring } from '@metamask/eth-snap-keyring';
import type { SnapController } from '@metamask/snaps-controllers';
import browser from 'webextension-polyfill';
import { SnapId } from '@metamask/snaps-sdk';
import {
Expand Down Expand Up @@ -98,7 +97,6 @@ export async function showAccountNameSuggestionDialog(
* Constructs a SnapKeyring builder with specified handlers for managing snap accounts.
*
* @param controllerMessenger - The controller messenger instance.
* @param getSnapController - A function that retrieves the Snap Controller instance.
* @param persistKeyringHelper - A function that persists all keyrings in the vault.
* @param removeAccountHelper - A function to help remove an account based on its address.
* @param trackEvent - A function to track MetaMetrics events.
Expand All @@ -112,7 +110,6 @@ export async function showAccountNameSuggestionDialog(
*/
export const snapKeyringBuilder = (
controllerMessenger: SnapKeyringBuilderMessenger,
getSnapController: () => SnapController,
persistKeyringHelper: () => Promise<void>,
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -131,7 +128,7 @@ export const snapKeyringBuilder = (
const builder = (() => {
// TODO: Replace `any` with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return new SnapKeyring(getSnapController() as any, {
return new SnapKeyring(controllerMessenger, {
addressExists: async (address) => {
const addresses = await controllerMessenger.call(
'KeyringController:getAccounts',
Expand Down
7 changes: 5 additions & 2 deletions app/scripts/lib/snap-keyring/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
ShowSuccess,
StartFlow,
} from '@metamask/approval-controller';
import { GetSnap, HandleSnapRequest } from '@metamask/snaps-controllers';

export type SnapKeyringBuilderAllowActions =
| StartFlow
Expand All @@ -31,10 +32,12 @@ export type SnapKeyringBuilderAllowActions =
| GetSubjectMetadata
| AccountsControllerSetSelectedAccountAction
| AccountsControllerGetAccountByAddressAction
| AccountsControllerSetAccountNameAction;
| AccountsControllerSetAccountNameAction
| HandleSnapRequest
| GetSnap;

export type SnapKeyringBuilderMessenger = RestrictedControllerMessenger<
'SnapKeyringBuilder',
'SnapKeyring',
SnapKeyringBuilderAllowActions,
never,
SnapKeyringBuilderAllowActions['type'],
Expand Down
10 changes: 6 additions & 4 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@ export default class MetamaskController extends EventEmitter {
'SnapController:stateChange',
'KeyringController:accountRemoved',
'KeyringController:stateChange',
'SnapKeyring:accountAssetListUpdated',
'SnapKeyring:accountBalancesUpdated',
'SnapKeyring:accountTransactionsUpdated',
],
allowedActions: [
'KeyringController:getAccounts',
Expand Down Expand Up @@ -1144,7 +1147,7 @@ export default class MetamaskController extends EventEmitter {

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
const snapKeyringBuildMessenger = this.controllerMessenger.getRestricted({
name: 'SnapKeyringBuilder',
name: 'SnapKeyring',
allowedActions: [
'ApprovalController:addRequest',
'ApprovalController:acceptRequest',
Expand All @@ -1159,11 +1162,11 @@ export default class MetamaskController extends EventEmitter {
'AccountsController:setSelectedAccount',
'AccountsController:getAccountByAddress',
'AccountsController:setAccountName',
'SnapController:handleRequest',
'SnapController:get',
],
});

const getSnapController = () => this.snapController;

// Necessary to persist the keyrings and update the accounts both within the keyring controller and accounts controller
const persistAndUpdateAccounts = async () => {
await this.keyringController.persistAllKeyrings();
Expand Down Expand Up @@ -1202,7 +1205,6 @@ export default class MetamaskController extends EventEmitter {
additionalKeyrings.push(
snapKeyringBuilder(
snapKeyringBuildMessenger,
getSnapController,
persistAndUpdateAccounts,
(address) => this.removeAccount(address),
this.metaMetricsController.trackEvent.bind(this.metaMetricsController),
Expand Down
10 changes: 3 additions & 7 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,6 @@
"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/logger": {
"globals": {
"console": true
},
"packages": {
"tslib": true
}
},
"@metamask/notification-services-controller>firebase>@firebase/messaging": {
Expand All @@ -565,6 +562,7 @@
"addEventListener": true,
"atob": true,
"btoa": true,
"clearTimeout": true,
"clients.matchAll": true,
"clients.openWindow": true,
"console.warn": true,
Expand All @@ -583,12 +581,12 @@
"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/component": true,
"@metamask/notification-services-controller>firebase>@firebase/installations": true,
"@metamask/notification-services-controller>firebase>@firebase/util": true,
"@metamask/notification-services-controller>firebase>@firebase/app>idb": true,
"tslib": true
"@metamask/notification-services-controller>firebase>@firebase/app>idb": true
}
},
"@metamask/notification-services-controller>firebase>@firebase/util": {
"globals": {
"WorkerGlobalScope": true,
"atob": true,
"browser": true,
"btoa": true,
Expand All @@ -598,7 +596,6 @@
"indexedDB": true,
"navigator": true,
"process": true,
"self": true,
"setTimeout": true
},
"packages": {
Expand Down Expand Up @@ -926,7 +923,6 @@
"@metamask/name-controller>async-mutex": true,
"bitcoin-address-validation": true,
"bn.js": true,
"cockatiel": true,
"lodash": true,
"@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true,
"single-call-balance-checker-abi": true,
Expand Down
10 changes: 3 additions & 7 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,6 @@
"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/logger": {
"globals": {
"console": true
},
"packages": {
"tslib": true
}
},
"@metamask/notification-services-controller>firebase>@firebase/messaging": {
Expand All @@ -565,6 +562,7 @@
"addEventListener": true,
"atob": true,
"btoa": true,
"clearTimeout": true,
"clients.matchAll": true,
"clients.openWindow": true,
"console.warn": true,
Expand All @@ -583,12 +581,12 @@
"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/component": true,
"@metamask/notification-services-controller>firebase>@firebase/installations": true,
"@metamask/notification-services-controller>firebase>@firebase/util": true,
"@metamask/notification-services-controller>firebase>@firebase/app>idb": true,
"tslib": true
"@metamask/notification-services-controller>firebase>@firebase/app>idb": true
}
},
"@metamask/notification-services-controller>firebase>@firebase/util": {
"globals": {
"WorkerGlobalScope": true,
"atob": true,
"browser": true,
"btoa": true,
Expand All @@ -598,7 +596,6 @@
"indexedDB": true,
"navigator": true,
"process": true,
"self": true,
"setTimeout": true
},
"packages": {
Expand Down Expand Up @@ -926,7 +923,6 @@
"@metamask/name-controller>async-mutex": true,
"bitcoin-address-validation": true,
"bn.js": true,
"cockatiel": true,
"lodash": true,
"@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true,
"single-call-balance-checker-abi": true,
Expand Down
10 changes: 3 additions & 7 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,6 @@
"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/logger": {
"globals": {
"console": true
},
"packages": {
"tslib": true
}
},
"@metamask/notification-services-controller>firebase>@firebase/messaging": {
Expand All @@ -565,6 +562,7 @@
"addEventListener": true,
"atob": true,
"btoa": true,
"clearTimeout": true,
"clients.matchAll": true,
"clients.openWindow": true,
"console.warn": true,
Expand All @@ -583,12 +581,12 @@
"@metamask/notification-services-controller>firebase>@firebase/app>@firebase/component": true,
"@metamask/notification-services-controller>firebase>@firebase/installations": true,
"@metamask/notification-services-controller>firebase>@firebase/util": true,
"@metamask/notification-services-controller>firebase>@firebase/app>idb": true,
"tslib": true
"@metamask/notification-services-controller>firebase>@firebase/app>idb": true
}
},
"@metamask/notification-services-controller>firebase>@firebase/util": {
"globals": {
"WorkerGlobalScope": true,
"atob": true,
"browser": true,
"btoa": true,
Expand All @@ -598,7 +596,6 @@
"indexedDB": true,
"navigator": true,
"process": true,
"self": true,
"setTimeout": true
},
"packages": {
Expand Down Expand Up @@ -926,7 +923,6 @@
"@metamask/name-controller>async-mutex": true,
"bitcoin-address-validation": true,
"bn.js": true,
"cockatiel": true,
"lodash": true,
"@ensdomains/content-hash>multicodec>uint8arrays>multiformats": true,
"single-call-balance-checker-abi": true,
Expand Down
Loading