Updated on 2026-08-14

This commit is contained in:
Tangem 2023-10-31 15:39:52 +05:00
parent 93f7f4b424
commit 9b1d655ab5
8 changed files with 24 additions and 15 deletions

View file

@ -26,11 +26,11 @@ class DefaultTxHistoryRepository(
private val txHistoryItemsStore: TxHistoryItemsStore,
) : TxHistoryRepository {
override suspend fun getTxHistoryItemsCount(userWalletId: UserWalletId, network: Network): Int {
override suspend fun getTxHistoryItemsCount(userWalletId: UserWalletId, currency: CryptoCurrency): Int {
val userWallet = getUserWallet(userWalletId)
val state = walletManagersFacade.getTxHistoryState(
userWalletId = userWallet.walletId,
network = network,
currency = currency,
)
return when (state) {
is TxHistoryState.Failed.FetchError -> throw TxHistoryStateError.DataError(state.exception)

View file

@ -157,12 +157,12 @@ class DefaultWalletManagersFacade(
return blockchain.getExploreUrl(address, contractAddress)
}
override suspend fun getTxHistoryState(userWalletId: UserWalletId, network: Network): TxHistoryState {
val blockchain = Blockchain.fromId(network.id.value)
override suspend fun getTxHistoryState(userWalletId: UserWalletId, currency: CryptoCurrency): TxHistoryState {
val blockchain = Blockchain.fromId(currency.network.id.value)
val walletManager = getOrCreateWalletManager(
userWalletId = userWalletId,
blockchain = blockchain,
derivationPath = network.derivationPath.value,
derivationPath = currency.network.derivationPath.value,
)
requireNotNull(walletManager) {
@ -170,7 +170,13 @@ class DefaultWalletManagersFacade(
}
return walletManager
.getTransactionHistoryState(walletManager.wallet.address)
.getTransactionHistoryState(
address = walletManager.wallet.address,
filterType = when (currency) {
is CryptoCurrency.Coin -> TransactionHistoryRequest.FilterType.Coin
is CryptoCurrency.Token -> TransactionHistoryRequest.FilterType.Contract(currency.contractAddress)
},
)
.let(txHistoryStateConverter::convert)
}

View file

@ -77,9 +77,9 @@ interface WalletManagersFacade {
* Returns transactions count
*
* @param userWalletId The ID of the user's wallet.
* @param network The network.
* @param currency currency.
*/
suspend fun getTxHistoryState(userWalletId: UserWalletId, network: Network): TxHistoryState
suspend fun getTxHistoryState(userWalletId: UserWalletId, currency: CryptoCurrency): TxHistoryState
/**
* Returns transaction history items wrapped to pagination

View file

@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow
interface TxHistoryRepository {
@Throws(TxHistoryStateError::class)
suspend fun getTxHistoryItemsCount(userWalletId: UserWalletId, network: Network): Int
suspend fun getTxHistoryItemsCount(userWalletId: UserWalletId, currency: CryptoCurrency): Int
@Throws(TxHistoryListError::class)
fun getTxHistoryItems(

View file

@ -3,7 +3,7 @@ package com.tangem.domain.txhistory.usecase
import arrow.core.Either
import arrow.core.raise.catch
import arrow.core.raise.either
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.txhistory.models.TxHistoryStateError
import com.tangem.domain.txhistory.repository.TxHistoryRepository
import com.tangem.domain.wallets.models.UserWalletId
@ -11,10 +11,13 @@ import com.tangem.domain.wallets.models.UserWalletId
// TODO: Add tests
class GetTxHistoryItemsCountUseCase(private val repository: TxHistoryRepository) {
suspend operator fun invoke(userWalletId: UserWalletId, network: Network): Either<TxHistoryStateError, Int> {
suspend operator fun invoke(
userWalletId: UserWalletId,
currency: CryptoCurrency,
): Either<TxHistoryStateError, Int> {
return either {
catch(
block = { repository.getTxHistoryItemsCount(userWalletId, network) },
block = { repository.getTxHistoryItemsCount(userWalletId, currency) },
catch = { throwable ->
raise(
when (throwable) {

View file

@ -195,7 +195,7 @@ internal class TokenDetailsViewModel @Inject constructor(
viewModelScope.launch(dispatchers.io) {
val txHistoryItemsCountEither = txHistoryItemsCountUseCase(
userWalletId = userWalletId,
network = cryptoCurrency.network,
currency = cryptoCurrency,
)
// if countEither is left, handling error state run inside getLoadingTxHistoryState

View file

@ -1332,7 +1332,7 @@ internal class WalletViewModel @Inject constructor(
viewModelScope.launch(dispatchers.io) {
val txHistoryItemsCountEither = txHistoryItemsCountUseCase(
userWalletId = userWalletId,
network = currencyStatus.currency.network,
currency = currencyStatus.currency,
)
uiState = stateFactory.getLoadingTxHistoryState(

View file

@ -81,7 +81,7 @@ spr-client = "3.6.2"
# endregion Other libraries
# region Tangem
tangemBlockchainSdk = "release-app_5.0-369"
tangemBlockchainSdk = "release-app_5.0-370"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "release-app_5.0-309"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds