Skip to content

Commit 547adb0

Browse files
authored
Allow overriding bundleId (#117)
1 parent 026a7de commit 547adb0

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

Assets/Thirdweb/Core/Scripts/ThirdwebManager.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ThirdwebManager : MonoBehaviour
4646
new ChainData("sepolia", "11155111", null),
4747
};
4848

49-
[Tooltip("Thirdweb Client ID (https://thirdweb.com/create-api-key/). Used for default thirdweb services such as Storage and Account Abstraction.")]
49+
[Tooltip("Thirdweb Client ID (https://thirdweb.com/create-api-key/). Used for default thirdweb services such as RPC, Storage and Account Abstraction.")]
5050
public string clientId;
5151

5252
[Tooltip("Whether the SDK should initialize on awake or not")]
@@ -55,6 +55,9 @@ public class ThirdwebManager : MonoBehaviour
5555
[Tooltip("Whether to show thirdweb sdk debug logs")]
5656
public bool showDebugLogs = true;
5757

58+
[Tooltip("Optional Bundle ID override for thirdweb services")]
59+
public string bundleIdOverride = null;
60+
5861
[Tooltip("The name of your app")]
5962
public string appName = null;
6063

@@ -146,6 +149,13 @@ public void Initialize(string chainIdentifier)
146149

147150
var options = new ThirdwebSDK.Options();
148151

152+
// Set up Client ID and Bundle ID
153+
154+
options.clientId = string.IsNullOrEmpty(clientId) ? null : clientId;
155+
options.bundleId = string.IsNullOrEmpty(bundleIdOverride) ? Application.identifier.ToLower() : bundleIdOverride;
156+
157+
// Set up supported chains
158+
149159
activeChain = chainIdentifier;
150160
string activeChainId = null;
151161
string activeChainRpc = null;
@@ -279,10 +289,6 @@ public void Initialize(string chainIdentifier)
279289
entryPointAddress = string.IsNullOrEmpty(entryPointAddress) ? Thirdweb.AccountAbstraction.Constants.DEFAULT_ENTRYPOINT_ADDRESS : entryPointAddress,
280290
};
281291

282-
// Set up Client ID
283-
284-
options.clientId = string.IsNullOrEmpty(clientId) ? null : clientId;
285-
286292
// Pass active chain rpc and chainId
287293

288294
SDK = new ThirdwebSDK(activeChainRpc, BigInteger.Parse(activeChainId), options);

Assets/Thirdweb/Core/Scripts/ThirdwebSDK.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public struct Options
4141
/// </summary>
4242
public string clientId;
4343

44+
/// <summary>
45+
/// Optional Bundle ID override for thirdweb services.
46+
/// </summary>
47+
public string bundleId;
48+
4449
public ThirdwebChainData[] supportedChains;
4550
}
4651

Assets/Thirdweb/Core/Scripts/ThirdwebSession.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ public class ThirdwebSession
1818
#region Properties
1919

2020

21-
public ThirdwebSDK.Options Options { get; private set; }
22-
public BigInteger ChainId { get; private set; }
23-
public string RPC { get; private set; }
24-
public SiweMessageService SiweSession { get; private set; }
25-
public Web3 Web3 { get; private set; }
26-
public ThirdwebChainData CurrentChainData { get; private set; }
21+
internal ThirdwebSDK.Options Options { get; private set; }
22+
internal BigInteger ChainId { get; private set; }
23+
internal string RPC { get; private set; }
24+
internal SiweMessageService SiweSession { get; private set; }
25+
internal Web3 Web3 { get; private set; }
26+
internal ThirdwebChainData CurrentChainData { get; private set; }
2727

28-
public IThirdwebWallet ActiveWallet { get; private set; }
28+
internal IThirdwebWallet ActiveWallet { get; private set; }
2929

30-
public static int Nonce = 0;
30+
internal static int Nonce = 0;
3131

32-
public string BundleId { get; private set; }
32+
internal string BundleId { get; private set; }
3333

3434
#endregion
3535

@@ -43,7 +43,7 @@ public ThirdwebSession(ThirdwebSDK.Options options, BigInteger chainId, string r
4343
SiweSession = new SiweMessageService();
4444
Web3 = new Web3(rpcUrl);
4545
CurrentChainData = options.supportedChains.ToList().Find(x => x.chainId == new HexBigInteger(chainId).HexValue);
46-
BundleId = Utils.GetBundleId();
46+
BundleId = Options.bundleId;
4747
}
4848

4949
#endregion
@@ -241,7 +241,7 @@ public static ThirdwebChainData FetchChainData(BigInteger chainId, string rpcOve
241241
#region Nested Classes
242242

243243
[System.Serializable]
244-
public class ChainIDNetworkData
244+
class ChainIDNetworkData
245245
{
246246
public string name;
247247
public string chain;
@@ -253,22 +253,22 @@ public class ChainIDNetworkData
253253
}
254254

255255
[System.Serializable]
256-
public class ChainIDNetworkNativeCurrency
256+
class ChainIDNetworkNativeCurrency
257257
{
258258
public string name;
259259
public string symbol;
260260
public string decimals;
261261
}
262262

263263
[System.Serializable]
264-
public class ChainIDNetworkExplorer
264+
class ChainIDNetworkExplorer
265265
{
266266
public string name;
267267
public string url;
268268
public string standard;
269269
}
270270

271-
public struct ChaiNIDNetworkIcon
271+
struct ChaiNIDNetworkIcon
272272
{
273273
public string url;
274274
public int width;

Assets/Thirdweb/Core/Scripts/Utils.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,16 @@ public static string ToChecksumAddress(this string address)
408408

409409
public static string GetBundleId()
410410
{
411-
return Application.identifier.ToLower();
411+
return ThirdwebManager.Instance.SDK?.session?.BundleId
412+
?? (string.IsNullOrEmpty(ThirdwebManager.Instance.bundleIdOverride) ? Application.identifier.ToLower() : ThirdwebManager.Instance.bundleIdOverride);
412413
}
413414

414415
public static string AppendBundleIdQueryParam(this string uri)
415416
{
416-
if (Utils.IsWebGLBuild())
417+
if (IsWebGLBuild())
417418
return uri;
418419

419-
uri += $"?bundleId={ThirdwebManager.Instance?.SDK?.session?.BundleId ?? GetBundleId()}";
420+
uri += $"?bundleId={GetBundleId()}";
420421
return uri;
421422
}
422423

Assets/Thirdweb/Editor/ThirdwebManagerEditor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ThirdwebManagerEditor : Editor
1010
private SerializedProperty activeChainProperty;
1111
private SerializedProperty supportedChainsProperty;
1212
private SerializedProperty clientIdProperty;
13+
private SerializedProperty bundleIdOverrideProperty;
1314
private SerializedProperty initializeOnAwakeProperty;
1415
private SerializedProperty showDebugLogsProperty;
1516
private SerializedProperty appNameProperty;
@@ -50,6 +51,7 @@ private void OnEnable()
5051
activeChainProperty = serializedObject.FindProperty("activeChain");
5152
supportedChainsProperty = serializedObject.FindProperty("supportedChains");
5253
clientIdProperty = serializedObject.FindProperty("clientId");
54+
bundleIdOverrideProperty = serializedObject.FindProperty("bundleIdOverride");
5355
initializeOnAwakeProperty = serializedObject.FindProperty("initializeOnAwake");
5456
showDebugLogsProperty = serializedObject.FindProperty("showDebugLogs");
5557
appNameProperty = serializedObject.FindProperty("appName");
@@ -168,6 +170,7 @@ public override void OnInspectorGUI()
168170
EditorGUILayout.Space(10);
169171
supportedChainsList.DoLayoutList();
170172
EditorGUILayout.PropertyField(clientIdProperty);
173+
EditorGUILayout.PropertyField(bundleIdOverrideProperty);
171174
EditorGUILayout.PropertyField(initializeOnAwakeProperty);
172175
EditorGUILayout.PropertyField(showDebugLogsProperty);
173176
EditorGUILayout.EndVertical();

0 commit comments

Comments
 (0)