diff --git a/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs b/Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs index 62edf4aa..08009671 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,11 @@ 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)); + 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) { @@ -181,7 +201,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..0a36a872 100644 --- a/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs +++ b/Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs @@ -175,6 +175,15 @@ public class ReownOptions [JsonProperty("excludedWalletIds")] public string[] ExcludedWalletIds; + [JsonProperty("featuredWalletIds")] + public string[] FeaturedWalletIds; + + [JsonProperty("singleWalletId")] + public string SingleWalletId; + + [JsonProperty("tryResumeSession")] + public bool TryResumeSession; + public ReownOptions( string projectId = null, string name = null, @@ -182,9 +191,16 @@ public ReownOptions( string url = null, string iconUrl = null, string[] includedWalletIds = null, - string[] excludedWalletIds = null + string[] excludedWalletIds = null, + string[] featuredWalletIds = null, + string singleWalletId = null, + bool tryResumeSession = true ) { + 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 +208,9 @@ public ReownOptions( this.IconUrl = iconUrl ?? "https://thirdweb.com/favicon.ico"; this.IncludedWalletIds = includedWalletIds; this.ExcludedWalletIds = excludedWalletIds; + this.FeaturedWalletIds = featuredWalletIds; + this.SingleWalletId = singleWalletId; + this.TryResumeSession = tryResumeSession; } } @@ -429,7 +448,10 @@ 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, + 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 7600513f..87696e85 100644 --- a/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs +++ b/Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs @@ -32,7 +32,10 @@ public static async Task Create( string url, string iconUrl, string[] includedWalletIds, - string[] excludedWalletIds + string[] excludedWalletIds, + string[] featuredWalletIds, + string singleWalletId, + bool tryResumeSession ) { _client = client; @@ -54,8 +57,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, @@ -72,7 +76,7 @@ string[] excludedWalletIds ThirdwebDebug.Log("Reown AppKit initialized."); var connectionTimeout = TimeSpan.FromSeconds(120); - var connected = await TryResumeExistingSessionAsync(); + var connected = tryResumeSession && await TryResumeExistingSessionAsync(); if (connected) { @@ -81,7 +85,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 +272,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 +299,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": {