Skip to content

Commit

Permalink
Merge branch 'MetaMask:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
100manbul authored Feb 26, 2025
2 parents 2f4a385 + d249fa7 commit 1717512
Show file tree
Hide file tree
Showing 76 changed files with 2,327 additions and 807 deletions.
11 changes: 11 additions & 0 deletions .github/scripts/check-template-and-add-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
RegressionStage,
craftRegressionLabel,
externalContributorLabel,
needsTriageLabel,
flakyTestsLabel,
invalidIssueTemplateLabel,
invalidPullRequestTemplateLabel,
Expand Down Expand Up @@ -139,6 +140,9 @@ async function main(): Promise<void> {

// Add regression label to the bug report issue
addRegressionLabelToIssue(octokit, labelable);

// Add needs triage label to the bug report issue
addNeedsTriageLabelToIssue(octokit, labelable);
} else {
const errorMessage =
"Issue body does not match any of expected templates ('general-issue.yml' or 'bug-report.yml').\n\nMake sure issue's body includes all section titles.\n\nSections titles are listed here: https://github.com/MetaMask/metamask-extension/blob/main/.github/scripts/shared/template.ts#L14-L37";
Expand Down Expand Up @@ -260,6 +264,13 @@ function extractReleaseVersionFromBugReportIssueBody(
return version;
}

// This function adds the "needs-triage" label to the issue if it doesn't have it
function addNeedsTriageLabelToIssue(
octokit: InstanceType<typeof GitHub>,
issue: Labelable,
): Promise<void> {
await addLabelToLabelable(octokit, issue, needsTriageLabel);
}
// This function adds the correct regression label to the issue, and removes other ones
async function addRegressionLabelToIssue(
octokit: InstanceType<typeof GitHub>,
Expand Down
6 changes: 6 additions & 0 deletions .github/scripts/shared/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export const externalContributorLabel: Label = {
description: 'Issue or PR created by user outside org',
};

export const needsTriageLabel: Label = {
name: 'needs-triage',
color: '#68AEE6',
description: 'Issue needs to be triaged',
};

export const flakyTestsLabel: Label = {
name: 'flaky tests',
color: 'BE564E',
Expand Down
10 changes: 8 additions & 2 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { draftTransactionInitialState } from '../ui/ducks/send';
import { KeyringType } from '../shared/constants/keyring';
import { NetworkStatus } from '@metamask/network-controller';
import { EthAccountType } from '@metamask/keyring-api';
import { EthAccountType, EthScope } from '@metamask/keyring-api';
import {
CHAIN_IDS,
LINEA_MAINNET_DISPLAY_NAME,
Expand All @@ -10,7 +10,7 @@ import { copyable, divider, heading, panel, text } from '@metamask/snaps-sdk';
import { getJsxElementFromComponent } from '@metamask/snaps-utils';
import { FirstTimeFlowType } from '../shared/constants/onboarding';
import { ETH_EOA_METHODS } from '../shared/constants/eth-methods';
import { mockNetworkState } from '../test/stub/networks';
import { mockNetworkState, mockMultichainNetworkState } from '../test/stub/networks';

const state = {
invalidCustomNetwork: {
Expand Down Expand Up @@ -325,6 +325,7 @@ const state = {
options: {},
methods: ETH_EOA_METHODS,
type: EthAccountType.Eoa,
scopes: [EthScope.Eoa],
},
'07c2cfec-36c9-46c4-8115-3836d3ac9047': {
address: '0xb19ac54efa18cc3a14a5b821bfec73d284bf0c5e',
Expand All @@ -338,6 +339,7 @@ const state = {
options: {},
methods: ETH_EOA_METHODS,
type: EthAccountType.Eoa,
scopes: [EthScope.Eoa],
},
'15e69915-2a1a-4019-93b3-916e11fd432f': {
address: '0x9d0ba4ddac06032527b140912ec808ab9451b788',
Expand All @@ -351,6 +353,7 @@ const state = {
options: {},
methods: ETH_EOA_METHODS,
type: EthAccountType.Eoa,
scopes: [EthScope.Eoa],
},
'784225f4-d30b-4e77-a900-c8bbce735b88': {
address: '0xeb9e64b93097bc15f01f13eae97015c57ab64823',
Expand All @@ -364,6 +367,7 @@ const state = {
options: {},
methods: ETH_EOA_METHODS,
type: EthAccountType.Eoa,
scopes: [EthScope.Eoa],
},
'b990b846-b384-4508-93d9-587461f1123e': {
address: '0x71C7656EC7ab88b098defB751B7401B5f6d8976F',
Expand All @@ -377,6 +381,7 @@ const state = {
options: {},
methods: ETH_EOA_METHODS,
type: EthAccountType.Eoa,
scopes: [EthScope.Eoa],
},
},
selectedAccount: 'cf8dace4-9439-4bd4-b3a8-88c821c8fcb3',
Expand Down Expand Up @@ -1283,6 +1288,7 @@ const state = {
nickname: 'Localhost 8545',
},
),
...mockMultichainNetworkState(),
accountTokens: {
'0x64a845a5b02460acf8a3d84503b0d68d028b4bb4': {
'0x1': [
Expand Down
8 changes: 8 additions & 0 deletions app/_locales/en/messages.json

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

8 changes: 8 additions & 0 deletions app/_locales/en_GB/messages.json

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

24 changes: 19 additions & 5 deletions app/scripts/controllers/network-order.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { BtcScope, SolScope } from '@metamask/keyring-api';
import { BaseController, RestrictedMessenger } from '@metamask/base-controller';
import {
NetworkControllerStateChangeEvent,
NetworkState,
} from '@metamask/network-controller';
import { Hex } from '@metamask/utils';
import { toEvmCaipChainId } from '@metamask/multichain-network-controller';
import type { CaipChainId, Hex } from '@metamask/utils';
import type { Patch } from 'immer';
import { TEST_CHAINS } from '../../../shared/constants/network';

Expand All @@ -14,7 +16,7 @@ const controllerName = 'NetworkOrderController';
* Information about an ordered network.
*/
export type NetworksInfo = {
networkId: Hex; // The network's chain id
networkId: CaipChainId; // The network's chain id
};

// State shape for NetworkOrderController
Expand Down Expand Up @@ -112,10 +114,15 @@ export class NetworkOrderController extends BaseController<
}: NetworkState) {
this.update((state) => {
// Filter out testnets, which are in the state but not orderable
const chainIds = Object.keys(networkConfigurationsByChainId).filter(
const hexChainIds = Object.keys(networkConfigurationsByChainId).filter(
(chainId) =>
!TEST_CHAINS.includes(chainId as (typeof TEST_CHAINS)[number]),
) as Hex[];
const chainIds: CaipChainId[] = hexChainIds.map(toEvmCaipChainId);
const nonEvmChainIds: CaipChainId[] = [
BtcScope.Mainnet,
SolScope.Mainnet,
];

const newNetworks = chainIds
.filter(
Expand All @@ -128,7 +135,14 @@ export class NetworkOrderController extends BaseController<

state.orderedNetworkList = state.orderedNetworkList
// Filter out deleted networks
.filter(({ networkId }) => chainIds.includes(networkId))
.filter(
({ networkId }) =>
chainIds.includes(networkId) ||
// Since Bitcoin and Solana are not part of the @metamask/network-controller, we have
// to add a second check to make sure it is not filtered out.
// TODO: Update this logic to @metamask/multichain-network-controller once all networks are migrated.
nonEvmChainIds.includes(networkId),
)
// Append new networks to the end
.concat(newNetworks);
});
Expand All @@ -140,7 +154,7 @@ export class NetworkOrderController extends BaseController<
* @param networkList - The list of networks to update in the state.
*/

updateNetworksList(chainIds: Hex[]) {
updateNetworksList(chainIds: CaipChainId[]) {
this.update((state) => {
state.orderedNetworkList = chainIds.map((chainId) => ({
networkId: chainId,
Expand Down
106 changes: 62 additions & 44 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,15 @@ import {
UserStorageController,
} from '@metamask/profile-sync-controller';
import {
NotificationServicesPushController,
NotificationServicesController,
} from '@metamask/notification-services-controller';
TRIGGER_TYPES,
Controller as NotificationServicesController,
} from '@metamask/notification-services-controller/notification-services';
import { Controller as NotificationServicesPushController } from '@metamask/notification-services-controller/push-services';
import {
createRegToken,
deleteRegToken,
createSubscribeToPushNotifications,
} from '@metamask/notification-services-controller/push-services/web';
import {
Caip25CaveatMutators,
Caip25CaveatType,
Expand Down Expand Up @@ -374,7 +380,6 @@ import {
SnapsRegistryInit,
} from './controller-init/snaps';

const { TRIGGER_TYPES } = NotificationServicesController.Constants;
export const METAMASK_CONTROLLER_EVENTS = {
// Fired after state changes that impact the extension badge (unapproved msg count)
// The process of updating the badge happens in app/scripts/background.js.
Expand Down Expand Up @@ -1339,14 +1344,15 @@ export default class MetamaskController extends EventEmitter {
}),
});

/** @type {import('@metamask/notification-services-controller/push-services').NotificationServicesPushControllerMessenger} */
const notificationServicesPushControllerMessenger =
this.controllerMessenger.getRestricted({
name: 'NotificationServicesPushController',
allowedActions: ['AuthenticationController:getBearerToken'],
allowedEvents: [],
});
this.notificationServicesPushController =
new NotificationServicesPushController.Controller({
new NotificationServicesPushController({
messenger: notificationServicesPushControllerMessenger,
state: initState.NotificationServicesPushController,
env: {
Expand All @@ -1360,10 +1366,17 @@ export default class MetamaskController extends EventEmitter {
vapidKey: process.env.VAPID_KEY ?? '',
},
config: {
isPushEnabled: isManifestV3,
isPushFeatureEnabled: isManifestV3,
platform: 'extension',
onPushNotificationReceived,
onPushNotificationClicked,
pushService: {
createRegToken,
deleteRegToken,
subscribeToPushNotifications: createSubscribeToPushNotifications({
messenger: notificationServicesPushControllerMessenger,
onReceivedHandler: onPushNotificationReceived,
onClickHandler: onPushNotificationClicked,
}),
},
},
});
notificationServicesPushControllerMessenger.subscribe(
Expand Down Expand Up @@ -1395,41 +1408,44 @@ export default class MetamaskController extends EventEmitter {
},
);

this.notificationServicesController =
new NotificationServicesController.Controller({
messenger: this.controllerMessenger.getRestricted({
name: 'NotificationServicesController',
allowedActions: [
'KeyringController:getAccounts',
'KeyringController:getState',
'AuthenticationController:getBearerToken',
'AuthenticationController:isSignedIn',
'AuthenticationController:performSignIn',
'UserStorageController:getStorageKey',
'UserStorageController:performGetStorage',
'UserStorageController:performSetStorage',
'NotificationServicesPushController:enablePushNotifications',
'NotificationServicesPushController:disablePushNotifications',
'NotificationServicesPushController:subscribeToPushNotifications',
'NotificationServicesPushController:updateTriggerPushNotifications',
],
allowedEvents: [
'KeyringController:stateChange',
'KeyringController:lock',
'KeyringController:unlock',
'NotificationServicesPushController:onNewNotifications',
],
}),
state: initState.NotificationServicesController,
env: {
isPushIntegrated: isManifestV3,
featureAnnouncements: {
platform: 'extension',
spaceId: process.env.CONTENTFUL_ACCESS_SPACE_ID ?? '',
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN ?? '',
},
},
/** @type {import('@metamask/notification-services-controller/notification-services').NotificationServicesControllerMessenger} */
const notificationServicesControllerMessenger =
this.controllerMessenger.getRestricted({
name: 'NotificationServicesController',
allowedActions: [
'KeyringController:getAccounts',
'KeyringController:getState',
'AuthenticationController:getBearerToken',
'AuthenticationController:isSignedIn',
'AuthenticationController:performSignIn',
'UserStorageController:getStorageKey',
'UserStorageController:performGetStorage',
'UserStorageController:performSetStorage',
'NotificationServicesPushController:enablePushNotifications',
'NotificationServicesPushController:disablePushNotifications',
'NotificationServicesPushController:subscribeToPushNotifications',
'NotificationServicesPushController:updateTriggerPushNotifications',
],
allowedEvents: [
'KeyringController:stateChange',
'KeyringController:lock',
'KeyringController:unlock',
'NotificationServicesPushController:onNewNotifications',
'NotificationServicesPushController:stateChange',
],
});
this.notificationServicesController = new NotificationServicesController({
messenger: notificationServicesControllerMessenger,
state: initState.NotificationServicesController,
env: {
isPushIntegrated: isManifestV3,
featureAnnouncements: {
platform: 'extension',
spaceId: process.env.CONTENTFUL_ACCESS_SPACE_ID ?? '',
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN ?? '',
},
},
});

// account tracker watches balances, nonces, and any code at their address
this.accountTrackerController = new AccountTrackerController({
Expand Down Expand Up @@ -3324,8 +3340,10 @@ export default class MetamaskController extends EventEmitter {
verifyPassword: this.verifyPassword.bind(this),

// network management
setActiveNetwork: (networkConfigurationId) => {
return this.networkController.setActiveNetwork(networkConfigurationId);
setActiveNetwork: async (id) => {
// The multichain network controller will proxy the call to the network controller
// in the case that the ID is an EVM network client ID.
return await this.multichainNetworkController.setActiveNetwork(id);
},
// Avoids returning the promise so that initial call to switch network
// doesn't block on the network lookup step
Expand Down
Loading

0 comments on commit 1717512

Please sign in to comment.