Updated on 2026-08-14

This commit is contained in:
Tangem 2025-10-10 12:28:38 +05:00
parent d30713a914
commit cfd8ae2957
13 changed files with 209 additions and 140 deletions

View file

@ -2,7 +2,6 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers.convert
import com.tangem.common.ui.account.AccountCryptoPortfolioItemStateConverter
import com.tangem.common.ui.tokens.TokenItemStateConverter
import com.tangem.core.ui.components.token.state.TokenItemState
import com.tangem.core.ui.components.tokenlist.state.PortfolioTokensListItemUM
import com.tangem.core.ui.components.tokenlist.state.TokensListItemUM
import com.tangem.core.ui.extensions.resourceReference
@ -14,9 +13,7 @@ import com.tangem.domain.models.TotalFiatBalance
import com.tangem.domain.models.account.Account
import com.tangem.domain.models.account.AccountId
import com.tangem.domain.models.account.AccountStatus
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.currency.yieldSupplyKey
import com.tangem.domain.models.tokenlist.TokenList
import com.tangem.domain.models.tokenlist.TokenList.GroupedByNetwork.NetworkGroup
import com.tangem.domain.models.wallet.UserWallet
@ -37,7 +34,7 @@ internal class TokenListStateConverter(
private val params: TokenConverterParams,
private val selectedWallet: UserWallet,
private val clickIntents: WalletClickIntents,
private val apyMap: Map<String, String> = emptyMap(),
private val apyMap: Map<String, String>,
) : Converter<WalletTokensListState, WalletTokensListState> {
private val onTokenClick: (accountId: AccountId?, currencyStatus: CryptoCurrencyStatus) -> Unit =
@ -52,6 +49,7 @@ internal class TokenListStateConverter(
private fun tokenStatusConverter(accountId: AccountId? = null) = TokenItemStateConverter(
appCurrency = appCurrency,
apyMap = apyMap,
onItemClick = { _, status -> onTokenClick(accountId, status) },
onItemLongClick = { _, status -> onTokenLongClick(accountId, status) },
)
@ -168,52 +166,13 @@ internal class TokenListStateConverter(
tokenConverter: TokenItemStateConverter,
token: CryptoCurrencyStatus,
): List<TokensListItemUM> {
val tokenItemState = tokenConverter.convert(token).withEarnApyBadge(token)
val tokenItemState = tokenConverter.convert(token)
add(TokensListItemUM.Token(tokenItemState))
return this
}
private fun TokenItemState.withEarnApyBadge(cryptoCurrencyStatus: CryptoCurrencyStatus): TokenItemState {
val apy: String? = resolveEarnApy(cryptoCurrencyStatus)
val shouldApply = apy != null && this.titleState is TokenItemState.TitleState.Content
return if (!shouldApply) {
this
} else {
val contentTitle = this.titleState as TokenItemState.TitleState.Content
val newTitle = contentTitle.copy(
earnApy = resourceReference(
R.string.yield_module_earn_badge,
wrappedList(apy),
),
)
when (this) {
is TokenItemState.Content -> this.copy(titleState = newTitle)
is TokenItemState.Unreachable -> this.copy(titleState = newTitle)
is TokenItemState.NoAddress -> this.copy(titleState = newTitle)
is TokenItemState.Loading -> this.copy(titleState = newTitle)
is TokenItemState.Draggable -> this.copy(titleState = newTitle)
is TokenItemState.Locked -> this
}
}
}
private fun resolveEarnApy(cryptoCurrencyStatus: CryptoCurrencyStatus): String? {
if (apyMap.isEmpty()) return null
val isYieldSupplyActive = (cryptoCurrencyStatus.value as? CryptoCurrencyStatus.Loaded)
?.yieldSupplyStatus?.isActive == true
if (isYieldSupplyActive) return null
val token = cryptoCurrencyStatus.currency as? CryptoCurrency.Token ?: return null
return apyMap[token.yieldSupplyKey()]
}
private fun getOrganizeTokensButtonState(tokenList: TokenList): WalletOrganizeTokensButtonConfig? {
val currenciesSize = when (tokenList) {
TokenList.Empty -> return null