Skip to content

Commit

Permalink
fix modal closed edge case
Browse files Browse the repository at this point in the history
more consistent in webgl
  • Loading branch information
0xFirekeeper committed Nov 27, 2024
1 parent c16fc9a commit 2853058
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions Assets/Thirdweb/Runtime/Unity/Wallets/Core/WalletConnectWallet.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Nethereum.ABI.EIP712;
using WalletConnectSharp.Sign.Models;
Expand Down Expand Up @@ -60,6 +59,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
}

CreateNewSession(eip155ChainsSupported);
WalletConnectModal.ModalClosed += OnModalClosed;

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

if (_exception != null)
{
WalletConnectModal.ModalClosed -= OnModalClosed;
throw _exception;
}
else
Expand All @@ -93,7 +94,7 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
return new WalletConnectWallet(client);
}

public async Task EnsureCorrectNetwork(BigInteger chainId)
public async Task SwitchNetwork(BigInteger chainId)
{
var currentChainId = WalletConnect.Instance.ActiveChainId;
if (currentChainId == $"eip155:{chainId}")
Expand Down Expand Up @@ -125,6 +126,12 @@ public async Task EnsureCorrectNetwork(BigInteger chainId)
await WalletConnect.Instance.SignClient.AddressProvider.SetDefaultChainIdAsync($"eip155:{chainId}");
}

[Obsolete("Use SwitchNetwork instead.")]
public Task EnsureCorrectNetwork(BigInteger chainId)
{
return SwitchNetwork(chainId);
}

#region IThirdwebWallet

public Task<string> GetAddress()
Expand Down Expand Up @@ -254,6 +261,26 @@ public Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, TypedData<
throw new NotImplementedException();
}

public Task<List<LinkedAccount>> LinkAccount(
IThirdwebWallet walletToLink,
string otp = null,
bool? isMobile = null,
Action<string> browserOpenAction = null,
string mobileRedirectScheme = "thirdweb://",
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
)
{
throw new InvalidOperationException("LinkAccount is not supported by external wallets.");
}

public Task<List<LinkedAccount>> GetLinkedAccounts()
{
throw new InvalidOperationException("GetLinkedAccounts is not supported by external wallets.");
}

#endregion

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

var connectOptions = new ConnectOptions { OptionalNamespaces = optionalNamespaces, };

// Open modal
WalletConnectModal.Open(new WalletConnectModalOptions { ConnectOptions = connectOptions, IncludedWalletIds = _includedWalletIds });
WalletConnectModal.ModalClosed += (sender, e) =>
{
_exception = new Exception("WalletConnect modal was closed.");
};
}
catch (Exception e)
{
_exception = e;
}
}

protected static void OnModalClosed(object sender, EventArgs e)
{
if (!WalletConnect.Instance.IsConnected)
{
_exception = new Exception("WalletConnect modal was closed.");
}
}

#endregion

private void SessionRequestDeeplink()
Expand All @@ -299,25 +328,5 @@ private void SessionRequestDeeplink()
WalletConnect.Instance.Linker.OpenSessionRequestDeepLinkAfterMessageFromSession(activeSessionTopic);
#endif
}

public Task<List<LinkedAccount>> LinkAccount(
IThirdwebWallet walletToLink,
string otp = null,
bool? isMobile = null,
Action<string> browserOpenAction = null,
string mobileRedirectScheme = "thirdweb://",
IThirdwebBrowser browser = null,
BigInteger? chainId = null,
string jwt = null,
string payload = null
)
{
throw new InvalidOperationException("LinkAccount is not supported by external wallets.");
}

public Task<List<LinkedAccount>> GetLinkedAccounts()
{
throw new InvalidOperationException("GetLinkedAccounts is not supported by external wallets.");
}
}
}

0 comments on commit 2853058

Please sign in to comment.