Skip to content

Commit d6f0d6b

Browse files
committed
Upgrade WC, add default chains, network add/switch
1 parent 7927efb commit d6f0d6b

File tree

65 files changed

+6489
-1516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+6489
-1516
lines changed

Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ private async void ConnectWallet(WalletOptions options)
8484
{
8585
// Connect the wallet
8686

87-
Debug.Log(1);
8887
var wallet = await ThirdwebManager.Instance.ConnectWallet(options);
8988

9089
// Initialize the wallet panel
@@ -395,7 +394,7 @@ private async void InitializeAccountAbstractionPanel()
395394
}
396395
catch (System.Exception e)
397396
{
398-
Log(panel.LogText, e.ToString());
397+
Log(panel.LogText, e.Message);
399398
}
400399
});
401400

Assets/Thirdweb/Plugins/WalletConnectUnity/com.walletconnect.core/CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [3.1.10] - 2024-07-31
9+
10+
### Changed
11+
12+
- Upgraded WalletConnectSharp to [v2.4.1](https://github.com/WalletConnect/WalletConnectSharp/releases/tag/v2.4.1)
13+
14+
### Fixed
15+
16+
- Occasionally a grey texture would appear instead of a QR code
17+
- Deep linking didn't work with some wallets on mobile
18+
19+
## [3.1.10] - 2024-07-16
20+
21+
- Upgraded WalletConnectSharp to [v2.4.0](https://github.com/WalletConnect/WalletConnectSharp/releases/tag/v2.4.0)
22+
23+
## [3.1.8] - 2024-06-26
24+
25+
### Fixed
26+
27+
- Incorrect Ronin chain explorer URL
28+
- Warming about unnecessary zxing asmdef file
29+
30+
## [3.1.7] - 2024-06-07
31+
32+
### Changed
33+
34+
- Upgraded WalletConnectSharp to [v2.3.8](https://github.com/WalletConnect/WalletConnectSharp/releases/tag/v2.3.8)
35+
36+
### Fixed
37+
38+
- `Unreachable code detected` warnings
39+
- `WalletConnectInterceptor` doesn't support `eth_signTypedData_v4` requests with more than 1 parameter
40+
- Deprecated Polygon RPC URL
41+
- Dependency collision with UniRx and Cysharp/R3
42+
- Generated QR code textures taking up too much memory
43+
844
## [3.1.6] - 2024-05-09
945

1046
### Added

Assets/Thirdweb/Plugins/WalletConnectUnity/com.walletconnect.core/Plugins.meta

Lines changed: 2 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Thirdweb/Plugins/WalletConnectUnity/com.walletconnect.core/Runtime/Chain.cs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ namespace WalletConnectUnity.Core
77
public class Chain
88
{
99
public virtual string Name { get; }
10+
11+
// https://github.com/wevm/viem/blob/main/src/chains/index.ts
12+
public virtual string ViemName { get; }
1013
public virtual Currency NativeCurrency { get; }
1114
public virtual BlockExplorer BlockExplorer { get; }
1215
public virtual string RpcUrl { get; }
@@ -28,7 +31,8 @@ public Chain(
2831
BlockExplorer blockExplorer,
2932
string rpcUrl,
3033
bool isTestnet,
31-
string imageUrl)
34+
string imageUrl,
35+
string viemName = null)
3236
{
3337
ChainNamespace = chainNamespace;
3438
ChainReference = chainReference;
@@ -38,6 +42,7 @@ public Chain(
3842
RpcUrl = rpcUrl;
3943
IsTestnet = isTestnet;
4044
ImageUrl = imageUrl;
45+
ViemName = viemName;
4146
}
4247
}
4348

@@ -141,7 +146,8 @@ public static class Chains
141146
new BlockExplorer("Etherscan", "https://etherscan.io"),
142147
"https://cloudflare-eth.com",
143148
false,
144-
$"{ChainImageUrl}/{ImageIds[References.Ethereum]}"
149+
$"{ChainImageUrl}/{ImageIds[References.Ethereum]}",
150+
"mainnet"
145151
);
146152

147153
public static readonly Chain EthereumGoerli = new(
@@ -152,7 +158,8 @@ public static class Chains
152158
new BlockExplorer("Etherscan", "https://goerli.etherscan.io"),
153159
"https://goerli.infura.io/v3/",
154160
true,
155-
$"{ChainImageUrl}/{ImageIds[References.EthereumGoerli]}"
161+
$"{ChainImageUrl}/{ImageIds[References.EthereumGoerli]}",
162+
"goerli"
156163
);
157164

158165
public static readonly Chain Optimism = new(
@@ -163,18 +170,20 @@ public static class Chains
163170
new BlockExplorer("Optimistic Etherscan", "https://optimistic.etherscan.io"),
164171
"https://mainnet.optimism.io",
165172
false,
166-
$"{ChainImageUrl}/{ImageIds[References.Optimism]}"
173+
$"{ChainImageUrl}/{ImageIds[References.Optimism]}",
174+
"optimism"
167175
);
168176

169177
public static readonly Chain Ronin = new(
170178
Namespaces.Evm,
171179
References.Ronin,
172180
"Ronin",
173181
new Currency("Ronin", "RON", 18),
174-
new BlockExplorer("Ronin Explorer", "https://api-gateway.skymavis.com/rpc"),
182+
new BlockExplorer("Ronin Explorer", "https://app.roninchain.com/"),
175183
"https://api.roninchain.com/rpc",
176184
false,
177-
$"{ChainImageUrl}/{ImageIds[References.Ronin]}"
185+
$"{ChainImageUrl}/{ImageIds[References.Ronin]}",
186+
"ronin"
178187
);
179188

180189
public static readonly Chain RoninSaigon = new(
@@ -185,7 +194,8 @@ public static class Chains
185194
new BlockExplorer("Ronin Explorer", "https://explorer.roninchain.com"),
186195
"\thttps://api-gateway.skymavis.com/rpc/testnet",
187196
false,
188-
$"{ChainImageUrl}/{ImageIds[References.Ronin]}"
197+
$"{ChainImageUrl}/{ImageIds[References.Ronin]}",
198+
"saigon"
189199
);
190200

191201
public static readonly Chain Arbitrum = new(
@@ -196,7 +206,8 @@ public static class Chains
196206
new BlockExplorer("Arbitrum Explorer", "https://arbiscan.io"),
197207
"https://arb1.arbitrum.io/rpc",
198208
false,
199-
$"{ChainImageUrl}/{ImageIds[References.Arbitrum]}"
209+
$"{ChainImageUrl}/{ImageIds[References.Arbitrum]}",
210+
"arbitrum"
200211
);
201212

202213
public static readonly Chain Celo = new(
@@ -207,7 +218,8 @@ public static class Chains
207218
new BlockExplorer("Celo Explorer", "https://explorer.celo.org"),
208219
"https://forno.celo.org",
209220
false,
210-
$"{ChainImageUrl}/{ImageIds[References.Celo]}"
221+
$"{ChainImageUrl}/{ImageIds[References.Celo]}",
222+
"celo"
211223
);
212224

213225
public static readonly Chain CeloAlfajores = new(
@@ -218,7 +230,8 @@ public static class Chains
218230
new BlockExplorer("Celo Explorer", "https://alfajores-blockscout.celo-testnet.org"),
219231
"https://alfajores-forno.celo-testnet.org",
220232
true,
221-
$"{ChainImageUrl}/{ImageIds[References.CeloAlfajores]}"
233+
$"{ChainImageUrl}/{ImageIds[References.CeloAlfajores]}",
234+
"celoAlfajores"
222235
);
223236

224237
public static readonly Chain Base = new(
@@ -229,7 +242,8 @@ public static class Chains
229242
new BlockExplorer("BaseScan", "https://basescan.org/"),
230243
"https://mainnet.base.org",
231244
false,
232-
$"{ChainImageUrl}/{ImageIds[References.Base]}"
245+
$"{ChainImageUrl}/{ImageIds[References.Base]}",
246+
"base"
233247
);
234248

235249
public static readonly Chain BaseGoerli = new(
@@ -240,7 +254,8 @@ public static class Chains
240254
new BlockExplorer("BaseScan", "https://goerli.basescan.org/"),
241255
"https://goerli.base.org",
242256
true,
243-
$"{ChainImageUrl}/{ImageIds[References.BaseGoerli]}"
257+
$"{ChainImageUrl}/{ImageIds[References.BaseGoerli]}",
258+
"baseGoerli"
244259
);
245260

246261
public static readonly Chain Polygon = new(
@@ -249,9 +264,10 @@ public static class Chains
249264
"Polygon",
250265
new Currency("Matic", "MATIC", 18),
251266
new BlockExplorer("Polygon Explorer", "https://polygonscan.com"),
252-
"https://rpc-mainnet.maticvigil.com",
267+
"https://polygon-rpc.com",
253268
false,
254-
$"{ChainImageUrl}/{ImageIds[References.Polygon]}"
269+
$"{ChainImageUrl}/{ImageIds[References.Polygon]}",
270+
"polygon"
255271
);
256272

257273
public static readonly Chain Avalanche = new(
@@ -262,7 +278,8 @@ public static class Chains
262278
new BlockExplorer("Avalanche Explorer", "https://snowtrace.io/"),
263279
"https://api.avax.network/ext/bc/C/rpc",
264280
false,
265-
$"{ChainImageUrl}/{ImageIds[References.Avalanche]}"
281+
$"{ChainImageUrl}/{ImageIds[References.Avalanche]}",
282+
"avalanche"
266283
);
267284

268285
public static readonly Chain Solana = new(
@@ -273,7 +290,8 @@ public static class Chains
273290
new BlockExplorer("Solana Explorer", "https://explorer.solana.com"),
274291
"https://api.mainnet-beta.solana.com",
275292
false,
276-
$"{ChainImageUrl}/{ImageIds[References.Solana]}"
293+
$"{ChainImageUrl}/{ImageIds[References.Solana]}",
294+
"solana"
277295
);
278296

279297
public static readonly IReadOnlyCollection<Chain> All = new HashSet<Chain>

Assets/Thirdweb/Plugins/WalletConnectUnity/com.walletconnect.core/Runtime/EVM/Extensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public static async Task SwitchEthereumChainAsync(this IWalletConnect walletConn
1313
throw new ArgumentNullException(nameof(ethereumChain));
1414

1515
var ciap2ChainId = $"eip155:{ethereumChain.chainIdDecimal}";
16-
if (!walletConnect.ActiveSession.Namespaces.TryGetValue("eip155", out var @namespace) || !@namespace.Chains.Contains(ciap2ChainId))
16+
if (!walletConnect.ActiveSession.Namespaces.TryGetValue("eip155", out var @namespace)
17+
|| !@namespace.Chains.Contains(ciap2ChainId))
1718
{
1819
var request = new WalletAddEthereumChain(ethereumChain);
1920

@@ -31,4 +32,4 @@ public static async Task SwitchEthereumChainAsync(this IWalletConnect walletConn
3132
await walletConnect.RequestAsync<WalletSwitchEthereumChain, string>(data);
3233
}
3334
}
34-
}
35+
}

Assets/Thirdweb/Plugins/WalletConnectUnity/com.walletconnect.core/Runtime/Linker.cs

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ public static void OpenSessionProposalDeepLink(string uri, Wallet wallet)
3737
#if UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
3838
// In editor we cannot open _mobile_ deep links, so we just log the uri
3939
Debug.Log($"[Linker] Requested to open mobile deep link. The uri: {uri}");
40-
return;
4140
#else
42-
4341
var link = Application.isMobilePlatform ? wallet.MobileLink : wallet.DesktopLink;
4442

4543
if (string.IsNullOrWhiteSpace(link))
46-
throw new Exception($"[Linker] No link found for {Application.platform} platform in wallet {wallet.Name}.");
44+
throw new Exception(
45+
$"[Linker] No link found for {Application.platform} platform in wallet {wallet.Name}.");
4746

4847
var url = BuildConnectionDeepLink(link, uri);
4948

@@ -58,20 +57,34 @@ public static void OpenSessionRequestDeepLink(in SessionStruct session)
5857
if (string.IsNullOrWhiteSpace(session.Topic))
5958
throw new Exception("[Linker] No session topic found in provided session. Cannot open deep link.");
6059

61-
if (session.Peer.Metadata != null)
60+
if (session.Peer.Metadata == null)
61+
return;
62+
63+
var redirectNative = session.Peer.Metadata.Redirect?.Native;
64+
65+
if (string.IsNullOrWhiteSpace(redirectNative))
6266
{
63-
var redirectNative = session.Peer.Metadata.Redirect.Native;
67+
if (!WalletUtils.TryGetRecentWallet(out var recentWallet))
68+
return;
6469

65-
if (string.IsNullOrWhiteSpace(redirectNative) && WalletUtils.TryGetRecentWallet(out var recentWallet))
66-
{
67-
WCLogger.LogError($"[Linker] No redirect found for {session.Peer.Metadata.Name}. Using deep link from the Recent Wallet.");
68-
Application.OpenURL(Application.isMobilePlatform ? recentWallet.MobileLink : recentWallet.DesktopLink);
69-
}
70-
else
71-
{
72-
WCLogger.Log($"[Linker] Open native deep link: {redirectNative}");
73-
Application.OpenURL(redirectNative);
74-
}
70+
Debug.LogWarning(
71+
$"[Linker] No redirect found for {session.Peer.Metadata.Name}. Using deep link from the Recent Wallet."
72+
);
73+
74+
redirectNative = Application.isMobilePlatform ? recentWallet.MobileLink : recentWallet.DesktopLink;
75+
if (!redirectNative.EndsWith("://"))
76+
redirectNative = $"{redirectNative}://";
77+
78+
Application.OpenURL(redirectNative);
79+
}
80+
else
81+
{
82+
WCLogger.Log($"[Linker] Open native deep link: {redirectNative}");
83+
84+
if (!redirectNative.EndsWith("://"))
85+
redirectNative = $"{redirectNative}://";
86+
87+
Application.OpenURL(redirectNative);
7588
}
7689
}
7790

@@ -90,7 +103,7 @@ public static string BuildConnectionDeepLink(string appLink, string wcUri)
90103
safeAppUrl = $"{safeAppUrl}://";
91104
}
92105

93-
if (!safeAppUrl.EndsWith("/"))
106+
if (!safeAppUrl.EndsWith('/'))
94107
safeAppUrl = $"{safeAppUrl}/";
95108

96109
var encodedWcUrl = Uri.EscapeDataString(wcUri);
@@ -112,24 +125,21 @@ public virtual void OpenSessionRequestDeepLink()
112125

113126
protected virtual void OnPublisherPublishedMessage(object sender, PublishParams publishParams)
114127
{
115-
WalletConnect.UnitySyncContext.Post(
116-
_ =>
117-
{
118-
if (string.IsNullOrWhiteSpace(publishParams.Topic))
119-
return;
128+
WalletConnect.UnitySyncContext.Post(_ =>
129+
{
130+
if (string.IsNullOrWhiteSpace(publishParams.Topic))
131+
return;
120132

121-
if (_sessionMessagesCounter.TryGetValue(publishParams.Topic, out var messageCount))
133+
if (_sessionMessagesCounter.TryGetValue(publishParams.Topic, out var messageCount))
134+
{
135+
WCLogger.Log($"[Linker] OnPublisherPublishedMessage. Message count: {messageCount}");
136+
if (messageCount != 0)
122137
{
123-
WCLogger.Log($"[Linker] OnPublisherPublishedMessage. Message count: {messageCount}");
124-
if (messageCount != 0)
125-
{
126-
_sessionMessagesCounter[publishParams.Topic] = messageCount - 1;
127-
OpenSessionRequestDeepLink(publishParams.Topic);
128-
}
138+
_sessionMessagesCounter[publishParams.Topic] = messageCount - 1;
139+
OpenSessionRequestDeepLink(publishParams.Topic);
129140
}
130-
},
131-
null
132-
);
141+
}
142+
}, null);
133143
}
134144

135145
public void OpenSessionRequestDeepLinkAfterMessageFromSession(string sessionTopic)
@@ -180,13 +190,12 @@ public void Dispose()
180190

181191
protected virtual void Dispose(bool disposing)
182192
{
183-
if (disposed)
184-
return;
193+
if (disposed) return;
185194

186195
if (disposing)
187196
_walletConnect.SignClient.Core.Relayer.Publisher.OnPublishedMessage -= OnPublisherPublishedMessage;
188197

189198
disposed = true;
190199
}
191200
}
192-
}
201+
}

Assets/Thirdweb/Plugins/WalletConnectUnity/com.walletconnect.core/Runtime/Networking/UnityWebRequestExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ namespace WalletConnectUnity.Core.Networking
44
{
55
public static class UnityWebRequestExtensions
66
{
7-
public static string sdkType = "wcm";
8-
public static string sdkVersion = "unity-sdk-v1.0.0";
9-
107
public static UnityWebRequest SetWalletConnectRequestHeaders(this UnityWebRequest uwr)
118
{
129
var projectId = ProjectConfiguration.Load().Id;
1310

1411
uwr.SetRequestHeader("x-project-id", projectId);
15-
uwr.SetRequestHeader("x-sdk-type", sdkType);
16-
uwr.SetRequestHeader("x-sdk-version", sdkVersion);
12+
uwr.SetRequestHeader("x-sdk-type", SdkMetadata.Type);
13+
uwr.SetRequestHeader("x-sdk-version", SdkMetadata.Version);
1714

1815
return uwr;
1916
}

0 commit comments

Comments
 (0)