Skip to content

Handling null market cap since the API can now return a null value #1206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,9 @@ fun PreviewTokenPage() {
uiState = TokenPageUIState(
currentSessionNodesInSwarm = 5,
currentSessionNodesSecuringMessages = 125349,
currentSentPriceUSD = SerializableBigDecimal(1.23),
currentSentPriceUSDString = "$1,472.22 USD",
networkSecuredBySENTString = "12M SENT",
networkSecuredByUSDString = "$1,234,567 USD",
currentMarketCapUSD = SerializableBigDecimal(420_000_000),
currentStakingRewardPool = SerializableBigDecimal(40_000_000),
currentMarketCapUSDString = "$20,456,259 USD",
currentStakingRewardPoolString = "40,567,789,654,789 SESH",
Expand All @@ -837,10 +835,8 @@ fun PreviewTokenPageLoading() {
uiState = TokenPageUIState(
currentSessionNodesInSwarm = 5,
currentSessionNodesSecuringMessages = 123,
currentSentPriceUSD = SerializableBigDecimal(1.23),
networkSecuredBySENTString = "12M SENT",
networkSecuredByUSDString = "$1,234,567 USD",
currentMarketCapUSD = SerializableBigDecimal(420_000_000),
currentStakingRewardPool = SerializableBigDecimal(40_000_000),
showNodeCountsAsRefreshing = true
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data class PriceData(
@SerialName("usd") val tokenPriceUSD: SerializableBigDecimal,

// Current market cap value in US dollars
@SerialName("usd_market_cap") val marketCapUSD: SerializableBigDecimal,
@SerialName("usd_market_cap") val marketCapUSD: SerializableBigDecimal?,

// The timestamp (in seconds) of when the server's CoinGecko-sourced token price data was last updated
@SerialName("t_price") val priceTimestampSecs: Long,
Expand All @@ -44,17 +44,7 @@ data class PriceData(
// current time is lower than `t_stale`, and if it is then we don't poll the server again as
// we'd just be getting the same data.
@SerialName("t_stale") val staleTimestampSecs: Long
) {
// Get the token price in USD to 2 decimal places in a locale-aware manner
fun getLocaleFormattedTokenPriceString(): String {
return "\$" + tokenPriceUSD.formatWithDecimalPlaces(2) + " USD"
}

// Get the token price in USD to ZERO decimal places in a locale-aware manner
fun getLocaleFormattedMarketCapString(): String {
return "\$" + marketCapUSD.formatWithDecimalPlaces( 0) + " USD"
}
}
)

// Data class to hold details provided in a InfoResponse or via the `GET /token` endpoint
@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ data class TokenPageUIState(
// ----- PriceResponse / PriceData UI representations -----

// Number so we can perform calculation (this value is obtained from PriceData.usd)
var currentSentPriceUSD: SerializableBigDecimal = BigDecimal.ZERO,
var currentSentPriceUSDString: String = "",

// Number so we can perform calculations (this value is obtained from PriceData.usd_market_cap)
val currentMarketCapUSD: SerializableBigDecimal = BigDecimal.ZERO,
val currentMarketCapUSDString: String = "",

// ----- TokenResponse / TokenData UI representations -----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ class TokenPageViewModel @Inject constructor(

showNodeCountsAsRefreshing = false,

currentSentPriceUSD = infoResponse.priceData.tokenPriceUSD, // Raw token price value "1.23" etc.
currentSentPriceUSDString = infoResponse.priceData.getLocaleFormattedTokenPriceString(), // Formatted token price value "$1.23 USD" etc.
currentMarketCapUSD = infoResponse.priceData.marketCapUSD, // Raw market cap value "1,234,567" etc.
currentMarketCapUSDString = infoResponse.priceData.getLocaleFormattedMarketCapString(), // Formatted market cap value "$1,234,567 USD" etc.

currentSentPriceUSDString = "\$" + infoResponse.priceData.tokenPriceUSD.formatWithDecimalPlaces(2) + " $USD_NAME_SHORT", // Formatted token price value "$1.23 USD" etc.
currentMarketCapUSDString = if(infoResponse.priceData.marketCapUSD == null) unavailableString
else "\$" + infoResponse.priceData.marketCapUSD.formatWithDecimalPlaces( 0) + " $USD_NAME_SHORT", // Formatted market cap value "$1,234,567 USD" etc.

currentStakingRewardPool = infoResponse.tokenData.stakingRewardPool,
currentStakingRewardPoolString = infoResponse.tokenData.getLocaleFormattedStakingRewardPool() + " $TOKEN_NAME_SHORT",

Expand Down