Updated on 2026-08-14
This commit is contained in:
parent
6480fb498d
commit
b0ec8d2fd2
4 changed files with 72 additions and 13 deletions
|
|
@ -18,6 +18,7 @@ internal sealed interface StakingBlockUM {
|
|||
val cryptoAmount: BigDecimal?,
|
||||
val fiatAmount: BigDecimal?,
|
||||
val onStakeClicked: () -> Unit,
|
||||
val isBetaMode: Boolean = false,
|
||||
) : StakingBlockUM
|
||||
|
||||
data class StakeAvailable(
|
||||
|
|
@ -26,5 +27,6 @@ internal sealed interface StakingBlockUM {
|
|||
val subtitleText: TextReference,
|
||||
val isEnabled: Boolean,
|
||||
val onStakeClicked: () -> Unit,
|
||||
val isBetaMode: Boolean = false,
|
||||
) : StakingBlockUM
|
||||
}
|
||||
|
|
@ -15,6 +15,8 @@ import com.tangem.domain.models.staking.RewardBlockType
|
|||
import com.tangem.domain.models.staking.StakingBalance
|
||||
import com.tangem.domain.staking.model.StakingAvailability
|
||||
import com.tangem.domain.staking.model.StakingEntryInfo
|
||||
import com.tangem.domain.staking.model.StakingIntegrationID
|
||||
import com.tangem.domain.staking.model.optionOrNull
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.IconState
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM
|
||||
|
|
@ -53,12 +55,20 @@ internal class TokenDetailsStakingInfoConverter(
|
|||
StakingAvailability.TemporaryUnavailable -> StakingBlockUM.TemporaryUnavailable
|
||||
StakingAvailability.Unavailable -> null
|
||||
is StakingAvailability.Full -> getStakedBlockOrNull(status)
|
||||
is StakingAvailability.Available -> getStakingInfoBlock(status, state)
|
||||
is StakingAvailability.Available -> getStakingInfoBlock(
|
||||
status = status,
|
||||
state = state,
|
||||
isBetaMode = stakingAvailability.optionOrNull?.integrationId == StakingIntegrationID.P2PEthPool,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("CyclomaticComplexMethod")
|
||||
private fun getStakingInfoBlock(status: CryptoCurrencyStatus, state: TokenDetailsState): StakingBlockUM? {
|
||||
private fun getStakingInfoBlock(
|
||||
status: CryptoCurrencyStatus,
|
||||
state: TokenDetailsState,
|
||||
isBetaMode: Boolean,
|
||||
): StakingBlockUM? {
|
||||
val stakingBalance = status.value.stakingBalance as? StakingBalance.Data
|
||||
|
||||
val stakingCryptoAmount = stakingBalance?.getTotalStakingBalance(status.currency.network.rawId)
|
||||
|
|
@ -88,7 +98,12 @@ internal class TokenDetailsStakingInfoConverter(
|
|||
return when {
|
||||
stakingCryptoAmount.isNullOrZero() && stakingEntryInfo != null -> {
|
||||
if (!hasPendingBalances) {
|
||||
getStakeAvailableState(stakingEntryInfo, iconState, isStakingButtonEnabled(status))
|
||||
getStakeAvailableState(
|
||||
stakingEntryInfo = stakingEntryInfo,
|
||||
iconState = iconState,
|
||||
isEnabled = isStakingButtonEnabled(status),
|
||||
isBetaMode = isBetaMode,
|
||||
)
|
||||
} else {
|
||||
getStakedBlockWithFiatAmount(status, pendingAmount, null)
|
||||
}
|
||||
|
|
@ -165,6 +180,7 @@ internal class TokenDetailsStakingInfoConverter(
|
|||
stakingEntryInfo: StakingEntryInfo,
|
||||
iconState: IconState,
|
||||
isEnabled: Boolean,
|
||||
isBetaMode: Boolean,
|
||||
): StakingBlockUM.StakeAvailable {
|
||||
return StakingBlockUM.StakeAvailable(
|
||||
titleText = resourceReference(id = R.string.token_details_staking_block_title),
|
||||
|
|
@ -175,6 +191,7 @@ internal class TokenDetailsStakingInfoConverter(
|
|||
iconState = iconState,
|
||||
isEnabled = isEnabled,
|
||||
onStakeClicked = clickIntents::onStakeBannerClick,
|
||||
isBetaMode = isBetaMode,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -205,6 +222,7 @@ internal class TokenDetailsStakingInfoConverter(
|
|||
),
|
||||
rewardValue = getRewardText(status, stakingRewardAmount),
|
||||
onStakeClicked = clickIntents::onStakeBannerClick,
|
||||
isBetaMode = status.value.stakingBalance is StakingBalance.Data.P2PEthPool,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,10 +40,8 @@ internal fun StakingBalanceBlock(
|
|||
verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4),
|
||||
modifier = Modifier.weight(1f),
|
||||
) {
|
||||
Text(
|
||||
text = stringResourceSafe(R.string.staking_native),
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
StakingBalanceTitleRow(
|
||||
isBetaMode = state.isBetaMode,
|
||||
modifier = Modifier.padding(vertical = TangemTheme.dimens.spacing2),
|
||||
)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing8)) {
|
||||
|
|
@ -84,6 +82,32 @@ internal fun StakingBalanceBlock(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StakingBalanceTitleRow(isBetaMode: Boolean, modifier: Modifier = Modifier) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4),
|
||||
modifier = modifier,
|
||||
) {
|
||||
Text(
|
||||
text = stringResourceSafe(R.string.staking_native),
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
if (isBetaMode) {
|
||||
Text(
|
||||
text = StringsSigns.DOT,
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
Text(
|
||||
text = stringResourceSafe(R.string.beta_mode_warning_title),
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// region Preview
|
||||
@Preview(showBackground = true, widthDp = 360)
|
||||
@Preview(showBackground = true, widthDp = 360, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPre
|
|||
import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM
|
||||
import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.CurrencyIcon
|
||||
import com.tangem.features.tokendetails.impl.R
|
||||
import com.tangem.utils.StringsSigns
|
||||
|
||||
/**
|
||||
* Token staking block
|
||||
|
|
@ -99,12 +100,26 @@ private fun StakingAvailableContent(state: StakingBlockUM.StakeAvailable, modifi
|
|||
)
|
||||
SpacerW8()
|
||||
Column {
|
||||
Text(
|
||||
text = state.titleText.resolveReference(),
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
modifier = Modifier.testTag(TokenDetailsScreenTestTags.STAKING_SERVICE_TITLE),
|
||||
)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4)) {
|
||||
Text(
|
||||
text = state.titleText.resolveReference(),
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
modifier = Modifier.testTag(TokenDetailsScreenTestTags.STAKING_SERVICE_TITLE),
|
||||
)
|
||||
if (state.isBetaMode) {
|
||||
Text(
|
||||
text = StringsSigns.DOT,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
)
|
||||
Text(
|
||||
text = stringResourceSafe(R.string.beta_mode_warning_title),
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
style = TangemTheme.typography.subtitle2,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.size(TangemTheme.dimens.size4))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue