From d1a09370c7b81b4316857aa18eb2ae9e66eef221 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 9 Aug 2023 13:09:47 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../tap/data/RuntimeUserWalletsStore.kt | 3 + .../tangem/tap/proxy/TxHistoryManagerImpl.kt | 86 ------------------- .../com/tangem/tap/proxy/di/ProxyModule.kt | 7 -- .../local/userwallet/UserWalletsStore.kt | 2 + data/txhistory/build.gradle.kts | 6 ++ .../data/txhistory/di/TxHistoryDataModule.kt | 12 ++- .../data/txhistory/mock/MockTxHistoryItems.kt | 70 --------------- .../repository/DefaultTxHistoryRepository.kt | 66 ++++++++++++++ .../repository/MockTxHistoryRepository.kt | 25 ------ .../paging/TxHistoryPagingSource.kt | 22 ++--- domain/legacy/build.gradle.kts | 1 + .../DefaultWalletManagersFacade.kt | 69 +++++++++++++-- .../walletmanager/WalletManagersFacade.kt | 34 ++++++++ .../SdkTransactionHistoryItemConverter.kt | 29 +++++++ .../SdkTransactionHistoryStateConverter.kt | 16 ++++ domain/txhistory/build.gradle.kts | 2 + domain/txhistory/models/.gitignore | 1 + domain/txhistory/models/build.gradle.kts | 4 + .../txhistory/models/PaginationWrapper.kt | 8 ++ .../domain/txhistory/models}/TxHistoryItem.kt | 4 +- .../txhistory/models}/TxHistoryListError.kt | 2 +- .../domain/txhistory/models/TxHistoryState.kt | 15 ++++ .../txhistory/models}/TxHistoryStateError.kt | 2 +- .../repository/TxHistoryRepository.kt | 15 ++-- .../usecase/GetTxHistoryItemsCountUseCase.kt | 5 +- .../usecase/GetTxHistoryItemsUseCase.kt | 10 ++- features/tokendetails/impl/build.gradle.kts | 4 + features/wallet/impl/build.gradle.kts | 1 + .../state/factory/WalletStateFactory.kt | 6 +- .../WalletLoadedTxHistoryConverter.kt | 4 +- .../WalletLoadingTxHistoryConverter.kt | 2 +- .../WalletTxHistoryItemFlowConverter.kt | 4 +- .../wallet/viewmodels/WalletViewModel.kt | 21 +++-- gradle/dependencies.toml | 2 +- .../com/tangem/lib/crypto/TxHistoryManager.kt | 18 ---- .../txhistory/ProxyTransactionHistoryItem.kt | 21 ----- .../txhistory/ProxyTransactionHistoryState.kt | 15 ---- .../txhistory/ProxyTransactionStatus.kt | 3 - settings.gradle.kts | 1 + 39 files changed, 317 insertions(+), 301 deletions(-) delete mode 100644 app/src/main/java/com/tangem/tap/proxy/TxHistoryManagerImpl.kt delete mode 100644 data/txhistory/src/main/kotlin/com/tangem/data/txhistory/mock/MockTxHistoryItems.kt create mode 100644 data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/DefaultTxHistoryRepository.kt delete mode 100644 data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/MockTxHistoryRepository.kt create mode 100644 domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryItemConverter.kt create mode 100644 domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryStateConverter.kt create mode 100644 domain/txhistory/models/.gitignore create mode 100644 domain/txhistory/models/build.gradle.kts create mode 100644 domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/PaginationWrapper.kt rename domain/txhistory/{src/main/kotlin/com/tangem/domain/txhistory/model => models/src/main/kotlin/com/tangem/domain/txhistory/models}/TxHistoryItem.kt (87%) rename domain/txhistory/{src/main/kotlin/com/tangem/domain/txhistory/error => models/src/main/kotlin/com/tangem/domain/txhistory/models}/TxHistoryListError.kt (75%) create mode 100644 domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryState.kt rename domain/txhistory/{src/main/kotlin/com/tangem/domain/txhistory/error => models/src/main/kotlin/com/tangem/domain/txhistory/models}/TxHistoryStateError.kt (85%) delete mode 100644 libs/crypto/src/main/java/com/tangem/lib/crypto/TxHistoryManager.kt delete mode 100644 libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryItem.kt delete mode 100644 libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryState.kt delete mode 100644 libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionStatus.kt diff --git a/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt b/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt index d46dfadcad..a84ddc77c6 100644 --- a/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt +++ b/app/src/main/java/com/tangem/tap/data/RuntimeUserWalletsStore.kt @@ -12,6 +12,9 @@ internal class RuntimeUserWalletsStore( private val walletsStateHolder: WalletsStateHolder, ) : UserWalletsStore { + override val selectedUserWalletOrNull: UserWallet? + get() = walletsStateHolder.userWalletsListManager?.selectedUserWalletSync + override suspend fun getSyncOrNull(key: UserWalletId): UserWallet? { return walletsStateHolder.userWalletsListManager ?.userWallets diff --git a/app/src/main/java/com/tangem/tap/proxy/TxHistoryManagerImpl.kt b/app/src/main/java/com/tangem/tap/proxy/TxHistoryManagerImpl.kt deleted file mode 100644 index ff8b430a00..0000000000 --- a/app/src/main/java/com/tangem/tap/proxy/TxHistoryManagerImpl.kt +++ /dev/null @@ -1,86 +0,0 @@ -package com.tangem.tap.proxy - -import com.tangem.blockchain.common.Blockchain -import com.tangem.blockchain.common.TransactionStatus -import com.tangem.blockchain.common.WalletManager -import com.tangem.blockchain.common.txhistory.TransactionHistoryItem -import com.tangem.blockchain.common.txhistory.TransactionHistoryState -import com.tangem.blockchain.extensions.Result -import com.tangem.domain.common.BlockchainNetwork -import com.tangem.domain.common.extensions.fromNetworkId -import com.tangem.lib.crypto.TxHistoryManager -import com.tangem.lib.crypto.models.ProxyAmount -import com.tangem.lib.crypto.models.txhistory.ProxyTransactionHistoryItem -import com.tangem.lib.crypto.models.txhistory.ProxyTransactionHistoryState -import com.tangem.lib.crypto.models.txhistory.ProxyTransactionStatus - -class TxHistoryManagerImpl( - private val appStateHolder: AppStateHolder, -) : TxHistoryManager { - - override suspend fun checkTxHistoryState(networkId: String, derivationPath: String?): ProxyTransactionHistoryState { - val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" } - val walletManager = getActualWalletManager(blockchain, derivationPath) - val state = walletManager.getTransactionHistoryState(address = walletManager.wallet.address) - return state.mapToProxy() - } - - override suspend fun getTxHistoryItems( - networkId: String, - derivationPath: String?, - page: Int, - pageSize: Int, - ): List { - val blockchain = requireNotNull(Blockchain.fromNetworkId(networkId)) { "blockchain not found" } - val walletManager = getActualWalletManager(blockchain, derivationPath) - val itemsResult = walletManager.getTransactionsHistory( - address = walletManager.wallet.address, - page = page, - pageSize = pageSize, - ) - - return when (itemsResult) { - is Result.Success -> itemsResult.data.map { historyItem -> historyItem.mapToProxy() } - is Result.Failure -> error(itemsResult.error.message ?: itemsResult.error.customMessage) - } - } - - private fun getActualWalletManager(blockchain: Blockchain, derivationPath: String?): WalletManager { - val blockchainNetwork = BlockchainNetwork(blockchain, derivationPath, emptyList()) - val walletManager = appStateHolder.walletState?.getWalletManager(blockchainNetwork) - return requireNotNull(walletManager) { "no wallet manager found" } - } - - private fun TransactionHistoryState.mapToProxy(): ProxyTransactionHistoryState { - return when (this) { - TransactionHistoryState.Success.Empty -> ProxyTransactionHistoryState.Success.Empty - is TransactionHistoryState.Failed.FetchError -> ProxyTransactionHistoryState.Failed.FetchError(exception) - TransactionHistoryState.NotImplemented -> ProxyTransactionHistoryState.NotImplemented - is TransactionHistoryState.Success.HasTransactions -> - ProxyTransactionHistoryState.Success.HasTransactions(txCount) - } - } - - private fun TransactionHistoryItem.mapToProxy() = ProxyTransactionHistoryItem( - txHash = txHash, - timestamp = timestamp, - direction = when (val direction = direction) { - is TransactionHistoryItem.TransactionDirection.Incoming -> - ProxyTransactionHistoryItem.TransactionDirection.Incoming(direction.from) - is TransactionHistoryItem.TransactionDirection.Outgoing -> - ProxyTransactionHistoryItem.TransactionDirection.Outgoing(direction.to) - }, - status = when (status) { - TransactionStatus.Confirmed -> ProxyTransactionStatus.Confirmed - TransactionStatus.Unconfirmed -> ProxyTransactionStatus.Unconfirmed - }, - type = when (type) { - TransactionHistoryItem.TransactionType.Transfer -> ProxyTransactionHistoryItem.TransactionType.Transfer - }, - amount = ProxyAmount( - currencySymbol = amount.currencySymbol, - value = requireNotNull(amount.value) { "Amount value must not be null" }, - decimals = amount.decimals, - ), - ) -} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt b/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt index 9bae439352..fcd78bd469 100644 --- a/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt +++ b/app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt @@ -8,7 +8,6 @@ import com.tangem.domain.common.util.cardTypesResolver import com.tangem.feature.learn2earn.domain.api.Learn2earnDependencyProvider import com.tangem.lib.crypto.DerivationManager import com.tangem.lib.crypto.TransactionManager -import com.tangem.lib.crypto.TxHistoryManager import com.tangem.lib.crypto.UserWalletManager import com.tangem.tap.proxy.* import dagger.Module @@ -59,12 +58,6 @@ class ProxyModule { ) } - @Provides - @Singleton - fun provideTxHistoryManager(appStateHolder: AppStateHolder): TxHistoryManager { - return TxHistoryManagerImpl(appStateHolder = appStateHolder) - } - // regions FeatureConsumers @Provides @Singleton diff --git a/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt b/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt index a42253ee50..c905063cc3 100644 --- a/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt +++ b/core/datasource/src/main/java/com/tangem/datasource/local/userwallet/UserWalletsStore.kt @@ -5,5 +5,7 @@ import com.tangem.domain.wallets.models.UserWalletId interface UserWalletsStore { + val selectedUserWalletOrNull: UserWallet? + suspend fun getSyncOrNull(key: UserWalletId): UserWallet? } \ No newline at end of file diff --git a/data/txhistory/build.gradle.kts b/data/txhistory/build.gradle.kts index d2aa98d0fd..7ffda888cc 100644 --- a/data/txhistory/build.gradle.kts +++ b/data/txhistory/build.gradle.kts @@ -10,7 +10,13 @@ android { } dependencies { + implementation(projects.core.utils) + implementation(projects.core.datasource) + implementation(projects.domain.legacy) + implementation(projects.domain.tokens.models) implementation(projects.domain.txhistory) + implementation(projects.domain.txhistory.models) + implementation(projects.domain.wallets.models) implementation(deps.kotlin.coroutines) implementation(deps.androidx.paging.runtime) diff --git a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/di/TxHistoryDataModule.kt b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/di/TxHistoryDataModule.kt index 6fe0d348de..da8b08603c 100644 --- a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/di/TxHistoryDataModule.kt +++ b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/di/TxHistoryDataModule.kt @@ -1,7 +1,9 @@ package com.tangem.data.txhistory.di -import com.tangem.data.txhistory.repository.MockTxHistoryRepository +import com.tangem.data.txhistory.repository.DefaultTxHistoryRepository +import com.tangem.datasource.local.userwallet.UserWalletsStore import com.tangem.domain.txhistory.repository.TxHistoryRepository +import com.tangem.domain.walletmanager.WalletManagersFacade import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -14,5 +16,11 @@ internal object TxHistoryDataModule { @Provides @Singleton - fun provideTxHistoryRepository(): TxHistoryRepository = MockTxHistoryRepository() + fun provideTxHistoryRepository( + walletManagersFacade: WalletManagersFacade, + userWalletsStore: UserWalletsStore, + ): TxHistoryRepository = DefaultTxHistoryRepository( + walletManagersFacade = walletManagersFacade, + userWalletsStore = userWalletsStore, + ) } \ No newline at end of file diff --git a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/mock/MockTxHistoryItems.kt b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/mock/MockTxHistoryItems.kt deleted file mode 100644 index 583fbaa5ee..0000000000 --- a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/mock/MockTxHistoryItems.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.tangem.data.txhistory.mock - -import com.tangem.domain.txhistory.model.TxHistoryItem -import java.math.BigDecimal - -internal object MockTxHistoryItems { - - private val txHistoryItem1 = TxHistoryItem( - txHash = "noster", - timestamp = System.currentTimeMillis(), - direction = TxHistoryItem.TransactionDirection.Incoming("address"), - status = TxHistoryItem.TxStatus.Confirmed, - type = TxHistoryItem.TransactionType.Transfer, - amount = BigDecimal("1000000000.5"), - ) - - private val txHistoryItem2 = TxHistoryItem( - txHash = "noster", - timestamp = 1689844346000, - direction = TxHistoryItem.TransactionDirection.Incoming("address2"), - status = TxHistoryItem.TxStatus.Unconfirmed, - type = TxHistoryItem.TransactionType.Transfer, - amount = BigDecimal("1000000000.5"), - ) - - private val txHistoryItem3 = TxHistoryItem( - txHash = "noster", - timestamp = 1689757946000, - direction = TxHistoryItem.TransactionDirection.Outgoing("address3"), - status = TxHistoryItem.TxStatus.Confirmed, - type = TxHistoryItem.TransactionType.Transfer, - amount = BigDecimal("1000000000.5"), - ) - - private val txHistoryItem4 = TxHistoryItem( - txHash = "noster", - timestamp = 1689671546000, - direction = TxHistoryItem.TransactionDirection.Incoming("address4"), - status = TxHistoryItem.TxStatus.Confirmed, - type = TxHistoryItem.TransactionType.Transfer, - amount = BigDecimal("1000000000.5"), - ) - - private val txHistoryItem5 = TxHistoryItem( - txHash = "noster", - timestamp = 1689585146000, - direction = TxHistoryItem.TransactionDirection.Outgoing("address5"), - status = TxHistoryItem.TxStatus.Unconfirmed, - type = TxHistoryItem.TransactionType.Transfer, - amount = BigDecimal("1000000000.5"), - ) - - private val txHistoryItem6 = TxHistoryItem( - txHash = "noster", - timestamp = 1689585146000, - direction = TxHistoryItem.TransactionDirection.Incoming("address6"), - status = TxHistoryItem.TxStatus.Confirmed, - type = TxHistoryItem.TransactionType.Transfer, - amount = BigDecimal("1000000000.5"), - ) - - val txHistoryItems = listOf( - txHistoryItem1, - txHistoryItem2, - txHistoryItem3, - txHistoryItem4, - txHistoryItem5, - txHistoryItem6, - ) -} \ No newline at end of file diff --git a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/DefaultTxHistoryRepository.kt b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/DefaultTxHistoryRepository.kt new file mode 100644 index 0000000000..a042400894 --- /dev/null +++ b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/DefaultTxHistoryRepository.kt @@ -0,0 +1,66 @@ +package com.tangem.data.txhistory.repository + +import androidx.paging.Pager +import androidx.paging.PagingConfig +import androidx.paging.PagingData +import com.tangem.data.txhistory.repository.paging.TxHistoryPagingSource +import com.tangem.datasource.local.userwallet.UserWalletsStore +import com.tangem.domain.tokens.models.Network +import com.tangem.domain.txhistory.models.TxHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryState +import com.tangem.domain.txhistory.models.TxHistoryStateError +import com.tangem.domain.txhistory.repository.TxHistoryRepository +import com.tangem.domain.walletmanager.WalletManagersFacade +import com.tangem.domain.wallets.models.UserWallet +import kotlinx.coroutines.flow.Flow + +class DefaultTxHistoryRepository( + private val walletManagersFacade: WalletManagersFacade, + private val userWalletsStore: UserWalletsStore, +) : TxHistoryRepository { + + override suspend fun getTxHistoryItemsCount(networkId: Network.ID, derivationPath: String?): Int { + val userWallet = getUserWallet() + val state = walletManagersFacade.getTxHistoryState( + userWalletId = userWallet.walletId, + networkId = networkId, + rawDerivationPath = derivationPath, + ) + return when (state) { + is TxHistoryState.Failed.FetchError -> throw TxHistoryStateError.DataError(state.exception) + TxHistoryState.NotImplemented -> throw TxHistoryStateError.TxHistoryNotImplemented + TxHistoryState.Success.Empty -> throw TxHistoryStateError.EmptyTxHistories + is TxHistoryState.Success.HasTransactions -> state.txCount + } + } + + override fun getTxHistoryItems( + networkId: Network.ID, + derivationPath: String?, + pageSize: Int, + ): Flow> { + val userWallet = getUserWallet() + return Pager( + config = PagingConfig( + pageSize = pageSize, + ), + pagingSourceFactory = { + TxHistoryPagingSource( + loadPage = { page: Int, pageSize: Int -> + walletManagersFacade.getTxHistoryItems( + userWalletId = userWallet.walletId, + networkId = networkId, + rawDerivationPath = derivationPath, + page = page, + pageSize = pageSize, + ) + }, + ) + }, + ).flow + } + + private fun getUserWallet(): UserWallet = requireNotNull(userWalletsStore.selectedUserWalletOrNull) { + "Selected wallet must not be null" + } +} \ No newline at end of file diff --git a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/MockTxHistoryRepository.kt b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/MockTxHistoryRepository.kt deleted file mode 100644 index 59829686e4..0000000000 --- a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/MockTxHistoryRepository.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.tangem.data.txhistory.repository - -import androidx.paging.Pager -import androidx.paging.PagingConfig -import androidx.paging.PagingData -import com.tangem.data.txhistory.repository.paging.TxHistoryPagingSource -import com.tangem.domain.txhistory.model.TxHistoryItem -import com.tangem.domain.txhistory.repository.TxHistoryRepository -import kotlinx.coroutines.flow.Flow - -internal class MockTxHistoryRepository : TxHistoryRepository { - - override suspend fun getTxHistoryItemsCount(networkId: String, derivationPath: String): Int { - return 0 - } - - override fun getTxHistoryItems(networkId: String, pageSize: Int): Flow> { - return Pager( - config = PagingConfig( - pageSize = pageSize, - ), - pagingSourceFactory = { TxHistoryPagingSource() }, - ).flow - } -} \ No newline at end of file diff --git a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt index 3eba3ed6ce..a3ebb06194 100644 --- a/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt +++ b/data/txhistory/src/main/kotlin/com/tangem/data/txhistory/repository/paging/TxHistoryPagingSource.kt @@ -2,12 +2,14 @@ package com.tangem.data.txhistory.repository.paging import androidx.paging.PagingSource import androidx.paging.PagingState -import com.tangem.data.txhistory.mock.MockTxHistoryItems -import com.tangem.domain.txhistory.model.TxHistoryItem +import com.tangem.domain.txhistory.models.PaginationWrapper +import com.tangem.domain.txhistory.models.TxHistoryItem private const val INITIAL_PAGE = 1 -internal class TxHistoryPagingSource : PagingSource() { +internal class TxHistoryPagingSource( + private val loadPage: suspend (page: Int, pageSize: Int) -> PaginationWrapper, +) : PagingSource() { override fun getRefreshKey(state: PagingState): Int? { return state.anchorPosition?.let { anchorPosition -> @@ -19,20 +21,12 @@ internal class TxHistoryPagingSource : PagingSource() { override suspend fun load(params: LoadParams): LoadResult { val currentPage = params.key ?: INITIAL_PAGE return try { - // TODO: [REDACTED_JIRA] - // val result = txHistoryManager.getTxHistoryItems( - // networkId = networkId, - // derivationPath = derivationPath, - // page = currentPage, - // pageSize = params.loadSize, - // ) - val result = MockTxHistoryItems.txHistoryItems + val result = loadPage(currentPage, params.loadSize) LoadResult.Page( - data = result, + data = result.items, prevKey = if (currentPage > INITIAL_PAGE) currentPage.minus(1) else null, - // TODO: handle end of reached [REDACTED_JIRA] - nextKey = null, + nextKey = if (result.page < result.totalPages) currentPage.plus(1) else null, ) } catch (e: Exception) { LoadResult.Error(e) diff --git a/domain/legacy/build.gradle.kts b/domain/legacy/build.gradle.kts index 99665896d3..eb321b25e0 100644 --- a/domain/legacy/build.gradle.kts +++ b/domain/legacy/build.gradle.kts @@ -13,6 +13,7 @@ dependencies { implementation(projects.domain.models) implementation(projects.domain.tokens) implementation(projects.domain.tokens.models) + implementation(projects.domain.txhistory.models) implementation(projects.domain.wallets.models) /** Tangem libraries */ diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt index 1b942ab4ce..a798df5e73 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/DefaultWalletManagersFacade.kt @@ -3,6 +3,7 @@ package com.tangem.domain.walletmanager import com.tangem.blockchain.common.Blockchain import com.tangem.blockchain.common.BlockchainSdkError import com.tangem.blockchain.common.WalletManager +import com.tangem.blockchain.extensions.Result import com.tangem.crypto.hdWallet.DerivationPath import com.tangem.datasource.config.ConfigManager import com.tangem.datasource.local.userwallet.UserWalletsStore @@ -12,10 +13,11 @@ import com.tangem.domain.common.util.hasDerivation import com.tangem.domain.demo.DemoConfig import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.models.Network +import com.tangem.domain.txhistory.models.PaginationWrapper +import com.tangem.domain.txhistory.models.TxHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryState import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult -import com.tangem.domain.walletmanager.utils.SdkTokenConverter -import com.tangem.domain.walletmanager.utils.UpdateWalletManagerResultFactory -import com.tangem.domain.walletmanager.utils.WalletManagerFactory +import com.tangem.domain.walletmanager.utils.* import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import timber.log.Timber @@ -32,24 +34,22 @@ class DefaultWalletManagersFacade( private val resultFactory by lazy { UpdateWalletManagerResultFactory() } private val walletManagerFactory by lazy { WalletManagerFactory(configManager) } private val sdkTokenConverter by lazy { SdkTokenConverter() } + private val txHistoryStateConverter by lazy { SdkTransactionHistoryStateConverter() } + private val txHistoryItemConverter by lazy { SdkTransactionHistoryItemConverter() } override suspend fun update( userWalletId: UserWalletId, networkId: Network.ID, extraTokens: Set, ): UpdateWalletManagerResult { - val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) { - "Unable to find a user wallet with provided ID: $userWalletId" - } + val userWallet = getUserWallet(userWalletId) val blockchain = Blockchain.fromId(networkId.value) return getAndUpdateWalletManager(userWallet, blockchain, extraTokens) } override suspend fun getExploreUrl(userWalletId: UserWalletId, networkId: Network.ID): String { - val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) { - "Unable to find a user wallet with provided ID: $userWalletId" - } + val userWallet = getUserWallet(userWalletId) val blockchain = Blockchain.fromId(networkId.value) @@ -63,6 +63,57 @@ class DefaultWalletManagersFacade( .orEmpty() } + override suspend fun getTxHistoryState( + userWalletId: UserWalletId, + networkId: Network.ID, + rawDerivationPath: String?, + ): TxHistoryState { + val userWallet = getUserWallet(userWalletId) + val blockchain = Blockchain.fromId(networkId.value) + val derivationPath = rawDerivationPath?.let(::DerivationPath) + val walletManager = requireNotNull(getOrCreateWalletManager(userWallet, blockchain, derivationPath)) { + "Unable to get a wallet manager for blockchain: $blockchain" + } + return walletManager + .getTransactionHistoryState(walletManager.wallet.address) + .let(txHistoryStateConverter::convert) + } + + override suspend fun getTxHistoryItems( + userWalletId: UserWalletId, + networkId: Network.ID, + rawDerivationPath: String?, + page: Int, + pageSize: Int, + ): PaginationWrapper { + val userWallet = getUserWallet(userWalletId) + val blockchain = Blockchain.fromId(networkId.value) + val derivationPath = rawDerivationPath?.let(::DerivationPath) + val walletManager = requireNotNull(getOrCreateWalletManager(userWallet, blockchain, derivationPath)) { + "Unable to get a wallet manager for blockchain: $blockchain" + } + val itemsResult = walletManager.getTransactionsHistory( + address = walletManager.wallet.address, + page = page, + pageSize = pageSize, + ) + + return when (itemsResult) { + is Result.Success -> PaginationWrapper( + page = itemsResult.data.page, + totalPages = itemsResult.data.totalPages, + itemsOnPage = itemsResult.data.itemsOnPage, + items = txHistoryItemConverter.convertList(itemsResult.data.items), + ) + is Result.Failure -> error(itemsResult.error.message ?: itemsResult.error.customMessage) + } + } + + private suspend fun getUserWallet(userWalletId: UserWalletId) = + requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) { + "Unable to find a user wallet with provided ID: $userWalletId" + } + private suspend fun getAndUpdateWalletManager( userWallet: UserWallet, blockchain: Blockchain, diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/WalletManagersFacade.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/WalletManagersFacade.kt index a2ed074675..9a9a85aa35 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/WalletManagersFacade.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/WalletManagersFacade.kt @@ -2,6 +2,9 @@ package com.tangem.domain.walletmanager import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.models.Network +import com.tangem.domain.txhistory.models.PaginationWrapper +import com.tangem.domain.txhistory.models.TxHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryState import com.tangem.domain.walletmanager.model.UpdateWalletManagerResult import com.tangem.domain.wallets.models.UserWalletId @@ -26,4 +29,35 @@ interface WalletManagersFacade { ): UpdateWalletManagerResult suspend fun getExploreUrl(userWalletId: UserWalletId, networkId: Network.ID): String + + /** + * Returns transactions count + * + * @param userWalletId The ID of the user's wallet. + * @param networkId The network ID. + * @param rawDerivationPath Derivation path in raw form. + + */ + suspend fun getTxHistoryState( + userWalletId: UserWalletId, + networkId: Network.ID, + rawDerivationPath: String?, + ): TxHistoryState + + /** + * Returns transaction history items wrapped to pagination + * + * @param userWalletId The ID of the user's wallet. + * @param networkId The network ID. + * @param rawDerivationPath Derivation path in raw form. + * @param page Pagination page. + * @param pageSize Pagination size. + */ + suspend fun getTxHistoryItems( + userWalletId: UserWalletId, + networkId: Network.ID, + rawDerivationPath: String?, + page: Int, + pageSize: Int, + ): PaginationWrapper } \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryItemConverter.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryItemConverter.kt new file mode 100644 index 0000000000..8df6e63c54 --- /dev/null +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryItemConverter.kt @@ -0,0 +1,29 @@ +package com.tangem.domain.walletmanager.utils + +import com.tangem.blockchain.common.TransactionStatus +import com.tangem.blockchain.common.txhistory.TransactionHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryItem +import com.tangem.utils.converter.Converter +import com.tangem.blockchain.common.txhistory.TransactionHistoryItem as SdkTransactionHistoryItem + +internal class SdkTransactionHistoryItemConverter : Converter { + + override fun convert(value: SdkTransactionHistoryItem): TxHistoryItem = TxHistoryItem( + txHash = value.txHash, + timestampInMillis = value.timestamp, + direction = when (val direction = value.direction) { + is SdkTransactionHistoryItem.TransactionDirection.Incoming -> + TxHistoryItem.TransactionDirection.Incoming(direction.from) + is SdkTransactionHistoryItem.TransactionDirection.Outgoing -> + TxHistoryItem.TransactionDirection.Outgoing(direction.to) + }, + status = when (value.status) { + TransactionStatus.Confirmed -> TxHistoryItem.TxStatus.Confirmed + TransactionStatus.Unconfirmed -> TxHistoryItem.TxStatus.Unconfirmed + }, + type = when (value.type) { + TransactionHistoryItem.TransactionType.Transfer -> TxHistoryItem.TransactionType.Transfer + }, + amount = requireNotNull(value.amount.value) { "Transaction amount value must not be null" }, + ) +} \ No newline at end of file diff --git a/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryStateConverter.kt b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryStateConverter.kt new file mode 100644 index 0000000000..6750e05410 --- /dev/null +++ b/domain/legacy/src/main/java/com/tangem/domain/walletmanager/utils/SdkTransactionHistoryStateConverter.kt @@ -0,0 +1,16 @@ +package com.tangem.domain.walletmanager.utils + +import com.tangem.blockchain.common.txhistory.TransactionHistoryState +import com.tangem.domain.txhistory.models.TxHistoryState +import com.tangem.utils.converter.Converter +import com.tangem.blockchain.common.txhistory.TransactionHistoryState as SdkTransactionHistoryState + +internal class SdkTransactionHistoryStateConverter : Converter { + + override fun convert(value: TransactionHistoryState): TxHistoryState = when (value) { + is TransactionHistoryState.Success.Empty -> TxHistoryState.Success.Empty + is TransactionHistoryState.Success.HasTransactions -> TxHistoryState.Success.HasTransactions(value.txCount) + is TransactionHistoryState.Failed.FetchError -> TxHistoryState.Failed.FetchError(value.exception) + is TransactionHistoryState.NotImplemented -> TxHistoryState.NotImplemented + } +} \ No newline at end of file diff --git a/domain/txhistory/build.gradle.kts b/domain/txhistory/build.gradle.kts index 1237e8f782..2ba0547f59 100644 --- a/domain/txhistory/build.gradle.kts +++ b/domain/txhistory/build.gradle.kts @@ -14,4 +14,6 @@ dependencies { implementation(deps.androidx.paging.runtime) implementation(projects.core.utils) + implementation(projects.domain.tokens.models) + implementation(projects.domain.txhistory.models) } \ No newline at end of file diff --git a/domain/txhistory/models/.gitignore b/domain/txhistory/models/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/domain/txhistory/models/.gitignore @@ -0,0 +1 @@ +/build diff --git a/domain/txhistory/models/build.gradle.kts b/domain/txhistory/models/build.gradle.kts new file mode 100644 index 0000000000..7ff7fb7522 --- /dev/null +++ b/domain/txhistory/models/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + alias(deps.plugins.kotlin.jvm) + id("configuration") +} \ No newline at end of file diff --git a/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/PaginationWrapper.kt b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/PaginationWrapper.kt new file mode 100644 index 0000000000..92ea34de36 --- /dev/null +++ b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/PaginationWrapper.kt @@ -0,0 +1,8 @@ +package com.tangem.domain.txhistory.models + +data class PaginationWrapper( + val page: Int, + val totalPages: Int, + val itemsOnPage: Int, + val items: List, +) \ No newline at end of file diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/model/TxHistoryItem.kt b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryItem.kt similarity index 87% rename from domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/model/TxHistoryItem.kt rename to domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryItem.kt index 41d5c76d8e..447a9395ff 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/model/TxHistoryItem.kt +++ b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryItem.kt @@ -1,10 +1,10 @@ -package com.tangem.domain.txhistory.model +package com.tangem.domain.txhistory.models import java.math.BigDecimal data class TxHistoryItem( val txHash: String, - val timestamp: Long, + val timestampInMillis: Long, val direction: TransactionDirection, val status: TxStatus, val type: TransactionType, diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/error/TxHistoryListError.kt b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryListError.kt similarity index 75% rename from domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/error/TxHistoryListError.kt rename to domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryListError.kt index 1538b27e0b..618980c881 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/error/TxHistoryListError.kt +++ b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryListError.kt @@ -1,4 +1,4 @@ -package com.tangem.domain.txhistory.error +package com.tangem.domain.txhistory.models sealed class TxHistoryListError : Throwable() { data class DataError(override val cause: Throwable) : TxHistoryListError() diff --git a/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryState.kt b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryState.kt new file mode 100644 index 0000000000..0436102e66 --- /dev/null +++ b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryState.kt @@ -0,0 +1,15 @@ +package com.tangem.domain.txhistory.models + +sealed class TxHistoryState { + + sealed class Success : TxHistoryState() { + object Empty : Success() + data class HasTransactions(val txCount: Int) : Success() + } + + sealed class Failed : TxHistoryState() { + data class FetchError(val exception: Exception) : Failed() + } + + object NotImplemented : TxHistoryState() +} \ No newline at end of file diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/error/TxHistoryStateError.kt b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryStateError.kt similarity index 85% rename from domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/error/TxHistoryStateError.kt rename to domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryStateError.kt index 3f93a3cf12..1b5f07333c 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/error/TxHistoryStateError.kt +++ b/domain/txhistory/models/src/main/kotlin/com/tangem/domain/txhistory/models/TxHistoryStateError.kt @@ -1,4 +1,4 @@ -package com.tangem.domain.txhistory.error +package com.tangem.domain.txhistory.models sealed class TxHistoryStateError : Throwable() { diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/repository/TxHistoryRepository.kt b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/repository/TxHistoryRepository.kt index 1ebb8ae1dd..8ff4c05cff 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/repository/TxHistoryRepository.kt +++ b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/repository/TxHistoryRepository.kt @@ -1,16 +1,21 @@ package com.tangem.domain.txhistory.repository import androidx.paging.PagingData -import com.tangem.domain.txhistory.error.TxHistoryListError -import com.tangem.domain.txhistory.error.TxHistoryStateError -import com.tangem.domain.txhistory.model.TxHistoryItem +import com.tangem.domain.tokens.models.Network +import com.tangem.domain.txhistory.models.TxHistoryListError +import com.tangem.domain.txhistory.models.TxHistoryStateError +import com.tangem.domain.txhistory.models.TxHistoryItem import kotlinx.coroutines.flow.Flow interface TxHistoryRepository { @Throws(TxHistoryStateError::class) - suspend fun getTxHistoryItemsCount(networkId: String, derivationPath: String): Int + suspend fun getTxHistoryItemsCount(networkId: Network.ID, derivationPath: String?): Int @Throws(TxHistoryListError::class) - fun getTxHistoryItems(networkId: String, pageSize: Int): Flow> + fun getTxHistoryItems( + networkId: Network.ID, + derivationPath: String?, + pageSize: Int, + ): Flow> } \ No newline at end of file diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsCountUseCase.kt b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsCountUseCase.kt index 1ecdc72dd6..172c8c2b3f 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsCountUseCase.kt +++ b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsCountUseCase.kt @@ -3,12 +3,13 @@ package com.tangem.domain.txhistory.usecase import arrow.core.Either import arrow.core.raise.catch import arrow.core.raise.either -import com.tangem.domain.txhistory.error.TxHistoryStateError +import com.tangem.domain.tokens.models.Network +import com.tangem.domain.txhistory.models.TxHistoryStateError import com.tangem.domain.txhistory.repository.TxHistoryRepository class GetTxHistoryItemsCountUseCase(private val repository: TxHistoryRepository) { - suspend operator fun invoke(networkId: String, derivationPath: String): Either { + suspend operator fun invoke(networkId: Network.ID, derivationPath: String?): Either { return either { catch( block = { repository.getTxHistoryItemsCount(networkId, derivationPath) }, diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsUseCase.kt b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsUseCase.kt index 9f3fc2fbe0..38fbf4b87e 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsUseCase.kt +++ b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetTxHistoryItemsUseCase.kt @@ -3,8 +3,9 @@ package com.tangem.domain.txhistory.usecase import androidx.paging.PagingData import arrow.core.Either import arrow.core.raise.either -import com.tangem.domain.txhistory.error.TxHistoryListError -import com.tangem.domain.txhistory.model.TxHistoryItem +import com.tangem.domain.tokens.models.Network +import com.tangem.domain.txhistory.models.TxHistoryListError +import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.domain.txhistory.repository.TxHistoryRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch @@ -14,12 +15,13 @@ private const val DEFAULT_PAGE_SIZE = 20 class GetTxHistoryItemsUseCase(private val repository: TxHistoryRepository) { operator fun invoke( - networkId: String, + networkId: Network.ID, + derivationPath: String?, pageSize: Int = DEFAULT_PAGE_SIZE, ): Either>> { return either { repository - .getTxHistoryItems(networkId = networkId, pageSize = pageSize) + .getTxHistoryItems(networkId = networkId, derivationPath = derivationPath, pageSize = pageSize) .catch { raise(TxHistoryListError.DataError(it)) } } } diff --git a/features/tokendetails/impl/build.gradle.kts b/features/tokendetails/impl/build.gradle.kts index d3af011dcd..e37da473bc 100644 --- a/features/tokendetails/impl/build.gradle.kts +++ b/features/tokendetails/impl/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { implementation(deps.compose.coil) implementation(deps.kotlin.immutable.collections) + implementation(deps.arrow.core) /** DI */ implementation(deps.hilt.android) @@ -37,6 +38,9 @@ dependencies { implementation(projects.core.ui) implementation(projects.core.navigation) + implementation(projects.domain.txhistory) + implementation(projects.domain.txhistory.models) + /** Feature Apis */ implementation(projects.features.tokendetails.api) } \ No newline at end of file diff --git a/features/wallet/impl/build.gradle.kts b/features/wallet/impl/build.gradle.kts index 265fb7ce41..d517ab1def 100644 --- a/features/wallet/impl/build.gradle.kts +++ b/features/wallet/impl/build.gradle.kts @@ -53,6 +53,7 @@ dependencies { implementation(projects.domain.tokens) implementation(projects.domain.tokens.models) implementation(projects.domain.txhistory) + implementation(projects.domain.txhistory.models) implementation(projects.domain.wallets) implementation(projects.domain.wallets.models) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt index a3bb1b915c..69a67bea5e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt @@ -7,9 +7,9 @@ import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.tokens.error.TokenListError import com.tangem.domain.tokens.model.TokenList -import com.tangem.domain.txhistory.error.TxHistoryListError -import com.tangem.domain.txhistory.error.TxHistoryStateError -import com.tangem.domain.txhistory.model.TxHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryListError +import com.tangem.domain.txhistory.models.TxHistoryStateError +import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.presentation.wallet.state.WalletLoading import com.tangem.feature.wallet.presentation.wallet.state.WalletMultiCurrencyState diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt index 8f4e728d13..1364a89682 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadedTxHistoryConverter.kt @@ -6,8 +6,8 @@ import com.tangem.common.Provider import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.txhistory.error.TxHistoryListError -import com.tangem.domain.txhistory.model.TxHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryListError +import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt index ffe28ac46d..8ea55731fd 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletLoadingTxHistoryConverter.kt @@ -7,7 +7,7 @@ import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import com.tangem.core.ui.components.transactions.TransactionState import com.tangem.domain.common.CardTypesResolver -import com.tangem.domain.txhistory.error.TxHistoryStateError +import com.tangem.domain.txhistory.models.TxHistoryStateError import com.tangem.feature.wallet.presentation.wallet.state.WalletSingleCurrencyState import com.tangem.feature.wallet.presentation.wallet.state.WalletStateHolder import com.tangem.feature.wallet.presentation.wallet.state.components.WalletManageButton diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt index 7d61b17351..698ac67c5a 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/txhistory/WalletTxHistoryItemFlowConverter.kt @@ -4,7 +4,7 @@ import android.text.format.DateUtils import androidx.paging.* import com.tangem.blockchain.common.Blockchain import com.tangem.core.ui.components.transactions.TransactionState -import com.tangem.domain.txhistory.model.TxHistoryItem +import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState import com.tangem.feature.wallet.presentation.wallet.state.components.WalletTxHistoryState.TxHistoryItemState import com.tangem.feature.wallet.presentation.wallet.viewmodels.WalletClickIntents @@ -180,7 +180,7 @@ internal class WalletTxHistoryItemFlowConverter( * * @see [convert] */ - private fun TxHistoryItem.getRawTimestamp() = this.timestamp.toString() + private fun TxHistoryItem.getRawTimestamp() = this.timestampInMillis.toString() private fun TxHistoryItemState?.getTimestamp(): Long? { return if (this is TxHistoryItemState.Transaction && this.state is TransactionState.Content) { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 6d08a629c2..6083b4973d 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -5,12 +5,12 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.* import androidx.paging.cachedIn -import com.tangem.blockchain.common.DerivationStyle import com.tangem.common.Provider import com.tangem.common.doOnFailure import com.tangem.common.doOnSuccess import com.tangem.domain.card.* import com.tangem.domain.common.CardTypesResolver +import com.tangem.domain.common.TapWorkarounds.derivationStyle import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.settings.IsUserAlreadyRateAppUseCase @@ -143,23 +143,30 @@ internal class WalletViewModel @Inject constructor( private fun updateByTxHistory(index: Int) { viewModelScope.launch(dispatchers.io) { - val blockchain = getWallet(index).scanResponse.cardTypesResolver.getBlockchain() + val wallet = getWallet(index) + val blockchain = wallet.scanResponse.cardTypesResolver.getBlockchain() + val derivationPath = blockchain.derivationPath(style = wallet.scanResponse.card.derivationStyle)?.rawPath val txHistoryItemsCountEither = txHistoryItemsCountUseCase( - networkId = blockchain.id, - derivationPath = requireNotNull(blockchain.derivationPath(style = DerivationStyle.LEGACY)).rawPath, + networkId = Network.ID(blockchain.id), + derivationPath = derivationPath, ) uiState = stateFactory.getLoadingTxHistoryState(itemsCountEither = txHistoryItemsCountEither) - txHistoryItemsCountEither.onRight { updateTxHistory(networkId = blockchain.id) } + txHistoryItemsCountEither.onRight { + updateTxHistory( + networkId = Network.ID(blockchain.id), + derivationPath = derivationPath, + ) + } updateNotifications(index) } } - private fun updateTxHistory(networkId: String) { + private fun updateTxHistory(networkId: Network.ID, derivationPath: String?) { uiState = stateFactory.getLoadedTxHistoryState( - txHistoryEither = txHistoryItemsUseCase(networkId = networkId).map { it.cachedIn(viewModelScope) }, + txHistoryEither = txHistoryItemsUseCase(networkId, derivationPath).map { it.cachedIn(viewModelScope) }, ) } diff --git a/gradle/dependencies.toml b/gradle/dependencies.toml index edb6ad70d8..06a5bc01d8 100644 --- a/gradle/dependencies.toml +++ b/gradle/dependencies.toml @@ -80,7 +80,7 @@ okHttp-prettyLogging = "3.1.0" # endregion Other libraries # region Tangem -tangemBlockchainSdk = "develop-297" +tangemBlockchainSdk = "develop-306" #tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds tangemCardSdk = "develop-280" #tangemCardSdk = "0.0.1" # Keep it! - used for local builds diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/TxHistoryManager.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/TxHistoryManager.kt deleted file mode 100644 index de50d8b4ee..0000000000 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/TxHistoryManager.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.tangem.lib.crypto - -import com.tangem.lib.crypto.models.txhistory.ProxyTransactionHistoryItem -import com.tangem.lib.crypto.models.txhistory.ProxyTransactionHistoryState - -interface TxHistoryManager { - - @Throws(IllegalStateException::class) - suspend fun checkTxHistoryState(networkId: String, derivationPath: String?): ProxyTransactionHistoryState - - @Throws(IllegalStateException::class) - suspend fun getTxHistoryItems( - networkId: String, - derivationPath: String?, - page: Int, - pageSize: Int, - ): List -} \ No newline at end of file diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryItem.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryItem.kt deleted file mode 100644 index 387a7518e6..0000000000 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryItem.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.tangem.lib.crypto.models.txhistory - -import com.tangem.lib.crypto.models.ProxyAmount - -data class ProxyTransactionHistoryItem( - val txHash: String, - val timestamp: Long, - val direction: TransactionDirection, - val status: ProxyTransactionStatus, - val type: TransactionType, - val amount: ProxyAmount, -) { - sealed interface TransactionDirection { - data class Incoming(val from: String) : TransactionDirection - data class Outgoing(val to: String) : TransactionDirection - } - - sealed interface TransactionType { - object Transfer : TransactionType - } -} \ No newline at end of file diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryState.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryState.kt deleted file mode 100644 index ddeeba4d3f..0000000000 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionHistoryState.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.tangem.lib.crypto.models.txhistory - -sealed class ProxyTransactionHistoryState { - - sealed class Success : ProxyTransactionHistoryState() { - object Empty : Success() - data class HasTransactions(val txCount: Int) : Success() - } - - sealed class Failed : ProxyTransactionHistoryState() { - data class FetchError(val exception: Exception) : Failed() - } - - object NotImplemented : ProxyTransactionHistoryState() -} \ No newline at end of file diff --git a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionStatus.kt b/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionStatus.kt deleted file mode 100644 index 2e5ffd5aaf..0000000000 --- a/libs/crypto/src/main/java/com/tangem/lib/crypto/models/txhistory/ProxyTransactionStatus.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.tangem.lib.crypto.models.txhistory - -enum class ProxyTransactionStatus { Confirmed, Unconfirmed } \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 7378b7b744..8c859f1b92 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -107,6 +107,7 @@ include(":domain:tokens:models") include(":domain:wallets") include(":domain:wallets:models") include(":domain:txhistory") +include(":domain:txhistory:models") // endregion Domain modules // region Data modules