@@ -72,16 +72,20 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
72
72
}
73
73
else
74
74
{
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 } ")
83
77
{
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
+ }
85
89
}
86
90
_walletConnectService = new WalletConnectServiceCore ( WalletConnect . Instance . SignClient ) ;
87
91
}
@@ -91,6 +95,11 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
91
95
92
96
public async Task EnsureCorrectNetwork ( BigInteger chainId )
93
97
{
98
+ var currentChainId = WalletConnect . Instance . ActiveChainId ;
99
+ if ( currentChainId == $ "eip155:{ chainId } ")
100
+ {
101
+ return ;
102
+ }
94
103
var chainInfo = await Utils . GetChainMetadata ( _client , chainId ) ;
95
104
var wcChainInfo = new EthereumChain ( )
96
105
{
0 commit comments