Updated on 2026-08-14
This commit is contained in:
parent
54800d32cc
commit
faa58cf142
39 changed files with 722 additions and 245 deletions
|
|
@ -1,10 +1,7 @@
|
|||
package com.tangem.core.ui.components.marketprice
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
|
@ -26,6 +23,11 @@ fun PriceChangeInPercent(
|
|||
modifier: Modifier = Modifier,
|
||||
textStyle: TextStyle = TangemTheme.typography.body2,
|
||||
) {
|
||||
if (valueInPercent.isBlank()) {
|
||||
Box(modifier)
|
||||
return
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = modifier,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,13 @@ object BigDecimalFormatter {
|
|||
private const val FIAT_MARKET_DEFAULT_DIGITS = 2
|
||||
private const val FIAT_MARKET_EXTENDED_DIGITS = 6
|
||||
|
||||
private val bigDecimal01 = BigDecimal("0.1")
|
||||
private val bigDecimal001 = BigDecimal("0.01")
|
||||
private val bigDecimal0001 = BigDecimal("0.001")
|
||||
private val bigDecimal00001 = BigDecimal("0.0001")
|
||||
private val bigDecimal000001 = BigDecimal("0.00001")
|
||||
private val bigDecimal0000001 = BigDecimal("0.000001")
|
||||
|
||||
fun formatCryptoAmount(
|
||||
cryptoAmount: BigDecimal?,
|
||||
cryptoCurrency: String,
|
||||
|
|
@ -169,6 +176,28 @@ object BigDecimalFormatter {
|
|||
.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol)
|
||||
}
|
||||
|
||||
fun formatFiatPriceUncapped(
|
||||
fiatAmount: BigDecimal?,
|
||||
fiatCurrencyCode: String,
|
||||
fiatCurrencySymbol: String,
|
||||
locale: Locale = Locale.getDefault(),
|
||||
): String {
|
||||
if (fiatAmount == null) return EMPTY_BALANCE_SIGN
|
||||
val formatterCurrency = getCurrency(fiatCurrencyCode)
|
||||
|
||||
val decimals = getProperFiatPriceDecimals(fiatAmount)
|
||||
|
||||
val formatter = NumberFormat.getCurrencyInstance(locale).apply {
|
||||
currency = formatterCurrency
|
||||
maximumFractionDigits = decimals
|
||||
minimumFractionDigits = FIAT_MARKET_DEFAULT_DIGITS
|
||||
roundingMode = RoundingMode.HALF_UP
|
||||
}
|
||||
|
||||
return formatter.format(fiatAmount)
|
||||
.replace(formatterCurrency.getSymbol(locale), fiatCurrencySymbol)
|
||||
}
|
||||
|
||||
fun formatFiatEditableAmount(
|
||||
fiatAmount: String?,
|
||||
fiatCurrencyCode: String,
|
||||
|
|
@ -330,4 +359,18 @@ object BigDecimalFormatter {
|
|||
}
|
||||
|
||||
private fun BigDecimal.isLessThanThreshold() = this > BigDecimal.ZERO && this < FIAT_FORMAT_THRESHOLD
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
fun getProperFiatPriceDecimals(price: BigDecimal): Int {
|
||||
return when {
|
||||
price >= BigDecimal.ONE -> 2
|
||||
price >= bigDecimal01 -> 3
|
||||
price >= bigDecimal001 -> 4
|
||||
price >= bigDecimal0001 -> 6
|
||||
price >= bigDecimal00001 -> 8
|
||||
price >= bigDecimal000001 -> 10
|
||||
price >= bigDecimal0000001 -> 12
|
||||
else -> price.stripTrailingZeros().scale()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,8 +10,6 @@ import java.util.Locale
|
|||
@Suppress("MagicNumber")
|
||||
object DateTimeFormatters {
|
||||
|
||||
private const val DDMMYYYY = "dd.MM.yyyy"
|
||||
|
||||
/**
|
||||
* Two SS means, SHORT style for date and time.
|
||||
* If pattern contains "a", it means time is in 12 hour format.
|
||||
|
|
@ -51,7 +49,7 @@ object DateTimeFormatters {
|
|||
|
||||
val dateDDMMYYYY: DateTimeFormatter by lazy {
|
||||
DateTimeFormatterBuilder()
|
||||
.appendPattern(DDMMYYYY)
|
||||
.appendPattern("dd.MM.yyyy")
|
||||
.toFormatter()
|
||||
.withLocale(Locale.getDefault())
|
||||
}
|
||||
|
|
@ -59,18 +57,12 @@ object DateTimeFormatters {
|
|||
/**
|
||||
* In API version < 24, there may be some problems with getting the best date and time format pattern.
|
||||
*/
|
||||
val dateMMMMd: DateTimeFormatter by lazy {
|
||||
DateTimeFormatterBuilder()
|
||||
.appendPattern(DateFormat.getBestDateTimePattern(Locale.getDefault(), "dd MMM"))
|
||||
.toFormatter()
|
||||
.withLocale(Locale.getDefault())
|
||||
val dateMMMdd: DateTimeFormatter by lazy {
|
||||
getBestFormatterBySkeleton("dd MMM")
|
||||
}
|
||||
|
||||
val dateYYYY: DateTimeFormatter by lazy {
|
||||
DateTimeFormatterBuilder()
|
||||
.appendPattern(DateFormat.getBestDateTimePattern(Locale.getDefault(), "yyyy"))
|
||||
.toFormatter()
|
||||
.withLocale(Locale.getDefault())
|
||||
getBestFormatterBySkeleton("yyyy")
|
||||
}
|
||||
|
||||
val dateTimeFormatter: DateTimeFormatter by lazy {
|
||||
|
|
@ -80,4 +72,11 @@ object DateTimeFormatters {
|
|||
fun formatDate(date: DateTime, formatter: DateTimeFormatter = dateFormatter): String {
|
||||
return formatter.print(date)
|
||||
}
|
||||
|
||||
fun getBestFormatterBySkeleton(skeleton: String): DateTimeFormatter {
|
||||
return DateTimeFormatterBuilder()
|
||||
.appendPattern(DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton))
|
||||
.toFormatter()
|
||||
.withLocale(Locale.getDefault())
|
||||
}
|
||||
}
|
||||
|
|
@ -29,5 +29,12 @@ fun Long.toDateFormatWithTodayYesterday(formatter: DateTimeFormatter = DateTimeF
|
|||
* Returns formatted time according to [formatter].
|
||||
*/
|
||||
fun Long.toTimeFormat(formatter: DateTimeFormatter = DateTimeFormatters.timeFormatter): String {
|
||||
return formatAsDateTime(formatter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted date-time according to [formatter].
|
||||
*/
|
||||
fun Long.formatAsDateTime(formatter: DateTimeFormatter): String {
|
||||
return DateTimeFormatters.formatDate(date = DateTime(this, DateTimeZone.getDefault()), formatter = formatter)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue