Updated on 2026-08-14
This commit is contained in:
parent
32884bd743
commit
b28720df71
3 changed files with 15 additions and 28 deletions
|
|
@ -2,10 +2,8 @@ package com.tangem.data.txhistory.repository.paging
|
||||||
|
|
||||||
import androidx.paging.PagingSource
|
import androidx.paging.PagingSource
|
||||||
import androidx.paging.PagingState
|
import androidx.paging.PagingState
|
||||||
import com.tangem.blockchain.common.Blockchain
|
|
||||||
import com.tangem.data.common.cache.CacheRegistry
|
import com.tangem.data.common.cache.CacheRegistry
|
||||||
import com.tangem.datasource.local.txhistory.TxHistoryItemsStore
|
import com.tangem.datasource.local.txhistory.TxHistoryItemsStore
|
||||||
import com.tangem.domain.common.extensions.fromNetworkId
|
|
||||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||||
import com.tangem.domain.txhistory.models.Page
|
import com.tangem.domain.txhistory.models.Page
|
||||||
import com.tangem.domain.txhistory.models.PaginationWrapper
|
import com.tangem.domain.txhistory.models.PaginationWrapper
|
||||||
|
|
@ -82,17 +80,9 @@ internal class TxHistoryPagingSource(
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun PaginationWrapper<TxHistoryItem>.addRecentTransactions(): PaginationWrapper<TxHistoryItem> {
|
private suspend fun PaginationWrapper<TxHistoryItem>.addRecentTransactions(): PaginationWrapper<TxHistoryItem> {
|
||||||
val blockchain = Blockchain.fromNetworkId(sourceParams.currency.network.backendId)
|
|
||||||
|
|
||||||
if (blockchain == null) {
|
|
||||||
Timber.e("Blockchain not found")
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
val recentItems = walletManagersFacade.getRecentTransactions(
|
val recentItems = walletManagersFacade.getRecentTransactions(
|
||||||
userWalletId = sourceParams.userWalletId,
|
userWalletId = sourceParams.userWalletId,
|
||||||
blockchain = blockchain,
|
currency = sourceParams.currency,
|
||||||
derivationPath = sourceParams.currency.network.derivationPath.value,
|
|
||||||
)
|
)
|
||||||
.filterUnconfirmedTransaction()
|
.filterUnconfirmedTransaction()
|
||||||
.filterIfTxAlreadyAdded(apiItems = items)
|
.filterIfTxAlreadyAdded(apiItems = items)
|
||||||
|
|
|
||||||
|
|
@ -520,27 +520,28 @@ class DefaultWalletManagersFacade(
|
||||||
|
|
||||||
override suspend fun getRecentTransactions(
|
override suspend fun getRecentTransactions(
|
||||||
userWalletId: UserWalletId,
|
userWalletId: UserWalletId,
|
||||||
blockchain: Blockchain,
|
currency: CryptoCurrency,
|
||||||
derivationPath: String?,
|
|
||||||
): List<TxHistoryItem> {
|
): List<TxHistoryItem> {
|
||||||
val walletManager = getOrCreateWalletManager(
|
val walletManager = getOrCreateWalletManager(userWalletId = userWalletId, network = currency.network)
|
||||||
userWalletId = userWalletId,
|
|
||||||
blockchain = blockchain,
|
|
||||||
derivationPath = derivationPath,
|
|
||||||
)
|
|
||||||
val feePaidCurrency = blockchain.feePaidCurrency()
|
|
||||||
|
|
||||||
if (walletManager == null) {
|
if (walletManager == null) {
|
||||||
Timber.e("Unable to get a wallet manager for blockchain: $blockchain")
|
Timber.e("Unable to get a wallet manager for blockchain: ${currency.network.id}")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
val transactionDataConverter = TransactionDataToTxHistoryItemConverter(
|
val transactionDataConverter = TransactionDataToTxHistoryItemConverter(
|
||||||
walletAddresses = SdkAddressToAddressConverter.convertList(walletManager.wallet.addresses).toSet(),
|
walletAddresses = SdkAddressToAddressConverter.convertList(walletManager.wallet.addresses).toSet(),
|
||||||
feePaidCurrency = feePaidCurrency,
|
feePaidCurrency = walletManager.wallet.blockchain.feePaidCurrency(),
|
||||||
)
|
)
|
||||||
|
|
||||||
return walletManager.wallet.recentTransactions.mapNotNull(transactionDataConverter::convert)
|
return walletManager.wallet.recentTransactions
|
||||||
|
.filter { transaction ->
|
||||||
|
when (currency) {
|
||||||
|
is CryptoCurrency.Coin -> transaction.amount.type is AmountType.Coin
|
||||||
|
is CryptoCurrency.Token -> transaction.contractAddress == currency.contractAddress
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.mapNotNull(transactionDataConverter::convert)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun tokenBalance(
|
override suspend fun tokenBalance(
|
||||||
|
|
|
||||||
|
|
@ -227,12 +227,8 @@ interface WalletManagersFacade {
|
||||||
network: Network,
|
network: Network,
|
||||||
): SimpleResult
|
): SimpleResult
|
||||||
|
|
||||||
/** Get recent transactions of [userWalletId] for [blockchain] with [derivationPath] */
|
/** Get recent transactions of [userWalletId] for [currency] */
|
||||||
suspend fun getRecentTransactions(
|
suspend fun getRecentTransactions(userWalletId: UserWalletId, currency: CryptoCurrency): List<TxHistoryItem>
|
||||||
userWalletId: UserWalletId,
|
|
||||||
blockchain: Blockchain,
|
|
||||||
derivationPath: String?,
|
|
||||||
): List<TxHistoryItem>
|
|
||||||
|
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
suspend fun tokenBalance(
|
suspend fun tokenBalance(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue