From c56d18aef1b7281ee7b87485985d0a54627c1c91 Mon Sep 17 00:00:00 2001 From: Mathieu Artu Date: Tue, 22 Apr 2025 14:26:31 +0200 Subject: [PATCH 1/2] feat: rename profile sync to backup and sync --- packages/profile-sync-controller/CHANGELOG.md | 2 + .../AuthenticationController.ts | 2 +- .../UserStorageController.test.ts | 56 ++++++------------- .../user-storage/UserStorageController.ts | 26 ++++----- .../controller-integration.test.ts | 8 +-- .../account-syncing/sync-utils.test.ts | 14 ++--- .../account-syncing/sync-utils.ts | 4 +- 7 files changed, 46 insertions(+), 66 deletions(-) diff --git a/packages/profile-sync-controller/CHANGELOG.md b/packages/profile-sync-controller/CHANGELOG.md index d537a53cca0..c1657ee31a7 100644 --- a/packages/profile-sync-controller/CHANGELOG.md +++ b/packages/profile-sync-controller/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **BREAKING:** Replace all "Profile Syncing" mentions to "Backup & Sync" + - Replaces state properties `isProfileSyncingEnabled` to `isBackupAndSyncEnabled`, and `isProfileSyncingUpdateLoading` to `isBackupAndSyncUpdateLoading` - **BREAKING:** Bump `@metamask/snaps-controllers` peer dependency from ^9.19.0 to ^11.0.0 ([#5639](https://github.com/MetaMask/core/pull/5639)) - **BREAKING:** Bump `@metamask/providers` peer dependency from ^18.1.1 to ^21.0.0 ([#5639](https://github.com/MetaMask/core/pull/5639)) - Bump `@metamask/snaps-sdk` from ^6.17.1 to ^6.22.0 ([#5639](https://github.com/MetaMask/core/pull/5639)) diff --git a/packages/profile-sync-controller/src/controllers/authentication/AuthenticationController.ts b/packages/profile-sync-controller/src/controllers/authentication/AuthenticationController.ts index 24db3d6c477..a48adbc244c 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/AuthenticationController.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/AuthenticationController.ts @@ -104,7 +104,7 @@ export type AuthenticationControllerMessenger = RestrictedMessenger< /** * Controller that enables authentication for restricted endpoints. - * Used for Global Profile Syncing and Notifications + * Used for Backup & Sync, Notifications, and other services. */ export default class AuthenticationController extends BaseController< typeof controllerName, diff --git a/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.test.ts b/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.test.ts index 733a494c5ca..eb01a865423 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.test.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.test.ts @@ -34,7 +34,7 @@ describe('user-storage/user-storage-controller - constructor() tests', () => { messenger: messengerMocks.messenger, }); - expect(controller.state.isProfileSyncingEnabled).toBe(true); + expect(controller.state.isBackupAndSyncEnabled).toBe(true); }); it('should call startNetworkSyncing', async () => { @@ -608,28 +608,6 @@ describe('user-storage/user-storage-controller - getStorageKey() tests', () => { }); }); -describe('user-storage/user-storage-controller - disableProfileSyncing() tests', () => { - const arrangeMocks = async () => { - return { - messengerMocks: mockUserStorageMessenger(), - }; - }; - - it('should disable user storage / profile syncing when called', async () => { - const { messengerMocks } = await arrangeMocks(); - const controller = new UserStorageController({ - messenger: messengerMocks.messenger, - }); - - expect(controller.state.isProfileSyncingEnabled).toBe(true); - await controller.setIsBackupAndSyncFeatureEnabled( - BACKUPANDSYNC_FEATURES.main, - false, - ); - expect(controller.state.isProfileSyncingEnabled).toBe(false); - }); -}); - describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnabled tests', () => { const arrangeMocks = async () => { return { @@ -644,8 +622,8 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable const controller = new UserStorageController({ messenger: messengerMocks.messenger, state: { - isProfileSyncingEnabled: false, - isProfileSyncingUpdateLoading: false, + isBackupAndSyncEnabled: false, + isBackupAndSyncUpdateLoading: false, isAccountSyncingEnabled: false, hasAccountSyncingSyncedAtLeastOnce: false, isAccountSyncingReadyToBeDispatched: false, @@ -653,12 +631,12 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable }, }); - expect(controller.state.isProfileSyncingEnabled).toBe(false); + expect(controller.state.isBackupAndSyncEnabled).toBe(false); await controller.setIsBackupAndSyncFeatureEnabled( BACKUPANDSYNC_FEATURES.main, true, ); - expect(controller.state.isProfileSyncingEnabled).toBe(true); + expect(controller.state.isBackupAndSyncEnabled).toBe(true); expect(messengerMocks.mockAuthIsSignedIn).toHaveBeenCalled(); expect(messengerMocks.mockAuthPerformSignIn).toHaveBeenCalled(); }); @@ -670,8 +648,8 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable const controller = new UserStorageController({ messenger: messengerMocks.messenger, state: { - isProfileSyncingEnabled: false, - isProfileSyncingUpdateLoading: false, + isBackupAndSyncEnabled: false, + isBackupAndSyncUpdateLoading: false, isAccountSyncingEnabled: false, hasAccountSyncingSyncedAtLeastOnce: false, isAccountSyncingReadyToBeDispatched: false, @@ -679,7 +657,7 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable }, }); - expect(controller.state.isProfileSyncingEnabled).toBe(false); + expect(controller.state.isBackupAndSyncEnabled).toBe(false); messengerMocks.mockAuthPerformSignIn.mockRejectedValue(new Error('error')); await expect( @@ -688,7 +666,7 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable true, ), ).rejects.toThrow('error'); - expect(controller.state.isProfileSyncingEnabled).toBe(false); + expect(controller.state.isBackupAndSyncEnabled).toBe(false); }); it('should not disable backup and sync when disabling account syncing', async () => { @@ -698,8 +676,8 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable const controller = new UserStorageController({ messenger: messengerMocks.messenger, state: { - isProfileSyncingEnabled: true, - isProfileSyncingUpdateLoading: false, + isBackupAndSyncEnabled: true, + isBackupAndSyncUpdateLoading: false, isAccountSyncingEnabled: true, hasAccountSyncingSyncedAtLeastOnce: false, isAccountSyncingReadyToBeDispatched: false, @@ -707,13 +685,13 @@ describe('user-storage/user-storage-controller - setIsBackupAndSyncFeatureEnable }, }); - expect(controller.state.isProfileSyncingEnabled).toBe(true); + expect(controller.state.isBackupAndSyncEnabled).toBe(true); await controller.setIsBackupAndSyncFeatureEnabled( BACKUPANDSYNC_FEATURES.accountSyncing, false, ); expect(controller.state.isAccountSyncingEnabled).toBe(false); - expect(controller.state.isProfileSyncingEnabled).toBe(true); + expect(controller.state.isBackupAndSyncEnabled).toBe(true); }); }); @@ -912,7 +890,7 @@ describe('user-storage/user-storage-controller - error handling edge cases', () messenger: messengerMocks.messenger, state: { ...defaultState, - isProfileSyncingEnabled: false, + isBackupAndSyncEnabled: false, }, }); @@ -920,7 +898,7 @@ describe('user-storage/user-storage-controller - error handling edge cases', () BACKUPANDSYNC_FEATURES.main, false, ); - expect(controller.state.isProfileSyncingEnabled).toBe(false); + expect(controller.state.isBackupAndSyncEnabled).toBe(false); }); it('handles enabling backup & sync when already enabled and signed in', async () => { @@ -931,7 +909,7 @@ describe('user-storage/user-storage-controller - error handling edge cases', () messenger: messengerMocks.messenger, state: { ...defaultState, - isProfileSyncingEnabled: true, + isBackupAndSyncEnabled: true, }, }); @@ -939,7 +917,7 @@ describe('user-storage/user-storage-controller - error handling edge cases', () BACKUPANDSYNC_FEATURES.main, true, ); - expect(controller.state.isProfileSyncingEnabled).toBe(true); + expect(controller.state.isBackupAndSyncEnabled).toBe(true); expect(messengerMocks.mockAuthPerformSignIn).not.toHaveBeenCalled(); }); }); diff --git a/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts b/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts index 1e985207155..06af7a089a5 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/UserStorageController.ts @@ -59,11 +59,11 @@ export type UserStorageControllerState = { /** * Condition used by UI and to determine if we can use some of the User Storage methods. */ - isProfileSyncingEnabled: boolean; + isBackupAndSyncEnabled: boolean; /** - * Loading state for the profile syncing update + * Loading state for the backup and sync update */ - isProfileSyncingUpdateLoading: boolean; + isBackupAndSyncUpdateLoading: boolean; /** * Condition used by UI to determine if account syncing is enabled. */ @@ -89,8 +89,8 @@ export type UserStorageControllerState = { }; export const defaultState: UserStorageControllerState = { - isProfileSyncingEnabled: true, - isProfileSyncingUpdateLoading: false, + isBackupAndSyncEnabled: true, + isBackupAndSyncUpdateLoading: false, isAccountSyncingEnabled: true, hasAccountSyncingSyncedAtLeastOnce: false, isAccountSyncingReadyToBeDispatched: false, @@ -98,11 +98,11 @@ export const defaultState: UserStorageControllerState = { }; const metadata: StateMetadata = { - isProfileSyncingEnabled: { + isBackupAndSyncEnabled: { persist: true, anonymous: true, }, - isProfileSyncingUpdateLoading: { + isBackupAndSyncUpdateLoading: { persist: false, anonymous: false, }, @@ -612,7 +612,7 @@ export default class UserStorageController extends BaseController< enabled: boolean, ): Promise { try { - this.#setIsProfileSyncingUpdateLoading(true); + this.#setIsBackupAndSyncUpdateLoading(true); if (enabled) { // If any of the features are enabled, we need to ensure the user is signed in @@ -624,7 +624,7 @@ export default class UserStorageController extends BaseController< this.update((state) => { if (feature === BACKUPANDSYNC_FEATURES.main) { - state.isProfileSyncingEnabled = enabled; + state.isBackupAndSyncEnabled = enabled; } if (feature === BACKUPANDSYNC_FEATURES.accountSyncing) { @@ -639,15 +639,15 @@ export default class UserStorageController extends BaseController< `${controllerName} - failed to ${enabled ? 'enable' : 'disable'} ${feature} - ${errorMessage}`, ); } finally { - this.#setIsProfileSyncingUpdateLoading(false); + this.#setIsBackupAndSyncUpdateLoading(false); } } - #setIsProfileSyncingUpdateLoading( - isProfileSyncingUpdateLoading: boolean, + #setIsBackupAndSyncUpdateLoading( + isBackupAndSyncUpdateLoading: boolean, ): void { this.update((state) => { - state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading; + state.isBackupAndSyncUpdateLoading = isBackupAndSyncUpdateLoading; }); } diff --git a/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/controller-integration.test.ts b/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/controller-integration.test.ts index fd3ed5fe27b..620f19e8ef9 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/controller-integration.test.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/controller-integration.test.ts @@ -27,9 +27,9 @@ import { import { MOCK_STORAGE_KEY } from '../mocks'; const baseState = { - isProfileSyncingEnabled: true, + isBackupAndSyncEnabled: true, isAccountSyncingEnabled: true, - isProfileSyncingUpdateLoading: false, + isBackupAndSyncUpdateLoading: false, hasAccountSyncingSyncedAtLeastOnce: false, isAccountSyncingReadyToBeDispatched: false, isAccountSyncingInProgress: false, @@ -96,7 +96,7 @@ describe('user-storage/account-syncing/controller-integration - syncInternalAcco it('returns void if UserStorage is not enabled', async () => { const { controller, messengerMocks, options } = await arrangeMocks({ stateOverrides: { - isProfileSyncingEnabled: false, + isBackupAndSyncEnabled: false, }, }); @@ -973,7 +973,7 @@ describe('user-storage/account-syncing/controller-integration - saveInternalAcco it('returns void if UserStorage is not enabled', async () => { const { options } = await arrangeMocks({ stateOverrides: { - isProfileSyncingEnabled: false, + isBackupAndSyncEnabled: false, }, }); diff --git a/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.test.ts b/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.test.ts index a1ac78ef568..6808206a048 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.test.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.test.ts @@ -11,7 +11,7 @@ import type { AccountSyncingOptions } from './types'; describe('user-storage/account-syncing/sync-utils', () => { describe('canPerformAccountSyncing', () => { const arrangeMocks = ({ - isProfileSyncingEnabled = true, + isBackupAndSyncEnabled = true, isAccountSyncingEnabled = true, isAccountSyncingInProgress = false, messengerCallControllerAndAction = 'AuthenticationController:isSignedIn', @@ -29,7 +29,7 @@ describe('user-storage/account-syncing/sync-utils', () => { }), getUserStorageControllerInstance: jest.fn().mockReturnValue({ state: { - isProfileSyncingEnabled, + isBackupAndSyncEnabled, isAccountSyncingEnabled, isAccountSyncingInProgress, }, @@ -40,14 +40,14 @@ describe('user-storage/account-syncing/sync-utils', () => { }; const failureCases = [ - ['profile syncing is not enabled', { isProfileSyncingEnabled: false }], + ['backup and sync is not enabled', { isBackupAndSyncEnabled: false }], [ - 'profile syncing is not enabled but account syncing is', - { isProfileSyncingEnabled: false, isAccountSyncingEnabled: true }, + 'backup and sync is not enabled but account syncing is', + { isBackupAndSyncEnabled: false, isAccountSyncingEnabled: true }, ], [ - 'profile syncing is enabled but not account syncing', - { isProfileSyncingEnabled: true, isAccountSyncingEnabled: false }, + 'backup and sync is enabled but not account syncing', + { isBackupAndSyncEnabled: true, isAccountSyncingEnabled: false }, ], [ 'authentication is not enabled', diff --git a/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.ts b/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.ts index fe891f2cea6..a02630f0aa9 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/account-syncing/sync-utils.ts @@ -16,7 +16,7 @@ export function canPerformAccountSyncing( const { getMessenger, getUserStorageControllerInstance } = options; const { - isProfileSyncingEnabled, + isBackupAndSyncEnabled, isAccountSyncingEnabled, isAccountSyncingInProgress, } = getUserStorageControllerInstance().state; @@ -25,7 +25,7 @@ export function canPerformAccountSyncing( ); if ( - !isProfileSyncingEnabled || + !isBackupAndSyncEnabled || !isAccountSyncingEnabled || !isAuthEnabled || isAccountSyncingInProgress From dd19f5085115a67ad2fac3529858d0548c9dfe82 Mon Sep 17 00:00:00 2001 From: Mathieu Artu Date: Tue, 22 Apr 2025 14:35:51 +0200 Subject: [PATCH 2/2] fix: update CHANGELOG --- packages/profile-sync-controller/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/profile-sync-controller/CHANGELOG.md b/packages/profile-sync-controller/CHANGELOG.md index c1657ee31a7..b3fcc435c05 100644 --- a/packages/profile-sync-controller/CHANGELOG.md +++ b/packages/profile-sync-controller/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- **BREAKING:** Replace all "Profile Syncing" mentions to "Backup & Sync" +- **BREAKING:** Replace all "Profile Syncing" mentions to "Backup & Sync" ([#5686](https://github.com/MetaMask/core/pull/5686)) - Replaces state properties `isProfileSyncingEnabled` to `isBackupAndSyncEnabled`, and `isProfileSyncingUpdateLoading` to `isBackupAndSyncUpdateLoading` - **BREAKING:** Bump `@metamask/snaps-controllers` peer dependency from ^9.19.0 to ^11.0.0 ([#5639](https://github.com/MetaMask/core/pull/5639)) - **BREAKING:** Bump `@metamask/providers` peer dependency from ^18.1.1 to ^21.0.0 ([#5639](https://github.com/MetaMask/core/pull/5639))