Skip to content
5 changes: 5 additions & 0 deletions packages/account-tree-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix group naming for PK/Hardware accounts ([#6677](https://github.com/MetaMask/core/pull/6677))
- Previously, the first PK/Hardware account would start as `Account 2` as opposed to `Account 1` and thus subsequent group names were off as well.

## [1.0.0]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ describe('AccountTreeController', () => {
type: AccountGroupType.SingleAccount,
accounts: [MOCK_SNAP_ACCOUNT_2.id],
metadata: {
name: 'Account 2', // Updated: per-wallet numbering (different wallet)
name: 'Account 1', // Updated: per-wallet numbering (different wallet)
pinned: false,
hidden: false,
},
Expand All @@ -610,7 +610,7 @@ describe('AccountTreeController', () => {
type: AccountGroupType.SingleAccount,
accounts: [MOCK_HARDWARE_ACCOUNT_1.id],
metadata: {
name: 'Account 2', // Updated: per-wallet numbering (different wallet)
name: 'Account 1', // Updated: per-wallet numbering (different wallet)
pinned: false,
hidden: false,
},
Expand Down Expand Up @@ -652,13 +652,13 @@ describe('AccountTreeController', () => {
},
[expectedKeyringWalletIdGroup]: {
name: {
value: 'Account 2', // Updated: per-wallet numbering (different wallet)
value: 'Account 1', // Updated: per-wallet numbering (different wallet)
lastUpdatedAt: expect.any(Number),
},
},
[expectedSnapWalletIdGroup]: {
name: {
value: 'Account 2', // Updated: per-wallet numbering (different wallet)
value: 'Account 1', // Updated: per-wallet numbering (different wallet)
lastUpdatedAt: expect.any(Number),
},
},
Expand Down Expand Up @@ -2430,8 +2430,8 @@ describe('AccountTreeController', () => {

// Groups should use consistent default naming regardless of import time
// Updated expectations based on per-wallet sequential naming logic
expect(group1?.metadata.name).toBe('Account 3'); // Updated: reflects actual naming logic
expect(group2?.metadata.name).toBe('Account 2'); // Updated: reflects actual naming logic
expect(group1?.metadata.name).toBe('Account 2'); // Updated: reflects actual naming logic
expect(group2?.metadata.name).toBe('Account 1'); // Updated: reflects actual naming logic
});

it('uses fallback naming when rule-based naming returns empty string', () => {
Expand Down Expand Up @@ -2903,8 +2903,8 @@ describe('AccountTreeController', () => {
expect(uniqueNames.size).toBe(2);

// Due to optimization, names start at wallet.length, so we get "Account 3" and "Account 4"
expect(allNames).toContain('Account 3');
expect(allNames).toContain('Account 4');
expect(allNames).toContain('Account 1');
expect(allNames).toContain('Account 2');

// Verify they're actually different
expect(group1.metadata.name).not.toBe(group2.metadata.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ export class AccountTreeController extends BaseController<
} else {
// For other wallet types, start with the number of existing groups
// This gives us the next logical sequential number
proposedNameIndex = Object.keys(wallet.groups).length;
proposedNameIndex = Object.keys(wallet.groups).length - 1;
}

// Use the higher of the two: highest parsed index or computed index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Use the lowest of the two: highest parsed index or computed index

proposedNameIndex = Math.max(highestAccountNameIndex, proposedNameIndex);
proposedNameIndex = Math.min(highestAccountNameIndex, proposedNameIndex);

// Find a unique name by checking for conflicts and incrementing if needed
let nameExists: boolean;
Expand Down
Loading