From 74ce53555067254f0f85ffab8af52bfd19810f1b Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 30 Oct 2023 19:26:02 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../tokens/model/CryptoCurrencyStatus.kt | 2 +- .../operations/CurrencyStatusOperations.kt | 1 + .../domain/tokens/mock/MockTokensStates.kt | 4 ++ .../TokenDetailsLoadedBalanceConverter.kt | 28 +++++++---- ...letSingleCurrencyLoadedBalanceConverter.kt | 48 +++++++++++-------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt index 5b353a1918..5ba1af68eb 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/CryptoCurrencyStatus.kt @@ -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 } /** diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt index dc6f9e3113..131c775492 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CurrencyStatusOperations.kt @@ -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, diff --git a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt index 5b6a22aa34..38338ba598 100644 --- a/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt +++ b/domain/tokens/src/test/kotlin/com/tangem/domain/tokens/mock/MockTokensStates.kt @@ -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, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt index 0899710563..0710f995f6 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsLoadedBalanceConverter.kt @@ -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 diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt index 9d4b7bd566..fade7dadd7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletSingleCurrencyLoadedBalanceConverter.kt @@ -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