Skip to content

Commit ba05c07

Browse files
Handle null Token.Price case in json
1 parent 26c9542 commit ba05c07

File tree

1 file changed

+11
-1
lines changed
  • Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum

1 file changed

+11
-1
lines changed

Packages/Sequence-Unity/Sequence/SequenceSDK/Ethereum/Token.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,17 @@ public override Token ReadJson(JsonReader reader, Type objectType, Token existin
112112
BigInteger decimals = (jsonObject["decimals"]?.Value<ulong>() ?? 18);
113113
decimal priceUsd = jsonObject["priceUsd"]?.Value<decimal>() ?? default;
114114
string logoUri = jsonObject["logoUri"]?.Value<string>();
115-
BigInteger price = (jsonObject["price"]?.Value<ulong>() ?? 0);
115+
BigInteger price = 0;
116+
JToken priceToken = jsonObject["price"];
117+
if (priceToken != null && priceToken.Type != JTokenType.Null)
118+
{
119+
string priceStr = priceToken.Value<string>();
120+
if (!string.IsNullOrWhiteSpace(priceStr) && BigInteger.TryParse(priceStr, out var parsedPrice))
121+
{
122+
price = parsedPrice;
123+
}
124+
}
125+
116126

117127
return new Token(chainId, contractAddress, tokenId, symbol, name, decimals, priceUsd, logoUri, price);
118128
}

0 commit comments

Comments
 (0)