Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-10 08:58:37 +03:00
parent 7d9da40464
commit 519f5332f1
23 changed files with 379 additions and 132 deletions

View file

@ -9,11 +9,15 @@ android {
}
dependencies {
implementation(deps.arrow.core)
implementation(deps.kotlin.coroutines)
implementation(deps.androidx.paging.runtime)
implementation(projects.core.utils)
/** Project - Domain */
implementation(projects.domain.core)
implementation(projects.domain.tokens.models)
implementation(projects.domain.txhistory.models)
implementation(projects.domain.wallets.models)
/** Project - Other */
implementation(projects.core.utils)
/** Android - Other */
implementation(deps.androidx.paging.runtime)
}

View file

@ -6,13 +6,19 @@ import com.tangem.domain.tokens.model.Network
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryListError
import com.tangem.domain.txhistory.models.TxHistoryStateError
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
interface TxHistoryRepository {
@Throws(TxHistoryStateError::class)
suspend fun getTxHistoryItemsCount(network: Network): Int
suspend fun getTxHistoryItemsCount(userWalletId: UserWalletId, network: Network): Int
@Throws(TxHistoryListError::class)
fun getTxHistoryItems(currency: CryptoCurrency, pageSize: Int): Flow<PagingData<TxHistoryItem>>
fun getTxHistoryItems(
userWalletId: UserWalletId,
currency: CryptoCurrency,
pageSize: Int,
refresh: Boolean,
): Flow<PagingData<TxHistoryItem>>
}

View file

@ -6,14 +6,15 @@ import arrow.core.raise.either
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.txhistory.models.TxHistoryStateError
import com.tangem.domain.txhistory.repository.TxHistoryRepository
import com.tangem.domain.wallets.models.UserWalletId
// TODO: Add tests
class GetTxHistoryItemsCountUseCase(private val repository: TxHistoryRepository) {
// FIXME: Provide UserWalletId
suspend operator fun invoke(network: Network): Either<TxHistoryStateError, Int> {
suspend operator fun invoke(userWalletId: UserWalletId, network: Network): Either<TxHistoryStateError, Int> {
return either {
catch(
block = { repository.getTxHistoryItemsCount(network) },
block = { repository.getTxHistoryItemsCount(userWalletId, network) },
catch = { throwable ->
raise(
when (throwable) {

View file

@ -7,21 +7,25 @@ import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.models.TxHistoryListError
import com.tangem.domain.txhistory.repository.TxHistoryRepository
import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
private const val DEFAULT_PAGE_SIZE = 50
// TODO: Add tests
class GetTxHistoryItemsUseCase(private val repository: TxHistoryRepository) {
// FIXME: Provide UserWalletId
operator fun invoke(
userWalletId: UserWalletId,
currency: CryptoCurrency,
pageSize: Int = DEFAULT_PAGE_SIZE,
refresh: Boolean = false,
): Either<TxHistoryListError, Flow<PagingData<TxHistoryItem>>> {
return either {
repository
.getTxHistoryItems(currency = currency, pageSize = pageSize)
.getTxHistoryItems(userWalletId, currency, pageSize, refresh)
.catch { raise(TxHistoryListError.DataError(it)) }
}
}