Skip to content

Commit 2853058

Browse files
committed
fix modal closed edge case
more consistent in webgl
1 parent c16fc9a commit 2853058

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

Diff for: Assets/Thirdweb/Runtime/Unity/Wallets/Core/WalletConnectWallet.cs

+37-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Numerics;
4-
using System.Text;
54
using System.Threading.Tasks;
65
using Nethereum.ABI.EIP712;
76
using WalletConnectSharp.Sign.Models;
@@ -60,6 +59,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
6059
}
6160

6261
CreateNewSession(eip155ChainsSupported);
62+
WalletConnectModal.ModalClosed += OnModalClosed;
6363

6464
while (!WalletConnect.Instance.IsConnected && _exception == null)
6565
{
@@ -68,6 +68,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
6868

6969
if (_exception != null)
7070
{
71+
WalletConnectModal.ModalClosed -= OnModalClosed;
7172
throw _exception;
7273
}
7374
else
@@ -93,7 +94,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
9394
return new WalletConnectWallet(client);
9495
}
9596

96-
public async Task EnsureCorrectNetwork(BigInteger chainId)
97+
public async Task SwitchNetwork(BigInteger chainId)
9798
{
9899
var currentChainId = WalletConnect.Instance.ActiveChainId;
99100
if (currentChainId == $"eip155:{chainId}")
@@ -125,6 +126,12 @@ public async Task EnsureCorrectNetwork(BigInteger chainId)
125126
await WalletConnect.Instance.SignClient.AddressProvider.SetDefaultChainIdAsync($"eip155:{chainId}");
126127
}
127128

129+
[Obsolete("Use SwitchNetwork instead.")]
130+
public Task EnsureCorrectNetwork(BigInteger chainId)
131+
{
132+
return SwitchNetwork(chainId);
133+
}
134+
128135
#region IThirdwebWallet
129136

130137
public Task<string> GetAddress()
@@ -254,6 +261,26 @@ public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<
254261
throw new NotImplementedException();
255262
}
256263

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+
257284
#endregion
258285

259286
#region UI
@@ -276,20 +303,22 @@ protected static void CreateNewSession(string[] supportedChains)
276303
};
277304

278305
var connectOptions = new ConnectOptions { OptionalNamespaces = optionalNamespaces, };
279-
280-
// Open modal
281306
WalletConnectModal.Open(new WalletConnectModalOptions { ConnectOptions = connectOptions, IncludedWalletIds = _includedWalletIds });
282-
WalletConnectModal.ModalClosed += (sender, e) =>
283-
{
284-
_exception = new Exception("WalletConnect modal was closed.");
285-
};
286307
}
287308
catch (Exception e)
288309
{
289310
_exception = e;
290311
}
291312
}
292313

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+
293322
#endregion
294323

295324
private void SessionRequestDeeplink()
@@ -299,25 +328,5 @@ private void SessionRequestDeeplink()
299328
WalletConnect.Instance.Linker.OpenSessionRequestDeepLinkAfterMessageFromSession(activeSessionTopic);
300329
#endif
301330
}
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-
}
322331
}
323332
}

0 commit comments

Comments
 (0)