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 index ed640bfe95..85277a038f 100644 --- 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 @@ -75,28 +75,18 @@ class DefaultTxHistoryRepository( return pager.flow } - @Deprecated("Replace with getTxExploreUrl [UserWalletId, Network] instead") - override fun getTxExploreUrl(txHash: String, networkId: Network.ID): String { + override fun getTxExploreUrl(txHash: String, networkId: Network.ID, currency: CryptoCurrency): String { val blockchain = networkId.toBlockchain() - return when (val txExploreState = blockchain.getExploreTxUrl(txHash)) { + val txExploreState = when (currency) { + is CryptoCurrency.Token -> blockchain.getTokenExplorerTxUrl(txHash) + else -> blockchain.getExploreTxUrl(txHash) + } + return when (txExploreState) { is TxExploreState.Url -> txExploreState.url is TxExploreState.Unsupported -> "" } } - override suspend fun getTxExploreUrl(userWalletId: UserWalletId, network: Network): String { - val blockchain = network.toBlockchain() - val walletManager = walletManagersFacade.getOrCreateWalletManager( - userWalletId = userWalletId, - network = network, - ) - val lastTxHash = walletManager?.wallet?.recentTransactions?.last()?.hash.orEmpty() - return when (val txExploreState = blockchain.getExploreTxUrl(lastTxHash)) { - is TxExploreState.Url -> txExploreState.url - else -> "" - } - } - override suspend fun getFixedSizeTxHistoryItems( userWalletId: UserWalletId, currency: CryptoCurrency, diff --git a/domain/txhistory/build.gradle.kts b/domain/txhistory/build.gradle.kts index 5654e0148d..4e4655573b 100644 --- a/domain/txhistory/build.gradle.kts +++ b/domain/txhistory/build.gradle.kts @@ -1,6 +1,8 @@ plugins { alias(deps.plugins.android.library) alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.kapt) + alias(deps.plugins.hilt.android) id("configuration") } @@ -23,4 +25,8 @@ dependencies { implementation(deps.androidx.paging.runtime) api(projects.core.pagination) + + /** DI */ + implementation(deps.hilt.android) + kapt(deps.hilt.kapt) } \ No newline at end of file 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 d040f021e3..31a250f6f3 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 @@ -22,10 +22,7 @@ interface TxHistoryRepository { refresh: Boolean, ): Flow> - fun getTxExploreUrl(txHash: String, networkId: Network.ID): String - - /** Get transaction url in explorer via last transaction from wallet's recentTransactions list */ - suspend fun getTxExploreUrl(userWalletId: UserWalletId, network: Network): String + fun getTxExploreUrl(txHash: String, networkId: Network.ID, currency: CryptoCurrency): String @Throws(TxHistoryListError::class) suspend fun getFixedSizeTxHistoryItems( diff --git a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt index dcbec88d76..4f196ee9e1 100644 --- a/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt +++ b/domain/txhistory/src/main/kotlin/com/tangem/domain/txhistory/usecase/GetExplorerTransactionUrlUseCase.kt @@ -3,18 +3,24 @@ package com.tangem.domain.txhistory.usecase import arrow.core.Either import arrow.core.raise.catch import arrow.core.raise.either +import com.tangem.domain.models.currency.CryptoCurrency import com.tangem.domain.models.network.Network import com.tangem.domain.txhistory.models.TxStatusError import com.tangem.domain.txhistory.repository.TxHistoryRepository +import javax.inject.Inject -class GetExplorerTransactionUrlUseCase( +class GetExplorerTransactionUrlUseCase @Inject constructor( private val repository: TxHistoryRepository, ) { - operator fun invoke(txHash: String, networkId: Network.ID): Either { + operator fun invoke( + txHash: String, + networkId: Network.ID, + currency: CryptoCurrency, + ): Either { return either { catch( block = { - repository.getTxExploreUrl(txHash, networkId).ifEmpty { + repository.getTxExploreUrl(txHash, networkId, currency).ifEmpty { raise(TxStatusError.EmptyUrlError) } }, diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt index 6fcd04be67..065b3f29ab 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt @@ -460,6 +460,7 @@ internal class SendConfirmModel @Inject constructor( val txUrl = getExplorerTransactionUrlUseCase( txHash = txData.hash.orEmpty(), networkId = cryptoCurrency.network.id, + currency = cryptoCurrency, ).getOrNull().orEmpty() _uiState.update(SendConfirmSentStateTransformer(txData, txUrl)) } diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/confirm/model/NFTSendConfirmModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/confirm/model/NFTSendConfirmModel.kt index 8bab99a2a4..548a368a73 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/confirm/model/NFTSendConfirmModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/sendnft/confirm/model/NFTSendConfirmModel.kt @@ -335,6 +335,7 @@ internal class NFTSendConfirmModel @Inject constructor( val txUrl = getExplorerTransactionUrlUseCase( txHash = txData.hash.orEmpty(), networkId = cryptoCurrency.network.id, + currency = cryptoCurrency, ).getOrElse { "" } _uiState.update(NFTSendConfirmSentStateTransformer(txData, txUrl)) } diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/helpers/StakingTransactionSender.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/helpers/StakingTransactionSender.kt index ef5030f334..f05d4cde06 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/helpers/StakingTransactionSender.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/helpers/StakingTransactionSender.kt @@ -253,7 +253,8 @@ internal class StakingTransactionSender @AssistedInject constructor( val txUrl = getExplorerTransactionUrlUseCase( txHash = transactionHashes.last(), networkId = cryptoCurrencyStatus.currency.network.id, - ).getOrNull() ?: "" + currency = cryptoCurrencyStatus.currency, + ).getOrNull().orEmpty() balanceUpdater.updateAfterTransaction() onSendSuccess(txUrl) diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt index 3fcd6d870c..993f4ea095 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/sendviaswap/confirm/model/SendWithSwapConfirmModel.kt @@ -288,6 +288,7 @@ internal class SendWithSwapConfirmModel @Inject constructor( val txUrl = getExplorerTransactionUrlUseCase( txHash = txHash, networkId = primaryCurrencyStatus.currency.network.id, + currency = primaryCurrencyStatus.currency, ).getOrNull().orEmpty() sendSuccessAnalytics() uiState.transformerUpdate( diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt index 38d591dd72..65dba91ee9 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt @@ -781,6 +781,7 @@ internal class SwapModel @Inject constructor( val url = getExplorerTransactionUrlUseCase( txHash = swapTransactionState.txHash, networkId = fromCurrency.currency.network.id, + currency = fromCurrency.currency, ).getOrElse { Timber.i("tx hash explore not supported") "" diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt index 0b39af391f..f1e1c2c815 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/model/TokenDetailsModel.kt @@ -830,6 +830,7 @@ internal class TokenDetailsModel @Inject constructor( getExplorerTransactionUrlUseCase( txHash = txHash, networkId = cryptoCurrency.network.id, + currency = cryptoCurrency, ).fold( ifLeft = { Timber.e(it.toString()) }, ifRight = { router.openUrl(url = it) }, diff --git a/features/txhistory/impl/src/main/kotlin/com/tangem/features/txhistory/model/TxHistoryModel.kt b/features/txhistory/impl/src/main/kotlin/com/tangem/features/txhistory/model/TxHistoryModel.kt index b5586fdb53..88c8216469 100644 --- a/features/txhistory/impl/src/main/kotlin/com/tangem/features/txhistory/model/TxHistoryModel.kt +++ b/features/txhistory/impl/src/main/kotlin/com/tangem/features/txhistory/model/TxHistoryModel.kt @@ -222,6 +222,7 @@ internal class TxHistoryModel @Inject constructor( getExplorerTransactionUrlUseCase( txHash = txHash, networkId = params.currency.network.id, + currency = params.currency, ).fold( ifLeft = { Timber.e(it.toString()) }, ifRight = { urlOpener.openUrl(url = it) }, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/intents/WalletContentClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/intents/WalletContentClickIntents.kt index 2fa16a3f5f..d301a20f0c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/intents/WalletContentClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/child/wallet/model/intents/WalletContentClickIntents.kt @@ -322,11 +322,14 @@ internal class WalletContentClickIntentsImplementor @Inject constructor( ?.currency ?: return@launch - getExplorerTransactionUrlUseCase(txHash = txHash, networkId = currency.network.id) - .fold( - ifLeft = { Timber.e(it.toString()) }, - ifRight = { router.openUrl(url = it) }, - ) + getExplorerTransactionUrlUseCase( + txHash = txHash, + networkId = currency.network.id, + currency = currency, + ).fold( + ifLeft = { Timber.e(it.toString()) }, + ifRight = { router.openUrl(url = it) }, + ) } }