Updated on 2026-08-14

This commit is contained in:
Tangem 2024-02-27 16:11:50 +05:00
parent f3906a385a
commit 0fae3c188c
5 changed files with 92 additions and 1 deletions

View file

@ -23,4 +23,12 @@ interface TxHistoryRepository {
): Flow<PagingData<TxHistoryItem>>
fun getTxExploreUrl(txHash: String, networkId: Network.ID): String
@Throws(TxHistoryListError::class)
suspend fun getFixedSizeTxHistoryItems(
userWalletId: UserWalletId,
currency: CryptoCurrency,
pageSize: Int,
refresh: Boolean,
): List<TxHistoryItem>
}

View file

@ -0,0 +1,36 @@
package com.tangem.domain.txhistory.usecase
import arrow.core.Either
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.flow
/**
* Returns first page with size [DEFAULT_PAGE_SIZE] of tx history.
* Page size is preserved to reuse cached data in Token Details Screen.
*
* IMPORTANT!!!
* If page size bigger than [DEFAULT_PAGE_SIZE] is needed consider to implement another use case
* without use of cached data or increase [DEFAULT_PAGE_SIZE]
*/
class GetFixedTxHistoryItemsUseCase(
private val repository: TxHistoryRepository,
) {
operator fun invoke(
userWalletId: UserWalletId,
currency: CryptoCurrency,
pageSize: Int = DEFAULT_PAGE_SIZE,
refresh: Boolean = false,
): Either<TxHistoryListError, Flow<List<TxHistoryItem>>> {
return Either.catch {
flow {
emit(repository.getFixedSizeTxHistoryItems(userWalletId, currency, pageSize, refresh))
}
}.mapLeft { TxHistoryListError.DataError(it) }
}
}

View file

@ -11,7 +11,7 @@ import com.tangem.domain.wallets.models.UserWalletId
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
private const val DEFAULT_PAGE_SIZE = 50
const val DEFAULT_PAGE_SIZE = 50
// TODO: Add tests
class GetTxHistoryItemsUseCase(private val repository: TxHistoryRepository) {