Skip to content

Commit fd6fd5e

Browse files
Merge pull request #1206 from session-foundation/feature/updated-network-api
Handling null market cap since the API can now return a null value
2 parents be0ba0f + ac85b33 commit fd6fd5e

File tree

4 files changed

+6
-23
lines changed

4 files changed

+6
-23
lines changed

app/src/main/java/org/thoughtcrime/securesms/tokenpage/TokenPage.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,9 @@ fun PreviewTokenPage() {
812812
uiState = TokenPageUIState(
813813
currentSessionNodesInSwarm = 5,
814814
currentSessionNodesSecuringMessages = 125349,
815-
currentSentPriceUSD = SerializableBigDecimal(1.23),
816815
currentSentPriceUSDString = "$1,472.22 USD",
817816
networkSecuredBySENTString = "12M SENT",
818817
networkSecuredByUSDString = "$1,234,567 USD",
819-
currentMarketCapUSD = SerializableBigDecimal(420_000_000),
820818
currentStakingRewardPool = SerializableBigDecimal(40_000_000),
821819
currentMarketCapUSDString = "$20,456,259 USD",
822820
currentStakingRewardPoolString = "40,567,789,654,789 SESH",
@@ -837,10 +835,8 @@ fun PreviewTokenPageLoading() {
837835
uiState = TokenPageUIState(
838836
currentSessionNodesInSwarm = 5,
839837
currentSessionNodesSecuringMessages = 123,
840-
currentSentPriceUSD = SerializableBigDecimal(1.23),
841838
networkSecuredBySENTString = "12M SENT",
842839
networkSecuredByUSDString = "$1,234,567 USD",
843-
currentMarketCapUSD = SerializableBigDecimal(420_000_000),
844840
currentStakingRewardPool = SerializableBigDecimal(40_000_000),
845841
showNodeCountsAsRefreshing = true
846842
),

app/src/main/java/org/thoughtcrime/securesms/tokenpage/TokenPageDataTypes.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data class PriceData(
3333
@SerialName("usd") val tokenPriceUSD: SerializableBigDecimal,
3434

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

3838
// The timestamp (in seconds) of when the server's CoinGecko-sourced token price data was last updated
3939
@SerialName("t_price") val priceTimestampSecs: Long,
@@ -44,17 +44,7 @@ data class PriceData(
4444
// current time is lower than `t_stale`, and if it is then we don't poll the server again as
4545
// we'd just be getting the same data.
4646
@SerialName("t_stale") val staleTimestampSecs: Long
47-
) {
48-
// Get the token price in USD to 2 decimal places in a locale-aware manner
49-
fun getLocaleFormattedTokenPriceString(): String {
50-
return "\$" + tokenPriceUSD.formatWithDecimalPlaces(2) + " USD"
51-
}
52-
53-
// Get the token price in USD to ZERO decimal places in a locale-aware manner
54-
fun getLocaleFormattedMarketCapString(): String {
55-
return "\$" + marketCapUSD.formatWithDecimalPlaces( 0) + " USD"
56-
}
57-
}
47+
)
5848

5949
// Data class to hold details provided in a InfoResponse or via the `GET /token` endpoint
6050
@Serializable

app/src/main/java/org/thoughtcrime/securesms/tokenpage/TokenPageUIState.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ data class TokenPageUIState(
2424
// ----- PriceResponse / PriceData UI representations -----
2525

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

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

3432
// ----- TokenResponse / TokenData UI representations -----

app/src/main/java/org/thoughtcrime/securesms/tokenpage/TokenPageViewModel.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,10 @@ class TokenPageViewModel @Inject constructor(
164164

165165
showNodeCountsAsRefreshing = false,
166166

167-
currentSentPriceUSD = infoResponse.priceData.tokenPriceUSD, // Raw token price value "1.23" etc.
168-
currentSentPriceUSDString = infoResponse.priceData.getLocaleFormattedTokenPriceString(), // Formatted token price value "$1.23 USD" etc.
169-
currentMarketCapUSD = infoResponse.priceData.marketCapUSD, // Raw market cap value "1,234,567" etc.
170-
currentMarketCapUSDString = infoResponse.priceData.getLocaleFormattedMarketCapString(), // Formatted market cap value "$1,234,567 USD" etc.
171-
167+
currentSentPriceUSDString = "\$" + infoResponse.priceData.tokenPriceUSD.formatWithDecimalPlaces(2) + " $USD_NAME_SHORT", // Formatted token price value "$1.23 USD" etc.
168+
currentMarketCapUSDString = if(infoResponse.priceData.marketCapUSD == null) unavailableString
169+
else "\$" + infoResponse.priceData.marketCapUSD.formatWithDecimalPlaces( 0) + " $USD_NAME_SHORT", // Formatted market cap value "$1,234,567 USD" etc.
170+
172171
currentStakingRewardPool = infoResponse.tokenData.stakingRewardPool,
173172
currentStakingRewardPoolString = infoResponse.tokenData.getLocaleFormattedStakingRewardPool() + " $TOKEN_NAME_SHORT",
174173

0 commit comments

Comments
 (0)