From 4f30b811aa7de7a1ad0ac114e511873e1edd0077 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Fri, 17 Oct 2025 03:32:09 +0700 Subject: [PATCH 1/3] Add featured and single wallet options to Reown integration Introduces support for 'featuredWalletIds' and 'singleWalletId' in ReownOptions, allowing more granular control over wallet selection in the Reown wallet integration. Updates the PlaygroundManager example to showcase these new options and adds an OAuthProvider enum for improved social login handling. Also updates Reown package dependencies to version 1.5.1. --- .../Examples/Scripts/PlaygroundManager.cs | 53 +++++++++++++++- .../Runtime/Unity/ThirdwebManagerBase.cs | 20 +++++- .../Unity/Wallets/Reown/ReownWallet.cs | 22 +++++-- Packages/manifest.json | 22 +++---- Packages/packages-lock.json | 62 +++++++++---------- 5 files changed, 127 insertions(+), 52 deletions(-) diff --git a/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs b/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs index 62edf4aa..eab5b3b6 100644 --- a/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs +++ b/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs @@ -8,6 +8,21 @@ namespace Thirdweb.Unity.Examples { + public enum OAuthProvider + { + Google, + Apple, + Facebook, + Discord, + Twitch, + Github, + Coinbase, + X, + TikTok, + Line, + Steam, + } + /// /// A simple manager to demonstrate core functionality of the thirdweb SDK. /// This is not production-ready code. Do not use this in production. @@ -20,6 +35,7 @@ public class PlaygroundManager : MonoBehaviour public ulong ChainId; public string Email; public string Phone; + public OAuthProvider Social = OAuthProvider.Google; public Transform ActionButtonParent; public GameObject ActionButtonPrefab; public GameObject LogPanel; @@ -130,7 +146,8 @@ private async void Wallet_Guest() private async void Wallet_Social() { - var walletOptions = new WalletOptions(provider: WalletProvider.InAppWallet, chainId: this.ChainId, new InAppWalletOptions(authprovider: AuthProvider.Github)); + var parsedOAuthProvider = (AuthProvider)System.Enum.Parse(typeof(AuthProvider), this.Social.ToString()); + var walletOptions = new WalletOptions(provider: WalletProvider.InAppWallet, chainId: this.ChainId, new InAppWalletOptions(authprovider: parsedOAuthProvider)); var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions); if (this.AlwaysUpgradeToSmartWallet) { @@ -181,7 +198,39 @@ private async void Wallet_External() var walletOptions = new WalletOptions( provider: WalletProvider.ReownWallet, chainId: this.ChainId, - reownOptions: new ReownOptions(projectId: null, name: null, description: null, url: null, iconUrl: null, includedWalletIds: null, excludedWalletIds: null) + reownOptions: new ReownOptions( + projectId: null, + name: null, + description: null, + url: null, + iconUrl: null, + includedWalletIds: null, + excludedWalletIds: null, + featuredWalletIds: new string[] + { + "c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96", + "18388be9ac2d02726dbac9777c96efaac06d744b2f6d580fccdd4127a6d01fd1", + "541d5dcd4ede02f3afaf75bf8e3e4c4f1fb09edb5fa6c4377ebf31c2785d9adf", + } + ) + ); + var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions); + if (this.AlwaysUpgradeToSmartWallet) + { + wallet = await ThirdwebManager.Instance.UpgradeToSmartWallet(wallet, chainId: this.ChainId, smartWalletOptions: new SmartWalletOptions(sponsorGas: true)); + } + var address = await wallet.GetAddress(); + this.LogPlayground($"[SIWE] Connected to wallet:\n{address}"); + } + +#pragma warning disable IDE0051 // Remove unused private members: This is a showcase of an alternative way to use Reown + private async void Wallet_External_Direct() +#pragma warning restore IDE0051 // Remove unused private members: This is a showcase of an alternative way to use Reown + { + var walletOptions = new WalletOptions( + provider: WalletProvider.ReownWallet, + chainId: this.ChainId, + reownOptions: new ReownOptions(singleWalletId: "c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96") ); var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions); if (this.AlwaysUpgradeToSmartWallet) diff --git a/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs b/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs index cda82db3..0edaad3d 100644 --- a/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs +++ b/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs @@ -175,6 +175,12 @@ public class ReownOptions [JsonProperty("excludedWalletIds")] public string[] ExcludedWalletIds; + [JsonProperty("featuredWalletIds")] + public string[] FeaturedWalletIds; + + [JsonProperty("singleWalletId")] + public string SingleWalletId; + public ReownOptions( string projectId = null, string name = null, @@ -182,9 +188,15 @@ public ReownOptions( string url = null, string iconUrl = null, string[] includedWalletIds = null, - string[] excludedWalletIds = null + string[] excludedWalletIds = null, + string[] featuredWalletIds = null, + string singleWalletId = null ) { + if (singleWalletId != null && (includedWalletIds != null || excludedWalletIds != null || featuredWalletIds != null)) + { + throw new ArgumentException("singleWalletId cannot be used with includedWalletIds, excludedWalletIds, or featuredWalletIds."); + } this.ProjectId = projectId ?? "35603765088f9ed24db818100fdbb6f9"; this.Name = name ?? "thirdweb"; this.Description = description ?? "thirdweb powered game"; @@ -192,6 +204,8 @@ public ReownOptions( this.IconUrl = iconUrl ?? "https://thirdweb.com/favicon.ico"; this.IncludedWalletIds = includedWalletIds; this.ExcludedWalletIds = excludedWalletIds; + this.FeaturedWalletIds = featuredWalletIds; + this.SingleWalletId = singleWalletId; } } @@ -429,7 +443,9 @@ public virtual async Task ConnectWallet(WalletOptions walletOpt url: walletOptions.ReownOptions.Url, iconUrl: walletOptions.ReownOptions.IconUrl, includedWalletIds: walletOptions.ReownOptions.IncludedWalletIds, - excludedWalletIds: walletOptions.ReownOptions.ExcludedWalletIds + excludedWalletIds: walletOptions.ReownOptions.ExcludedWalletIds, + featuredWalletIds: walletOptions.ReownOptions.FeaturedWalletIds, + singleWalletId: walletOptions.ReownOptions.SingleWalletId ); break; #else diff --git a/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs b/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs index 7600513f..69df9889 100644 --- a/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs +++ b/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs @@ -32,7 +32,9 @@ public static async Task Create( string url, string iconUrl, string[] includedWalletIds, - string[] excludedWalletIds + string[] excludedWalletIds, + string[] featuredWalletIds, + string singleWalletId ) { _client = client; @@ -54,8 +56,9 @@ string[] excludedWalletIds var appKitConfig = new AppKitConfig { projectId = projectId, - includedWalletIds = includedWalletIds, - excludedWalletIds = excludedWalletIds, + includedWalletIds = singleWalletId == null ? includedWalletIds : null, + excludedWalletIds = singleWalletId == null ? excludedWalletIds : null, + featuredWalletIds = singleWalletId == null ? featuredWalletIds : null, metadata = new Metadata(name: name, description: description, url: url, iconUrl: iconUrl, redirect: new RedirectData() { Native = ThirdwebManager.Instance.MobileRedirectScheme }), enableEmail = false, enableOnramp = false, @@ -81,7 +84,7 @@ string[] excludedWalletIds else { ThirdwebDebug.Log($"Awaiting Reown connection (timeout {connectionTimeout.TotalSeconds} seconds)..."); - connected = await WaitForInteractiveConnectionAsync(connectionTimeout); + connected = await WaitForInteractiveConnectionAsync(connectionTimeout, singleWalletId); } if (!connected) @@ -268,7 +271,7 @@ private static async Task TryResumeExistingSessionAsync() } } - private static async Task WaitForInteractiveConnectionAsync(TimeSpan timeout) + private static async Task WaitForInteractiveConnectionAsync(TimeSpan timeout, string singleWalletId = null) { if (AppKit.ConnectorController.IsAccountConnected) { @@ -295,7 +298,14 @@ void OnAccountConnected(object sender, AccountConnectedEventArgs args) if (!AppKit.ConnectorController.IsAccountConnected) { - AppKit.OpenModal(); + if (singleWalletId != null) + { + await AppKit.ConnectAsync(singleWalletId); + } + else + { + AppKit.OpenModal(); + } } var timeoutMilliseconds = (int)Math.Max(0, timeout.TotalMilliseconds); diff --git a/Packages/manifest.json b/Packages/manifest.json index aee558c3..37bd8694 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,17 +1,17 @@ { "dependencies": { "com.nethereum.unity": "5.0.0", - "com.reown.appkit.unity": "1.5.0", - "com.reown.core": "1.5.0", - "com.reown.core.common": "1.5.0", - "com.reown.core.crypto": "1.5.0", - "com.reown.core.network": "1.5.0", - "com.reown.core.storage": "1.5.0", - "com.reown.sign": "1.5.0", - "com.reown.sign.nethereum": "1.5.0", - "com.reown.sign.nethereum.unity": "1.5.0", - "com.reown.sign.unity": "1.5.0", - "com.reown.unity.dependencies": "1.5.0", + "com.reown.appkit.unity": "1.5.1", + "com.reown.core": "1.5.1", + "com.reown.core.common": "1.5.1", + "com.reown.core.crypto": "1.5.1", + "com.reown.core.network": "1.5.1", + "com.reown.core.storage": "1.5.1", + "com.reown.sign": "1.5.1", + "com.reown.sign.nethereum": "1.5.1", + "com.reown.sign.nethereum.unity": "1.5.1", + "com.reown.sign.unity": "1.5.1", + "com.reown.unity.dependencies": "1.5.1", "com.unity.ide.rider": "3.0.36", "com.unity.ide.visualstudio": "2.0.23", "com.unity.mobile.android-logcat": "1.4.5", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 0231c456..91bc3c6d 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -8,33 +8,33 @@ "url": "https://package.openupm.com" }, "com.reown.appkit.unity": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.sign.nethereum.unity": "1.5.0", - "com.reown.sign.unity": "1.5.0", - "com.reown.core": "1.5.0", - "com.reown.unity.dependencies": "1.5.0", + "com.reown.sign.nethereum.unity": "1.5.1", + "com.reown.sign.unity": "1.5.1", + "com.reown.core": "1.5.1", + "com.reown.unity.dependencies": "1.5.1", "com.unity.vectorgraphics": "2.0.0-preview.24" }, "url": "https://package.openupm.com" }, "com.reown.core": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.core.common": "1.5.0", - "com.reown.core.network": "1.5.0", - "com.reown.core.storage": "1.5.0", - "com.reown.core.crypto": "1.5.0", - "com.reown.unity.dependencies": "1.5.0" + "com.reown.core.common": "1.5.1", + "com.reown.core.network": "1.5.1", + "com.reown.core.storage": "1.5.1", + "com.reown.core.crypto": "1.5.1", + "com.reown.unity.dependencies": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.core.common": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { @@ -43,76 +43,76 @@ "url": "https://package.openupm.com" }, "com.reown.core.crypto": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.core.common": "1.5.0", - "com.reown.core.network": "1.5.0", - "com.reown.core.storage": "1.5.0", - "com.reown.unity.dependencies": "1.5.0" + "com.reown.core.common": "1.5.1", + "com.reown.core.network": "1.5.1", + "com.reown.core.storage": "1.5.1", + "com.reown.unity.dependencies": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.core.network": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.core.common": "1.5.0" + "com.reown.core.common": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.core.storage": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.core.common": "1.5.0" + "com.reown.core.common": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.sign": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.core": "1.5.0" + "com.reown.core": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.sign.nethereum": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.sign": "1.5.0", + "com.reown.sign": "1.5.1", "com.nethereum.unity": "5.0.0" }, "url": "https://package.openupm.com" }, "com.reown.sign.nethereum.unity": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { - "com.reown.sign.nethereum": "1.5.0", - "com.reown.sign.unity": "1.5.0" + "com.reown.sign.nethereum": "1.5.1", + "com.reown.sign.unity": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.sign.unity": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { "com.unity.modules.androidjni": "1.0.0", - "com.reown.sign": "1.5.0" + "com.reown.sign": "1.5.1" }, "url": "https://package.openupm.com" }, "com.reown.unity.dependencies": { - "version": "1.5.0", + "version": "1.5.1", "depth": 0, "source": "registry", "dependencies": { From 03e5b6739f745df5946abda6acaf6e3d71eb22ed Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Fri, 17 Oct 2025 04:35:38 +0700 Subject: [PATCH 2/3] Handle invalid social auth provider gracefully Replaces Enum.Parse with Enum.TryParse for social auth provider selection. Defaults to Google provider if parsing fails, preventing potential runtime errors. --- Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs b/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs index eab5b3b6..08009671 100644 --- a/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs +++ b/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs @@ -146,7 +146,10 @@ private async void Wallet_Guest() private async void Wallet_Social() { - var parsedOAuthProvider = (AuthProvider)System.Enum.Parse(typeof(AuthProvider), this.Social.ToString()); + if (!System.Enum.TryParse(this.Social.ToString(), out var parsedOAuthProvider)) + { + parsedOAuthProvider = AuthProvider.Google; + } var walletOptions = new WalletOptions(provider: WalletProvider.InAppWallet, chainId: this.ChainId, new InAppWalletOptions(authprovider: parsedOAuthProvider)); var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions); if (this.AlwaysUpgradeToSmartWallet) From 28ce01b03267ef77b702ab1f6ceba9e9d8766c3f Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Wed, 22 Oct 2025 19:21:10 +0700 Subject: [PATCH 3/3] Add tryResumeSession option to Reown wallet flow Introduces a tryResumeSession boolean to ReownOptions and propagates it through the wallet initialization flow. This allows control over whether to attempt resuming an existing session when initializing the Reown wallet. --- Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs | 10 ++++++++-- .../Runtime/Unity/Wallets/Reown/ReownWallet.cs | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs b/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs index 0edaad3d..0a36a872 100644 --- a/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs +++ b/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs @@ -181,6 +181,9 @@ public class ReownOptions [JsonProperty("singleWalletId")] public string SingleWalletId; + [JsonProperty("tryResumeSession")] + public bool TryResumeSession; + public ReownOptions( string projectId = null, string name = null, @@ -190,7 +193,8 @@ public ReownOptions( string[] includedWalletIds = null, string[] excludedWalletIds = null, string[] featuredWalletIds = null, - string singleWalletId = null + string singleWalletId = null, + bool tryResumeSession = true ) { if (singleWalletId != null && (includedWalletIds != null || excludedWalletIds != null || featuredWalletIds != null)) @@ -206,6 +210,7 @@ public ReownOptions( this.ExcludedWalletIds = excludedWalletIds; this.FeaturedWalletIds = featuredWalletIds; this.SingleWalletId = singleWalletId; + this.TryResumeSession = tryResumeSession; } } @@ -445,7 +450,8 @@ public virtual async Task ConnectWallet(WalletOptions walletOpt includedWalletIds: walletOptions.ReownOptions.IncludedWalletIds, excludedWalletIds: walletOptions.ReownOptions.ExcludedWalletIds, featuredWalletIds: walletOptions.ReownOptions.FeaturedWalletIds, - singleWalletId: walletOptions.ReownOptions.SingleWalletId + singleWalletId: walletOptions.ReownOptions.SingleWalletId, + tryResumeSession: walletOptions.ReownOptions.TryResumeSession ); break; #else diff --git a/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs b/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs index 69df9889..87696e85 100644 --- a/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs +++ b/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs @@ -34,7 +34,8 @@ public static async Task Create( string[] includedWalletIds, string[] excludedWalletIds, string[] featuredWalletIds, - string singleWalletId + string singleWalletId, + bool tryResumeSession ) { _client = client; @@ -75,7 +76,7 @@ string singleWalletId ThirdwebDebug.Log("Reown AppKit initialized."); var connectionTimeout = TimeSpan.FromSeconds(120); - var connected = await TryResumeExistingSessionAsync(); + var connected = tryResumeSession && await TryResumeExistingSessionAsync(); if (connected) {