Updated on 2026-08-14

This commit is contained in:
Tangem 2026-02-06 12:40:48 +03:00
commit 870c3fa9d3
291 changed files with 4985 additions and 5870 deletions

View file

@ -13,6 +13,10 @@ android {
dependencies {
implementation(projects.core.utils)
api(projects.domain.models)
api(projects.domain.appCurrency.models)
api(projects.domain.staking.models)
api(projects.libs.crypto)
// region Firebase libraries
implementation(platform(deps.firebase.bom))

View file

@ -0,0 +1,33 @@
package com.tangem.common
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.models.staking.StakingBalance
import com.tangem.utils.extensions.orZero
import java.math.BigDecimal
/**
* Calculates the total fiat amount by adding the main fiat amount and the fiat value of the staked balance.
*/
fun CryptoCurrencyStatus.getTotalFiatAmount(): BigDecimal? {
val fiatAmount = value.fiatAmount
val fiatStakedBalance = value.fiatRate?.times(getStakedBalance().orZero()) ?: return fiatAmount
val totalAmount = fiatAmount?.plus(fiatStakedBalance) ?: return fiatStakedBalance
return totalAmount
}
/**
* Calculates the total cryptocurrency amount by adding the main crypto amount and the staked balance.
*/
fun CryptoCurrencyStatus.getTotalCryptoAmount(): BigDecimal? {
val cryptoAmount = value.amount
val cryptoStakedBalance = getStakedBalance() ?: return cryptoAmount
val totalAmount = cryptoAmount?.plus(cryptoStakedBalance) ?: return cryptoStakedBalance
return totalAmount
}
private fun CryptoCurrencyStatus.getStakedBalance() = (value.stakingBalance as? StakingBalance.Data)
?.getTotalWithRewardsStakingBalance(blockchainId = currency.network.rawId)

View file

@ -0,0 +1,89 @@
package com.tangem.common
import com.tangem.domain.models.staking.BalanceType
import com.tangem.domain.models.staking.StakingBalance
import com.tangem.lib.crypto.BlockchainUtils
import java.math.BigDecimal
/**
* Provider-agnostic extension to get total balance including rewards.
* Works for both StakeKit and P2PEthPool providers.
*
* Returns sum of all staking-related balances including rewards
* (staked + unstaking + withdrawable + rewards).
*
* When [BlockchainUtils.isIncludeStakingTotalBalance] is false, the staked balance
* is already included in the main wallet balance, so we only return rewards.
*/
fun StakingBalance.Data.getTotalWithRewardsStakingBalance(blockchainId: String): BigDecimal {
return when (this) {
is StakingBalance.Data.StakeKit -> getTotalWithRewardsStakingBalanceStakeKit(blockchainId)
is StakingBalance.Data.P2PEthPool -> {
val rewards = totalRewards
if (BlockchainUtils.isIncludeStakingTotalBalance(blockchainId)) {
totalStaked + unstakingAmount + withdrawableAmount + rewards
} else {
rewards
}
}
}
}
/**
* Provider-agnostic extension to get total staking balance excluding rewards.
* Works for both StakeKit and P2PEthPool providers.
*
* Returns sum of all staking-related balances (staked + unstaking + withdrawable)
* excluding rewards.
*/
fun StakingBalance.Data.getTotalStakingBalance(blockchainId: String): BigDecimal {
return when (this) {
is StakingBalance.Data.StakeKit -> getTotalStakingBalanceStakeKit(blockchainId)
is StakingBalance.Data.P2PEthPool -> totalStaked + unstakingAmount + withdrawableAmount
}
}
/**
* StakeKit-specific extension to get total balance including rewards.
*/
private fun StakingBalance.Data.StakeKit.getTotalWithRewardsStakingBalanceStakeKit(blockchainId: String): BigDecimal {
return if (BlockchainUtils.isIncludeStakingTotalBalance(blockchainId = blockchainId)) {
balance.items.sumOf { it.amount }
} else {
getRewardStakingBalance()
}
}
/**
* StakeKit-specific extension to get total staked balance excluding rewards.
*/
private fun StakingBalance.Data.StakeKit.getTotalStakingBalanceStakeKit(blockchainId: String): BigDecimal {
return if (BlockchainUtils.isIncludeStakingTotalBalance(blockchainId = blockchainId)) {
balance.items
.filterNot { it.type == BalanceType.REWARDS }
.sumOf { it.amount }
} else {
balance.items
.filterNot { it.type == BalanceType.REWARDS }
.sumOf { it.amount } - getRewardStakingBalance()
}
}
/**
* StakeKit-specific extension to get reward balance.
*/
fun StakingBalance.Data.StakeKit.getRewardStakingBalance(): BigDecimal {
return balance.items
.filter { it.type == BalanceType.REWARDS }
.sumOf { it.amount }
}
/**
* StakeKit-specific extension to get validators count.
*/
fun StakingBalance.Data.StakeKit.getValidatorsCount(): Int {
return balance.items
.filterNot { it.validatorAddress.isNullOrBlank() }
.distinctBy { it.validatorAddress }
.size
}

View file

@ -9,6 +9,7 @@ android {
}
dependencies {
api(projects.common)
/** Compose */
implementation(deps.compose.material3)

View file

@ -94,6 +94,7 @@ private fun SwapStoriesText(current: SwapStoriesUM.Content.Config) {
),
color = TangemTheme.colors.text.constantWhite,
textAlign = TextAlign.Center,
modifier = Modifier.testTag(SwapStoriesScreenTestTags.TITLE),
)
Text(
text = current.subtitle.resolveReference(),
@ -105,6 +106,7 @@ private fun SwapStoriesText(current: SwapStoriesUM.Content.Config) {
),
color = SubtitleColor,
textAlign = TextAlign.Center,
modifier = Modifier.testTag(SwapStoriesScreenTestTags.SUBTITLE),
)
}
}

View file

@ -1,5 +1,7 @@
package com.tangem.common.ui.tokens
import com.tangem.common.getTotalCryptoAmount
import com.tangem.common.getTotalFiatAmount
import com.tangem.common.ui.R
import com.tangem.core.ui.components.currency.icon.CurrencyIconState
import com.tangem.core.ui.components.currency.icon.converter.CryptoCurrencyToIconStateConverter
@ -25,11 +27,8 @@ import com.tangem.domain.staking.model.StakingAvailability
import com.tangem.domain.staking.model.StakingOption
import com.tangem.domain.staking.model.common.RewardInfo
import com.tangem.domain.staking.model.common.RewardType
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.utils.StringsSigns.DASH_SIGN
import com.tangem.utils.converter.Converter
import com.tangem.utils.extensions.orZero
import kotlinx.collections.immutable.toImmutableList
import java.math.BigDecimal
@ -156,29 +155,6 @@ class TokenItemStateConverter(
}
companion object {
fun CryptoCurrencyStatus.getFormattedFiatAmount(appCurrency: AppCurrency): String {
val fiatAmount = value.fiatAmount ?: return DASH_SIGN
val fiatYieldBalance = value.fiatRate?.times(getStakedBalance()).orZero()
val totalAmount = fiatAmount.plus(fiatYieldBalance)
return totalAmount.format {
fiat(fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol)
}
}
fun CryptoCurrencyStatus.getFormattedCryptoAmount(): String {
val cryptoAmount = value.amount ?: return DASH_SIGN
val totalAmount = cryptoAmount.plus(getStakedBalance())
return totalAmount.format { crypto(currency) }
}
private fun CryptoCurrencyStatus.getStakedBalance() = (value.stakingBalance as? StakingBalance.Data)
?.getTotalWithRewardsStakingBalance(blockchainId = currency.network.rawId).orZero()
private fun createTitleState(
currencyStatus: CryptoCurrencyStatus,
yieldModuleApyMap: Map<String, BigDecimal>,
@ -348,7 +324,9 @@ class TokenItemStateConverter(
is CryptoCurrencyStatus.NoAccount,
-> {
TokenItemState.Subtitle2State.TextContent(
text = status.getFormattedCryptoAmount(),
text = status.getTotalCryptoAmount().format {
crypto(status.currency)
},
isFlickering = status.value.isFlickering(),
)
}
@ -371,7 +349,12 @@ class TokenItemStateConverter(
is CryptoCurrencyStatus.NoAccount,
-> {
TokenItemState.FiatAmountState.Content(
text = status.getFormattedFiatAmount(appCurrency = appCurrency),
text = status.getTotalFiatAmount().format {
fiat(
fiatCurrencyCode = appCurrency.code,
fiatCurrencySymbol = appCurrency.symbol,
)
},
isFlickering = status.value.isFlickering(),
icons = buildList {
if (status.value.yieldSupplyStatus?.isActive == true &&