@@ -72,16 +72,20 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
7272 }
7373 else
7474 {
75- try
76- {
77- var data = new WalletSwitchEthereumChain ( new HexBigInteger ( initialChainId ) . HexValue ) ;
78- await WalletConnect . Instance . RequestAsync < WalletSwitchEthereumChain , string > ( data ) ;
79- await Task . Delay ( 5000 ) ; // wait for chain switch to take effect
80- await WalletConnect . Instance . SignClient . AddressProvider . SetDefaultChainIdAsync ( $ "eip155:{ initialChainId } ") ;
81- }
82- catch ( Exception e )
75+ var currentChainId = WalletConnect . Instance . ActiveChainId ;
76+ if ( currentChainId != $ "eip155:{ initialChainId } ")
8377 {
84- ThirdwebDebug . LogWarning ( $ "Failed to ensure wallet is on active chain: { e . Message } ") ;
78+ try
79+ {
80+ var data = new WalletSwitchEthereumChain ( new HexBigInteger ( initialChainId ) . HexValue ) ;
81+ await WalletConnect . Instance . RequestAsync < WalletSwitchEthereumChain , string > ( data ) ;
82+ await Task . Delay ( 5000 ) ; // wait for chain switch to take effect
83+ await WalletConnect . Instance . SignClient . AddressProvider . SetDefaultChainIdAsync ( $ "eip155:{ initialChainId } ") ;
84+ }
85+ catch ( Exception e )
86+ {
87+ ThirdwebDebug . LogWarning ( $ "Failed to ensure wallet is on active chain: { e . Message } ") ;
88+ }
8589 }
8690 _walletConnectService = new WalletConnectServiceCore ( WalletConnect . Instance . SignClient ) ;
8791 }
@@ -91,6 +95,11 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
9195
9296 public async Task EnsureCorrectNetwork ( BigInteger chainId )
9397 {
98+ var currentChainId = WalletConnect . Instance . ActiveChainId ;
99+ if ( currentChainId == $ "eip155:{ chainId } ")
100+ {
101+ return ;
102+ }
94103 var chainInfo = await Utils . GetChainMetadata ( _client , chainId ) ;
95104 var wcChainInfo = new EthereumChain ( )
96105 {
0 commit comments