@@ -83,7 +83,7 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
8383 } ) ) ,
8484 } ;
8585
86- this . currentChainId = options . defaultChainId ;
86+ this . currentChainId = options . defaultChainId || chains [ 0 ] . chainId ;
8787 }
8888
8989 get currentChain ( ) : CustomChainConfig {
@@ -230,10 +230,10 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
230230
231231 protected initCachedConnectorAndChainId ( ) {
232232 this . cachedConnector = storageAvailable ( this . storage ) ? window [ this . storage ] . getItem ( CONNECTOR_CACHE_KEY ) : null ;
233- // init chainId using cached chainId if it exists and is valid, otherwise use the first chain
233+ // init chainId using cached chainId if it exists and is valid, otherwise use the defaultChainId or the first chain
234234 const cachedChainId = storageAvailable ( this . storage ) ? window [ this . storage ] . getItem ( CURRENT_CHAIN_CACHE_KEY ) : null ;
235235 const isCachedChainIdValid = cachedChainId && this . coreOptions . chains . some ( ( chain ) => chain . chainId === cachedChainId ) ;
236- this . currentChainId = isCachedChainIdValid ? cachedChainId : this . coreOptions . defaultChainId ;
236+ this . currentChainId = isCachedChainIdValid ? cachedChainId : this . coreOptions . defaultChainId || this . coreOptions . chains [ 0 ] . chainId ;
237237 }
238238
239239 protected async setupCommonJRPCProvider ( ) {
@@ -266,8 +266,8 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
266266
267267 // add injected connectors
268268 const isMipdEnabled = this . coreOptions . multiInjectedProviderDiscovery ?? true ;
269+ const chainNamespaces = new Set ( this . coreOptions . chains . map ( ( chain ) => chain . chainNamespace ) ) ;
269270 if ( isMipdEnabled ) {
270- const chainNamespaces = new Set ( this . coreOptions . chains . map ( ( chain ) => chain . chainNamespace ) ) ;
271271 // Solana chains
272272 if ( chainNamespaces . has ( CHAIN_NAMESPACES . SOLANA ) ) {
273273 const { createSolanaMipd, hasSolanaWalletStandardFeatures, walletStandardConnector } = await import ( "@/core/injected-solana-connector" ) ;
@@ -295,16 +295,16 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
295295 } ) ;
296296 connectorFns . push ( ...evmMipd . getProviders ( ) . map ( injectedEvmConnector ) ) ;
297297 }
298+ }
298299
299- // add WalletConnectV2 connector if enabled
300- if (
301- projectConfig . wallet_connect_enabled &&
302- projectConfig . wallet_connect_project_id &&
303- ( chainNamespaces . has ( CHAIN_NAMESPACES . SOLANA ) || chainNamespaces . has ( CHAIN_NAMESPACES . EIP155 ) )
304- ) {
305- const { walletConnectV2Connector } = await import ( "@/core/wallet-connect-v2-connector" ) ;
306- connectorFns . push ( walletConnectV2Connector ( ) ) ;
307- }
300+ // add WalletConnectV2 connector if enabled
301+ if (
302+ projectConfig . wallet_connect_enabled &&
303+ projectConfig . wallet_connect_project_id &&
304+ ( chainNamespaces . has ( CHAIN_NAMESPACES . SOLANA ) || chainNamespaces . has ( CHAIN_NAMESPACES . EIP155 ) )
305+ ) {
306+ const { walletConnectV2Connector } = await import ( "@/core/wallet-connect-v2-connector" ) ;
307+ connectorFns . push ( walletConnectV2Connector ( ) ) ;
308308 }
309309
310310 const connectors = connectorFns . map ( ( connectorFn ) => connectorFn ( config ) ) ;
@@ -433,7 +433,6 @@ export class Web3AuthNoModal extends SafeEventEmitter<Web3AuthNoModalEvents> imp
433433 * @throws WalletInitializationError If no chain is found for the connector's namespace
434434 */
435435 protected getInitialChainIdForConnector ( connector : IConnector < unknown > ) : CustomChainConfig {
436- // TODO: combine this logic with chainId input from web3auth options
437436 let initialChain = this . currentChain ;
438437 if ( initialChain . chainNamespace !== connector . connectorNamespace && connector . connectorNamespace !== CONNECTOR_NAMESPACES . MULTICHAIN ) {
439438 initialChain = this . coreOptions . chains . find ( ( x ) => x . chainNamespace === connector . connectorNamespace ) ;
0 commit comments