Skip to content

Commit 20e97cb

Browse files
Fix/new marketplace types (#297)
* Fix a bug with EnumConverter; when encountering unknown values, it was throwing exceptions. This was dangerous for when new service providers (for example) are added and the backend starts returning those as options. * Updated some payloads, enums, and response structs based on updated ridl definitions
1 parent a5d6d46 commit 20e97cb

File tree

8 files changed

+78
-8
lines changed

8 files changed

+78
-8
lines changed

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CollectiblesFilter.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ public class CollectiblesFilter
1616
public string[] notInAccounts = null; // Filter out any collectibles owned by the specified addresses
1717
public string[] ordersCreatedBy = null; // Filter for orders created by the specified addresses
1818
public string[] ordersNotCreatedBy = null; // Filter out any orders created by the specified addresses
19+
public string[] inCurrencyAddresses = null; // Filter for collectibles priced with the specified currency addresses
20+
public string[] notInCurrencyAddresses = null; // Filter out any collectibles priced with the specified currency addresses
1921

20-
public CollectiblesFilter(bool includeEmpty, string searchText = "", PropertyFilter[] properties = null, MarketplaceKind[] marketplaces = null, string[] inAccounts = null, string[] notInAccounts = null, string[] ordersCreatedBy = null, string[] ordersNotCreatedBy = null)
22+
public CollectiblesFilter(bool includeEmpty, string searchText = "", PropertyFilter[] properties = null, MarketplaceKind[] marketplaces = null, string[] inAccounts = null, string[] notInAccounts = null, string[] ordersCreatedBy = null, string[] ordersNotCreatedBy = null, string[] inCurrencyAddresses = null, string[] notInCurrencyAddresses = null)
2123
{
2224
this.includeEmpty = includeEmpty;
2325
this.searchText = searchText;
@@ -27,11 +29,13 @@ public CollectiblesFilter(bool includeEmpty, string searchText = "", PropertyFil
2729
this.notInAccounts = notInAccounts;
2830
this.ordersCreatedBy = ordersCreatedBy;
2931
this.ordersNotCreatedBy = ordersNotCreatedBy;
32+
this.inCurrencyAddresses = inCurrencyAddresses;
33+
this.notInCurrencyAddresses = notInCurrencyAddresses;
3034
}
3135

3236
[Preserve]
3337
[JsonConstructor]
34-
public CollectiblesFilter(bool includeEmpty, string searchText, PropertyFilter[] properties, string[] marketplaces, string[] inAccounts, string[] notInAccounts, string[] ordersCreatedBy, string[] ordersNotCreatedBy)
38+
public CollectiblesFilter(bool includeEmpty, string searchText, PropertyFilter[] properties, string[] marketplaces, string[] inAccounts, string[] notInAccounts, string[] ordersCreatedBy, string[] ordersNotCreatedBy, string[] inCurrencyAddresses = null, string[] notInCurrencyAddresses = null)
3539
{
3640
this.includeEmpty = includeEmpty;
3741
this.searchText = searchText;
@@ -41,6 +45,8 @@ public CollectiblesFilter(bool includeEmpty, string searchText, PropertyFilter[]
4145
this.notInAccounts = notInAccounts;
4246
this.ordersCreatedBy = ordersCreatedBy;
4347
this.ordersNotCreatedBy = ordersNotCreatedBy;
48+
this.inCurrencyAddresses = inCurrencyAddresses;
49+
this.notInCurrencyAddresses = notInCurrencyAddresses;
4450
}
4551

4652
private string[] MarketplacesToStringArray(MarketplaceKind[] marketplaces)

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/Currency.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Currency
1111
public ulong id;
1212
public Chain chain;
1313
public string contractAddress;
14+
public CurrencyStatus status;
1415
public string name;
1516
public string symbol;
1617
public ulong decimals;
@@ -22,7 +23,7 @@ public class Currency
2223
public string deletedAt;
2324

2425
public const string NativeCurrencyAddress = "0x0000000000000000000000000000000000000000";
25-
26+
2627
public Currency(ulong id, Chain chain, string contractAddress, string name, string symbol, ulong decimals, string imageUrl, double exchangeRate, bool defaultChainCurrency, string createdAt, string updatedAt, string deletedAt = "")
2728
{
2829
this.id = id;
@@ -43,13 +44,35 @@ public Currency(ulong id, Chain chain, string contractAddress, string name, stri
4344
}
4445
}
4546

47+
public Currency(ulong id, Chain chain, string contractAddress, CurrencyStatus status, string name, string symbol, ulong decimals, string imageUrl, double exchangeRate, bool defaultChainCurrency, string createdAt, string updatedAt, string deletedAt = "")
48+
{
49+
this.id = id;
50+
this.chain = chain;
51+
this.contractAddress = contractAddress;
52+
this.status = status;
53+
this.name = name;
54+
this.symbol = symbol;
55+
this.decimals = decimals;
56+
this.imageUrl = imageUrl;
57+
this.exchangeRate = exchangeRate;
58+
this.defaultChainCurrency = defaultChainCurrency;
59+
this.createdAt = createdAt;
60+
this.updatedAt = updatedAt;
61+
this.deletedAt = deletedAt;
62+
if (this.contractAddress == null)
63+
{
64+
this.contractAddress = NativeCurrencyAddress;
65+
}
66+
}
67+
4668
[Preserve]
4769
[JsonConstructor]
48-
public Currency(ulong id, BigInteger chainId, string contractAddress, string name, string symbol, ulong decimals, string imageUrl, double exchangeRate, bool defaultChainCurrency, string createdAt, string updatedAt, string deletedAt = "")
70+
public Currency(ulong id, BigInteger chainId, string contractAddress, CurrencyStatus status, string name, string symbol, ulong decimals, string imageUrl, double exchangeRate, bool defaultChainCurrency, string createdAt, string updatedAt, string deletedAt = "")
4971
{
5072
this.id = id;
5173
this.chain = ChainDictionaries.ChainById[chainId.ToString()];
5274
this.contractAddress = contractAddress;
75+
this.status = status;
5376
this.name = name;
5477
this.symbol = symbol;
5578
this.decimals = decimals;
@@ -98,5 +121,10 @@ public static Currency GetNativeCurrency(this Currency[] currencies)
98121
{
99122
return currencies.GetCurrencyByContractAddress(Currency.NativeCurrencyAddress);
100123
}
124+
125+
public static bool IsActive(this Currency currency)
126+
{
127+
return currency.status == CurrencyStatus.active;
128+
}
101129
}
102130
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Newtonsoft.Json;
2+
using Sequence.Utils;
3+
4+
namespace Sequence.Marketplace
5+
{
6+
[JsonConverter(typeof(EnumConverter<CurrencyStatus>))]
7+
public enum CurrencyStatus
8+
{
9+
unknown,
10+
created,
11+
syncing_metadata,
12+
active,
13+
failed,
14+
}
15+
}

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/CurrencyStatus.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/OrderData.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ public class OrderData
77
{
88
public string orderId;
99
public string quantity;
10+
public string tokenId;
1011

1112
[Preserve]
12-
public OrderData(string orderId, string quantity)
13+
public OrderData(string orderId, string quantity, string tokenId = null)
1314
{
1415
this.orderId = orderId;
1516
this.quantity = quantity;
17+
this.tokenId = tokenId;
1618
}
1719
}
1820
}

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/OrderStatus.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public enum OrderStatus
1414
expired,
1515
cancelled,
1616
filled,
17+
decimals_missing,
1718
}
1819
}

Packages/Sequence-Unity/Sequence/SequenceSDK/Marketplace/DataTypes/TransactionSwapProvider.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Newtonsoft.Json;
23
using Sequence.Utils;
34

@@ -7,6 +8,8 @@ namespace Sequence.Marketplace
78
public enum TransactionSwapProvider
89
{
910
unknown,
10-
zerox
11+
[Obsolete("zerox is no longer supported")]
12+
zerox,
13+
lifi
1114
}
1215
}

Packages/Sequence-Unity/Sequence/SequenceSDK/Utils/EnumConverter.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using Newtonsoft.Json;
33
using Newtonsoft.Json.Linq;
4+
using UnityEngine;
45

56
namespace Sequence.Utils
67
{
@@ -36,16 +37,27 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
3637
var enumValues = new T[array.Count];
3738
for (int i = 0; i < array.Count; i++)
3839
{
39-
enumValues[i] = Enum.Parse<T>(array[i].ToString());
40+
enumValues[i] = ParseEnum<T>(array[i].ToString());
4041
}
4142
return enumValues;
4243
}
4344
else
4445
{
4546
var enumString = JToken.Load(reader).ToString();
46-
return Enum.Parse<T>(enumString);
47+
return ParseEnum<T>(enumString);
4748
}
4849
}
50+
51+
private T ParseEnum<T>(string enumString) where T : struct
52+
{
53+
if (!Enum.TryParse<T>(enumString, ignoreCase: true, out var parsed))
54+
{
55+
Debug.LogWarning($"Unknown enum value '{enumString}' for type {typeof(T).Name}. Returning default.");
56+
return default(T);
57+
}
58+
59+
return parsed;
60+
}
4961
}
5062

5163
}

0 commit comments

Comments
 (0)