Skip to content

Commit

Permalink
Merge branch 'main' into mms-2025-ellipsis-text
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoRSSilva authored Mar 7, 2025
2 parents caf9831 + a011959 commit 7d2cf53
Show file tree
Hide file tree
Showing 68 changed files with 2,540 additions and 854 deletions.
6 changes: 6 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ npmAuditIgnoreAdvisories:
# New package name format for new versions: @ethereumjs/wallet.
- 'ethereumjs-wallet (deprecation)'

# The new trezor version breaks the webpack build due to issues with ESM and CommonJS
# Leading to this error on start: `Uncaught ReferenceError: exports is not defined`
# We temporarily ignore the audit failure until we can safely upgrade to the new version without breaking the webpack build
# Check Trezor 9.5.X Changelog for more info: https://github.com/trezor/trezor-suite/blob/develop/packages/connect/CHANGELOG.md
- '@trezor/connect-web (deprecation)'

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-allow-scripts.cjs
spec: 'https://raw.githubusercontent.com/LavaMoat/LavaMoat/main/packages/yarn-plugin-allow-scripts/bundles/@yarnpkg/plugin-allow-scripts.js'
Expand Down
7 changes: 7 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.

7 changes: 7 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.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function buildControllerMock(

function buildInitRequestMock(): jest.Mocked<
ControllerInitRequest<
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
TransactionControllerMessenger,
TransactionControllerInitMessenger
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { TransactionMetricsRequest } from '../../../../shared/types/metametrics'

export const TransactionControllerInit: ControllerInitFunction<
TransactionController,
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
TransactionControllerMessenger,
TransactionControllerInitMessenger
> = (request) => {
Expand Down Expand Up @@ -189,7 +188,6 @@ function getApi(

function getControllers(
request: ControllerInitRequest<
// @ts-expect-error TODO: Resolve mismatch between base-controller versions.
TransactionControllerMessenger,
TransactionControllerInitMessenger
>,
Expand Down
10 changes: 8 additions & 2 deletions app/scripts/controller-init/controller-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
RateLimitController,
RateLimitedApiMap,
} from '@metamask/rate-limit-controller';
import { Controller as AuthenticationController } from '@metamask/profile-sync-controller/auth';
import { Controller as UserStorageController } from '@metamask/profile-sync-controller/user-storage';
import OnboardingController from '../controllers/onboarding';
import { PreferencesController } from '../controllers/preferences-controller';
import SwapsController from '../controllers/swaps';
Expand All @@ -38,6 +40,7 @@ import SwapsController from '../controllers/swaps';
* Union of all controllers supporting or required by modular initialization.
*/
export type Controller =
| AuthenticationController
| CronjobController
| ExecutionService
| GasFeeController
Expand Down Expand Up @@ -65,13 +68,15 @@ export type Controller =
| (TransactionUpdateController & {
name: 'TransactionUpdateController';
state: Record<string, unknown>;
});
})
| UserStorageController;

/**
* Flat state object for all controllers supporting or required by modular initialization.
* e.g. `{ transactions: [] }`.
*/
export type ControllerFlatState = AccountsController['state'] &
AuthenticationController['state'] &
CronjobController['state'] &
GasFeeController['state'] &
JsonSnapsRegistry['state'] &
Expand All @@ -94,4 +99,5 @@ export type ControllerFlatState = AccountsController['state'] &
SnapInsightsController['state'] &
SnapInterfaceController['state'] &
TransactionController['state'] &
SwapsController['state'];
SwapsController['state'] &
UserStorageController['state'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Controller as AuthenticationController } from '@metamask/profile-sync-controller/auth';
import { Messenger } from '@metamask/base-controller';
import { buildControllerInitRequestMock } from '../test/utils';
import { ControllerInitRequest } from '../types';
import {
getAuthenticationControllerMessenger,
AuthenticationControllerMessenger,
} from '../messengers/identity';
import { AuthenticationControllerInit } from './authentication-controller-init';

jest.mock('@metamask/profile-sync-controller/auth');

function buildInitRequestMock(): jest.Mocked<
ControllerInitRequest<AuthenticationControllerMessenger>
> {
const baseControllerMessenger = new Messenger();

return {
...buildControllerInitRequestMock(),
controllerMessenger: getAuthenticationControllerMessenger(
baseControllerMessenger,
),
initMessenger: undefined,
};
}

describe('AuthenticationControllerInit', () => {
const AuthenticationControllerClassMock = jest.mocked(
AuthenticationController,
);

beforeEach(() => {
jest.resetAllMocks();
});

it('returns controller instance', () => {
const requestMock = buildInitRequestMock();
expect(AuthenticationControllerInit(requestMock).controller).toBeInstanceOf(
AuthenticationController,
);
});

it('initializes with correct messenger and state', () => {
const requestMock = buildInitRequestMock();
AuthenticationControllerInit(requestMock);

expect(AuthenticationControllerClassMock).toHaveBeenCalledWith({
messenger: requestMock.controllerMessenger,
state: requestMock.persistedState.AuthenticationController,
metametrics: {
getMetaMetricsId: requestMock.getMetaMetricsId,
agent: 'extension',
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
AuthenticationControllerState,
Controller as AuthenticationController,
} from '@metamask/profile-sync-controller/auth';
import { ControllerInitFunction } from '../types';
import { AuthenticationControllerMessenger } from '../messengers/identity';

/**
* Initialize the Authentication controller.
*
* @param request - The request object.
* @param request.controllerMessenger - The messenger to use for the controller.
* @param request.persistedState - The persisted state of the extension.
* @param request.getMetaMetricsId
* @returns The initialized controller.
*/
export const AuthenticationControllerInit: ControllerInitFunction<
AuthenticationController,
AuthenticationControllerMessenger
> = ({ controllerMessenger, persistedState, getMetaMetricsId }) => {
const controller = new AuthenticationController({
messenger: controllerMessenger,
state:
persistedState.AuthenticationController as AuthenticationControllerState,
metametrics: {
getMetaMetricsId,
agent: 'extension',
},
});

return {
controller,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Controller as UserStorageController } from '@metamask/profile-sync-controller/user-storage';
import { Messenger } from '@metamask/base-controller';
import { buildControllerInitRequestMock } from '../test/utils';
import { ControllerInitRequest } from '../types';
import {
getUserStorageControllerMessenger,
UserStorageControllerMessenger,
} from '../messengers/identity';
import { UserStorageControllerInit } from './user-storage-controller-init';

jest.mock('@metamask/profile-sync-controller/user-storage');
jest.mock('../../../../shared/modules/mv3.utils', () => ({
isManifestV3: true,
}));
jest.mock('../../../../shared/modules/environment', () => ({
isProduction: () => false,
}));

function buildInitRequestMock(): jest.Mocked<
ControllerInitRequest<UserStorageControllerMessenger>
> {
const baseControllerMessenger = new Messenger();

return {
...buildControllerInitRequestMock(),
controllerMessenger: getUserStorageControllerMessenger(
baseControllerMessenger,
),
initMessenger: undefined,
};
}

describe('UserStorageControllerInit', () => {
const UserStorageControllerClassMock = jest.mocked(UserStorageController);

beforeEach(() => {
jest.resetAllMocks();
});

it('returns controller instance', () => {
const requestMock = buildInitRequestMock();
expect(UserStorageControllerInit(requestMock).controller).toBeInstanceOf(
UserStorageController,
);
});

it('initializes with correct messenger and state', () => {
const requestMock = buildInitRequestMock();
UserStorageControllerInit(requestMock);

expect(UserStorageControllerClassMock).toHaveBeenCalledWith({
messenger: requestMock.controllerMessenger,
state: requestMock.persistedState.UserStorageController,
config: {
accountSyncing: {
maxNumberOfAccountsToAdd: 100,
onAccountAdded: expect.any(Function),
onAccountNameUpdated: expect.any(Function),
onAccountSyncErroneousSituation: expect.any(Function),
},
},
env: {
isAccountSyncingEnabled: true,
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {
UserStorageControllerMessenger,
UserStorageControllerState,
Controller as UserStorageController,
} from '@metamask/profile-sync-controller/user-storage';
import { captureException } from '@sentry/browser';
import { ControllerInitFunction } from '../types';
import { isProduction } from '../../../../shared/modules/environment';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '../../../../shared/constants/metametrics';
import { isManifestV3 } from '../../../../shared/modules/mv3.utils';

/**
* Initialize the UserStorage controller.
*
* @param request - The request object.
* @param request.controllerMessenger - The messenger to use for the controller.
* @param request.persistedState - The persisted state of the extension.
* @returns The initialized controller.
*/
export const UserStorageControllerInit: ControllerInitFunction<
UserStorageController,
UserStorageControllerMessenger
> = (request) => {
const { controllerMessenger, persistedState, trackEvent } = request;
const controller = new UserStorageController({
messenger: controllerMessenger,
state: persistedState.UserStorageController as UserStorageControllerState,
config: {
accountSyncing: {
maxNumberOfAccountsToAdd: isProduction() ? undefined : 100,
onAccountAdded: (profileId) => {
trackEvent({
category: MetaMetricsEventCategory.ProfileSyncing,
event: MetaMetricsEventName.AccountsSyncAdded,
properties: {
profile_id: profileId,
},
});
},
onAccountNameUpdated: (profileId) => {
trackEvent({
category: MetaMetricsEventCategory.ProfileSyncing,
event: MetaMetricsEventName.AccountsSyncNameUpdated,
properties: {
profile_id: profileId,
},
});
},
onAccountSyncErroneousSituation: (
profileId,
situationMessage,
sentryContext,
) => {
captureException(
new Error(`Account sync - ${situationMessage}`),
sentryContext,
);
trackEvent({
category: MetaMetricsEventCategory.ProfileSyncing,
event: MetaMetricsEventName.AccountsSyncErroneousSituation,
properties: {
profile_id: profileId,
situation_message: situationMessage,
},
});
},
},
},
env: {
isAccountSyncingEnabled: isManifestV3,
},
});

return {
controller,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Messenger, RestrictedMessenger } from '@metamask/base-controller';
import { getAuthenticationControllerMessenger } from './authentication-controller-messenger';

describe('getAuthenticationControllerMessenger', () => {
it('returns a restricted messenger', () => {
const messenger = new Messenger<never, never>();
const authenticationControllerMessenger =
getAuthenticationControllerMessenger(messenger);

expect(authenticationControllerMessenger).toBeInstanceOf(
RestrictedMessenger,
);
});
});
Loading

0 comments on commit 7d2cf53

Please sign in to comment.