-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: account syncing was not working after upgrading from a previous …
…version (#29701) ## **Description** Account syncing was depending on `_addAccountsWithBalance` to be finished before being triggered. But `_addAccountsWithBalance` was only triggered after onboarding. So people upgrading from a previous version of the extension were not able to use account syncing since `_addAccountsWithBalance` was triggered during their original onboarding, at a time where account syncing was not available. Additionally, the state value `isAccountSyncingReadyToBeDispatched` from `UserStorageController` was not persisted. So people were not able to use account syncing after upgrading their extension version, even coming from a version that had account syncing enabled and working. This PR fixes that, by adding a migration that sets `isAccountSyncingReadyToBeDispatched` to true if `completedOnboarding` is true. Also, bumping `@metamask/profile-sync-controller` to version `v4.1.0` will ensure that `isAccountSyncingReadyToBeDispatched` is persisted. (MetaMask/core#5147) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29701?quickstart=1) ## **Related issues** Fixes: #29679 ## **Manual testing steps** 1. Install MetaMask v12.9.3 2. Complete onboarding 3. Upgrade to this PR version 4. Verify that account syncing is working ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [x] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [x] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
- Loading branch information
1 parent
31915a6
commit d8ce2c7
Showing
5 changed files
with
148 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { migrate, version, VersionedData } from './137'; | ||
|
||
const oldVersion = 136; | ||
|
||
describe(`migration #${version}`, () => { | ||
it('updates the version metadata', async () => { | ||
const oldStorage: VersionedData = { | ||
meta: { version: oldVersion }, | ||
data: {}, | ||
}; | ||
const newStorage = await migrate(oldStorage); | ||
expect(newStorage.meta).toStrictEqual({ version }); | ||
}); | ||
|
||
describe(`migration #${version}`, () => { | ||
it('sets isAccountSyncingReadyToBeDispatched to true if completedOnboarding is true', async () => { | ||
const oldStorage: VersionedData = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
OnboardingController: { | ||
completedOnboarding: true, | ||
}, | ||
UserStorageController: { | ||
isAccountSyncingReadyToBeDispatched: false, | ||
}, | ||
}, | ||
}; | ||
const expectedData = { | ||
OnboardingController: { | ||
completedOnboarding: true, | ||
}, | ||
UserStorageController: { | ||
isAccountSyncingReadyToBeDispatched: true, | ||
}, | ||
}; | ||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(expectedData); | ||
}); | ||
|
||
it('sets isAccountSyncingReadyToBeDispatched to false if completedOnboarding is false', async () => { | ||
const oldStorage: VersionedData = { | ||
meta: { version: oldVersion }, | ||
data: { | ||
OnboardingController: { | ||
completedOnboarding: false, | ||
}, | ||
UserStorageController: { | ||
isAccountSyncingReadyToBeDispatched: true, | ||
}, | ||
}, | ||
}; | ||
const expectedData = { | ||
OnboardingController: { | ||
completedOnboarding: false, | ||
}, | ||
UserStorageController: { | ||
isAccountSyncingReadyToBeDispatched: false, | ||
}, | ||
}; | ||
const newStorage = await migrate(oldStorage); | ||
|
||
expect(newStorage.data).toStrictEqual(expectedData); | ||
}); | ||
}); | ||
}); |
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,75 @@ | ||
import { hasProperty, isObject } from '@metamask/utils'; | ||
import { cloneDeep } from 'lodash'; | ||
|
||
export type VersionedData = { | ||
meta: { | ||
version: number; | ||
}; | ||
data: { | ||
OnboardingController?: { | ||
completedOnboarding?: boolean; | ||
}; | ||
UserStorageController?: { | ||
isAccountSyncingReadyToBeDispatched?: boolean; | ||
}; | ||
}; | ||
}; | ||
|
||
export const version = 137; | ||
|
||
function transformState(state: VersionedData['data']) { | ||
if ( | ||
!hasProperty(state, 'OnboardingController') || | ||
!isObject(state.OnboardingController) | ||
) { | ||
global.sentry?.captureException?.( | ||
new Error( | ||
`Invalid OnboardingController state: ${typeof state.OnboardingController}`, | ||
), | ||
); | ||
return state; | ||
} | ||
|
||
if ( | ||
!hasProperty(state, 'UserStorageController') || | ||
!isObject(state.UserStorageController) | ||
) { | ||
global.sentry?.captureException?.( | ||
new Error( | ||
`Invalid UserStorageController state: ${typeof state.UserStorageController}`, | ||
), | ||
); | ||
return state; | ||
} | ||
|
||
const { OnboardingController } = state; | ||
|
||
const currentCompletedOnboardingStatus = | ||
OnboardingController.completedOnboarding; | ||
|
||
if (currentCompletedOnboardingStatus) { | ||
state.UserStorageController.isAccountSyncingReadyToBeDispatched = true; | ||
} else { | ||
state.UserStorageController.isAccountSyncingReadyToBeDispatched = false; | ||
} | ||
|
||
return state; | ||
} | ||
|
||
/** | ||
* This migration sets isAccountSyncingReadyToBeDispatched to true if completedOnboarding is true | ||
* | ||
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist. | ||
* @param originalVersionedData.meta - State metadata. | ||
* @param originalVersionedData.meta.version - The current state version. | ||
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller. | ||
* @returns Updated versioned MetaMask extension state. | ||
*/ | ||
export async function migrate( | ||
originalVersionedData: VersionedData, | ||
): Promise<VersionedData> { | ||
const versionedData = cloneDeep(originalVersionedData); | ||
versionedData.meta.version = version; | ||
transformState(versionedData.data); | ||
return versionedData; | ||
} |
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