Updated on 2026-08-14
This commit is contained in:
parent
0dc09b91b2
commit
74ce535550
5 changed files with 52 additions and 31 deletions
|
|
@ -75,13 +75,13 @@ data class CryptoCurrencyStatus(
|
|||
*/
|
||||
data class NoAccount(
|
||||
val amountToCreateAccount: BigDecimal,
|
||||
override val fiatAmount: BigDecimal?,
|
||||
override val priceChange: BigDecimal?,
|
||||
override val fiatRate: BigDecimal?,
|
||||
override val networkAddress: NetworkAddress?,
|
||||
) : Status(isError = false) {
|
||||
|
||||
override val amount: BigDecimal = BigDecimal.ZERO
|
||||
override val fiatAmount: BigDecimal = BigDecimal.ZERO
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ internal class CurrencyStatusOperations(
|
|||
private fun createNoAccountStatus(status: NetworkStatus.NoAccount): CryptoCurrencyStatus.NoAccount =
|
||||
CryptoCurrencyStatus.NoAccount(
|
||||
amountToCreateAccount = status.amountToCreateAccount,
|
||||
fiatAmount = if (quote == null) null else BigDecimal.ZERO,
|
||||
priceChange = quote?.priceChange,
|
||||
fiatRate = quote?.fiatRate,
|
||||
networkAddress = status.address,
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ internal object MockTokensStates {
|
|||
val tokenState7 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token7,
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
fiatAmount = BigDecimal.ZERO,
|
||||
priceChange = MockQuotes.quote7.priceChange,
|
||||
fiatRate = MockQuotes.quote7.fiatRate,
|
||||
amountToCreateAccount = MockNetworks.amountToCreateAccount,
|
||||
|
|
@ -70,6 +71,7 @@ internal object MockTokensStates {
|
|||
val tokenState8 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token8,
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
fiatAmount = BigDecimal.ZERO,
|
||||
priceChange = MockQuotes.quote8.priceChange,
|
||||
fiatRate = MockQuotes.quote8.fiatRate,
|
||||
amountToCreateAccount = MockNetworks.amountToCreateAccount,
|
||||
|
|
@ -80,6 +82,7 @@ internal object MockTokensStates {
|
|||
val tokenState9 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token9,
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
fiatAmount = BigDecimal.ZERO,
|
||||
priceChange = MockQuotes.quote9.priceChange,
|
||||
fiatRate = MockQuotes.quote9.fiatRate,
|
||||
amountToCreateAccount = MockNetworks.amountToCreateAccount,
|
||||
|
|
@ -90,6 +93,7 @@ internal object MockTokensStates {
|
|||
val tokenState10 = CryptoCurrencyStatus(
|
||||
currency = MockTokens.token10,
|
||||
value = CryptoCurrencyStatus.NoAccount(
|
||||
fiatAmount = BigDecimal.ZERO,
|
||||
priceChange = MockQuotes.quote10.priceChange,
|
||||
fiatRate = MockQuotes.quote10.fiatRate,
|
||||
amountToCreateAccount = MockNetworks.amountToCreateAccount,
|
||||
|
|
|
|||
|
|
@ -90,23 +90,33 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
return when (status) {
|
||||
is CryptoCurrencyStatus.Loading -> MarketPriceBlockState.Loading(currencySymbol)
|
||||
is CryptoCurrencyStatus.NoQuote -> MarketPriceBlockState.Error(currencySymbol)
|
||||
is CryptoCurrencyStatus.NoAccount -> {
|
||||
if (status.fiatRate == null) {
|
||||
MarketPriceBlockState.Error(currencySymbol)
|
||||
} else {
|
||||
status.toContentConfig(currencySymbol)
|
||||
}
|
||||
}
|
||||
is CryptoCurrencyStatus.Loaded,
|
||||
is CryptoCurrencyStatus.Custom,
|
||||
is CryptoCurrencyStatus.MissedDerivation,
|
||||
is CryptoCurrencyStatus.NoAccount,
|
||||
is CryptoCurrencyStatus.Unreachable,
|
||||
is CryptoCurrencyStatus.NoAmount,
|
||||
-> MarketPriceBlockState.Content(
|
||||
currencySymbol = currencySymbol,
|
||||
price = formatPrice(status, appCurrencyProvider()),
|
||||
priceChangeConfig = PriceChangeState.Content(
|
||||
valueInPercent = formatPriceChange(status),
|
||||
type = getPriceChangeType(status),
|
||||
),
|
||||
)
|
||||
-> status.toContentConfig(currencySymbol)
|
||||
}
|
||||
}
|
||||
|
||||
private fun CryptoCurrencyStatus.Status.toContentConfig(currencySymbol: String): MarketPriceBlockState.Content {
|
||||
return MarketPriceBlockState.Content(
|
||||
currencySymbol = currencySymbol,
|
||||
price = formatPrice(status = this, appCurrency = appCurrencyProvider()),
|
||||
priceChangeConfig = PriceChangeState.Content(
|
||||
valueInPercent = formatPriceChange(status = this),
|
||||
type = getPriceChangeType(status = this),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun getPriceChangeType(status: CryptoCurrencyStatus.Status): PriceChangeType {
|
||||
val priceChange = status.priceChange ?: return PriceChangeType.DOWN
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ internal class WalletSingleCurrencyLoadedBalanceConverter(
|
|||
|
||||
state.copy(
|
||||
walletsListConfig = getUpdatedSelectedWallet(status = status.value, state = state),
|
||||
marketPriceBlockState = getMarketPriceState(status = status.value, currencyName = currencyName),
|
||||
marketPriceBlockState = getMarketPriceState(status = status.value, currencySymbol = currencyName),
|
||||
)
|
||||
}
|
||||
is WalletMultiCurrencyState.Content,
|
||||
|
|
@ -54,32 +54,27 @@ internal class WalletSingleCurrencyLoadedBalanceConverter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getMarketPriceState(status: CryptoCurrencyStatus.Status, currencyName: String): MarketPriceBlockState {
|
||||
private fun getMarketPriceState(
|
||||
status: CryptoCurrencyStatus.Status,
|
||||
currencySymbol: String,
|
||||
): MarketPriceBlockState {
|
||||
return when (status) {
|
||||
is CryptoCurrencyStatus.NoQuote -> MarketPriceBlockState.Error(currencyName)
|
||||
is CryptoCurrencyStatus.Loaded,
|
||||
is CryptoCurrencyStatus.NoAmount,
|
||||
-> MarketPriceBlockState.Content(
|
||||
currencySymbol = currencyName,
|
||||
price = formatPrice(status, appCurrencyProvider()),
|
||||
priceChangeConfig = PriceChangeState.Content(
|
||||
valueInPercent = formatPriceChange(status),
|
||||
type = getPriceChangeType(status),
|
||||
),
|
||||
)
|
||||
is CryptoCurrencyStatus.NoAccount -> MarketPriceBlockState.Content(
|
||||
currencySymbol = currencyName,
|
||||
price = formatPrice(status, appCurrencyProvider()),
|
||||
priceChangeConfig = PriceChangeState.Content(
|
||||
valueInPercent = formatPriceChange(status),
|
||||
type = getPriceChangeType(status),
|
||||
),
|
||||
)
|
||||
is CryptoCurrencyStatus.Loading -> MarketPriceBlockState.Loading(currencyName)
|
||||
-> status.toContentConfig(currencySymbol)
|
||||
is CryptoCurrencyStatus.NoAccount -> {
|
||||
if (status.fiatRate == null) {
|
||||
MarketPriceBlockState.Error(currencySymbol)
|
||||
} else {
|
||||
status.toContentConfig(currencySymbol)
|
||||
}
|
||||
}
|
||||
is CryptoCurrencyStatus.Loading -> MarketPriceBlockState.Loading(currencySymbol)
|
||||
is CryptoCurrencyStatus.Custom,
|
||||
is CryptoCurrencyStatus.MissedDerivation,
|
||||
is CryptoCurrencyStatus.Unreachable,
|
||||
-> MarketPriceBlockState.Error(currencyName)
|
||||
is CryptoCurrencyStatus.NoQuote,
|
||||
-> MarketPriceBlockState.Error(currencySymbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,6 +133,17 @@ internal class WalletSingleCurrencyLoadedBalanceConverter(
|
|||
)
|
||||
}
|
||||
|
||||
private fun CryptoCurrencyStatus.Status.toContentConfig(currencySymbol: String): MarketPriceBlockState.Content {
|
||||
return MarketPriceBlockState.Content(
|
||||
currencySymbol = currencySymbol,
|
||||
price = formatPrice(status = this, appCurrency = appCurrencyProvider()),
|
||||
priceChangeConfig = PriceChangeState.Content(
|
||||
valueInPercent = formatPriceChange(status = this),
|
||||
type = getPriceChangeType(status = this),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun getPriceChangeType(status: CryptoCurrencyStatus.Status): PriceChangeType {
|
||||
val priceChange = status.priceChange ?: return PriceChangeType.DOWN
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue