Updated on 2026-08-14
This commit is contained in:
parent
3183f5b955
commit
7ca9946f47
53 changed files with 355 additions and 462 deletions
|
|
@ -2,6 +2,8 @@ package com.tangem.feature.swap.converters
|
|||
|
||||
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
|
||||
import com.tangem.core.ui.extensions.*
|
||||
import com.tangem.core.ui.format.bigdecimal.crypto
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.core.ui.utils.BigDecimalFormatter
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -103,11 +105,9 @@ class TokensDataConverter(
|
|||
}
|
||||
|
||||
private fun formatCryptoAmount(cryptoCurrencyStatus: CryptoCurrencyStatus): String {
|
||||
return BigDecimalFormatter.formatCryptoAmount(
|
||||
cryptoCurrencyStatus.value.amount,
|
||||
cryptoCurrencyStatus.currency.symbol,
|
||||
cryptoCurrencyStatus.currency.decimals,
|
||||
)
|
||||
return cryptoCurrencyStatus.value.amount.format {
|
||||
crypto(cryptoCurrencyStatus.currency)
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatFiatAmount(cryptoCurrencyStatus: CryptoCurrencyStatus, appCurrency: AppCurrency): String {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.feature.swap.di
|
||||
|
||||
import com.tangem.feature.swap.di.impl.DefaultAmountFormatter
|
||||
import com.tangem.feature.swap.domain.models.ui.AmountFormatter
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class SwapSingletonModule {
|
||||
|
||||
@Provides
|
||||
fun provideAmountFormatter(): AmountFormatter {
|
||||
return DefaultAmountFormatter()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package com.tangem.feature.swap.di.impl
|
||||
|
||||
import com.tangem.core.ui.format.bigdecimal.crypto
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.ui.AmountFormatter
|
||||
import java.math.BigDecimal
|
||||
|
||||
class DefaultAmountFormatter : AmountFormatter {
|
||||
|
||||
override fun formatSwapAmountToUI(swapAmount: SwapAmount, currency: String): String {
|
||||
return swapAmount.value.format { crypto(symbol = currency, decimals = swapAmount.decimals) }
|
||||
}
|
||||
|
||||
override fun formatBigDecimalAmountToUI(amount: BigDecimal, decimals: Int, currency: String?): String {
|
||||
return amount.format { crypto(symbol = currency.orEmpty(), decimals = decimals) }
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,10 @@ import com.tangem.core.ui.components.notifications.NotificationConfig
|
|||
import com.tangem.core.ui.event.consumedEvent
|
||||
import com.tangem.core.ui.event.triggeredEvent
|
||||
import com.tangem.core.ui.extensions.*
|
||||
import com.tangem.core.ui.format.bigdecimal.anyDecimals
|
||||
import com.tangem.core.ui.format.bigdecimal.crypto
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.core.ui.format.bigdecimal.uncapped
|
||||
import com.tangem.core.ui.utils.BigDecimalFormatter
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
|
|
@ -19,12 +23,12 @@ import com.tangem.feature.swap.converters.TokensDataConverter
|
|||
import com.tangem.feature.swap.domain.models.ExpressDataError
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.domain.*
|
||||
import com.tangem.feature.swap.domain.models.formatToUIRepresentation
|
||||
import com.tangem.feature.swap.domain.models.ui.*
|
||||
import com.tangem.feature.swap.models.*
|
||||
import com.tangem.feature.swap.models.states.*
|
||||
import com.tangem.feature.swap.models.states.events.SwapEvent
|
||||
import com.tangem.feature.swap.presentation.R
|
||||
import com.tangem.feature.swap.utils.formatToUIRepresentation
|
||||
import com.tangem.feature.swap.utils.getExpressErrorMessage
|
||||
import com.tangem.feature.swap.utils.getExpressErrorTitle
|
||||
import com.tangem.feature.swap.viewmodels.SwapProcessDataState
|
||||
|
|
@ -469,10 +473,8 @@ internal class StateBuilder(
|
|||
domainWarning: Warning.ExistentialDepositWarning,
|
||||
): SwapWarning {
|
||||
val fromCurrency = quoteModel.fromTokenInfo.cryptoCurrencyStatus.currency
|
||||
val deposit = BigDecimalFormatter.formatCryptoAmountUncapped(
|
||||
cryptoAmount = domainWarning.existentialDeposit,
|
||||
cryptoCurrency = fromCurrency,
|
||||
)
|
||||
val deposit = domainWarning.existentialDeposit.format { crypto(fromCurrency).uncapped() }
|
||||
|
||||
return SwapWarning.GeneralError(
|
||||
NotificationConfig(
|
||||
title = resourceReference(R.string.send_notification_existential_deposit_title),
|
||||
|
|
@ -1546,8 +1548,12 @@ internal class StateBuilder(
|
|||
toTokenInfo.cryptoCurrencyStatus.currency.decimals,
|
||||
)
|
||||
val fromCurrencySymbol = fromTokenInfo.cryptoCurrencyStatus.currency.symbol
|
||||
val toCurrencySymbol = toTokenInfo.cryptoCurrencyStatus.currency.symbol
|
||||
val rateString = "1 $fromCurrencySymbol ≈ $rate $toCurrencySymbol"
|
||||
val rateString = buildString {
|
||||
append(BigDecimal.ONE.format { crypto(symbol = fromCurrencySymbol, decimals = 0).anyDecimals() })
|
||||
append(" ≈ ")
|
||||
append(rate.format { crypto(toTokenInfo.cryptoCurrencyStatus.currency) })
|
||||
}
|
||||
// val rateString = "1 $fromCurrencySymbol ≈ $rate $toCurrencySymbol"
|
||||
val badge = if (isRecommended) {
|
||||
ProviderState.AdditionalBadge.Recommended
|
||||
} else if (isNeedBestRateBadge && isBestRate) {
|
||||
|
|
@ -1628,7 +1634,7 @@ internal class StateBuilder(
|
|||
private fun CryptoCurrencyStatus.getFormattedAmount(isNeedSymbol: Boolean): String {
|
||||
val amount = value.amount ?: return DASH_SIGN
|
||||
val symbol = if (isNeedSymbol) currency.symbol else ""
|
||||
return BigDecimalFormatter.formatCryptoAmount(amount, symbol, currency.decimals)
|
||||
return amount.format { crypto(symbol, currency.decimals) }
|
||||
}
|
||||
|
||||
@Suppress("UnusedPrivateMember")
|
||||
|
|
@ -1646,7 +1652,7 @@ internal class StateBuilder(
|
|||
}
|
||||
|
||||
private fun SwapAmount.getFormattedCryptoAmount(token: CryptoCurrency): String {
|
||||
return BigDecimalFormatter.formatCryptoAmount(value, token.symbol, token.decimals)
|
||||
return value.format { crypto(token) }
|
||||
}
|
||||
|
||||
private fun BigDecimal.calculateRate(to: BigDecimal, decimals: Int): BigDecimal {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ package com.tangem.feature.swap.utils
|
|||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.format.bigdecimal.format
|
||||
import com.tangem.core.ui.format.bigdecimal.simple
|
||||
import com.tangem.feature.swap.domain.models.ExpressDataError
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.presentation.R
|
||||
|
||||
internal fun getExpressErrorMessage(expressDataError: ExpressDataError): TextReference {
|
||||
|
|
@ -38,4 +41,8 @@ internal fun getExpressErrorTitle(expressDataError: ExpressDataError): TextRefer
|
|||
is ExpressDataError.UnknownError -> resourceReference(R.string.common_error)
|
||||
else -> resourceReference(R.string.warning_express_refresh_required_title)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun SwapAmount.formatToUIRepresentation(): String {
|
||||
return value.format { simple(decimals = decimals) }
|
||||
}
|
||||
|
|
@ -40,7 +40,6 @@ import com.tangem.feature.swap.domain.models.ExpressDataError
|
|||
import com.tangem.feature.swap.domain.models.ExpressException
|
||||
import com.tangem.feature.swap.domain.models.SwapAmount
|
||||
import com.tangem.feature.swap.domain.models.domain.*
|
||||
import com.tangem.feature.swap.domain.models.formatToUIRepresentation
|
||||
import com.tangem.feature.swap.domain.models.ui.*
|
||||
import com.tangem.feature.swap.models.SwapStateHolder
|
||||
import com.tangem.feature.swap.models.SwapWarning
|
||||
|
|
@ -49,6 +48,7 @@ import com.tangem.feature.swap.presentation.R
|
|||
import com.tangem.feature.swap.router.SwapNavScreen
|
||||
import com.tangem.feature.swap.router.SwapRouter
|
||||
import com.tangem.feature.swap.ui.StateBuilder
|
||||
import com.tangem.feature.swap.utils.formatToUIRepresentation
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.coroutines.*
|
||||
import com.tangem.utils.isNullOrZero
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue