Skip to content

Commit f8074bc

Browse files
add warnings when trying to use the SDK in editor mode
1 parent 1701f24 commit f8074bc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Assets/Thirdweb/Scripts/Bridge.cs

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Runtime.InteropServices;
55
using System.Threading.Tasks;
66
using Newtonsoft.Json;
7+
using UnityEngine;
78

89
namespace Thirdweb
910
{
@@ -45,10 +46,18 @@ private static void jsCallback(string taskId, string result, string error)
4546
}
4647

4748
public static void Initialize(string chainOrRPC, ThirdwebSDK.Options options) {
49+
if (Application.isEditor) {
50+
Debug.LogWarning("Initializing the thirdweb SDK is not supported in the editor. Please build and run the app instead.");
51+
return;
52+
}
4853
ThirdwebInitialize(chainOrRPC, Utils.ToJson(options));
4954
}
5055

5156
public static async Task<string> Connect() {
57+
if (Application.isEditor) {
58+
Debug.LogWarning("Connecting wallets is not supported in the editor. Please build and run the app instead.");
59+
return "0x0000000000000000000000000000000000000000";
60+
}
5261
var task = new TaskCompletionSource<string>();
5362
string taskId = Guid.NewGuid().ToString();
5463
taskMap[taskId] = task;
@@ -58,11 +67,19 @@ public static async Task<string> Connect() {
5867
}
5968

6069
public static void SwitchNetwork(int chainId) {
70+
if (Application.isEditor) {
71+
Debug.LogWarning("Switching networks is not supported in the editor. Please build and run the app instead.");
72+
return;
73+
}
6174
ThirdwebSwitchNetwork(chainId);
6275
}
6376

6477
public static async Task<T> InvokeRoute<T>(string route, string[] body)
6578
{
79+
if (Application.isEditor) {
80+
Debug.LogWarning("Interacting with the thirdweb SDK is not supported in the editor. Please build and run the app instead.");
81+
return default(T);
82+
}
6683
var msg = Utils.ToJson(new RequestMessageBody(body));
6784
string taskId = Guid.NewGuid().ToString();
6885
var task = new TaskCompletionSource<string>();

Assets/ThirdwebSDKDemos.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public async void OnSignClick()
4141
{
4242
resultText.text = "Signing...";
4343
var data = await sdk.wallet.Authenticate("example.com");
44-
resultText.text = "Sig: " + data.payload.address.Substring(0, 6) + "...";
44+
if (data.payload.address != null) {
45+
resultText.text = "Sig: " + data.payload.address.Substring(0, 6) + "...";
46+
} else {
47+
resultText.text = "Failed to authenticate";
48+
}
4549
}
4650

4751
public async void GetERC721()
@@ -149,7 +153,6 @@ public async void MintERC20()
149153
// Mint
150154
var contract = sdk.GetContract("0xB4870B21f80223696b68798a755478C86ce349bE"); // Token
151155
var result = await contract.ERC20.Mint("1.2");
152-
Debug.Log("result: " + result);
153156
if (result.isSuccessful()) {
154157
resultText.text = "mint successful";
155158
} else {

0 commit comments

Comments
 (0)