From 706e21f4fbb2317dfe02c29faa8b5971df4421f1 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 3 Jun 2024 16:05:50 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../utils/CryptoCurrencyFormatExtensions.kt | 21 ------------------- .../feature/swap/domain/SwapInteractorImpl.kt | 16 ++++++++------ 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/core/utils/src/main/java/com/tangem/utils/CryptoCurrencyFormatExtensions.kt b/core/utils/src/main/java/com/tangem/utils/CryptoCurrencyFormatExtensions.kt index a2533147f7..ce1a6d2470 100644 --- a/core/utils/src/main/java/com/tangem/utils/CryptoCurrencyFormatExtensions.kt +++ b/core/utils/src/main/java/com/tangem/utils/CryptoCurrencyFormatExtensions.kt @@ -40,25 +40,4 @@ fun BigDecimal.toFormattedCurrencyString( ) val formattedCurrency = currency?.let { " $it" } ?: "" return "$formattedAmount$formattedCurrency" -} - -fun BigDecimal.toFiatString( - rateValue: BigDecimal, - fiatCurrencyName: String, - formatWithSpaces: Boolean = false, -): String { - val fiatValue = rateValue.multiply(this) - val formatter = NumberFormat.getInstance(Locale.getDefault()) as? DecimalFormat - val df = formatter?.apply { - maximumFractionDigits = 2 - minimumFractionDigits = 2 - isGroupingUsed = true - this.roundingMode = roundingMode - } - val formatted = if (formatWithSpaces) { - "${df?.format(fiatValue)} $fiatCurrencyName" - } else { - "${df?.format(fiatValue)}$fiatCurrencyName" - } - return formatted } \ No newline at end of file diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index ab1e044b30..9babfe5a73 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -9,6 +9,7 @@ import com.tangem.blockchain.common.BlockchainSdkError import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchain.common.transaction.TransactionFee import com.tangem.blockchainsdk.utils.minimalAmount +import com.tangem.core.ui.utils.BigDecimalFormatter import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase import com.tangem.domain.appcurrency.extenstions.unwrap @@ -46,7 +47,6 @@ import com.tangem.lib.crypto.UserWalletManager import com.tangem.lib.crypto.models.* import com.tangem.lib.crypto.models.transactions.SendTxResult import com.tangem.utils.coroutines.CoroutineDispatcherProvider -import com.tangem.utils.toFiatString import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.firstOrNull import timber.log.Timber @@ -905,10 +905,10 @@ internal class SwapInteractorImpl @Inject constructor( private suspend fun createEmptyAmountState(): SwapState { val appCurrency = getSelectedAppCurrencyUseCase.unwrap() return SwapState.EmptyAmountState( - zeroAmountEquivalent = BigDecimal.ZERO.toFiatString( - rateValue = BigDecimal.ONE, - fiatCurrencyName = appCurrency.symbol, - formatWithSpaces = true, + zeroAmountEquivalent = BigDecimalFormatter.formatFiatAmount( + fiatAmount = BigDecimal.ZERO, + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, ), ) } @@ -1155,7 +1155,11 @@ internal class SwapInteractorImpl @Inject constructor( val rates = getQuotes(feeCurrencyId) return rates[feeCurrencyId]?.fiatRate?.let { rate -> fees.map { fee -> - fee.toFiatString(rate, appCurrency.symbol, true) + BigDecimalFormatter.formatFiatAmount( + fiatAmount = rate.multiply(fee), + fiatCurrencyCode = appCurrency.code, + fiatCurrencySymbol = appCurrency.symbol, + ) } }.orEmpty() }