Updated on 2026-08-14

This commit is contained in:
Tangem 2023-12-25 11:54:39 +03:00
parent f03f9d1b0d
commit 20bd61d4f4
10 changed files with 25 additions and 29 deletions

View file

@ -13,7 +13,7 @@ internal class ExchangeStatusConverter : Converter<ExchangeStatusResponse, Excha
it.name.lowercase() == value.externalStatus.name.lowercase()
},
txId = value.externalTxId,
txUrl = value.externalTxUrl,
txExternalUrl = value.externalTxUrl,
)
}
}

View file

@ -4,7 +4,7 @@ data class ExchangeStatusModel(
val providerId: String,
val status: ExchangeStatus? = null,
val txId: String? = null,
val txUrl: String? = null,
val txExternalUrl: String? = null,
)
enum class ExchangeStatus {

View file

@ -9,9 +9,8 @@ sealed class TxState {
val fromAmountValue: BigDecimal? = null,
val toAmount: String? = null,
val toAmountValue: BigDecimal? = null,
val txAddress: String,
val txHash: String,
val txExternalUrl: String? = null,
val txUrl: String? = null,
val timestamp: Long,
) : TxState()

View file

@ -11,5 +11,5 @@ interface BlockchainInteractor {
*/
fun getBlockchainInfo(networkId: String): NetworkInfo
fun getExplorerTransactionLink(networkId: String, txAddress: String): String
fun getExplorerTransactionLink(networkId: String, txHash: String): String
}

View file

@ -18,7 +18,7 @@ internal class DefaultBlockchainInteractor @Inject constructor(
}
}
override fun getExplorerTransactionLink(networkId: String, txAddress: String): String {
return transactionManager.getExplorerTransactionLink(networkId, txAddress)
override fun getExplorerTransactionLink(networkId: String, txHash: String): String {
return transactionManager.getExplorerTransactionLink(networkId, txHash)
}
}

View file

@ -54,7 +54,6 @@ internal class SwapInteractorImpl @Inject constructor(
private val dispatcher: CoroutineDispatcherProvider,
private val swapTransactionRepository: SwapTransactionRepository,
private val initialToCurrencyResolver: InitialToCurrencyResolver,
private val blockchainInteractor: BlockchainInteractor,
) : SwapInteractor {
private val estimateFeeUseCase by lazy(LazyThreadSafetyMode.NONE) {
@ -215,7 +214,7 @@ internal class SwapInteractorImpl @Inject constructor(
is SendTxResult.Success -> {
allowPermissionsHandler.addAddressToInProgress(permissionOptions.forTokenContractAddress)
TxState.TxSent(
txAddress = userWalletManager.getLastTransactionHash(networkId, derivationPath).orEmpty(),
txHash = userWalletManager.getLastTransactionHash(networkId, derivationPath).orEmpty(),
timestamp = System.currentTimeMillis(),
)
}
@ -463,7 +462,7 @@ internal class SwapInteractorImpl @Inject constructor(
currencyToGet.symbol,
),
toAmountValue = swapData.toTokenAmount.value,
txAddress = userWalletManager.getLastTransactionHash(networkId, derivationPath).orEmpty(),
txHash = userWalletManager.getLastTransactionHash(networkId, derivationPath).orEmpty(),
timestamp = System.currentTimeMillis(),
)
}
@ -537,10 +536,6 @@ internal class SwapInteractorImpl @Inject constructor(
},
ifRight = {
val timestamp = System.currentTimeMillis()
val txUrl = blockchainInteractor.getExplorerTransactionLink(
networkId = currencyToSend.currency.network.backendId,
txAddress = exchangeData.transaction.txTo,
)
storeSwapTransaction(
currencyToSend = currencyToSend,
currencyToGet = currencyToGet,
@ -548,7 +543,7 @@ internal class SwapInteractorImpl @Inject constructor(
swapProvider = swapProvider,
swapDataModel = exchangeData,
timestamp = timestamp,
txUrl = txUrl,
txExternalUrl = externalUrl.orEmpty(),
)
storeLastCryptoCurrencyId(currencyToGet.currency)
TxState.TxSent(
@ -562,12 +557,11 @@ internal class SwapInteractorImpl @Inject constructor(
currencyToGet.currency.symbol,
),
toAmountValue = exchangeData.toTokenAmount.value,
txAddress = userWalletManager.getLastTransactionHash(
txHash = userWalletManager.getLastTransactionHash(
currencyToSend.currency.network.backendId,
derivationPath,
).orEmpty(),
txExternalUrl = externalUrl,
txUrl = txUrl,
timestamp = timestamp,
)
},
@ -602,7 +596,7 @@ internal class SwapInteractorImpl @Inject constructor(
swapProvider: SwapProvider,
swapDataModel: SwapDataModel,
timestamp: Long,
txUrl: String,
txExternalUrl: String,
) {
swapTransactionRepository.storeTransaction(
userWalletId = UserWalletId(userWalletManager.getWalletId()),
@ -618,7 +612,7 @@ internal class SwapInteractorImpl @Inject constructor(
providerId = swapProvider.providerId,
status = ExchangeStatus.New,
txId = swapDataModel.transaction.txId,
txUrl = txUrl,
txExternalUrl = txExternalUrl,
),
),
)

View file

@ -42,7 +42,6 @@ class SwapDomainModule {
walletManagersFacade: WalletManagersFacade,
coroutineDispatcherProvider: CoroutineDispatcherProvider,
initialToCurrencyResolver: InitialToCurrencyResolver,
blockchainInteractor: BlockchainInteractor,
): SwapInteractor {
return SwapInteractorImpl(
transactionManager = transactionManager,
@ -57,7 +56,6 @@ class SwapDomainModule {
dispatcher = coroutineDispatcherProvider,
swapTransactionRepository = swapTransactionRepository,
initialToCurrencyResolver = initialToCurrencyResolver,
blockchainInteractor = blockchainInteractor,
)
}

View file

@ -732,6 +732,7 @@ internal class StateBuilder(
dataState: SwapProcessDataState,
onExploreClick: () -> Unit,
onStatusClick: () -> Unit,
txUrl: String,
): SwapStateHolder {
val fee = requireNotNull(dataState.selectedFee)
val fromCryptoCurrency = requireNotNull(dataState.fromCryptoCurrency)
@ -746,7 +747,7 @@ internal class StateBuilder(
return uiState.copy(
successState = SwapSuccessStateHolder(
timestamp = txState.timestamp,
txUrl = txState.txUrl.orEmpty(),
txUrl = txUrl,
providerName = stringReference(providerState.name),
providerType = stringReference(providerState.type),
showStatusButton = providerState.type == ExchangeProviderType.CEX.name,

View file

@ -462,15 +462,19 @@ internal class SwapViewModel @Inject constructor(
}.onSuccess {
when (it) {
is TxState.TxSent -> {
val url = blockchainInteractor.getExplorerTransactionLink(
networkId = fromCurrency.currency.network.backendId,
txHash = it.txHash,
)
updateWalletBalance()
uiState = stateBuilder.createSuccessState(
uiState = uiState,
txState = it,
dataState = dataState,
txUrl = url,
onExploreClick = {
val txUrl = it.txUrl
if (!txUrl.isNullOrBlank()) {
swapRouter.openUrl(txUrl)
if (it.txHash.isNotEmpty()) {
swapRouter.openUrl(url)
}
analyticsEventHandler.send(
event = SwapEvents.ButtonExplore(initialCryptoCurrency.symbol),

View file

@ -66,7 +66,7 @@ internal class TokenDetailsSwapTransactionsStateConverter(
SwapTransactionsState(
txId = transaction.txId,
provider = transaction.provider,
txUrl = transaction.status?.txUrl,
txUrl = transaction.status?.txExternalUrl,
timestamp = TextReference.Str("${timestamp.toDateFormat()}, ${timestamp.toTimeFormat()}"),
fiatSymbol = appCurrency.symbol,
statuses = getStatuses(transaction.status?.status),
@ -74,7 +74,7 @@ internal class TokenDetailsSwapTransactionsStateConverter(
activeStatus = transaction.status?.status,
notification = getNotification(
transaction.status?.status,
transaction.status?.txUrl,
transaction.status?.txExternalUrl,
),
toCryptoCurrencyId = toCurrency.currency.id,
toCryptoAmount = BigDecimalFormatter.formatCryptoAmount(
@ -112,9 +112,9 @@ internal class TokenDetailsSwapTransactionsStateConverter(
return tx.copy(
activeStatus = statusModel.status,
hasFailed = hasFailed,
notification = getNotification(statusModel.status, statusModel.txUrl),
notification = getNotification(statusModel.status, statusModel.txExternalUrl),
statuses = getStatuses(statusModel.status, hasFailed),
txUrl = statusModel.txUrl,
txUrl = statusModel.txExternalUrl,
)
}