From c12ce8c2410352edb94647ff7ee126daa11943a0 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 21 Oct 2024 17:40:40 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../tokendetails/TokenDetailsPreviewData.kt | 4 +- .../tokendetails/state/StakingBlockUM.kt | 4 +- .../components/staking/StakingBalanceBlock.kt | 21 +--- .../staking/StakingUnavailableBlock.kt | 8 +- .../components/staking/TokenStakingBlock.kt | 104 ++++++++---------- 5 files changed, 51 insertions(+), 90 deletions(-) diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt index 747cf08519..3f49fe9fb2 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/TokenDetailsPreviewData.kt @@ -155,7 +155,7 @@ internal object TokenDetailsPreviewData { onStakeClicked = {}, ) - val stakedBlock = StakingBlockUM.Staked( + val stakingBalanceBlock = StakingBlockUM.Staked( cryptoValue = stringReference("5 SOL"), fiatValue = stringReference("456.34 $"), rewardValue = resourceReference(R.string.staking_details_no_rewards_to_claim, wrappedList("0.43 $")), @@ -351,6 +351,6 @@ internal object TokenDetailsPreviewData { value = PagingData.from(txHistoryItems), ), ), - stakingBlocksState = stakedBlock, + stakingBlocksState = stakingBalanceBlock, ) } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt index 55ba3c6fcc..0072e90707 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/StakingBlockUM.kt @@ -1,10 +1,10 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state -import androidx.compose.runtime.Stable +import androidx.compose.runtime.Immutable import com.tangem.core.ui.extensions.TextReference import java.math.BigDecimal -@Stable +@Immutable internal sealed interface StakingBlockUM { data object TemporaryUnavailable : StakingBlockUM diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt index 1107eba6ae..76bc8386d6 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingBalanceBlock.kt @@ -1,18 +1,12 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.staking import android.content.res.Configuration -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.material3.Icon import androidx.compose.material3.Text -import androidx.compose.material3.ripple import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -23,7 +17,7 @@ import com.tangem.core.ui.extensions.orMaskWithStars import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakedBlock +import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingBalanceBlock import com.tangem.feature.tokendetails.presentation.tokendetails.state.StakingBlockUM import com.tangem.features.tokendetails.impl.R import com.tangem.utils.StringsSigns @@ -36,16 +30,7 @@ internal fun StakingBalanceBlock( ) { Row( verticalAlignment = Alignment.CenterVertically, - modifier = modifier - .fillMaxWidth() - .clip(TangemTheme.shapes.roundedCornersXMedium) - .background(TangemTheme.colors.background.primary) - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = ripple(), - onClick = state.onStakeClicked, - ) - .padding(TangemTheme.dimens.spacing12), + modifier = modifier.fillMaxWidth(), ) { Column( verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), @@ -108,6 +93,6 @@ private fun StakingBalanceBlock_Preview( private class StakingBalanceBlockPreviewProvider : PreviewParameterProvider { override val values: Sequence - get() = sequenceOf(stakedBlock) + get() = sequenceOf(stakingBalanceBlock) } // endregion \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingUnavailableBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingUnavailableBlock.kt index 2341b0cab8..2047a1f09f 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingUnavailableBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/StakingUnavailableBlock.kt @@ -1,12 +1,10 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.staking import android.content.res.Configuration -import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.tangem.core.ui.res.TangemTheme @@ -17,11 +15,7 @@ import com.tangem.features.tokendetails.impl.R internal fun StakingTemporaryUnavailableBlock(modifier: Modifier = Modifier) { Column( verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing4), - modifier = modifier - .fillMaxWidth() - .clip(TangemTheme.shapes.roundedCornersXMedium) - .background(TangemTheme.colors.background.primary) - .padding(TangemTheme.dimens.spacing12), + modifier = modifier.fillMaxWidth(), ) { Text( text = stringResource(R.string.staking_native), diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt index a4db00c78a..a8ba9f84c2 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/staking/TokenStakingBlock.kt @@ -3,8 +3,11 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components. import android.content.res.Configuration import androidx.compose.animation.AnimatedContent import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.material3.Text +import androidx.compose.material3.ripple import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -14,18 +17,15 @@ 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.datasource.CollectionPreviewParameterProvider -import com.tangem.core.ui.components.RectangleShimmer -import com.tangem.core.ui.components.SecondaryButton -import com.tangem.core.ui.components.SpacerW8 -import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.components.* import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview import com.tangem.core.ui.utils.getGreyScaleColorFilter +import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingBalanceBlock import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingAvailableBlock import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingLoadingBlock import com.tangem.feature.tokendetails.presentation.tokendetails.TokenDetailsPreviewData.stakingTemporaryUnavailableBlock -import com.tangem.feature.tokendetails.presentation.tokendetails.state.IconState 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 @@ -39,26 +39,35 @@ import com.tangem.features.tokendetails.impl.R */ @Composable internal fun TokenStakingBlock(state: StakingBlockUM, isBalanceHidden: Boolean, modifier: Modifier = Modifier) { - AnimatedContent( - targetState = state, - contentAlignment = Alignment.CenterStart, - label = "Staking block animation", + Column( + modifier = modifier + .clip(TangemTheme.shapes.roundedCornersXMedium) + .background(TangemTheme.colors.background.primary) + .clickable( + enabled = state is StakingBlockUM.Staked, + interactionSource = remember { MutableInteractionSource() }, + indication = ripple(), + onClick = { (state as? StakingBlockUM.Staked)?.onStakeClicked?.invoke() }, + ) + .fillMaxWidth() + .padding(all = TangemTheme.dimens.spacing12), ) { - when (it) { - is StakingBlockUM.TemporaryUnavailable -> StakingTemporaryUnavailableBlock(modifier) - is StakingBlockUM.Loading -> StakingLoading( - iconState = it.iconState, - modifier = modifier, - ) - is StakingBlockUM.Staked -> StakingBalanceBlock( - state = it, - isBalanceHidden = isBalanceHidden, - modifier = modifier, - ) - is StakingBlockUM.StakeAvailable -> StakingAvailableContent( - state = it, - modifier = modifier, - ) + AnimatedContent( + targetState = state, + contentAlignment = Alignment.CenterStart, + label = "Staking block animation", + ) { + when (it) { + is StakingBlockUM.TemporaryUnavailable -> StakingTemporaryUnavailableBlock() + is StakingBlockUM.Loading -> StakingLoading() + is StakingBlockUM.Staked -> StakingBalanceBlock( + state = it, + isBalanceHidden = isBalanceHidden, + ) + is StakingBlockUM.StakeAvailable -> StakingAvailableContent( + state = it, + ) + } } } } @@ -66,13 +75,7 @@ internal fun TokenStakingBlock(state: StakingBlockUM, isBalanceHidden: Boolean, @Composable private fun StakingAvailableContent(state: StakingBlockUM.StakeAvailable, modifier: Modifier = Modifier) { Column( - modifier = modifier - .background( - color = TangemTheme.colors.background.primary, - shape = TangemTheme.shapes.roundedCornersXMedium, - ) - .fillMaxWidth() - .padding(all = TangemTheme.dimens.spacing12), + modifier = modifier.fillMaxWidth(), ) { Row { val (alpha, colorFilter) = remember(state.iconState.isGrayscale) { @@ -115,52 +118,30 @@ private fun StakingAvailableContent(state: StakingBlockUM.StakeAvailable, modifi } @Composable -private fun StakingLoading(iconState: IconState, modifier: Modifier = Modifier) { +private fun StakingLoading(modifier: Modifier = Modifier) { Column( - modifier = modifier - .background( - color = TangemTheme.colors.background.primary, - shape = TangemTheme.shapes.roundedCornersXMedium, - ) - .fillMaxWidth() - .heightIn(min = TangemTheme.dimens.size72) - .padding(all = TangemTheme.dimens.spacing12), - + modifier = modifier.fillMaxWidth(), ) { Row { - val (alpha, colorFilter) = remember(iconState.isGrayscale) { - getGreyScaleColorFilter(iconState.isGrayscale) - } - CurrencyIcon( - modifier = Modifier - .size(TangemTheme.dimens.size20) - .clip(TangemTheme.shapes.roundedCorners8) - .align(Alignment.CenterVertically), - icon = iconState, - alpha = alpha, - colorFilter = colorFilter, - ) - SpacerW8() Column { RectangleShimmer( modifier = Modifier .fillMaxWidth() .height(TangemTheme.dimens.size20), ) - Spacer(modifier = Modifier.size(TangemTheme.dimens.size4)) + Spacer(modifier = Modifier.size(TangemTheme.dimens.size8)) RectangleShimmer( modifier = Modifier .fillMaxWidth() - .height(TangemTheme.dimens.size20), + .height(TangemTheme.dimens.size36), ) Spacer(modifier = Modifier.size(TangemTheme.dimens.size8)) } } - SecondaryButton( - modifier = Modifier.fillMaxWidth(), - showProgress = true, - text = TextReference.EMPTY.resolveReference(), - onClick = { /* no-op */ }, + RectangleShimmer( + modifier = Modifier + .fillMaxWidth() + .height(TangemTheme.dimens.size48), ) } } @@ -186,6 +167,7 @@ private class StakingBlockStateProvider : CollectionPreviewParameterProvider