Skip to content

Commit ee27afe

Browse files
Misc fixes, apply formatting, show error message in UI
1 parent 17d85d0 commit ee27afe

File tree

14 files changed

+110
-86
lines changed

14 files changed

+110
-86
lines changed

Assets/Plugin/thirdweb.jslib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var plugin = {
1717
})
1818
.catch((err) => {
1919
console.error("ThirdwebSDK invoke error", err);
20-
var msg = err.message;
20+
var msg = err.reason || err.message;
2121
var bufferSize = lengthBytesUTF8(msg) + 1;
2222
var buffer = _malloc(bufferSize);
2323
stringToUTF8(msg, buffer, bufferSize);

Assets/Thirdweb/Demo/ThirdwebDemoScene.unity

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RenderSettings:
3838
m_ReflectionIntensity: 1
3939
m_CustomReflection: {fileID: 0}
4040
m_Sun: {fileID: 705507994}
41-
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
41+
m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1}
4242
m_UseRadianceAmbientProbe: 0
4343
--- !u!157 &3
4444
LightmapSettings:
@@ -1174,9 +1174,9 @@ RectTransform:
11741174
m_RootOrder: 12
11751175
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
11761176
m_AnchorMin: {x: 0.5, y: 0}
1177-
m_AnchorMax: {x: 0.5, y: 0}
1177+
m_AnchorMax: {x: 0.5, y: 1}
11781178
m_AnchoredPosition: {x: -0.26769364, y: 64.86401}
1179-
m_SizeDelta: {x: 4924.909, y: 830.7549}
1179+
m_SizeDelta: {x: 4924.909, y: -249.06401}
11801180
m_Pivot: {x: 0.5, y: 0}
11811181
--- !u!114 &545609470
11821182
MonoBehaviour:

Assets/Thirdweb/Demo/ThirdwebSDKDemos.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public async void OnBalanceClick()
4242
public async void OnSignClick()
4343
{
4444
resultText.text = "Signing...";
45-
var data = await sdk.wallet.Authenticate("example.com");
46-
if (data.payload.address != null)
45+
try
4746
{
47+
var data = await sdk.wallet.Authenticate("example.com");
4848
resultText.text = "Sig: " + data.payload.address.Substring(0, 6) + "...";
4949
}
50-
else
50+
catch (System.Exception e)
5151
{
52-
resultText.text = "Failed to authenticate";
52+
resultText.text = "Auth Error: " + e.Message;
5353
}
5454
}
5555

@@ -80,12 +80,14 @@ public async void GetERC721()
8080

8181
public async void GetERC1155()
8282
{
83-
var contract = sdk.GetContract("0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A"); // Edition Drop
84-
// Fetch single NFT
85-
// count++;
86-
// resultText.text = "Fetching Token: " + count;
87-
// NFT result = await contract.ERC1155.Get(count.ToString());
88-
// resultText.text = result.metadata.name + " (x" + result.supply + ")";
83+
var contract = sdk.GetContract("0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A");
84+
85+
// Edition Drop
86+
// Fetch single NFT
87+
// count++;
88+
// resultText.text = "Fetching Token: " + count;
89+
// NFT result = await contract.ERC1155.Get(count.ToString());
90+
// resultText.text = result.metadata.name + " (x" + result.supply + ")";
8991

9092
// fetch all NFTs
9193
resultText.text = "Fetching all NFTs";
@@ -124,15 +126,15 @@ public async void MintERC721()
124126
};
125127
string connectedAddress = await sdk.wallet.GetAddress();
126128
var payload = new ERC721MintPayload(connectedAddress, meta);
127-
var p = await contract.ERC721.signature.Generate(payload); // typically generated on the backend
128-
var result = await contract.ERC721.signature.Mint(p);
129-
if (result.isSuccessful())
129+
try
130130
{
131+
var p = await contract.ERC721.signature.Generate(payload); // typically generated on the backend
132+
var result = await contract.ERC721.signature.Mint(p);
131133
resultText.text = "SigMinted tokenId: " + result.id;
132134
}
133-
else
135+
catch (System.Exception e)
134136
{
135-
resultText.text = "SigMint failed (see console)";
137+
resultText.text = "Sigmint Failed (see console): " + e.Message;
136138
}
137139
}
138140

@@ -146,15 +148,15 @@ public async void MintERC1155()
146148
var canClaim = await contract.ERC1155.claimConditions.CanClaim("0", 1);
147149
if (canClaim)
148150
{
149-
var result = await contract.ERC1155.Claim("0", 1);
150-
var newSupply = await contract.ERC1155.TotalSupply("0");
151-
if (result[0].isSuccessful())
151+
try
152152
{
153+
var result = await contract.ERC1155.Claim("0", 1);
154+
var newSupply = await contract.ERC1155.TotalSupply("0");
153155
resultText.text = "Claim successful! New supply: " + newSupply;
154156
}
155-
else
157+
catch (System.Exception e)
156158
{
157-
resultText.text = "Claim failed (see console)";
159+
resultText.text = "Claim Failed: " + e.Message;
158160
}
159161
}
160162
else
@@ -177,18 +179,16 @@ public async void MintERC20()
177179

178180
// Mint
179181
var contract = sdk.GetContract("0xB4870B21f80223696b68798a755478C86ce349bE"); // Token
180-
var result = await contract.ERC20.Mint("1.2");
181-
if (result.isSuccessful())
182+
try
182183
{
184+
var result = await contract.ERC20.Mint("1.2");
183185
resultText.text = "mint successful";
184186
}
185-
else
187+
catch (System.Exception e)
186188
{
187-
resultText.text = "Mint failed (see console)";
189+
resultText.text = "Mint failed (see console): " + e.Message;
188190
}
189191

190-
191-
192192
// sig mint
193193
// var contract = sdk.GetContract("0xB4870B21f80223696b68798a755478C86ce349bE"); // Token
194194
// var payload = new ERC20MintPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "3.2");
@@ -213,14 +213,14 @@ public async void BuyListing()
213213

214214
// buy listing
215215
var marketplace = sdk.GetContract("0xC7DBaD01B18403c041132C5e8c7e9a6542C4291A").marketplace; // Marketplace
216-
var result = await marketplace.BuyListing("0", 1);
217-
if (result.isSuccessful())
216+
try
218217
{
218+
var result = await marketplace.BuyListing("0", 1);
219219
resultText.text = "NFT bought successfully";
220220
}
221-
else
221+
catch (System.Exception e)
222222
{
223-
resultText.text = "Buy failed (see console)";
223+
resultText.text = "Error Buying listing (see console): " + e.Message;
224224
}
225225
}
226226

Assets/Thirdweb/Scripts/Bridge.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,34 @@ private static void jsCallback(string taskId, string result, string error)
3333
{
3434
if (taskMap.ContainsKey(taskId))
3535
{
36-
if (error != null)
36+
if (error != null)
3737
{
38-
// TODO wrap error in proper result type
3938
taskMap[taskId].TrySetException(new Exception(error));
40-
} else
39+
}
40+
else
4141
{
4242
taskMap[taskId].TrySetResult(result);
4343
}
4444
taskMap.Remove(taskId);
4545
}
4646
}
4747

48-
public static void Initialize(string chainOrRPC, ThirdwebSDK.Options options) {
49-
if (Application.isEditor) {
48+
public static void Initialize(string chainOrRPC, ThirdwebSDK.Options options)
49+
{
50+
if (Application.isEditor)
51+
{
5052
Debug.LogWarning("Initializing the thirdweb SDK is not supported in the editor. Please build and run the app instead.");
5153
return;
5254
}
5355
ThirdwebInitialize(chainOrRPC, Utils.ToJson(options));
5456
}
5557

56-
public static async Task<string> Connect() {
57-
if (Application.isEditor) {
58+
public static async Task<string> Connect()
59+
{
60+
if (Application.isEditor)
61+
{
5862
Debug.LogWarning("Connecting wallets is not supported in the editor. Please build and run the app instead.");
59-
return "0x0000000000000000000000000000000000000000";
63+
return Utils.AddressZero;
6064
}
6165
var task = new TaskCompletionSource<string>();
6266
string taskId = Guid.NewGuid().ToString();
@@ -66,8 +70,10 @@ public static async Task<string> Connect() {
6670
return result;
6771
}
6872

69-
public static async Task SwitchNetwork(int chainId) {
70-
if (Application.isEditor) {
73+
public static async Task SwitchNetwork(int chainId)
74+
{
75+
if (Application.isEditor)
76+
{
7177
Debug.LogWarning("Switching networks is not supported in the editor. Please build and run the app instead.");
7278
return;
7379
}
@@ -81,7 +87,8 @@ public static async Task SwitchNetwork(int chainId) {
8187

8288
public static async Task<T> InvokeRoute<T>(string route, string[] body)
8389
{
84-
if (Application.isEditor) {
90+
if (Application.isEditor)
91+
{
8592
Debug.LogWarning("Interacting with the thirdweb SDK is not supported in the editor. Please build and run the app instead.");
8693
return default(T);
8794
}
@@ -91,7 +98,7 @@ public static async Task<T> InvokeRoute<T>(string route, string[] body)
9198
taskMap[taskId] = task;
9299
ThirdwebInvoke(taskId, route, msg, jsCallback);
93100
string result = await task.Task;
94-
Debug.Log($"InvokeRoute Result: {result}");
101+
// Debug.Log($"InvokeRoute Result: {result}");
95102
return JsonConvert.DeserializeObject<Result<T>>(result).result;
96103
}
97104

Assets/Thirdweb/Scripts/Common.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
namespace Thirdweb {
2-
public abstract class Routable {
1+
namespace Thirdweb
2+
{
3+
public abstract class Routable
4+
{
35
public static string separator = "/";
46
public static string subSeparator = "#";
57

6-
public static string append(string route, string subRoute) {
8+
public static string append(string route, string subRoute)
9+
{
710
return $"{route}{separator}{subRoute}";
811
}
912

1013
protected string baseRoute;
1114

12-
public Routable(string baseRoute) {
15+
public Routable(string baseRoute)
16+
{
1317
this.baseRoute = baseRoute;
1418
}
1519

16-
protected string getRoute(string functionName) {
20+
protected string getRoute(string functionName)
21+
{
1722
return $"{baseRoute}{separator}{functionName}";
1823
}
1924
}

Assets/Thirdweb/Scripts/Deployer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ public async Task<string> DeployMarketplace(MarketplaceContractDeployMetadata me
6262
return await Bridge.InvokeRoute<string>(getRoute("deployMarketplace"), Utils.ToJsonStringArray(metadata));
6363
}
6464

65-
public async Task<string> DeployReleasedContract(string releaserAddress, string contractName, object[] constructorParams) {
65+
public async Task<string> DeployReleasedContract(string releaserAddress, string contractName, object[] constructorParams)
66+
{
6667
return await Bridge.InvokeRoute<string>(getRoute("deployReleasedContract"), Utils.ToJsonStringArray(releaserAddress, contractName, constructorParams));
6768
}
6869

69-
public async Task<string> DeployFromContractUri(string uri, object[] constructorParams) {
70+
public async Task<string> DeployFromContractUri(string uri, object[] constructorParams)
71+
{
7072
return await Bridge.InvokeRoute<string>(getRoute("deployContractFromUri"), Utils.ToJsonStringArray(uri, constructorParams));
7173
}
7274
}

Assets/Thirdweb/Scripts/ERC1155.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public async Task<int> TotalCount()
9090
/// </summary>
9191
public async Task<int> TotalSupply(string tokenId)
9292
{
93-
return await Bridge.InvokeRoute<int>(getRoute("totalUnclaimedSupply"), Utils.ToJsonStringArray(tokenId));
93+
return await Bridge.InvokeRoute<int>(getRoute("totalSupply"), Utils.ToJsonStringArray(tokenId));
9494
}
9595

9696
// WRITE FUNCTIONS
@@ -122,17 +122,17 @@ public async Task<TransactionResult> Burn(string tokenId, int amount)
122122
/// <summary>
123123
/// Claim NFTs from a Drop contract
124124
/// </summary>
125-
public async Task<TransactionResult[]> Claim(string tokenId, int amount)
125+
public async Task<TransactionResult> Claim(string tokenId, int amount)
126126
{
127-
return await Bridge.InvokeRoute<TransactionResult[]>(getRoute("claim"), Utils.ToJsonStringArray(tokenId, amount));
127+
return await Bridge.InvokeRoute<TransactionResult>(getRoute("claim"), Utils.ToJsonStringArray(tokenId, amount));
128128
}
129129

130130
/// <summary>
131131
/// Claim NFTs from a Drop contract and send them to the given address
132132
/// </summary>
133-
public async Task<TransactionResult[]> ClaimTo(string address, string tokenId, int amount)
133+
public async Task<TransactionResult> ClaimTo(string address, string tokenId, int amount)
134134
{
135-
return await Bridge.InvokeRoute<TransactionResult[]>(getRoute("claimTo"), Utils.ToJsonStringArray(address, tokenId, amount));
135+
return await Bridge.InvokeRoute<TransactionResult>(getRoute("claimTo"), Utils.ToJsonStringArray(address, tokenId, amount));
136136
}
137137

138138
/// <summary>
@@ -173,7 +173,7 @@ public async Task<TransactionResult> MintAdditionalSupplyTo(string address, stri
173173
/// </summary>
174174
public class ERC1155ClaimConditions : Routable
175175
{
176-
public ERC1155ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
176+
public ERC1155ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
177177
{
178178
}
179179

@@ -212,7 +212,7 @@ public async Task<bool> GetClaimerProofs(string tokenId, string claimerAddress)
212212

213213
// TODO switch to another JSON serializer that supports polymorphism
214214
[System.Serializable]
215-
#nullable enable
215+
#nullable enable
216216
public class ERC1155MintPayload
217217
{
218218
public string to;
@@ -310,7 +310,7 @@ public class ERC1155Signature : Routable
310310
/// <summary>
311311
/// Generate, verify and mint signed mintable payloads
312312
/// </summary>
313-
public ERC1155Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
313+
public ERC1155Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
314314
{
315315
}
316316

Assets/Thirdweb/Scripts/ERC20.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ public struct ERC20SignedPayload
185185
/// <summary>
186186
/// Fetch claim conditions for a given ERC20 drop contract
187187
/// </summary>
188-
#nullable enable
188+
#nullable enable
189189
public class ERC20ClaimConditions : Routable
190190
{
191-
public ERC20ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
191+
public ERC20ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
192192
{
193193
}
194194

@@ -234,7 +234,7 @@ public class ERC20Signature : Routable
234234
/// <summary>
235235
/// Generate, verify and mint signed mintable payloads
236236
/// </summary>
237-
public ERC20Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
237+
public ERC20Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
238238
{
239239
}
240240

Assets/Thirdweb/Scripts/ERC721.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public async Task<TransactionResult> MintTo(string address, NFTMetadata nft)
176176
/// </summary>
177177
public class ERC721ClaimConditions : Routable
178178
{
179-
public ERC721ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
179+
public ERC721ClaimConditions(string parentRoute) : base(Routable.append(parentRoute, "claimConditions"))
180180
{
181181
}
182182

@@ -214,7 +214,7 @@ public async Task<bool> GetClaimerProofs(string claimerAddress)
214214
}
215215

216216
[System.Serializable]
217-
#nullable enable
217+
#nullable enable
218218
public class ERC721MintPayload
219219
{
220220
public string to;
@@ -278,7 +278,7 @@ public class ERC721Signature : Routable
278278
/// <summary>
279279
/// Generate, verify and mint signed mintable payloads
280280
/// </summary>
281-
public ERC721Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
281+
public ERC721Signature(string parentRoute) : base(Routable.append(parentRoute, "signature"))
282282
{
283283
}
284284

Assets/Thirdweb/Scripts/Marketplace.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ public async Task<TransactionResult> CancelListing(string listingId)
119119

120120
// AUCTION
121121

122-
public class MarketplaceAuction : Routable {
122+
public class MarketplaceAuction : Routable
123+
{
123124
public MarketplaceAuction(string parentRoute) : base(Routable.append(parentRoute, "auction"))
124125
{
125126
}

0 commit comments

Comments
 (0)