Skip to content

Commit a682594

Browse files
committed
WalletConnect Connectivity Improvements
Fixed Android issues, still allowing a callback for switch network. Improved and cleaned up general behavior of WalletConnect.cs Also fixed a thrown Event Trigger from internal Wallet Connect Core scripts.
1 parent 89cb2b9 commit a682594

File tree

6 files changed

+160
-223
lines changed

6 files changed

+160
-223
lines changed

Assets/Thirdweb/Core/Scripts/Wallet.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,27 @@ public async Task<string> Connect(WalletConnection? walletConnection = null)
6868
oldSession.siweSession
6969
);
7070

71-
// Add chain
71+
// Switch to chain
7272
try
7373
{
74-
await WalletConnect.Instance.WalletAddEthChain(ThirdwebManager.Instance.SDK.currentChainData);
74+
await WalletConnect.Instance.WalletSwitchEthChain(new EthChain() { chainId = ThirdwebManager.Instance.SDK.currentChainData.chainId });
7575
}
7676
catch (System.Exception e)
7777
{
78-
Debug.Log("Adding chain error: " + e.Message);
79-
}
78+
Debug.LogWarning("Switching chain error, attempting to add chain: " + e.Message);
8079

81-
// Switch to chain
82-
await WalletConnect.Instance.WalletSwitchEthChain(new EthChain() { chainId = ThirdwebManager.Instance.SDK.currentChainData.chainId });
80+
// Add chain
81+
try
82+
{
83+
await WalletConnect.Instance.WalletAddEthChain(ThirdwebManager.Instance.SDK.currentChainData);
84+
await WalletConnect.Instance.WalletSwitchEthChain(new EthChain() { chainId = ThirdwebManager.Instance.SDK.currentChainData.chainId });
85+
}
86+
catch (System.Exception f)
87+
{
88+
Debug.LogWarning("Adding chain error: " + f.Message);
89+
return Nethereum.Util.AddressUtil.Current.ConvertToChecksumAddress(WalletConnect.Instance.Session.Accounts[0]);
90+
}
91+
}
8392

8493
return Nethereum.Util.AddressUtil.Current.ConvertToChecksumAddress(WalletConnect.Instance.Session.Accounts[0]);
8594
}

Assets/Thirdweb/Examples/Prefabs/Prefab_ConnectWalletNative.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ MonoBehaviour:
30533053
m_OnCullStateChanged:
30543054
m_PersistentCalls:
30553055
m_Calls: []
3056-
m_text: Mobile Wallet
3056+
m_text: Wallet Connect
30573057
m_isRightToLeft: 0
30583058
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
30593059
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}

Assets/Thirdweb/Plugins/WalletConnectSharp.Core/WalletConnectProtocol.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,24 @@ protected async void TransportOnMessageReceived(object sender, MessageReceivedEv
188188

189189
var json = await Cipher.DecryptWithKey(_keyRaw, encryptedPayload);
190190

191-
var payload = JsonConvert.DeserializeObject<JsonRpcResponse>(json); // Edited from JsonRpcPayload
192-
193-
if (payload != null)
191+
try
192+
{
193+
JsonRpcResponse payload = JsonConvert.DeserializeObject<JsonRpcResponse>(json); // Edited from JsonRpcPayload
194+
if (payload != null)
195+
Events.Trigger(payload.Event, json);
196+
}
197+
catch
194198
{
195-
Events.Trigger(payload.Event, json);
199+
try
200+
{
201+
JsonRpcPayload payload = JsonConvert.DeserializeObject<JsonRpcPayload>(json);
202+
if (payload != null)
203+
Events.Trigger(payload.Event, json);
204+
}
205+
catch
206+
{
207+
return;
208+
}
196209
}
197210
}
198211

Assets/Thirdweb/Plugins/WalletConnectSharp.Unity/UI/ChooseWalletScreen.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ private IEnumerator BuildWalletButtons()
3636

3737
walletImage.sprite = walletData.medimumIcon;
3838

39-
walletButton.onClick.AddListener(
40-
delegate
41-
{
42-
WalletConnect.OpenDeepLink(walletData);
43-
}
44-
);
39+
walletButton.onClick.RemoveAllListeners();
40+
walletButton.onClick.AddListener(() => WalletConnect.OpenDeepLink(walletData));
4541
}
4642

4743
Destroy(loadingText.gameObject);

0 commit comments

Comments
 (0)