Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-13 20:57:03 +05:00
parent 333e9fa9cb
commit 6851fb8b25
12 changed files with 75 additions and 27 deletions

View file

@ -24,6 +24,7 @@ internal class YieldBalanceConverter : Converter<YieldBalanceConverter.Data, Yie
amount = item.amount,
pricePerShare = item.pricePerShare,
rawCurrencyId = item.tokenDTO.coinGeckoId,
rawNetworkId = item.tokenDTO.network.name,
validatorAddress = item.validatorAddress,
pendingActions = pendingActionConverter.convertList(item.pendingActions),
)

View file

@ -36,6 +36,7 @@ data class BalanceItem(
val amount: BigDecimal,
val pricePerShare: BigDecimal,
val rawCurrencyId: String?,
val rawNetworkId: String,
val validatorAddress: String?,
val pendingActions: List<PendingAction>,
)

View file

@ -5,10 +5,13 @@ sealed class YieldBalanceList {
data class Data(
val balances: List<YieldBalance>,
) : YieldBalanceList() {
fun getBalance(rawCurrencyId: String?): YieldBalance {
fun getBalance(rawCurrencyId: String?, networkName: String): YieldBalance {
return balances.firstOrNull { yield ->
(yield as? YieldBalance.Data)?.balance?.items
?.any { it.rawCurrencyId == rawCurrencyId } == true
?.any {
rawCurrencyId == it.rawCurrencyId &&
networkName.equals(it.rawNetworkId, ignoreCase = true)
} == true
} ?: YieldBalance.Error
}
}

View file

@ -145,7 +145,10 @@ internal class CurrenciesStatusesLceOperations(
currencies.map { currency ->
val quote = quotes?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId }
val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network }
val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(currency.id.rawCurrencyId)
val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(
rawCurrencyId = currency.id.rawCurrencyId,
networkName = currency.network.name,
)
createCurrencyStatus(
currency = currency,

View file

@ -261,7 +261,10 @@ internal class CurrenciesStatusesOperations(
currencies.map { currency ->
val quote = quotes?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId }
val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network }
val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(currency.id.rawCurrencyId)
val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(
rawCurrencyId = currency.id.rawCurrencyId,
networkName = currency.network.name,
)
createCurrencyStatus(
currency = currency,
quote = quote,

View file

@ -129,7 +129,7 @@ internal object TokenDetailsPreviewData {
onBalanceSelect = {},
displayCryptoBalance = "966,96 XLM",
displayFiatBalance = "91,50$",
isBalanceSelectorEnabled = false,
isBalanceSelectorEnabled = true,
)
val balanceError = TokenDetailsBalanceBlockState.Error(
actionButtons = actionButtons,

View file

@ -147,17 +147,20 @@ private fun BalanceButtons(state: TokenDetailsBalanceBlockState) {
.padding(top = TangemTheme.dimens.spacing11)
.width(IntrinsicSize.Min),
) { config ->
val style = if (state.selectedBalanceType == config.type) {
TangemTheme.typography.caption1
} else {
TangemTheme.typography.caption2
}
Text(
text = config.title.resolveReference(),
color = TangemTheme.colors.text.primary1,
style = TangemTheme.typography.caption1,
style = style,
maxLines = 1,
modifier = Modifier
.padding(
start = TangemTheme.dimens.spacing5,
end = TangemTheme.dimens.spacing5,
top = TangemTheme.dimens.spacing3,
bottom = TangemTheme.dimens.spacing3,
horizontal = TangemTheme.dimens.spacing4,
vertical = TangemTheme.dimens.spacing6,
)
.align(Alignment.Center),
)

View file

@ -97,7 +97,7 @@ internal object WalletPreviewData {
id = UUID.randomUUID().toString(),
iconState = coinIconState,
titleState = TokenItemState.TitleState.Content(text = "Polygon", hasPending = true),
fiatAmountState = TokenItemState.FiatAmountState.Content(text = "321 $"),
fiatAmountState = TokenItemState.FiatAmountState.Content(text = "321 $", hasStaked = true),
cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = "5,412 MATIC"),
cryptoPriceState = TokenItemState.CryptoPriceState.Unknown,
onItemClick = {},
@ -117,7 +117,7 @@ internal object WalletPreviewData {
id = UUID.randomUUID().toString(),
iconState = tokenIconState,
titleState = TokenItemState.TitleState.Content(text = "Polygon"),
fiatAmountState = TokenItemState.FiatAmountState.Content(text = "321 $"),
fiatAmountState = TokenItemState.FiatAmountState.Content(text = "321 $", hasStaked = false),
cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = "5,412 MATIC"),
cryptoPriceState = TokenItemState.CryptoPriceState.Content(
price = "312 USD",

View file

@ -403,7 +403,10 @@ private class TokenItemStateProvider : CollectionPreviewParameterProvider<TokenI
text = "PolygonPolygonPolygonPolygonPolygonPolygon",
hasPending = true,
),
fiatAmountState = TokenItemState.FiatAmountState.Content(text = "3213123123321312312312312312 $"),
fiatAmountState = TokenItemState.FiatAmountState.Content(
text = "3213123123321312312312312312 $",
hasStaked = true,
),
cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = "5,4123123213123123123123123123 MATIC"),
cryptoPriceState = TokenItemState.CryptoPriceState.Content(
price = "312 USD",

View file

@ -1,14 +1,22 @@
package com.tangem.feature.wallet.presentation.common.component.token
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.rememberVectorPainter
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.style.TextOverflow
import com.tangem.core.ui.components.RectangleShimmer
import com.tangem.core.ui.res.TangemTheme
import com.tangem.feature.wallet.impl.R
import com.tangem.utils.StringsSigns
import com.tangem.feature.wallet.presentation.common.state.TokenItemState.FiatAmountState as TokenFiatAmountState
@ -18,7 +26,8 @@ internal fun TokenFiatAmount(state: TokenFiatAmountState?, isBalanceHidden: Bool
is TokenFiatAmountState.Content -> {
FiatAmountText(
text = if (isBalanceHidden) StringsSigns.STARS else state.text,
modifier,
hasStaked = state.hasStaked,
modifier = modifier,
)
}
is TokenFiatAmountState.Loading -> {
@ -32,15 +41,31 @@ internal fun TokenFiatAmount(state: TokenFiatAmountState?, isBalanceHidden: Bool
}
@Composable
private fun FiatAmountText(text: String, modifier: Modifier = Modifier) {
Text(
text = text,
private fun FiatAmountText(text: String, hasStaked: Boolean, modifier: Modifier = Modifier) {
Row(
modifier = modifier,
color = TangemTheme.colors.text.primary1,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = TangemTheme.typography.body2,
)
verticalAlignment = Alignment.CenterVertically,
) {
AnimatedVisibility(
visible = hasStaked,
) {
Icon(
painter = rememberVectorPainter(image = ImageVector.vectorResource(R.drawable.ic_staking_24)),
contentDescription = null,
tint = TangemTheme.colors.icon.accent,
modifier = Modifier
.padding(horizontal = TangemTheme.dimens.spacing4)
.size(TangemTheme.dimens.size12),
)
}
Text(
text = text,
color = TangemTheme.colors.text.primary1,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = TangemTheme.typography.body2,
)
}
}
private fun Modifier.placeholderSize(): Modifier = composed {

View file

@ -129,7 +129,10 @@ internal sealed class TokenItemState {
@Immutable
sealed class FiatAmountState {
data class Content(val text: String) : FiatAmountState()
data class Content(
val text: String,
val hasStaked: Boolean = false,
) : FiatAmountState()
object Loading : FiatAmountState()

View file

@ -1,5 +1,6 @@
package com.tangem.feature.wallet.presentation.wallet.state.transformers.converter
import com.tangem.common.extensions.isZero
import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter
import com.tangem.core.ui.components.marketprice.PriceChangeType
import com.tangem.core.ui.components.marketprice.utils.PriceChangeConverter
@ -55,6 +56,7 @@ internal class TokenItemStateConverter(
),
fiatAmountState = TokenItemState.FiatAmountState.Content(
text = getFormattedFiatAmount(),
hasStaked = !getStakedBalance().isZero(),
),
cryptoAmountState = TokenItemState.CryptoAmountState.Content(text = getFormattedAmount()),
cryptoPriceState = getCryptoPriceState(),
@ -64,21 +66,22 @@ internal class TokenItemStateConverter(
}
private fun CryptoCurrencyStatus.getFormattedAmount(): String {
val yieldBalance = (value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero()
val amount = value.amount?.plus(yieldBalance) ?: return DASH_SIGN
val amount = value.amount?.plus(getStakedBalance()) ?: return DASH_SIGN
return BigDecimalFormatter.formatCryptoAmount(amount, currency.symbol, currency.decimals)
}
private fun CryptoCurrencyStatus.getFormattedFiatAmount(): String {
val yieldBalance = (value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero()
val fiatYieldBalance = value.fiatRate?.times(yieldBalance).orZero()
val fiatYieldBalance = value.fiatRate?.times(getStakedBalance()).orZero()
val fiatAmount = value.fiatAmount?.plus(fiatYieldBalance) ?: return DASH_SIGN
val appCurrency = appCurrencyProvider()
return BigDecimalFormatter.formatFiatAmount(fiatAmount, appCurrency.code, appCurrency.symbol)
}
private fun CryptoCurrencyStatus.getStakedBalance() =
(value.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance().orZero()
private fun CryptoCurrencyStatus.mapToUnreachableTokenItemState() = TokenItemState.Unreachable(
id = currency.id.value,
iconState = iconStateConverter.convert(value = this),