Skip to content

Commit 30fef7a

Browse files
authored
Add featured and single wallet options to Reown integration (#244)
1 parent 156a566 commit 30fef7a

File tree

5 files changed

+138
-53
lines changed

5 files changed

+138
-53
lines changed

Assets/Thirdweb/Examples/Scripts/PlaygroundManager.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@
88

99
namespace Thirdweb.Unity.Examples
1010
{
11+
public enum OAuthProvider
12+
{
13+
Google,
14+
Apple,
15+
Facebook,
16+
Discord,
17+
Twitch,
18+
Github,
19+
Coinbase,
20+
X,
21+
TikTok,
22+
Line,
23+
Steam,
24+
}
25+
1126
/// <summary>
1227
/// A simple manager to demonstrate core functionality of the thirdweb SDK.
1328
/// This is not production-ready code. Do not use this in production.
@@ -20,6 +35,7 @@ public class PlaygroundManager : MonoBehaviour
2035
public ulong ChainId;
2136
public string Email;
2237
public string Phone;
38+
public OAuthProvider Social = OAuthProvider.Google;
2339
public Transform ActionButtonParent;
2440
public GameObject ActionButtonPrefab;
2541
public GameObject LogPanel;
@@ -130,7 +146,11 @@ private async void Wallet_Guest()
130146

131147
private async void Wallet_Social()
132148
{
133-
var walletOptions = new WalletOptions(provider: WalletProvider.InAppWallet, chainId: this.ChainId, new InAppWalletOptions(authprovider: AuthProvider.Github));
149+
if (!System.Enum.TryParse<AuthProvider>(this.Social.ToString(), out var parsedOAuthProvider))
150+
{
151+
parsedOAuthProvider = AuthProvider.Google;
152+
}
153+
var walletOptions = new WalletOptions(provider: WalletProvider.InAppWallet, chainId: this.ChainId, new InAppWalletOptions(authprovider: parsedOAuthProvider));
134154
var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions);
135155
if (this.AlwaysUpgradeToSmartWallet)
136156
{
@@ -181,7 +201,39 @@ private async void Wallet_External()
181201
var walletOptions = new WalletOptions(
182202
provider: WalletProvider.ReownWallet,
183203
chainId: this.ChainId,
184-
reownOptions: new ReownOptions(projectId: null, name: null, description: null, url: null, iconUrl: null, includedWalletIds: null, excludedWalletIds: null)
204+
reownOptions: new ReownOptions(
205+
projectId: null,
206+
name: null,
207+
description: null,
208+
url: null,
209+
iconUrl: null,
210+
includedWalletIds: null,
211+
excludedWalletIds: null,
212+
featuredWalletIds: new string[]
213+
{
214+
"c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96",
215+
"18388be9ac2d02726dbac9777c96efaac06d744b2f6d580fccdd4127a6d01fd1",
216+
"541d5dcd4ede02f3afaf75bf8e3e4c4f1fb09edb5fa6c4377ebf31c2785d9adf",
217+
}
218+
)
219+
);
220+
var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions);
221+
if (this.AlwaysUpgradeToSmartWallet)
222+
{
223+
wallet = await ThirdwebManager.Instance.UpgradeToSmartWallet(wallet, chainId: this.ChainId, smartWalletOptions: new SmartWalletOptions(sponsorGas: true));
224+
}
225+
var address = await wallet.GetAddress();
226+
this.LogPlayground($"[SIWE] Connected to wallet:\n{address}");
227+
}
228+
229+
#pragma warning disable IDE0051 // Remove unused private members: This is a showcase of an alternative way to use Reown
230+
private async void Wallet_External_Direct()
231+
#pragma warning restore IDE0051 // Remove unused private members: This is a showcase of an alternative way to use Reown
232+
{
233+
var walletOptions = new WalletOptions(
234+
provider: WalletProvider.ReownWallet,
235+
chainId: this.ChainId,
236+
reownOptions: new ReownOptions(singleWalletId: "c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96")
185237
);
186238
var wallet = await ThirdwebManager.Instance.ConnectWallet(walletOptions);
187239
if (this.AlwaysUpgradeToSmartWallet)

Assets/Thirdweb/Runtime/Unity/ThirdwebManagerBase.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,42 @@ public class ReownOptions
175175
[JsonProperty("excludedWalletIds")]
176176
public string[] ExcludedWalletIds;
177177

178+
[JsonProperty("featuredWalletIds")]
179+
public string[] FeaturedWalletIds;
180+
181+
[JsonProperty("singleWalletId")]
182+
public string SingleWalletId;
183+
184+
[JsonProperty("tryResumeSession")]
185+
public bool TryResumeSession;
186+
178187
public ReownOptions(
179188
string projectId = null,
180189
string name = null,
181190
string description = null,
182191
string url = null,
183192
string iconUrl = null,
184193
string[] includedWalletIds = null,
185-
string[] excludedWalletIds = null
194+
string[] excludedWalletIds = null,
195+
string[] featuredWalletIds = null,
196+
string singleWalletId = null,
197+
bool tryResumeSession = true
186198
)
187199
{
200+
if (singleWalletId != null && (includedWalletIds != null || excludedWalletIds != null || featuredWalletIds != null))
201+
{
202+
throw new ArgumentException("singleWalletId cannot be used with includedWalletIds, excludedWalletIds, or featuredWalletIds.");
203+
}
188204
this.ProjectId = projectId ?? "35603765088f9ed24db818100fdbb6f9";
189205
this.Name = name ?? "thirdweb";
190206
this.Description = description ?? "thirdweb powered game";
191207
this.Url = url ?? "https://thirdweb.com";
192208
this.IconUrl = iconUrl ?? "https://thirdweb.com/favicon.ico";
193209
this.IncludedWalletIds = includedWalletIds;
194210
this.ExcludedWalletIds = excludedWalletIds;
211+
this.FeaturedWalletIds = featuredWalletIds;
212+
this.SingleWalletId = singleWalletId;
213+
this.TryResumeSession = tryResumeSession;
195214
}
196215
}
197216

@@ -429,7 +448,10 @@ public virtual async Task<IThirdwebWallet> ConnectWallet(WalletOptions walletOpt
429448
url: walletOptions.ReownOptions.Url,
430449
iconUrl: walletOptions.ReownOptions.IconUrl,
431450
includedWalletIds: walletOptions.ReownOptions.IncludedWalletIds,
432-
excludedWalletIds: walletOptions.ReownOptions.ExcludedWalletIds
451+
excludedWalletIds: walletOptions.ReownOptions.ExcludedWalletIds,
452+
featuredWalletIds: walletOptions.ReownOptions.FeaturedWalletIds,
453+
singleWalletId: walletOptions.ReownOptions.SingleWalletId,
454+
tryResumeSession: walletOptions.ReownOptions.TryResumeSession
433455
);
434456
break;
435457
#else

Assets/Thirdweb/Runtime/Unity/Wallets/Reown/ReownWallet.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public static async Task<ReownWallet> Create(
3232
string url,
3333
string iconUrl,
3434
string[] includedWalletIds,
35-
string[] excludedWalletIds
35+
string[] excludedWalletIds,
36+
string[] featuredWalletIds,
37+
string singleWalletId,
38+
bool tryResumeSession
3639
)
3740
{
3841
_client = client;
@@ -54,8 +57,9 @@ string[] excludedWalletIds
5457
var appKitConfig = new AppKitConfig
5558
{
5659
projectId = projectId,
57-
includedWalletIds = includedWalletIds,
58-
excludedWalletIds = excludedWalletIds,
60+
includedWalletIds = singleWalletId == null ? includedWalletIds : null,
61+
excludedWalletIds = singleWalletId == null ? excludedWalletIds : null,
62+
featuredWalletIds = singleWalletId == null ? featuredWalletIds : null,
5963
metadata = new Metadata(name: name, description: description, url: url, iconUrl: iconUrl, redirect: new RedirectData() { Native = ThirdwebManager.Instance.MobileRedirectScheme }),
6064
enableEmail = false,
6165
enableOnramp = false,
@@ -72,7 +76,7 @@ string[] excludedWalletIds
7276
ThirdwebDebug.Log("Reown AppKit initialized.");
7377

7478
var connectionTimeout = TimeSpan.FromSeconds(120);
75-
var connected = await TryResumeExistingSessionAsync();
79+
var connected = tryResumeSession && await TryResumeExistingSessionAsync();
7680

7781
if (connected)
7882
{
@@ -81,7 +85,7 @@ string[] excludedWalletIds
8185
else
8286
{
8387
ThirdwebDebug.Log($"Awaiting Reown connection (timeout {connectionTimeout.TotalSeconds} seconds)...");
84-
connected = await WaitForInteractiveConnectionAsync(connectionTimeout);
88+
connected = await WaitForInteractiveConnectionAsync(connectionTimeout, singleWalletId);
8589
}
8690

8791
if (!connected)
@@ -268,7 +272,7 @@ private static async Task<bool> TryResumeExistingSessionAsync()
268272
}
269273
}
270274

271-
private static async Task<bool> WaitForInteractiveConnectionAsync(TimeSpan timeout)
275+
private static async Task<bool> WaitForInteractiveConnectionAsync(TimeSpan timeout, string singleWalletId = null)
272276
{
273277
if (AppKit.ConnectorController.IsAccountConnected)
274278
{
@@ -295,7 +299,14 @@ void OnAccountConnected(object sender, AccountConnectedEventArgs args)
295299

296300
if (!AppKit.ConnectorController.IsAccountConnected)
297301
{
298-
AppKit.OpenModal();
302+
if (singleWalletId != null)
303+
{
304+
await AppKit.ConnectAsync(singleWalletId);
305+
}
306+
else
307+
{
308+
AppKit.OpenModal();
309+
}
299310
}
300311

301312
var timeoutMilliseconds = (int)Math.Max(0, timeout.TotalMilliseconds);

Packages/manifest.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"dependencies": {
33
"com.nethereum.unity": "5.0.0",
4-
"com.reown.appkit.unity": "1.5.0",
5-
"com.reown.core": "1.5.0",
6-
"com.reown.core.common": "1.5.0",
7-
"com.reown.core.crypto": "1.5.0",
8-
"com.reown.core.network": "1.5.0",
9-
"com.reown.core.storage": "1.5.0",
10-
"com.reown.sign": "1.5.0",
11-
"com.reown.sign.nethereum": "1.5.0",
12-
"com.reown.sign.nethereum.unity": "1.5.0",
13-
"com.reown.sign.unity": "1.5.0",
14-
"com.reown.unity.dependencies": "1.5.0",
4+
"com.reown.appkit.unity": "1.5.1",
5+
"com.reown.core": "1.5.1",
6+
"com.reown.core.common": "1.5.1",
7+
"com.reown.core.crypto": "1.5.1",
8+
"com.reown.core.network": "1.5.1",
9+
"com.reown.core.storage": "1.5.1",
10+
"com.reown.sign": "1.5.1",
11+
"com.reown.sign.nethereum": "1.5.1",
12+
"com.reown.sign.nethereum.unity": "1.5.1",
13+
"com.reown.sign.unity": "1.5.1",
14+
"com.reown.unity.dependencies": "1.5.1",
1515
"com.unity.ide.rider": "3.0.36",
1616
"com.unity.ide.visualstudio": "2.0.23",
1717
"com.unity.mobile.android-logcat": "1.4.5",

Packages/packages-lock.json

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@
88
"url": "https://package.openupm.com"
99
},
1010
"com.reown.appkit.unity": {
11-
"version": "1.5.0",
11+
"version": "1.5.1",
1212
"depth": 0,
1313
"source": "registry",
1414
"dependencies": {
15-
"com.reown.sign.nethereum.unity": "1.5.0",
16-
"com.reown.sign.unity": "1.5.0",
17-
"com.reown.core": "1.5.0",
18-
"com.reown.unity.dependencies": "1.5.0",
15+
"com.reown.sign.nethereum.unity": "1.5.1",
16+
"com.reown.sign.unity": "1.5.1",
17+
"com.reown.core": "1.5.1",
18+
"com.reown.unity.dependencies": "1.5.1",
1919
"com.unity.vectorgraphics": "2.0.0-preview.24"
2020
},
2121
"url": "https://package.openupm.com"
2222
},
2323
"com.reown.core": {
24-
"version": "1.5.0",
24+
"version": "1.5.1",
2525
"depth": 0,
2626
"source": "registry",
2727
"dependencies": {
28-
"com.reown.core.common": "1.5.0",
29-
"com.reown.core.network": "1.5.0",
30-
"com.reown.core.storage": "1.5.0",
31-
"com.reown.core.crypto": "1.5.0",
32-
"com.reown.unity.dependencies": "1.5.0"
28+
"com.reown.core.common": "1.5.1",
29+
"com.reown.core.network": "1.5.1",
30+
"com.reown.core.storage": "1.5.1",
31+
"com.reown.core.crypto": "1.5.1",
32+
"com.reown.unity.dependencies": "1.5.1"
3333
},
3434
"url": "https://package.openupm.com"
3535
},
3636
"com.reown.core.common": {
37-
"version": "1.5.0",
37+
"version": "1.5.1",
3838
"depth": 0,
3939
"source": "registry",
4040
"dependencies": {
@@ -43,76 +43,76 @@
4343
"url": "https://package.openupm.com"
4444
},
4545
"com.reown.core.crypto": {
46-
"version": "1.5.0",
46+
"version": "1.5.1",
4747
"depth": 0,
4848
"source": "registry",
4949
"dependencies": {
50-
"com.reown.core.common": "1.5.0",
51-
"com.reown.core.network": "1.5.0",
52-
"com.reown.core.storage": "1.5.0",
53-
"com.reown.unity.dependencies": "1.5.0"
50+
"com.reown.core.common": "1.5.1",
51+
"com.reown.core.network": "1.5.1",
52+
"com.reown.core.storage": "1.5.1",
53+
"com.reown.unity.dependencies": "1.5.1"
5454
},
5555
"url": "https://package.openupm.com"
5656
},
5757
"com.reown.core.network": {
58-
"version": "1.5.0",
58+
"version": "1.5.1",
5959
"depth": 0,
6060
"source": "registry",
6161
"dependencies": {
62-
"com.reown.core.common": "1.5.0"
62+
"com.reown.core.common": "1.5.1"
6363
},
6464
"url": "https://package.openupm.com"
6565
},
6666
"com.reown.core.storage": {
67-
"version": "1.5.0",
67+
"version": "1.5.1",
6868
"depth": 0,
6969
"source": "registry",
7070
"dependencies": {
71-
"com.reown.core.common": "1.5.0"
71+
"com.reown.core.common": "1.5.1"
7272
},
7373
"url": "https://package.openupm.com"
7474
},
7575
"com.reown.sign": {
76-
"version": "1.5.0",
76+
"version": "1.5.1",
7777
"depth": 0,
7878
"source": "registry",
7979
"dependencies": {
80-
"com.reown.core": "1.5.0"
80+
"com.reown.core": "1.5.1"
8181
},
8282
"url": "https://package.openupm.com"
8383
},
8484
"com.reown.sign.nethereum": {
85-
"version": "1.5.0",
85+
"version": "1.5.1",
8686
"depth": 0,
8787
"source": "registry",
8888
"dependencies": {
89-
"com.reown.sign": "1.5.0",
89+
"com.reown.sign": "1.5.1",
9090
"com.nethereum.unity": "5.0.0"
9191
},
9292
"url": "https://package.openupm.com"
9393
},
9494
"com.reown.sign.nethereum.unity": {
95-
"version": "1.5.0",
95+
"version": "1.5.1",
9696
"depth": 0,
9797
"source": "registry",
9898
"dependencies": {
99-
"com.reown.sign.nethereum": "1.5.0",
100-
"com.reown.sign.unity": "1.5.0"
99+
"com.reown.sign.nethereum": "1.5.1",
100+
"com.reown.sign.unity": "1.5.1"
101101
},
102102
"url": "https://package.openupm.com"
103103
},
104104
"com.reown.sign.unity": {
105-
"version": "1.5.0",
105+
"version": "1.5.1",
106106
"depth": 0,
107107
"source": "registry",
108108
"dependencies": {
109109
"com.unity.modules.androidjni": "1.0.0",
110-
"com.reown.sign": "1.5.0"
110+
"com.reown.sign": "1.5.1"
111111
},
112112
"url": "https://package.openupm.com"
113113
},
114114
"com.reown.unity.dependencies": {
115-
"version": "1.5.0",
115+
"version": "1.5.1",
116116
"depth": 0,
117117
"source": "registry",
118118
"dependencies": {

0 commit comments

Comments
 (0)