Updated on 2026-08-14

This commit is contained in:
Tangem 2023-08-01 15:25:12 +08:00
parent 3ff771e48b
commit 160153bfa3
28 changed files with 913 additions and 368 deletions

View file

@ -12,12 +12,12 @@ class GetTxHistoryItemsCountUseCase(private val repository: TxHistoryRepository)
return either {
catch(
block = { repository.getTxHistoryItemsCount(networkId, derivationPath) },
catch = { e ->
catch = { throwable ->
raise(
when (e) {
is TxHistoryStateError.TxHistoryNotImplemented -> e
is TxHistoryStateError.EmptyTxHistories -> e
else -> TxHistoryStateError.DataError(e)
when (throwable) {
is TxHistoryStateError.TxHistoryNotImplemented -> throwable
is TxHistoryStateError.EmptyTxHistories -> throwable
else -> TxHistoryStateError.DataError(throwable)
},
)
},

View file

@ -2,17 +2,12 @@ package com.tangem.domain.txhistory.usecase
import androidx.paging.PagingData
import arrow.core.Either
import arrow.core.left
import arrow.core.raise.Raise
import arrow.core.raise.recover
import arrow.core.right
import arrow.core.raise.either
import com.tangem.domain.txhistory.error.TxHistoryListError
import com.tangem.domain.txhistory.model.TxHistoryItem
import com.tangem.domain.txhistory.repository.TxHistoryRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collect
private const val DEFAULT_PAGE_SIZE = 20
@ -21,29 +16,11 @@ class GetTxHistoryItemsUseCase(private val repository: TxHistoryRepository) {
operator fun invoke(
networkId: String,
pageSize: Int = DEFAULT_PAGE_SIZE,
): Flow<Either<TxHistoryListError,
PagingData<TxHistoryItem>,>,> {
return channelFlow {
recover(
block = {
getTxHistoryItems(
networkId = networkId,
pageSize = pageSize,
).collect { items ->
send(items.right())
}
},
recover = { error -> send(error.left()) },
)
): Either<TxHistoryListError, Flow<PagingData<TxHistoryItem>>> {
return either {
repository
.getTxHistoryItems(networkId = networkId, pageSize = pageSize)
.catch { raise(TxHistoryListError.DataError(it)) }
}
}
private fun Raise<TxHistoryListError>.getTxHistoryItems(
networkId: String,
pageSize: Int,
): Flow<PagingData<TxHistoryItem>> {
return repository
.getTxHistoryItems(networkId = networkId, pageSize = pageSize)
.catch { raise(TxHistoryListError.DataError(it)) }
}
}