@@ -348,7 +348,8 @@ export class WalletManager extends StateBase {
348
348
349
349
private _reconnect = async (
350
350
walletName : WalletName ,
351
- checkConnection = false
351
+ checkConnection = false ,
352
+ onlyChainNames ?: ChainName [ ]
352
353
) => {
353
354
if (
354
355
checkConnection &&
@@ -359,9 +360,21 @@ export class WalletManager extends StateBase {
359
360
this . logger ?. debug ( '[Event Emit] `refresh_connection` (manager)' ) ;
360
361
this . coreEmitter . emit ( 'refresh_connection' ) ;
361
362
await this . getMainWallet ( walletName ) . connect ( ) ;
362
- await this . getMainWallet ( walletName )
363
- . getChainWalletList ( true ) [ 0 ]
364
- ?. connect ( true ) ;
363
+ await Promise . all (
364
+ this . getMainWallet ( walletName )
365
+ . getChainWalletList ( true )
366
+ . map ( ( w , index ) =>
367
+ ! onlyChainNames
368
+ ? // If no chains specified, just connect the first chain wallet and sync to all active chain wallets.
369
+ index === 0
370
+ ? w . connect ( true )
371
+ : undefined
372
+ : // If chains specified, connect only the specified chains, without sync.
373
+ onlyChainNames . includes ( w . chainName )
374
+ ? w . connect ( false )
375
+ : undefined
376
+ )
377
+ ) ;
365
378
} ;
366
379
367
380
private _restoreAccounts = async ( ) => {
@@ -375,6 +388,7 @@ export class WalletManager extends StateBase {
375
388
const mainWallet = this . getMainWallet ( walletName ) ;
376
389
mainWallet . activate ( ) ;
377
390
391
+ let onlyChainNames : ChainName [ ] | undefined ;
378
392
if ( mainWallet . clientMutable . state === State . Done ) {
379
393
const accountsStr = window . localStorage . getItem (
380
394
'cosmos-kit@2:core//accounts'
@@ -462,11 +476,15 @@ export class WalletManager extends StateBase {
462
476
return ;
463
477
}
464
478
}
479
+
480
+ onlyChainNames = connectedChainRecords . map (
481
+ ( chainRecord ) => chainRecord . name
482
+ ) ;
465
483
}
466
484
}
467
485
468
486
if ( mainWallet . walletInfo . mode !== 'wallet-connect' ) {
469
- await this . _reconnect ( walletName ) ;
487
+ await this . _reconnect ( walletName , undefined , onlyChainNames ) ;
470
488
}
471
489
} catch ( error ) {
472
490
if ( error instanceof WalletNotProvidedError ) {
0 commit comments