Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

namespace Thirdweb.Unity.Examples
{
public enum OAuthProvider
{
Google,
Apple,
Facebook,
Discord,
Twitch,
Github,
Coinbase,
X,
TikTok,
Line,
Steam,
}

/// <summary>
/// A simple manager to demonstrate core functionality of the thirdweb SDK.
/// This is not production-ready code. Do not use this in production.
Expand All @@ -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;
Expand Down Expand Up @@ -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<AuthProvider>(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)
{
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 24 additions & 2 deletions Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,42 @@ 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,
string description = null,
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";
this.Url = url ?? "https://thirdweb.com";
this.IconUrl = iconUrl ?? "https://thirdweb.com/favicon.ico";
this.IncludedWalletIds = includedWalletIds;
this.ExcludedWalletIds = excludedWalletIds;
this.FeaturedWalletIds = featuredWalletIds;
this.SingleWalletId = singleWalletId;
this.TryResumeSession = tryResumeSession;
}
}

Expand Down Expand Up @@ -429,7 +448,10 @@ public virtual async Task<IThirdwebWallet> 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
Expand Down
25 changes: 18 additions & 7 deletions Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public static async Task<ReownWallet> Create(
string url,
string iconUrl,
string[] includedWalletIds,
string[] excludedWalletIds
string[] excludedWalletIds,
string[] featuredWalletIds,
string singleWalletId,
bool tryResumeSession
)
{
_client = client;
Expand All @@ -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,
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -268,7 +272,7 @@ private static async Task<bool> TryResumeExistingSessionAsync()
}
}

private static async Task<bool> WaitForInteractiveConnectionAsync(TimeSpan timeout)
private static async Task<bool> WaitForInteractiveConnectionAsync(TimeSpan timeout, string singleWalletId = null)
{
if (AppKit.ConnectorController.IsAccountConnected)
{
Expand All @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
62 changes: 31 additions & 31 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down