@@ -2187,6 +2187,70 @@ describe('AccountTreeController', () => {
2187
2187
} ) ;
2188
2188
2189
2189
describe ( 'Fallback Naming' , ( ) => {
2190
+ it ( 'detects new groups based on account import time' , ( ) => {
2191
+ const serviceStartTime = Date . now ( ) ;
2192
+ const mockAccountWithNewImportTime : Bip44Account < InternalAccount > = {
2193
+ ...MOCK_HD_ACCOUNT_1 ,
2194
+ options : {
2195
+ ...MOCK_HD_ACCOUNT_1 . options ,
2196
+ entropy : {
2197
+ ...MOCK_HD_ACCOUNT_1 . options . entropy ,
2198
+ id : MOCK_HD_KEYRING_1 . metadata . id ,
2199
+ groupIndex : 0 ,
2200
+ } ,
2201
+ } ,
2202
+ metadata : {
2203
+ ...MOCK_HD_ACCOUNT_1 . metadata ,
2204
+ importTime : serviceStartTime + 1000 , // Imported after service start
2205
+ } ,
2206
+ } ;
2207
+
2208
+ const mockAccountWithOldImportTime : Bip44Account < InternalAccount > = {
2209
+ ...MOCK_HD_ACCOUNT_2 ,
2210
+ options : {
2211
+ ...MOCK_HD_ACCOUNT_2 . options ,
2212
+ entropy : {
2213
+ ...MOCK_HD_ACCOUNT_2 . options . entropy ,
2214
+ id : MOCK_HD_KEYRING_1 . metadata . id ,
2215
+ groupIndex : 1 ,
2216
+ } ,
2217
+ } ,
2218
+ metadata : {
2219
+ ...MOCK_HD_ACCOUNT_2 . metadata ,
2220
+ importTime : serviceStartTime - 1000 , // Imported before service start
2221
+ } ,
2222
+ } ;
2223
+
2224
+ const { controller } = setup ( {
2225
+ accounts : [ mockAccountWithOldImportTime , mockAccountWithNewImportTime ] ,
2226
+ keyrings : [ MOCK_HD_KEYRING_1 ] ,
2227
+ } ) ;
2228
+
2229
+ controller . init ( ) ;
2230
+
2231
+ const expectedWalletId = toMultichainAccountWalletId (
2232
+ MOCK_HD_KEYRING_1 . metadata . id ,
2233
+ ) ;
2234
+
2235
+ const expectedGroupId1 = toMultichainAccountGroupId (
2236
+ expectedWalletId ,
2237
+ mockAccountWithNewImportTime . options . entropy . groupIndex ,
2238
+ ) ;
2239
+
2240
+ const expectedGroupId2 = toMultichainAccountGroupId (
2241
+ expectedWalletId ,
2242
+ mockAccountWithOldImportTime . options . entropy . groupIndex ,
2243
+ ) ;
2244
+
2245
+ const wallet = controller . state . accountTree . wallets [ expectedWalletId ] ;
2246
+ const group1 = wallet ?. groups [ expectedGroupId1 ] ;
2247
+ const group2 = wallet ?. groups [ expectedGroupId2 ] ;
2248
+
2249
+ // Groups should be named by index within the wallet
2250
+ expect ( group1 ?. metadata . name ) . toBe ( 'Account 1' ) ;
2251
+ expect ( group2 ?. metadata . name ) . toBe ( 'Account 2' ) ;
2252
+ } ) ;
2253
+
2190
2254
it ( 'uses fallback naming when rule-based naming returns empty string' , ( ) => {
2191
2255
// Create accounts with empty names to trigger fallback naming
2192
2256
const mockAccountWithEmptyName1 : Bip44Account < InternalAccount > = {
0 commit comments