Skip to content

Commit

Permalink
Avoid enforcing network if chain id = initial wc
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFirekeeper committed Oct 10, 2024
1 parent 0d7d412 commit b62acc9
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions Assets/Thirdweb/Runtime/Unity/Wallets/Core/WalletConnectWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,20 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI
}
else
{
try
{
var data = new WalletSwitchEthereumChain(new HexBigInteger(initialChainId).HexValue);
await WalletConnect.Instance.RequestAsync<WalletSwitchEthereumChain, string>(data);
await Task.Delay(5000); // wait for chain switch to take effect
await WalletConnect.Instance.SignClient.AddressProvider.SetDefaultChainIdAsync($"eip155:{initialChainId}");
}
catch (Exception e)
var currentChainId = WalletConnect.Instance.ActiveChainId;
if (currentChainId != $"eip155:{initialChainId}")
{
ThirdwebDebug.LogWarning($"Failed to ensure wallet is on active chain: {e.Message}");
try
{
var data = new WalletSwitchEthereumChain(new HexBigInteger(initialChainId).HexValue);
await WalletConnect.Instance.RequestAsync<WalletSwitchEthereumChain, string>(data);
await Task.Delay(5000); // wait for chain switch to take effect
await WalletConnect.Instance.SignClient.AddressProvider.SetDefaultChainIdAsync($"eip155:{initialChainId}");
}
catch (Exception e)
{
ThirdwebDebug.LogWarning($"Failed to ensure wallet is on active chain: {e.Message}");
}
}
_walletConnectService = new WalletConnectServiceCore(WalletConnect.Instance.SignClient);
}
Expand All @@ -91,6 +95,11 @@ public async static Task<WalletConnectWallet> Create(ThirdwebClient client, BigI

public async Task EnsureCorrectNetwork(BigInteger chainId)
{
var currentChainId = WalletConnect.Instance.ActiveChainId;
if (currentChainId == $"eip155:{chainId}")
{
return;
}
var chainInfo = await Utils.GetChainMetadata(_client, chainId);
var wcChainInfo = new EthereumChain()
{
Expand Down

0 comments on commit b62acc9

Please sign in to comment.