Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-18 12:20:15 +03:00
parent 3183f5b955
commit 7ca9946f47
53 changed files with 355 additions and 462 deletions

View file

@ -1,5 +1,7 @@
package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory
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.staking.model.stakekit.YieldBalance
@ -72,6 +74,6 @@ internal class TokenDetailsBalanceSelectStateConverter(
val amount = status.value.amount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN
val totalAmount = amount.getBalance(selectedBalanceType, stakingCryptoAmount)
return BigDecimalFormatter.formatCryptoAmount(totalAmount, status.currency.symbol, status.currency.decimals)
return totalAmount.format { crypto(status.currency) }
}
}

View file

@ -10,6 +10,9 @@ import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.format.bigdecimal.percent
import com.tangem.core.ui.utils.BigDecimalFormatter
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.staking.model.StakingAvailability
@ -215,10 +218,7 @@ internal class TokenDetailsLoadedBalanceConverter(
stakingEntryInfo: StakingEntryInfo,
iconState: IconState,
): StakingBlockUM.StakeAvailable {
val apr = BigDecimalFormatter.formatPercent(
percent = stakingEntryInfo.apr,
useAbsoluteValue = true,
)
val apr = stakingEntryInfo.apr.format { percent() }
return StakingBlockUM.StakeAvailable(
titleText = resourceReference(
id = R.string.token_details_staking_block_title,
@ -243,7 +243,7 @@ internal class TokenDetailsLoadedBalanceConverter(
cryptoAmount = stakingCryptoAmount,
fiatAmount = stakingFiatAmount,
cryptoValue = stringReference(
BigDecimalFormatter.formatCryptoAmount(stakingCryptoAmount, symbol, decimals),
stakingCryptoAmount.format { crypto(symbol = symbol, decimals = decimals) },
),
fiatValue = stringReference(
BigDecimalFormatter.formatFiatAmount(
@ -275,10 +275,7 @@ internal class TokenDetailsLoadedBalanceConverter(
private fun formatPriceChange(status: CryptoCurrencyStatus.Value): String {
val priceChange = status.priceChange ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN
return BigDecimalFormatter.formatPercent(
percent = priceChange,
useAbsoluteValue = true,
)
return priceChange.format { percent() }
}
private fun formatPrice(status: CryptoCurrencyStatus.Value, appCurrency: AppCurrency): String {
@ -315,7 +312,7 @@ internal class TokenDetailsLoadedBalanceConverter(
val amount = status.value.amount ?: return BigDecimalFormatter.EMPTY_BALANCE_SIGN
val totalAmount = amount.getBalance(selectedBalanceType, stakingCryptoAmount)
return BigDecimalFormatter.formatCryptoAmount(totalAmount, status.currency.symbol, status.currency.decimals)
return totalAmount.format { crypto(status.currency) }
}
private fun getRewardText(status: CryptoCurrencyStatus, stakingRewardAmount: BigDecimal?): TextReference {

View file

@ -2,8 +2,10 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchainsdk.utils.fromNetworkId
import com.tangem.core.ui.utils.BigDecimalFormatter
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.format.bigdecimal.shorted
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning
import com.tangem.domain.tokens.model.warnings.HederaWarnings
@ -78,11 +80,9 @@ internal class TokenDetailsNotificationConverter(
CryptoCurrencyWarning.SomeNetworksUnreachable -> NetworksUnreachable
is CryptoCurrencyWarning.SomeNetworksNoAccount -> NetworksNoAccount(
network = warning.amountCurrency.name,
amount = BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = warning.amountToCreateAccount,
cryptoCurrency = "",
decimals = warning.amountCurrency.decimals,
),
amount = warning.amountToCreateAccount.format {
crypto(symbol = "", decimals = warning.amountCurrency.decimals)
},
symbol = warning.amountCurrency.symbol,
)
is CryptoCurrencyWarning.TopUpWithoutReserve -> TopUpWithoutReserve
@ -105,11 +105,7 @@ internal class TokenDetailsNotificationConverter(
)
is HederaWarnings.AssociateWarningWithFee -> HederaAssociateWarning(
currency = warning.currency,
fee = BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = warning.fee,
cryptoCurrency = "",
decimals = warning.feeCurrencyDecimals,
),
fee = warning.fee.format { crypto(symbol = "", decimals = warning.feeCurrencyDecimals) },
feeCurrencySymbol = warning.feeCurrencySymbol,
onAssociateClick = clickIntents::onAssociateClick,
)
@ -127,11 +123,7 @@ internal class TokenDetailsNotificationConverter(
}
private fun formatMana(amount: BigDecimal): String {
return BigDecimalFormatter.formatCryptoAmountShorted(
cryptoAmount = amount,
cryptoCurrency = "",
decimals = Blockchain.Koinos.decimals(),
)
return amount.format { crypto("", Blockchain.Koinos.decimals()).shorted() }
}
// workaround for networks that users have misunderstanding

View file

@ -3,6 +3,8 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.factory
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter
import com.tangem.core.ui.extensions.TextReference
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.core.ui.utils.toDateFormatWithTodayYesterday
import com.tangem.core.ui.utils.toTimeFormat
@ -80,17 +82,11 @@ internal class TokenDetailsSwapTransactionsStateConverter(
activeStatus = transaction.status?.status,
notification = notifications,
toCryptoCurrency = toCryptoCurrency,
toCryptoAmount = BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = toAmount,
cryptoCurrency = toCryptoCurrency,
),
toCryptoAmount = toAmount.format { crypto(toCryptoCurrency) },
toFiatAmount = getFiatAmount(toFiatAmount),
toCurrencyIcon = iconStateConverter.convert(toCryptoCurrency),
fromCryptoCurrency = fromCryptoCurrency,
fromCryptoAmount = BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = fromAmount,
cryptoCurrency = fromCryptoCurrency,
),
fromCryptoAmount = fromAmount.format { crypto(fromCryptoCurrency) },
fromFiatAmount = getFiatAmount(fromFiatAmount),
fromCurrencyIcon = iconStateConverter.convert(fromCryptoCurrency),
showProviderLink = showProviderLink,

View file

@ -7,6 +7,8 @@ import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.utils.toTimeFormat
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryItem.*
@ -16,7 +18,6 @@ import com.tangem.utils.StringsSigns.MINUS
import com.tangem.utils.StringsSigns.PLUS
import com.tangem.utils.converter.Converter
import com.tangem.utils.toBriefAddressFormat
import com.tangem.utils.toFormattedCurrencyString
internal class TokenDetailsTxHistoryTransactionStateConverter(
private val symbol: String,
@ -129,6 +130,6 @@ internal class TokenDetailsTxHistoryTransactionStateConverter(
this.amount.isZero() -> ""
else -> if (isOutgoing) MINUS else PLUS
}
return prefix + amount.toFormattedCurrencyString(currency = symbol, decimals = decimals)
return prefix + amount.format { crypto(symbol = symbol, decimals = decimals) }
}
}