1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Numerics ;
4
- using System . Text ;
5
4
using System . Threading . Tasks ;
6
5
using Nethereum . ABI . EIP712 ;
7
6
using WalletConnectSharp . Sign . Models ;
@@ -60,6 +59,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
60
59
}
61
60
62
61
CreateNewSession ( eip155ChainsSupported ) ;
62
+ WalletConnectModal . ModalClosed += OnModalClosed ;
63
63
64
64
while ( ! WalletConnect . Instance . IsConnected && _exception == null )
65
65
{
@@ -68,6 +68,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
68
68
69
69
if ( _exception != null )
70
70
{
71
+ WalletConnectModal . ModalClosed -= OnModalClosed ;
71
72
throw _exception ;
72
73
}
73
74
else
@@ -93,7 +94,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
93
94
return new WalletConnectWallet ( client ) ;
94
95
}
95
96
96
- public async Task EnsureCorrectNetwork ( BigInteger chainId )
97
+ public async Task SwitchNetwork ( BigInteger chainId )
97
98
{
98
99
var currentChainId = WalletConnect . Instance . ActiveChainId ;
99
100
if ( currentChainId == $ "eip155:{ chainId } ")
@@ -125,6 +126,12 @@ public async Task EnsureCorrectNetwork(BigInteger chainId)
125
126
await WalletConnect . Instance . SignClient . AddressProvider . SetDefaultChainIdAsync ( $ "eip155:{ chainId } ") ;
126
127
}
127
128
129
+ [ Obsolete ( "Use SwitchNetwork instead." ) ]
130
+ public Task EnsureCorrectNetwork ( BigInteger chainId )
131
+ {
132
+ return SwitchNetwork ( chainId ) ;
133
+ }
134
+
128
135
#region IThirdwebWallet
129
136
130
137
public Task < string > GetAddress ( )
@@ -254,6 +261,26 @@ public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<
254
261
throw new NotImplementedException ( ) ;
255
262
}
256
263
264
+ public Task < List < LinkedAccount > > LinkAccount (
265
+ IThirdwebWallet walletToLink ,
266
+ string otp = null ,
267
+ bool ? isMobile = null ,
268
+ Action < string > browserOpenAction = null ,
269
+ string mobileRedirectScheme = "thirdweb://" ,
270
+ IThirdwebBrowser browser = null ,
271
+ BigInteger ? chainId = null ,
272
+ string jwt = null ,
273
+ string payload = null
274
+ )
275
+ {
276
+ throw new InvalidOperationException ( "LinkAccount is not supported by external wallets." ) ;
277
+ }
278
+
279
+ public Task < List < LinkedAccount > > GetLinkedAccounts ( )
280
+ {
281
+ throw new InvalidOperationException ( "GetLinkedAccounts is not supported by external wallets." ) ;
282
+ }
283
+
257
284
#endregion
258
285
259
286
#region UI
@@ -276,20 +303,22 @@ protected static void CreateNewSession(string[] supportedChains)
276
303
} ;
277
304
278
305
var connectOptions = new ConnectOptions { OptionalNamespaces = optionalNamespaces , } ;
279
-
280
- // Open modal
281
306
WalletConnectModal . Open ( new WalletConnectModalOptions { ConnectOptions = connectOptions , IncludedWalletIds = _includedWalletIds } ) ;
282
- WalletConnectModal . ModalClosed += ( sender , e ) =>
283
- {
284
- _exception = new Exception ( "WalletConnect modal was closed." ) ;
285
- } ;
286
307
}
287
308
catch ( Exception e )
288
309
{
289
310
_exception = e ;
290
311
}
291
312
}
292
313
314
+ protected static void OnModalClosed ( object sender , EventArgs e )
315
+ {
316
+ if ( ! WalletConnect . Instance . IsConnected )
317
+ {
318
+ _exception = new Exception ( "WalletConnect modal was closed." ) ;
319
+ }
320
+ }
321
+
293
322
#endregion
294
323
295
324
private void SessionRequestDeeplink ( )
@@ -299,25 +328,5 @@ private void SessionRequestDeeplink()
299
328
WalletConnect . Instance . Linker . OpenSessionRequestDeepLinkAfterMessageFromSession ( activeSessionTopic ) ;
300
329
#endif
301
330
}
302
-
303
- public Task < List < LinkedAccount > > LinkAccount (
304
- IThirdwebWallet walletToLink ,
305
- string otp = null ,
306
- bool ? isMobile = null ,
307
- Action < string > browserOpenAction = null ,
308
- string mobileRedirectScheme = "thirdweb://" ,
309
- IThirdwebBrowser browser = null ,
310
- BigInteger ? chainId = null ,
311
- string jwt = null ,
312
- string payload = null
313
- )
314
- {
315
- throw new InvalidOperationException ( "LinkAccount is not supported by external wallets." ) ;
316
- }
317
-
318
- public Task < List < LinkedAccount > > GetLinkedAccounts ( )
319
- {
320
- throw new InvalidOperationException ( "GetLinkedAccounts is not supported by external wallets." ) ;
321
- }
322
331
}
323
332
}
0 commit comments