Updated on 2026-08-14
This commit is contained in:
parent
1bd432de87
commit
87e327a220
5 changed files with 50 additions and 6 deletions
|
|
@ -7,4 +7,13 @@ sealed class SendTransactionError {
|
|||
data class DataError(val message: String?) : SendTransactionError()
|
||||
|
||||
data class NetworkError(val message: String?) : SendTransactionError()
|
||||
|
||||
data class BlockchainSdkError(val code: Int, val cause: Throwable?) : SendTransactionError()
|
||||
object UserCancelledError : SendTransactionError()
|
||||
data class TangemSdkError(val code: Int, val cause: Throwable?) : SendTransactionError()
|
||||
data class UnknownError(val ex: Exception? = null) : SendTransactionError()
|
||||
|
||||
companion object {
|
||||
const val USER_CANCELLED_ERROR_CODE = 50002
|
||||
}
|
||||
}
|
||||
|
|
@ -3,13 +3,17 @@ package com.tangem.domain.transaction.usecase
|
|||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import arrow.core.right
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
import com.tangem.blockchain.network.ResultChecker
|
||||
import com.tangem.common.core.TangemSdkError
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.common.TapWorkarounds.isStart2Coin
|
||||
import com.tangem.domain.demo.IsDemoCardUseCase
|
||||
import com.tangem.domain.tokens.model.Network
|
||||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
import com.tangem.domain.transaction.error.SendTransactionError.Companion.USER_CANCELLED_ERROR_CODE
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
|
||||
|
|
@ -52,10 +56,40 @@ class SendTransactionUseCase(
|
|||
ifRight = { result ->
|
||||
when (result) {
|
||||
is SimpleResult.Success -> true.right()
|
||||
is SimpleResult.Failure -> SendTransactionError.NetworkError(result.error.message).left()
|
||||
is SimpleResult.Failure -> handleError(result).left()
|
||||
}
|
||||
},
|
||||
ifLeft = { it.left() },
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleError(result: SimpleResult.Failure): SendTransactionError {
|
||||
if (ResultChecker.isNetworkError(result)) return SendTransactionError.NetworkError(result.error.message)
|
||||
val error = result.error as? BlockchainSdkError ?: return SendTransactionError.UnknownError()
|
||||
when (error) {
|
||||
is BlockchainSdkError.WrappedTangemError -> {
|
||||
val errorByCode = mapErrorByCode(error)
|
||||
if (errorByCode != null) {
|
||||
return errorByCode
|
||||
}
|
||||
val tangemSdkError = error.tangemError as? TangemSdkError ?: return SendTransactionError.UnknownError()
|
||||
if (tangemSdkError is TangemSdkError.UserCancelled) return SendTransactionError.UserCancelledError
|
||||
return SendTransactionError.TangemSdkError(tangemSdkError.code, tangemSdkError.cause)
|
||||
}
|
||||
else -> {
|
||||
return SendTransactionError.TangemSdkError(error.code, error.cause)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun mapErrorByCode(error: BlockchainSdkError.WrappedTangemError): SendTransactionError? {
|
||||
return when (error.code) {
|
||||
USER_CANCELLED_ERROR_CODE -> {
|
||||
return SendTransactionError.UserCancelledError
|
||||
}
|
||||
else -> {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -502,9 +502,10 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
return result.fold(
|
||||
ifLeft = {
|
||||
when (it) {
|
||||
SendTransactionError.UserCancelledError -> TxState.UserCancelled
|
||||
is SendTransactionError.BlockchainSdkError -> TxState.BlockchainError
|
||||
is SendTransactionError.TangemSdkError -> TxState.TangemSdkError
|
||||
is SendTransactionError.NetworkError -> TxState.NetworkError
|
||||
is SendTransactionError.DataError -> TxState.BlockchainError
|
||||
SendTransactionError.DemoCardError -> TxState.UnknownError
|
||||
else -> TxState.UnknownError
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -825,7 +825,7 @@ internal class StateBuilder(
|
|||
)
|
||||
}
|
||||
|
||||
fun updateSelectedFee(uiState: SwapStateHolder, selectedFee: FeeType): SwapStateHolder {
|
||||
fun updateSelectedFeeBottomSheet(uiState: SwapStateHolder, selectedFee: FeeType): SwapStateHolder {
|
||||
val config = uiState.bottomSheetConfig?.content as? ChooseFeeBottomSheetConfig
|
||||
return if (config != null) {
|
||||
uiState.copy(
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
fromToken = fromToken.currency,
|
||||
swapProvider = provider,
|
||||
bestRatedProviderId = bestRatedProviderId,
|
||||
isManyProviders = dataState.lastLoadedSwapStates.isNotEmpty(),
|
||||
isManyProviders = dataState.lastLoadedSwapStates.size > 1,
|
||||
selectedFeeType = dataState.selectedFee?.feeType ?: FeeType.NORMAL,
|
||||
)
|
||||
}
|
||||
|
|
@ -717,7 +717,7 @@ internal class SwapViewModel @Inject constructor(
|
|||
val fromToken = dataState.fromCryptoCurrency ?: return@UiActions
|
||||
val amountToSwap = dataState.amount ?: return@UiActions
|
||||
val selectedProvider = dataState.selectedProvider ?: return@UiActions
|
||||
uiState = stateBuilder.updateSelectedFee(uiState, it.feeType)
|
||||
uiState = stateBuilder.updateSelectedFeeBottomSheet(uiState, it.feeType)
|
||||
dataState = dataState.copy(selectedFee = it)
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
val updatedState = swapInteractor.updateQuotesStateWithSelectedFee(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue