-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mms-2025-ellipsis-text
- Loading branch information
Showing
68 changed files
with
2,540 additions
and
854 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/scripts/controller-init/identity/authentication-controller-init.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
app/scripts/controller-init/identity/authentication-controller-init.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
67 changes: 67 additions & 0 deletions
67
app/scripts/controller-init/identity/user-storage-controller-init.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
app/scripts/controller-init/identity/user-storage-controller-init.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
14 changes: 14 additions & 0 deletions
14
app/scripts/controller-init/messengers/identity/authentication-controller-messenger.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.