Skip to content

Commit b807cab

Browse files
authored
[WebGL] Expose additional WC QR Options (#160)
1 parent d3c0f8c commit b807cab

File tree

4 files changed

+32946
-31141
lines changed

4 files changed

+32946
-31141
lines changed

Assets/Thirdweb/Core/Scripts/ThirdwebManager.cs

Lines changed: 73 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,23 @@ public class ThirdwebManager : MonoBehaviour
9090
[Tooltip("WalletConnect Project ID (https://cloud.walletconnect.com/app)")]
9191
public string walletConnectProjectId = null;
9292

93-
[Tooltip("Wallets to show in the WalletConnect Modal (https://walletconnect.com/explorer)")]
94-
public string[] walletConnectExplorerRecommendedWalletIds = new string[] { };
93+
[Tooltip("WalletConnect WebGL QR Modal: enable recommended explorer wallet buttons")]
94+
public bool walletConnectEnableExplorer = false;
95+
96+
[Tooltip("WalletConnect WebGL QR Modal: wallets to display in the WC modal (https://walletconnect.com/explorer)")]
97+
public string[] walletConnectExplorerRecommendedWalletIds = null;
98+
99+
[Tooltip("WalletConnect WebGL QR Modal: mapping of wallet id to wallet image")]
100+
public List<StringPair> walletConnectWalletImages = null;
101+
102+
[Tooltip("WalletConnect WebGL QR Modal: custom desktop wallets to display.")]
103+
public ThirdwebSDK.WalletConnectWalletOptions[] walletConnectDesktopWallets;
104+
105+
[Tooltip("WalletConnect WebGL QR Modal: custom mobile wallets to display.")]
106+
public ThirdwebSDK.WalletConnectWalletOptions[] walletConnectMobileWallets;
107+
108+
[Tooltip("WalletConnect Theme Mode (light or dark)")]
109+
public string walletConnectThemeMode = null;
95110

96111
[Tooltip("Factory Contract Address")]
97112
public string factoryAddress;
@@ -224,60 +239,65 @@ public void Initialize(string chainIdentifier)
224239

225240
thirdwebConfig = Resources.Load<ThirdwebConfig>("ThirdwebConfig");
226241

242+
// Setup WalletConnect options
243+
244+
var wcImages = new Dictionary<string, string>();
245+
if (walletConnectWalletImages != null && walletConnectWalletImages.Count > 0)
246+
foreach (var pair in walletConnectWalletImages)
247+
wcImages.Add(pair.key, pair.value);
248+
249+
if (walletConnectDesktopWallets != null && walletConnectDesktopWallets.Length > 0)
250+
{
251+
for (int i = 0; i < walletConnectDesktopWallets.Length; i++)
252+
{
253+
if (walletConnectDesktopWallets[i].links == null)
254+
continue;
255+
256+
if (string.IsNullOrEmpty(walletConnectDesktopWallets[i].links.native) && string.IsNullOrEmpty(walletConnectDesktopWallets[i].links.universal))
257+
{
258+
walletConnectDesktopWallets[i].links = null;
259+
continue;
260+
}
261+
262+
walletConnectDesktopWallets[i].links.native = string.IsNullOrEmpty(walletConnectDesktopWallets[i].links.native) ? null : walletConnectDesktopWallets[i].links.native;
263+
walletConnectDesktopWallets[i].links.universal = string.IsNullOrEmpty(walletConnectDesktopWallets[i].links.universal) ? null : walletConnectDesktopWallets[i].links.universal;
264+
}
265+
}
266+
267+
if (walletConnectMobileWallets != null && walletConnectMobileWallets.Length > 0)
268+
{
269+
for (int i = 0; i < walletConnectMobileWallets.Length; i++)
270+
{
271+
if (walletConnectMobileWallets[i].links == null)
272+
continue;
273+
274+
if (string.IsNullOrEmpty(walletConnectMobileWallets[i].links.native) && string.IsNullOrEmpty(walletConnectMobileWallets[i].links.universal))
275+
{
276+
walletConnectMobileWallets[i].links = null;
277+
continue;
278+
}
279+
280+
walletConnectMobileWallets[i].links.native = string.IsNullOrEmpty(walletConnectMobileWallets[i].links.native) ? null : walletConnectMobileWallets[i].links.native;
281+
walletConnectMobileWallets[i].links.universal = string.IsNullOrEmpty(walletConnectMobileWallets[i].links.universal) ? null : walletConnectMobileWallets[i].links.universal;
282+
}
283+
}
284+
227285
options.wallet = new ThirdwebSDK.WalletOptions()
228286
{
229287
appName = string.IsNullOrEmpty(appName) ? "thirdweb powered dApp" : appName,
230288
appDescription = string.IsNullOrEmpty(appDescription) ? "thirdweb powered dApp" : appDescription,
231289
appIcons = (appIcons == null || appIcons.Length == 0 || string.IsNullOrEmpty(appIcons[0])) ? new string[] { "https://thirdweb.com/favicon.ico" } : appIcons,
232290
appUrl = string.IsNullOrEmpty(appUrl) ? "https://thirdweb.com" : appUrl,
233291
walletConnectProjectId = string.IsNullOrEmpty(walletConnectProjectId) ? "145769e410f16970a79ff77b2d89a1e0" : walletConnectProjectId,
292+
walletConnectEnableExplorer = walletConnectEnableExplorer,
234293
walletConnectExplorerRecommendedWalletIds =
235294
(walletConnectExplorerRecommendedWalletIds == null || walletConnectExplorerRecommendedWalletIds.Length == 0 || string.IsNullOrEmpty(walletConnectExplorerRecommendedWalletIds[0]))
236-
? new string[]
237-
{
238-
"c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96", // metamask
239-
"4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0", // trustwallet
240-
"225affb176778569276e484e1b92637ad061b01e13a048b35a9d280c3b58970f", // safe
241-
"1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369", // rainbow
242-
"a797aa35c0fadbfc1a53e7f675162ed5226968b44a19ee3d24385c64d1d3c393", // phantom
243-
"c03dfee351b6fcc421b4494ea33b9d4b92a984f87aa76d1663bb28705e95034a", // uniswap
244-
"ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18", // zerion
245-
"ef333840daf915aafdc4a004525502d6d49d77bd9c65e0642dbaefb3c2893bef", // imtoken
246-
"bc949c5d968ae81310268bf9193f9c9fb7bb4e1283e1284af8f2bd4992535fd6", // argent
247-
"74f8092562bd79675e276d8b2062a83601a4106d30202f2d509195e30e19673d", // spot
248-
"afbd95522f4041c71dd4f1a065f971fd32372865b416f95a0b1db759ae33f2a7", // omni
249-
"f2436c67184f158d1beda5df53298ee84abfc367581e4505134b5bcf5f46697d", // crypto.com
250-
"20459438007b75f4f4acb98bf29aa3b800550309646d375da5fd4aac6c2a2c66", // tokenpocket
251-
"8837dd9413b1d9b585ee937d27a816590248386d9dbf59f5cd3422dbbb65683e", // robinhood wallet
252-
"85db431492aa2e8672e93f4ea7acf10c88b97b867b0d373107af63dc4880f041", // frontier
253-
"84b43e8ddfcd18e5fcb5d21e7277733f9cccef76f7d92c836d0e481db0c70c04", // blockchain.com
254-
"0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150", // safepal
255-
"38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662", // bitkeep
256-
"9414d5a85c8f4eabc1b5b15ebe0cd399e1a2a9d35643ab0ad22a6e4a32f596f0", // zengo
257-
"c286eebc742a537cd1d6818363e9dc53b21759a1e8e5d9b263d0c03ec7703576", // 1inch
258-
"8a0ee50d1f22f6651afcae7eb4253e52a3310b90af5daef78a8c4929a9bb99d4", // binance defi wallet
259-
"e9ff15be73584489ca4a66f64d32c4537711797e30b6660dbcb71ea72a42b1f4", // exodus
260-
"19177a98252e07ddfc9af2083ba8e07ef627cb6103467ffebb3f8f4205fd7927", // ledger live
261-
"f5b4eeb6015d66be3f5940a895cbaa49ef3439e518cd771270e6b553b48f31d2", // mew wallet
262-
"138f51c8d00ac7b9ac9d8dc75344d096a7dfe370a568aa167eabc0a21830ed98", // alpha wallet
263-
"47bb07617af518642f3413a201ec5859faa63acb1dd175ca95085d35d38afb83", // keyring pro
264-
"76a3d548a08cf402f5c7d021f24fd2881d767084b387a5325df88bc3d4b6f21b", // lobstr wallet
265-
"dceb063851b1833cbb209e3717a0a0b06bf3fb500fe9db8cd3a553e4b1d02137", // onto
266-
"7674bb4e353bf52886768a3ddc2a4562ce2f4191c80831291218ebd90f5f5e26", // math wallet
267-
"8308656f4548bb81b3508afe355cfbb7f0cb6253d1cc7f998080601f838ecee3", // unstoppable domains
268-
"031f0187049b7f96c6f039d1c9c8138ff7a17fd75d38b34350c7182232cc29aa", // obvious
269-
"5864e2ced7c293ed18ac35e0db085c09ed567d67346ccb6f58a0327a75137489", // fireblocks
270-
"2c81da3add65899baeac53758a07e652eea46dbb5195b8074772c62a77bbf568", // ambire wallet
271-
"802a2041afdaf4c7e41a2903e98df333c8835897532699ad370f829390c6900f", // infinity wallet
272-
"7424d97904535b14fe34f09f63d8ca66935546f798758dabd5b26c2309f2b1f9", // bridge wallet
273-
"dd43441a6368ec9046540c46c5fdc58f79926d17ce61a176444568ca7c970dcd", // internet money wallet
274-
"c482dfe368d4f004479977fd88e80dc9e81107f3245d706811581a6dfe69c534", // now wallet
275-
"107bb20463699c4e614d3a2fb7b961e66f48774cb8f6d6c1aee789853280972c", // bitcoin.com wallet
276-
"053ac0ac602e0969736941cf5aa07a3af57396d4601cb521a173a626e1015fb1", // au wallet
277-
"2a3c89040ac3b723a1972a33a125b1db11e258a6975d3a61252cd64e6ea5ea01", // coin98 super app
278-
"b956da9052132e3dabdcd78feb596d5194c99b7345d8c4bd7a47cabdcb69a25f", // abc wallet
279-
}
295+
? null
280296
: walletConnectExplorerRecommendedWalletIds,
297+
walletConnectWalletImages = wcImages == null || wcImages.Count == 0 ? null : wcImages,
298+
walletConnectDesktopWallets = (walletConnectDesktopWallets == null || walletConnectDesktopWallets.Length == 0) ? null : walletConnectDesktopWallets,
299+
walletConnectMobileWallets = (walletConnectMobileWallets == null || walletConnectMobileWallets.Length == 0) ? null : walletConnectMobileWallets,
300+
walletConnectThemeMode = (string.IsNullOrEmpty(walletConnectThemeMode) || (walletConnectThemeMode != "light" && walletConnectThemeMode != "dark")) ? null : walletConnectThemeMode,
281301
customScheme = string.IsNullOrEmpty(thirdwebConfig.customScheme) ? null : thirdwebConfig.customScheme,
282302
};
283303

@@ -303,5 +323,12 @@ public void Initialize(string activeChainRpc, BigInteger activeChainId, Thirdweb
303323
{
304324
SDK = new ThirdwebSDK(activeChainRpc, activeChainId, options);
305325
}
326+
327+
[System.Serializable]
328+
public struct StringPair
329+
{
330+
public string key;
331+
public string value;
332+
}
306333
}
307334
}

Assets/Thirdweb/Core/Scripts/ThirdwebSDK.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,40 @@ public struct WalletOptions
7676
public string[] appIcons;
7777

7878
/// <summary>
79-
/// The project ID for WalletConnect authentication.
79+
/// WalletConnect Project ID (https://cloud.walletconnect.com/app).
8080
/// </summary>
8181
public string walletConnectProjectId;
8282

8383
/// <summary>
84-
/// Wallets to display in the WC modal (https://walletconnect.com/explorer)
84+
/// WalletConnect WebGL QR Modal: enable recommended explorer wallet buttons.
85+
/// </summary>
86+
public bool walletConnectEnableExplorer;
87+
88+
/// <summary>
89+
/// WalletConnect WebGL QR Modal: wallets to display in the WC modal (https://walletconnect.com/explorer).
8590
/// </summary>
8691
public string[] walletConnectExplorerRecommendedWalletIds;
8792

93+
/// <summary>
94+
/// WalletConnect WebGL QR Modal: mapping of wallet id to wallet image.
95+
/// </summary>
96+
public Dictionary<string, string> walletConnectWalletImages;
97+
98+
/// <summary>
99+
/// WalletConnect WebGL QR Modal: custom desktop wallets to display.
100+
/// </summary>
101+
public WalletConnectWalletOptions[] walletConnectDesktopWallets;
102+
103+
/// <summary>
104+
/// WalletConnect WebGL QR Modal: custom mobile wallets to display.
105+
/// </summary>
106+
public WalletConnectWalletOptions[] walletConnectMobileWallets;
107+
108+
/// <summary>
109+
/// WalletConnect WebGL QR Modal: set theme to 'light' or 'dark'.
110+
/// </summary>
111+
public string walletConnectThemeMode;
112+
88113
/// <summary>
89114
/// When using OAuth2 (e.g. Google) to login on mobile, you can provide a redirect URL such as 'myapp://'.
90115
/// </summary>
@@ -96,6 +121,24 @@ public struct WalletOptions
96121
public Dictionary<string, object> extras;
97122
}
98123

124+
/// <summary>
125+
/// Optional wallet configuration options for WalletConnect wallets, useful for displaying specific wallets only.
126+
/// </summary>
127+
[System.Serializable]
128+
public struct WalletConnectWalletOptions
129+
{
130+
public string id;
131+
public string name;
132+
public WalletConnectWalletLinks links;
133+
}
134+
135+
[System.Serializable]
136+
public class WalletConnectWalletLinks
137+
{
138+
public string native;
139+
public string universal;
140+
}
141+
99142
/// <summary>
100143
/// Smart wallet configuration options.
101144
/// </summary>

Assets/Thirdweb/Editor/ThirdwebManagerEditor.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public class ThirdwebManagerEditor : Editor
2424
private SerializedProperty forwarderDomainOverrideProperty;
2525
private SerializedProperty forwaderVersionOverrideProperty;
2626
private SerializedProperty walletConnectProjectIdProperty;
27+
private SerializedProperty walletConnectEnableExplorerProperty;
2728
private SerializedProperty walletConnectExplorerRecommendedWalletIdsProperty;
29+
private SerializedProperty walletConnectWalletImagesProperty;
30+
private SerializedProperty walletConnectDesktopWalletsProperty;
31+
private SerializedProperty walletConnectMobileWalletsProperty;
32+
private SerializedProperty walletConnectThemeModeProperty;
2833
private SerializedProperty factoryAddressProperty;
2934
private SerializedProperty gaslessProperty;
3035
private SerializedProperty erc20PaymasterAddressProperty;
@@ -66,7 +71,12 @@ private void OnEnable()
6671
forwarderDomainOverrideProperty = serializedObject.FindProperty("forwarderDomainOverride");
6772
forwaderVersionOverrideProperty = serializedObject.FindProperty("forwaderVersionOverride");
6873
walletConnectProjectIdProperty = serializedObject.FindProperty("walletConnectProjectId");
74+
walletConnectEnableExplorerProperty = serializedObject.FindProperty("walletConnectEnableExplorer");
6975
walletConnectExplorerRecommendedWalletIdsProperty = serializedObject.FindProperty("walletConnectExplorerRecommendedWalletIds");
76+
walletConnectWalletImagesProperty = serializedObject.FindProperty("walletConnectWalletImages");
77+
walletConnectDesktopWalletsProperty = serializedObject.FindProperty("walletConnectDesktopWallets");
78+
walletConnectMobileWalletsProperty = serializedObject.FindProperty("walletConnectMobileWallets");
79+
walletConnectThemeModeProperty = serializedObject.FindProperty("walletConnectThemeMode");
7080
factoryAddressProperty = serializedObject.FindProperty("factoryAddress");
7181
gaslessProperty = serializedObject.FindProperty("gasless");
7282
erc20PaymasterAddressProperty = serializedObject.FindProperty("erc20PaymasterAddress");
@@ -282,7 +292,12 @@ public override void OnInspectorGUI()
282292
{
283293
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
284294
EditorGUILayout.PropertyField(walletConnectProjectIdProperty);
295+
EditorGUILayout.PropertyField(walletConnectEnableExplorerProperty);
285296
EditorGUILayout.PropertyField(walletConnectExplorerRecommendedWalletIdsProperty);
297+
EditorGUILayout.PropertyField(walletConnectWalletImagesProperty, true);
298+
EditorGUILayout.PropertyField(walletConnectDesktopWalletsProperty, true);
299+
EditorGUILayout.PropertyField(walletConnectMobileWalletsProperty, true);
300+
EditorGUILayout.PropertyField(walletConnectThemeModeProperty);
286301
EditorGUILayout.EndVertical();
287302
}
288303
);

0 commit comments

Comments
 (0)