Updated on 2026-08-14
This commit is contained in:
parent
d2f28313e9
commit
96d5f31d82
4 changed files with 25 additions and 26 deletions
|
|
@ -58,7 +58,7 @@ internal class DefaultNewsRepository(
|
|||
return updateViewedStatusForNewsBatch(newsBatchFlow, context.coroutineScope)
|
||||
}
|
||||
|
||||
override fun getNews(config: NewsListConfig, limit: Int): Flow<List<ShortArticle>> {
|
||||
override fun getNews(config: NewsListConfig, limit: Int): Flow<Either<Throwable, List<ShortArticle>>> {
|
||||
return flow {
|
||||
val items = newsApi.getNews(
|
||||
page = FIRST_PAGE,
|
||||
|
|
@ -73,7 +73,7 @@ internal class DefaultNewsRepository(
|
|||
},
|
||||
onError = { error ->
|
||||
Timber.e(error, "Failed to get list of news")
|
||||
emptyList()
|
||||
throw error
|
||||
},
|
||||
)
|
||||
|
||||
|
|
@ -85,8 +85,9 @@ internal class DefaultNewsRepository(
|
|||
articlesToUpdate.map { article ->
|
||||
val isViewed = viewedFlags[article.id] == true
|
||||
article.copy(viewed = isViewed)
|
||||
}.sortedBy { it.viewed }
|
||||
}.sortedBy { it.viewed }.right()
|
||||
}
|
||||
.catch { it.left() }
|
||||
}
|
||||
|
||||
override fun observeDetailedArticles(): Flow<Map<Int, DetailedArticle>> {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ interface NewsRepository {
|
|||
*
|
||||
* @param config config for getting news list
|
||||
*/
|
||||
fun getNews(config: NewsListConfig, limit: Int): Flow<List<ShortArticle>>
|
||||
fun getNews(config: NewsListConfig, limit: Int): Flow<Either<Throwable, List<ShortArticle>>>
|
||||
|
||||
/**
|
||||
* Observes cached detailed articles.
|
||||
|
|
|
|||
|
|
@ -8,11 +8,9 @@ import kotlinx.coroutines.flow.Flow
|
|||
|
||||
class GetNewsUseCase(private val repository: NewsRepository) {
|
||||
|
||||
fun getNews(limit: Int, newsListConfig: NewsListConfig): Either<Throwable, Flow<List<ShortArticle>>> =
|
||||
Either.catch {
|
||||
fun getNews(limit: Int, newsListConfig: NewsListConfig): Flow<Either<Throwable, List<ShortArticle>>> =
|
||||
repository.getNews(
|
||||
config = newsListConfig,
|
||||
limit = limit,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,7 @@ import com.tangem.domain.wallets.usecase.GetWalletsUseCase
|
|||
import com.tangem.features.feed.components.market.details.DefaultMarketsTokenDetailsComponent
|
||||
import com.tangem.features.feed.components.market.details.analytics.MarketTokenAnalyticsEvent
|
||||
import com.tangem.features.feed.impl.R
|
||||
import com.tangem.features.feed.model.converter.ShortArticleToArticleConfigUMConverter
|
||||
import com.tangem.features.feed.model.market.details.analytics.MarketDetailsAnalyticsEvent
|
||||
import com.tangem.features.feed.model.market.details.converter.DescriptionConverter
|
||||
import com.tangem.features.feed.model.market.details.converter.ExchangeItemStateConverter
|
||||
|
|
@ -46,7 +47,6 @@ import com.tangem.features.feed.model.market.details.converter.TokenMarketInfoCo
|
|||
import com.tangem.features.feed.model.market.details.formatter.*
|
||||
import com.tangem.features.feed.model.market.details.state.QuotesStateUpdater
|
||||
import com.tangem.features.feed.model.market.details.state.TokenNetworksState
|
||||
import com.tangem.features.feed.model.converter.ShortArticleToArticleConfigUMConverter
|
||||
import com.tangem.features.feed.ui.market.detailed.state.ExchangesBottomSheetContent
|
||||
import com.tangem.features.feed.ui.market.detailed.state.MarketsTokenDetailsUM
|
||||
import com.tangem.lib.crypto.BlockchainUtils
|
||||
|
|
@ -313,8 +313,8 @@ internal class MarketsTokenDetailsModel @Inject constructor(
|
|||
snapshot = null,
|
||||
tokenIds = listOf(params.token.id.value),
|
||||
),
|
||||
).onRight { listOfArticles ->
|
||||
listOfArticles.collect { articles ->
|
||||
).collect { result ->
|
||||
result.onRight { articles ->
|
||||
state.update { marketsTokenDetailsUM ->
|
||||
val relatedNews = shortArticleToArticleConfigUMConverter.convert(articles)
|
||||
marketsTokenDetailsUM.copy(
|
||||
|
|
@ -343,7 +343,6 @@ internal class MarketsTokenDetailsModel @Inject constructor(
|
|||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}.onLeft { throwable ->
|
||||
val (code, message) = if (throwable is ApiResponseError.HttpException) {
|
||||
throwable.code.numericCode to throwable.message.orEmpty()
|
||||
|
|
@ -359,6 +358,7 @@ internal class MarketsTokenDetailsModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadChart(interval: PriceChangeInterval) {
|
||||
modelScope.launch {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue