Updated on 2026-08-14
This commit is contained in:
parent
2a6fd5ee3d
commit
eb9e376d40
3 changed files with 43 additions and 18 deletions
|
|
@ -6,19 +6,18 @@ import com.tangem.core.ui.components.marketprice.PriceChangeState
|
|||
import com.tangem.core.ui.components.marketprice.PriceChangeType
|
||||
import com.tangem.core.ui.components.marketprice.utils.PriceChangeConverter
|
||||
import com.tangem.core.ui.components.transactions.state.TxHistoryState
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.utils.BigDecimalFormatter
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.staking.model.StakingEntryInfo
|
||||
import com.tangem.domain.staking.model.stakekit.RewardBlockType
|
||||
import com.tangem.domain.staking.model.stakekit.YieldBalance
|
||||
import com.tangem.domain.tokens.error.CurrencyStatusError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.*
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsBalanceBlockState
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsTxHistoryTransactionStateConverter
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.utils.getBalance
|
||||
|
|
@ -26,6 +25,7 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.state.utils.get
|
|||
import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents
|
||||
import com.tangem.features.staking.api.featuretoggles.StakingFeatureToggles
|
||||
import com.tangem.features.tokendetails.impl.R
|
||||
import com.tangem.lib.crypto.BlockchainUtils.isSolana
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.converter.Converter
|
||||
import com.tangem.utils.isNullOrZero
|
||||
|
|
@ -157,6 +157,7 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) }
|
||||
|
||||
getStakedState(
|
||||
status = status,
|
||||
stakingCryptoAmount = stakingCryptoAmount,
|
||||
stakingFiatAmount = stakingFiatAmount,
|
||||
stakingRewardAmount = stakingRewardAmount,
|
||||
|
|
@ -211,6 +212,7 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
}
|
||||
|
||||
private fun getStakedState(
|
||||
status: CryptoCurrencyStatus,
|
||||
stakingCryptoAmount: BigDecimal?,
|
||||
stakingFiatAmount: BigDecimal?,
|
||||
stakingRewardAmount: BigDecimal?,
|
||||
|
|
@ -228,16 +230,7 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
appCurrencyProvider().symbol,
|
||||
),
|
||||
),
|
||||
rewardValue = resourceReference(
|
||||
R.string.staking_details_rewards_to_claim,
|
||||
wrappedList(
|
||||
BigDecimalFormatter.formatFiatAmount(
|
||||
stakingRewardAmount,
|
||||
appCurrencyProvider().code,
|
||||
appCurrencyProvider().symbol,
|
||||
),
|
||||
),
|
||||
),
|
||||
rewardValue = getRewardText(status, stakingRewardAmount),
|
||||
onStakeClicked = clickIntents::onStakeBannerClick,
|
||||
)
|
||||
}
|
||||
|
|
@ -302,4 +295,28 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
|
||||
return BigDecimalFormatter.formatCryptoAmount(totalAmount, status.currency.symbol, status.currency.decimals)
|
||||
}
|
||||
|
||||
private fun getRewardText(status: CryptoCurrencyStatus, stakingRewardAmount: BigDecimal?): TextReference {
|
||||
val isSolana = isSolana(status.currency.network.id.value)
|
||||
val rewardBlockType = when {
|
||||
isSolana -> RewardBlockType.RewardUnavailable
|
||||
stakingRewardAmount.isNullOrZero() -> RewardBlockType.NoRewards
|
||||
else -> RewardBlockType.Rewards
|
||||
}
|
||||
|
||||
return when (rewardBlockType) {
|
||||
RewardBlockType.Rewards -> resourceReference(
|
||||
R.string.staking_details_rewards_to_claim,
|
||||
wrappedList(
|
||||
BigDecimalFormatter.formatFiatAmount(
|
||||
stakingRewardAmount,
|
||||
appCurrencyProvider().code,
|
||||
appCurrencyProvider().symbol,
|
||||
),
|
||||
),
|
||||
)
|
||||
RewardBlockType.NoRewards -> resourceReference(R.string.staking_details_no_rewards_to_claim)
|
||||
RewardBlockType.RewardUnavailable -> TextReference.EMPTY
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import androidx.compose.ui.res.stringResource
|
|||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
|
|
@ -68,11 +69,13 @@ internal fun StakingBalanceBlock(state: StakingBlockUM.Staked, modifier: Modifie
|
|||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = state.rewardValue.resolveReference(),
|
||||
style = TangemTheme.typography.caption2,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
if (state.rewardValue != TextReference.EMPTY) {
|
||||
Text(
|
||||
text = state.rewardValue.resolveReference(),
|
||||
style = TangemTheme.typography.caption2,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
}
|
||||
}
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_chevron_right_24),
|
||||
|
|
|
|||
|
|
@ -72,6 +72,11 @@ object BlockchainUtils {
|
|||
return blockchain == Blockchain.Arbitrum
|
||||
}
|
||||
|
||||
fun isSolana(networkId: String): Boolean {
|
||||
val blockchain = Blockchain.fromId(networkId)
|
||||
return blockchain == Blockchain.Solana
|
||||
}
|
||||
|
||||
data class BlockchainInfo(
|
||||
val blockchainId: String,
|
||||
val name: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue