diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/FeedComponentModel.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/FeedComponentModel.kt index fde61b8825..bd7ea3d8c3 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/FeedComponentModel.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/FeedComponentModel.kt @@ -271,7 +271,7 @@ internal class FeedComponentModel @Inject constructor( earnListUM = if (feedFeatureToggle.isEarnBlockEnabled) { EarnListUM.Loading } else { - null + EarnListUM.Empty }, ) } diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/FeedStateController.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/FeedStateController.kt index 99440c5949..7100cff366 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/FeedStateController.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/FeedStateController.kt @@ -70,7 +70,7 @@ internal class FeedStateController @Inject constructor( earnListUM = if (feedFeatureToggle.isEarnBlockEnabled) { EarnListUM.Loading } else { - null + EarnListUM.Empty }, ) } diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/transformers/UpdateEarnStateTransformer.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/transformers/UpdateEarnStateTransformer.kt index fd81cc6428..d95b950076 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/transformers/UpdateEarnStateTransformer.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/model/feed/state/transformers/UpdateEarnStateTransformer.kt @@ -47,7 +47,7 @@ internal class UpdateEarnStateTransformer( } private fun handleEmptyState(currentState: FeedListUM): FeedListUM { - return currentState.copy(earnListUM = null) + return currentState.copy(earnListUM = EarnListUM.Empty) } private fun handleErrorState(currentState: FeedListUM, result: EarnError): FeedListUM { @@ -69,6 +69,8 @@ internal class UpdateEarnStateTransformer( currentState: FeedListUM, earnTokensWithCurrency: List, ): FeedListUM { + if (earnTokensWithCurrency.isEmpty()) return currentState.copy(earnListUM = EarnListUM.Empty) + val newItems = earnTokensWithCurrency .sortedWith( compareByDescending { diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/EarnContent.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/EarnContent.kt index fb0a94723b..9ff14d6bc1 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/EarnContent.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/EarnContent.kt @@ -108,8 +108,8 @@ private fun MostlyUsedContent(state: EarnListUM, onScroll: () -> Unit) { AnimatedContent( targetState = state, contentKey = { it::class.java }, - ) { st -> - when (st) { + ) { animatedState -> + when (animatedState) { is EarnListUM.Loading -> { MostlyUsedPlaceholder() } @@ -122,7 +122,7 @@ private fun MostlyUsedContent(state: EarnListUM, onScroll: () -> Unit) { horizontalArrangement = Arrangement.spacedBy(8.dp), ) { itemsIndexed( - items = st.items, + items = animatedState.items, key = { _, item -> "${item.tokenName}-${item.network}" }, ) { index, item -> val cardModifier = Modifier.conditional( @@ -154,9 +154,10 @@ private fun MostlyUsedContent(state: EarnListUM, onScroll: () -> Unit) { .padding(vertical = 32.dp, horizontal = 12.dp), contentAlignment = Alignment.Center, ) { - UnableToLoadData(onRetryClick = st.onRetryClicked) + UnableToLoadData(onRetryClick = animatedState.onRetryClicked) } } + EarnListUM.Empty -> Unit // no need to handle } } } diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/state/EarnListUM.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/state/EarnListUM.kt index c4506586bc..72ba54139d 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/state/EarnListUM.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/earn/state/EarnListUM.kt @@ -10,6 +10,7 @@ internal sealed interface EarnListUM { data object Loading : EarnListUM data class Content(val items: ImmutableList) : EarnListUM data class Error(val onRetryClicked: () -> Unit) : EarnListUM + data object Empty : EarnListUM } @Immutable diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/components/EarnBlock.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/components/EarnBlock.kt index 08e6849b20..d97e6bd7a3 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/components/EarnBlock.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/components/EarnBlock.kt @@ -24,8 +24,8 @@ import com.tangem.features.feed.ui.earn.state.EarnListUM import kotlinx.collections.immutable.ImmutableList @Composable -internal fun EarnBlock(onSeeAllClick: () -> Unit, earnListUM: EarnListUM?, modifier: Modifier = Modifier) { - if (earnListUM == null) return +internal fun EarnBlock(onSeeAllClick: () -> Unit, earnListUM: EarnListUM, modifier: Modifier = Modifier) { + if (earnListUM is EarnListUM.Empty) return Column(modifier = modifier) { Header( @@ -57,6 +57,7 @@ internal fun EarnBlock(onSeeAllClick: () -> Unit, earnListUM: EarnListUM?, modif is EarnListUM.Content -> EarnContentBlock(items = earnListUM.items) is EarnListUM.Error -> EarnErrorBlock(onRetryClick = earnListUM.onRetryClicked) EarnListUM.Loading -> EarnListPlaceholder(placeholderCount = PLACEHOLDER_ITEM_COUNT) + EarnListUM.Empty -> Unit } } } diff --git a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/state/FeedListUM.kt b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/state/FeedListUM.kt index 956cfde84f..8ba119a2d1 100644 --- a/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/state/FeedListUM.kt +++ b/features/feed/impl/src/main/kotlin/com/tangem/features/feed/ui/feed/state/FeedListUM.kt @@ -18,7 +18,7 @@ internal data class FeedListUM( val trendingArticle: ArticleConfigUM?, val marketChartConfig: MarketChartConfig, val globalState: GlobalFeedState = GlobalFeedState.Content, - val earnListUM: EarnListUM?, + val earnListUM: EarnListUM, ) internal data class FeedListCallbacks(