Updated on 2026-08-14

This commit is contained in:
Tangem 2024-04-12 17:20:20 +05:00
parent 16c1a70a4b
commit 7d15269083
5 changed files with 44 additions and 11 deletions

View file

@ -9,6 +9,7 @@ import com.tangem.data.common.cache.CacheRegistry
import com.tangem.data.txhistory.repository.paging.TxHistoryPagingSource
import com.tangem.datasource.local.txhistory.TxHistoryItemsStore
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.txhistory.models.Page
@ -69,6 +70,7 @@ class DefaultTxHistoryRepository(
return pager.flow
}
@Deprecated("Replace with getTxExploreUrl [UserWalletId, Network] instead")
override fun getTxExploreUrl(txHash: String, networkId: Network.ID): String {
val blockchain = Blockchain.fromId(networkId.value)
return when (val txExploreState = blockchain.getExploreTxUrl(txHash)) {
@ -77,6 +79,19 @@ class DefaultTxHistoryRepository(
}
}
override suspend fun getTxExploreUrl(userWalletId: UserWalletId, network: Network): String {
val blockchain = Blockchain.fromNetworkId(network.id.value)
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,

View file

@ -24,6 +24,9 @@ interface TxHistoryRepository {
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
@Throws(TxHistoryListError::class)
suspend fun getFixedSizeTxHistoryItems(
userWalletId: UserWalletId,

View file

@ -6,10 +6,12 @@ import arrow.core.raise.either
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.txhistory.models.TxStatusError
import com.tangem.domain.txhistory.repository.TxHistoryRepository
import com.tangem.domain.wallets.models.UserWalletId
class GetExplorerTransactionUrlUseCase(
private val repository: TxHistoryRepository,
) {
@Deprecated("Replace with invoke [UserWalletId, Network]")
operator fun invoke(txHash: String, networkId: Network.ID): Either<TxStatusError, String> {
return either {
catch(
@ -22,4 +24,17 @@ class GetExplorerTransactionUrlUseCase(
)
}
}
suspend operator fun invoke(userWalletId: UserWalletId, network: Network): Either<TxStatusError, String> {
return either {
catch(
block = {
repository.getTxExploreUrl(userWalletId, network).ifEmpty {
raise(TxStatusError.EmptyUrlError)
}
},
catch = { raise(TxStatusError.DataError(it)) },
)
}
}
}

View file

@ -8,7 +8,6 @@ import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.txhistory.models.TxHistoryItem
import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.domain.wallets.usecase.ValidateWalletMemoUseCase
import com.tangem.features.send.impl.R
@ -36,7 +35,6 @@ internal class SendStateFactory(
private val feeCryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus?>,
private val isTapHelpPreviewEnabledProvider: Provider<Boolean>,
private val validateWalletMemoUseCase: ValidateWalletMemoUseCase,
private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase,
) {
private val iconStateConverter by lazy(::CryptoCurrencyToIconStateConverter)
@ -251,14 +249,9 @@ internal class SendStateFactory(
)
}
fun getTransactionSendState(txData: TransactionData): SendUiState {
fun getTransactionSendState(txData: TransactionData, txUrl: String): SendUiState {
val state = currentStateProvider()
val cryptoCurrency = cryptoCurrencyStatusProvider().currency
val sendState = state.sendState ?: return state
val txUrl = getExplorerTransactionUrlUseCase(
txHash = txData.hash.orEmpty(),
networkId = cryptoCurrency.network.id,
).getOrElse { "" }
return state.copy(
sendState = sendState.copy(
transactionDate = txData.date?.timeInMillis ?: System.currentTimeMillis(),

View file

@ -89,9 +89,9 @@ internal class SendViewModel @Inject constructor(
private val parseQrCodeUseCase: ParseQrCodeUseCase,
private val isSendTapHelpEnabledUseCase: IsSendTapHelpEnabledUseCase,
private val neverShowTapHelpUseCase: NeverShowTapHelpUseCase,
private val getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase,
currencyChecksRepository: CurrencyChecksRepository,
isFeeApproximateUseCase: IsFeeApproximateUseCase,
getExplorerTransactionUrlUseCase: GetExplorerTransactionUrlUseCase,
validateWalletMemoUseCase: ValidateWalletMemoUseCase,
getBalanceNotEnoughForFeeWarningUseCase: GetBalanceNotEnoughForFeeWarningUseCase,
savedStateHandle: SavedStateHandle,
@ -123,7 +123,6 @@ internal class SendViewModel @Inject constructor(
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
feeCryptoCurrencyStatusProvider = Provider { feeCryptoCurrencyStatus },
validateWalletMemoUseCase = validateWalletMemoUseCase,
getExplorerTransactionUrlUseCase = getExplorerTransactionUrlUseCase,
isTapHelpPreviewEnabledProvider = Provider { isTapHelpPreviewEnabled },
)
@ -845,13 +844,21 @@ internal class SendViewModel @Inject constructor(
},
ifRight = {
uiState = stateFactory.getSendingStateUpdate(isSending = false)
uiState = stateFactory.getTransactionSendState(txData)
updateTransactionStatus(txData)
scheduleBalanceUpdate()
analyticsEventHandler.send(SendAnalyticEvents.TransactionScreenOpened)
},
)
}
private suspend fun updateTransactionStatus(txData: TransactionData) {
val txUrl = getExplorerTransactionUrlUseCase(
userWalletId = userWalletId,
network = cryptoCurrency.network,
).getOrElse { "" }
uiState = stateFactory.getTransactionSendState(txData, txUrl)
}
private fun scheduleBalanceUpdate() {
viewModelScope.launch(dispatchers.io) {
delay(BALANCE_UPDATE_DELAY)