Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-19 12:38:07 +02:00
parent c49b3a9176
commit 8467ada25d
16 changed files with 156 additions and 50 deletions

View file

@ -3,11 +3,7 @@ package com.tangem.core.ui.components.token.internal
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -85,14 +81,14 @@ private fun CurrencyNameText(name: String, isAvailable: Boolean, modifier: Modif
private fun YieldSupplyApyLabel(apy: TextReference?, isActive: Boolean, modifier: Modifier = Modifier) {
AnimatedVisibility(visible = apy != null, modifier = modifier) {
Box(
modifier = if (isActive) {
modifier.background(
color = TangemTheme.colors.text.accent.copy(alpha = 0.1f),
shape = TangemTheme.shapes.roundedCornersSmall2,
)
} else {
modifier
},
modifier = Modifier.background(
color = if (isActive) {
TangemTheme.colors.text.accent.copy(alpha = 0.1f)
} else {
TangemTheme.colors.control.unchecked
},
shape = TangemTheme.shapes.roundedCornersSmall2,
),
) {
Text(
text = apy?.resolveReference().orEmpty(),
@ -100,7 +96,7 @@ private fun YieldSupplyApyLabel(apy: TextReference?, isActive: Boolean, modifier
color = if (isActive) {
TangemTheme.colors.text.accent
} else {
TangemTheme.colors.text.tertiary
TangemTheme.colors.text.secondary
},
modifier = Modifier.padding(horizontal = 4.dp, vertical = 2.dp),
)

View file

@ -7,6 +7,7 @@ import java.util.Locale
class BigDecimalPercentFormat(
val isWithoutSign: Boolean = true,
val withPercentSign: Boolean = true,
val locale: Locale = Locale.getDefault(),
) : BigDecimalFormat {
override fun invoke(value: BigDecimal): String = default()(value)
@ -16,24 +17,30 @@ class BigDecimalPercentFormat(
fun BigDecimalFormatScope.percent(
withoutSign: Boolean = true,
withPercentSign: Boolean = true,
locale: Locale = Locale.getDefault(),
): BigDecimalPercentFormat {
return BigDecimalPercentFormat(
isWithoutSign = withoutSign,
locale = locale,
withPercentSign = withPercentSign,
)
}
// == Formatters ==
private fun BigDecimalPercentFormat.default(): BigDecimalFormat = BigDecimalFormat { value ->
val formatter = NumberFormat.getPercentInstance(locale).apply {
val formatter = if (withPercentSign) {
NumberFormat.getPercentInstance(locale)
} else {
NumberFormat.getNumberInstance(locale)
}.apply {
maximumFractionDigits = 2
minimumFractionDigits = 2
roundingMode = RoundingMode.HALF_UP
}
val valueToFormat = if (isWithoutSign) value.abs() else value
val finalValue = if (withPercentSign) valueToFormat else valueToFormat.movePointRight(2)
formatter.format(valueToFormat)
formatter.format(finalValue)
}