Updated on 2026-08-14
This commit is contained in:
parent
bc3534c277
commit
6a15cfd2e4
5 changed files with 96 additions and 38 deletions
|
|
@ -67,16 +67,17 @@ private fun LazyListScope.contentItems(
|
|||
},
|
||||
contentType = txHistoryItems.itemContentType { it::class.java },
|
||||
itemContent = { index ->
|
||||
val item = txHistoryItems[index]!!
|
||||
TxHistoryListItem(
|
||||
state = item,
|
||||
modifier = modifier
|
||||
.animateItemPlacement()
|
||||
.roundedShapeItemDecoration(
|
||||
currentIndex = index,
|
||||
lastIndex = txHistoryItems.itemSnapshotList.lastIndex,
|
||||
),
|
||||
)
|
||||
txHistoryItems[index]?.let { item ->
|
||||
TxHistoryListItem(
|
||||
state = item,
|
||||
modifier = modifier
|
||||
.animateItemPlacement()
|
||||
.roundedShapeItemDecoration(
|
||||
currentIndex = index,
|
||||
lastIndex = txHistoryItems.itemSnapshotList.lastIndex,
|
||||
),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,25 +51,36 @@ data class CryptoCurrencyStatus(
|
|||
object Loading : Status(isError = false)
|
||||
|
||||
/** Represents a state where the cryptocurrency is not reachable. */
|
||||
object Unreachable : Status(isError = true)
|
||||
data class Unreachable(
|
||||
override val priceChange: BigDecimal?,
|
||||
override val fiatRate: BigDecimal?,
|
||||
) : Status(isError = true)
|
||||
|
||||
/** Represents a state where the cryptocurrency's network amount not found. */
|
||||
object NoAmount : Status(isError = true)
|
||||
data class NoAmount(
|
||||
override val priceChange: BigDecimal?,
|
||||
override val fiatRate: BigDecimal?,
|
||||
) : Status(isError = true)
|
||||
|
||||
/** Represents a state where the cryptocurrency's derivation is missed. */
|
||||
object MissedDerivation : Status(isError = true)
|
||||
data class MissedDerivation(
|
||||
override val priceChange: BigDecimal?,
|
||||
override val fiatRate: BigDecimal?,
|
||||
) : Status(isError = true)
|
||||
|
||||
/**
|
||||
* Represents a state where there is no account associated with the cryptocurrency
|
||||
*
|
||||
* @property errorMessage error message
|
||||
*/
|
||||
data class NoAccount(val errorMessage: String) : Status(isError = false) {
|
||||
data class NoAccount(
|
||||
val errorMessage: String,
|
||||
override val priceChange: BigDecimal?,
|
||||
override val fiatRate: BigDecimal?,
|
||||
) : Status(isError = false) {
|
||||
|
||||
override val amount: BigDecimal = BigDecimal.ZERO
|
||||
override val fiatAmount: BigDecimal = BigDecimal.ZERO
|
||||
override val fiatRate: BigDecimal = BigDecimal.ZERO
|
||||
override val priceChange: BigDecimal = BigDecimal.ZERO
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,15 +18,28 @@ internal class CurrencyStatusOperations(
|
|||
private fun createStatus(): CryptoCurrencyStatus.Status {
|
||||
return when (val status = networkStatus?.value) {
|
||||
null -> CryptoCurrencyStatus.Loading
|
||||
is NetworkStatus.MissedDerivation -> CryptoCurrencyStatus.MissedDerivation
|
||||
is NetworkStatus.Unreachable -> CryptoCurrencyStatus.Unreachable
|
||||
is NetworkStatus.NoAccount -> CryptoCurrencyStatus.NoAccount(errorMessage = status.errorMessage)
|
||||
is NetworkStatus.MissedDerivation -> createMissedDerivationStatus()
|
||||
is NetworkStatus.Unreachable -> createUnreachableStatus()
|
||||
is NetworkStatus.NoAccount -> createNoAccountStatus(status.errorMessage)
|
||||
is NetworkStatus.Verified -> createStatus(status)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createMissedDerivationStatus(): CryptoCurrencyStatus.MissedDerivation =
|
||||
CryptoCurrencyStatus.MissedDerivation(priceChange = quote?.priceChange, fiatRate = quote?.fiatRate)
|
||||
|
||||
private fun createUnreachableStatus(): CryptoCurrencyStatus.Unreachable =
|
||||
CryptoCurrencyStatus.Unreachable(priceChange = quote?.priceChange, fiatRate = quote?.fiatRate)
|
||||
|
||||
private fun createNoAccountStatus(message: String): CryptoCurrencyStatus.NoAccount = CryptoCurrencyStatus.NoAccount(
|
||||
errorMessage = message,
|
||||
priceChange = quote?.priceChange,
|
||||
fiatRate = quote?.fiatRate,
|
||||
)
|
||||
|
||||
private fun createStatus(status: NetworkStatus.Verified): CryptoCurrencyStatus.Status {
|
||||
val amount = status.amounts[currency.id] ?: return CryptoCurrencyStatus.NoAmount
|
||||
val amount = status.amounts[currency.id]
|
||||
?: return CryptoCurrencyStatus.NoAmount(priceChange = quote?.priceChange, fiatRate = quote?.fiatRate)
|
||||
val hasCurrentNetworkTransactions = status.pendingTransactions.isNotEmpty()
|
||||
val currentTransactions = status.pendingTransactions.getOrElse(currency.id, ::emptySet)
|
||||
|
||||
|
|
|
|||
|
|
@ -9,52 +9,86 @@ internal object MockTokensStates {
|
|||
|
||||
val tokenState1 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token1,
|
||||
value = CryptoCurrencyStatus.Unreachable,
|
||||
value = CryptoCurrencyStatus.Unreachable(
|
||||
priceChange = MockQuotes.quote1.priceChange,
|
||||
fiatRate = MockQuotes.quote1.fiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState2 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token2,
|
||||
value = CryptoCurrencyStatus.Unreachable,
|
||||
value = CryptoCurrencyStatus.Unreachable(
|
||||
priceChange = MockQuotes.quote2.priceChange,
|
||||
fiatRate = MockQuotes.quote2.fiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState3 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token3,
|
||||
value = CryptoCurrencyStatus.Unreachable,
|
||||
value = CryptoCurrencyStatus.Unreachable(
|
||||
priceChange = MockQuotes.quote3.priceChange,
|
||||
fiatRate = MockQuotes.quote3.fiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState4 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token4,
|
||||
value = CryptoCurrencyStatus.MissedDerivation,
|
||||
value = CryptoCurrencyStatus.MissedDerivation(
|
||||
priceChange = MockQuotes.quote4.priceChange,
|
||||
fiatRate = MockQuotes.quote4.fiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState5 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token5,
|
||||
value = CryptoCurrencyStatus.MissedDerivation,
|
||||
value = CryptoCurrencyStatus.MissedDerivation(
|
||||
priceChange = MockQuotes.quote5.priceChange,
|
||||
fiatRate = MockQuotes.quote5.fiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState6 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token6,
|
||||
value = CryptoCurrencyStatus.MissedDerivation,
|
||||
value = CryptoCurrencyStatus.MissedDerivation(
|
||||
priceChange = MockQuotes.quote6.priceChange,
|
||||
fiatRate = MockQuotes.quote6.fiatRate,
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState7 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token7,
|
||||
value = CryptoCurrencyStatus.NoAccount(errorMessage = ""),
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
priceChange = MockQuotes.quote7.priceChange,
|
||||
fiatRate = MockQuotes.quote7.fiatRate,
|
||||
errorMessage = "",
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState8 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token8,
|
||||
value = CryptoCurrencyStatus.NoAccount(errorMessage = ""),
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
priceChange = MockQuotes.quote8.priceChange,
|
||||
fiatRate = MockQuotes.quote8.fiatRate,
|
||||
errorMessage = "",
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState9 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token9,
|
||||
value = CryptoCurrencyStatus.NoAccount(errorMessage = ""),
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
priceChange = MockQuotes.quote9.priceChange,
|
||||
fiatRate = MockQuotes.quote9.fiatRate,
|
||||
errorMessage = "",
|
||||
),
|
||||
)
|
||||
|
||||
val tokenState10 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token10,
|
||||
value = CryptoCurrencyStatus.NoAccount(errorMessage = ""),
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
priceChange = MockQuotes.quote10.priceChange,
|
||||
fiatRate = MockQuotes.quote10.fiatRate,
|
||||
errorMessage = "",
|
||||
),
|
||||
)
|
||||
|
||||
val failedTokenStates = nonEmptyListOf(
|
||||
|
|
|
|||
|
|
@ -84,8 +84,14 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
|
||||
private fun getMarketPriceState(status: CryptoCurrencyStatus.Status, currencyName: String): MarketPriceBlockState {
|
||||
return when (status) {
|
||||
is CryptoCurrencyStatus.NoQuote,
|
||||
is CryptoCurrencyStatus.Loading -> MarketPriceBlockState.Loading(currencyName)
|
||||
is CryptoCurrencyStatus.NoQuote -> MarketPriceBlockState.Error(currencyName)
|
||||
is CryptoCurrencyStatus.Loaded,
|
||||
is CryptoCurrencyStatus.Custom,
|
||||
is CryptoCurrencyStatus.MissedDerivation,
|
||||
is CryptoCurrencyStatus.NoAccount,
|
||||
is CryptoCurrencyStatus.NoAmount,
|
||||
is CryptoCurrencyStatus.Unreachable,
|
||||
-> MarketPriceBlockState.Content(
|
||||
currencyName = currencyName,
|
||||
price = formatPrice(status, appCurrencyProvider()),
|
||||
|
|
@ -94,13 +100,6 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
type = getPriceChangeType(status),
|
||||
),
|
||||
)
|
||||
is CryptoCurrencyStatus.Loading -> MarketPriceBlockState.Loading(currencyName)
|
||||
is CryptoCurrencyStatus.Custom,
|
||||
is CryptoCurrencyStatus.MissedDerivation,
|
||||
is CryptoCurrencyStatus.NoAccount,
|
||||
is CryptoCurrencyStatus.NoAmount,
|
||||
is CryptoCurrencyStatus.Unreachable,
|
||||
-> MarketPriceBlockState.Error(currencyName)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue