Skip to content

Commit 01bb412

Browse files
authored
feat(account-tree-controller): resolve group names conflicts in b&s operations (#6697)
## Explanation ```md - Set the `setAccountGroupName`'s option `autoHandleConflict` to `true` for all backup & sync operations ``` <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent d36a77d commit 01bb412

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

packages/account-tree-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- Set the `setAccountGroupName`'s option `autoHandleConflict` to `true` for all backup & sync operations ([#6697](https://github.com/MetaMask/core/pull/6697))
1213
- Add new group naming for non-HD keyring accounts ([#6679](https://github.com/MetaMask/core/pull/6679)), ([#6696](https://github.com/MetaMask/core/pull/6696))
1314
- Hardware-wallet account groups are now named: "Ledger|Trezor|QR|Lattice|OneKey Account N".
1415
- Private key account groups are now named: "Imported Account N".

packages/account-tree-controller/src/backup-and-sync/syncing/group.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ describe('BackupAndSync - Syncing - Group', () => {
278278
expect(mockContext.controller.setAccountGroupName).toHaveBeenCalledWith(
279279
mockLocalGroup.id,
280280
'New Name',
281+
true,
281282
);
282283
}
283284
/* eslint-enable jest/no-conditional-in-test */
@@ -600,6 +601,7 @@ describe('BackupAndSync - Syncing - Group', () => {
600601
expect(testContext.controller.setAccountGroupName).toHaveBeenCalledWith(
601602
mockLocalGroup.id,
602603
testGroupName,
604+
true,
603605
);
604606
});
605607
});

packages/account-tree-controller/src/backup-and-sync/syncing/group.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async function syncGroupMetadataAndCheckIfPushNeeded(
145145
validateUserStorageValue: (value) =>
146146
UserStorageSyncedWalletGroupSchema.schema.name.schema.value.is(value),
147147
applyLocalUpdate: (name: string) => {
148-
context.controller.setAccountGroupName(localGroup.id, name);
148+
context.controller.setAccountGroupName(localGroup.id, name, true);
149149
},
150150
analytics: {
151151
action: BackupAndSyncAnalyticsEvent.GroupRenamed,

packages/account-tree-controller/src/backup-and-sync/syncing/legacy.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ describe('BackupAndSync - Syncing - Legacy', () => {
174174
expect(mockContext.controller.setAccountGroupName).toHaveBeenCalledWith(
175175
'entropy:test-entropy/0',
176176
'Legacy Account 1',
177+
true,
177178
);
178179
expect(mockContext.controller.setAccountGroupName).toHaveBeenCalledWith(
179180
'entropy:test-entropy/1',
180181
'Legacy Account 2',
182+
true,
181183
);
182184
});
183185

@@ -302,14 +304,17 @@ describe('BackupAndSync - Syncing - Legacy', () => {
302304
expect(mockContext.controller.setAccountGroupName).toHaveBeenCalledWith(
303305
'entropy:test-entropy/0',
304306
'Main Account',
307+
true,
305308
);
306309
expect(mockContext.controller.setAccountGroupName).toHaveBeenCalledWith(
307310
'entropy:test-entropy/1',
308311
'Trading Account',
312+
true,
309313
);
310314
expect(mockContext.controller.setAccountGroupName).toHaveBeenCalledWith(
311315
'entropy:test-entropy/2',
312316
'Savings Account',
317+
true,
313318
);
314319

315320
expect(mockContext.emitAnalyticsEventFn).toHaveBeenCalledWith({

packages/account-tree-controller/src/backup-and-sync/syncing/legacy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const performLegacyAccountSyncing = async (
8888
group.accounts.includes(localAccountId),
8989
);
9090
if (localGroup) {
91-
context.controller.setAccountGroupName(localGroup.id, n);
91+
context.controller.setAccountGroupName(localGroup.id, n, true);
9292

9393
context.emitAnalyticsEventFn({
9494
action: BackupAndSyncAnalyticsEvent.LegacyGroupRenamed,

0 commit comments

Comments
 (0)