Updated on 2026-08-14
This commit is contained in:
parent
8583c777b7
commit
0e071aac19
6 changed files with 66 additions and 42 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.domain.transaction.error
|
||||
|
||||
sealed class IncompleteTransactionError {
|
||||
data class SendError(val error: SendTransactionError) : IncompleteTransactionError()
|
||||
data class DataError(val message: String?) : IncompleteTransactionError()
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ class DismissIncompleteTransactionUseCase(
|
|||
suspend operator fun invoke(
|
||||
userWalletId: UserWalletId,
|
||||
currency: CryptoCurrency,
|
||||
): Either<IncompleteTransactionError, Unit> {
|
||||
): Either<IncompleteTransactionError.DataError, Unit> {
|
||||
return either {
|
||||
catch(
|
||||
block = {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package com.tangem.domain.transaction.usecase
|
|||
import arrow.core.Either
|
||||
import arrow.core.raise.catch
|
||||
import arrow.core.raise.either
|
||||
import com.tangem.blockchain.common.BlockchainSdkError
|
||||
import com.tangem.blockchain.extensions.SimpleResult
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.transaction.error.IncompleteTransactionError
|
||||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
||||
|
|
@ -25,9 +27,19 @@ class RetryIncompleteTransactionUseCase(
|
|||
catch(
|
||||
block = {
|
||||
when (val result = walletManagersFacade.fulfillRequirements(userWalletId, currency, signer)) {
|
||||
is SimpleResult.Failure -> raise(
|
||||
IncompleteTransactionError.DataError(result.error.customMessage),
|
||||
)
|
||||
is SimpleResult.Failure -> {
|
||||
val error = result.error as? BlockchainSdkError
|
||||
when (error) {
|
||||
is BlockchainSdkError.WrappedTangemError -> parseWrappedError(error)
|
||||
null -> SendTransactionError.UnknownError()
|
||||
else -> SendTransactionError.BlockchainSdkError(
|
||||
code = error.code,
|
||||
message = error.customMessage,
|
||||
)
|
||||
}.let {
|
||||
raise(IncompleteTransactionError.SendError(it))
|
||||
}
|
||||
}
|
||||
SimpleResult.Success -> Unit
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -132,33 +132,33 @@ class SendTransactionUseCase(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseWrappedError(error: BlockchainSdkError.WrappedTangemError): SendTransactionError {
|
||||
return if (error.code == USER_CANCELLED_ERROR_CODE) {
|
||||
SendTransactionError.UserCancelledError
|
||||
} else {
|
||||
when (val tangemError = error.tangemError) {
|
||||
is TangemSdkError -> {
|
||||
val resource = tangemError.localizedDescriptionRes()
|
||||
val resId = resource.resId ?: R.string.common_unknown_error
|
||||
val resArgs = resource.args.map { it.value }
|
||||
SendTransactionError.TangemSdkError(tangemError.code, resId, wrappedList(resArgs))
|
||||
}
|
||||
is BlockchainSdkError.WrappedTangemError -> {
|
||||
parseWrappedError(tangemError) // todo remove when sdk errors are revised
|
||||
}
|
||||
is BlockchainSdkError.WrappedThrowable -> {
|
||||
val causeError = tangemError.cause
|
||||
if (causeError is BlockchainSdkError) {
|
||||
SendTransactionError.BlockchainSdkError(causeError.code, causeError.customMessage)
|
||||
} else {
|
||||
SendTransactionError.BlockchainSdkError(tangemError.code, tangemError.customMessage)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
SendTransactionError.BlockchainSdkError(error.code, tangemError.customMessage)
|
||||
fun parseWrappedError(error: BlockchainSdkError.WrappedTangemError): SendTransactionError {
|
||||
return if (error.code == USER_CANCELLED_ERROR_CODE) {
|
||||
SendTransactionError.UserCancelledError
|
||||
} else {
|
||||
when (val tangemError = error.tangemError) {
|
||||
is TangemSdkError -> {
|
||||
val resource = tangemError.localizedDescriptionRes()
|
||||
val resId = resource.resId ?: R.string.common_unknown_error
|
||||
val resArgs = resource.args.map { it.value }
|
||||
SendTransactionError.TangemSdkError(tangemError.code, resId, wrappedList(resArgs))
|
||||
}
|
||||
is BlockchainSdkError.WrappedTangemError -> {
|
||||
parseWrappedError(tangemError) // todo remove when sdk errors are revised
|
||||
}
|
||||
is BlockchainSdkError.WrappedThrowable -> {
|
||||
val causeError = tangemError.cause
|
||||
if (causeError is BlockchainSdkError) {
|
||||
SendTransactionError.BlockchainSdkError(causeError.code, causeError.customMessage)
|
||||
} else {
|
||||
SendTransactionError.BlockchainSdkError(tangemError.code, tangemError.customMessage)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
SendTransactionError.BlockchainSdkError(error.code, tangemError.customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,6 +78,7 @@ dependencies {
|
|||
implementation(projects.domain.balanceHiding)
|
||||
implementation(projects.domain.balanceHiding.models)
|
||||
implementation(projects.domain.transaction)
|
||||
implementation(projects.domain.transaction.models)
|
||||
implementation(projects.domain.staking)
|
||||
implementation(projects.domain.markets.models)
|
||||
implementation(projects.domain.onramp)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.*
|
|||
import androidx.paging.cachedIn
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.blockchain.common.address.AddressType
|
||||
import com.tangem.common.core.TangemSdkError
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.common.routing.bundle.unbundle
|
||||
|
|
@ -51,6 +52,7 @@ import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent.Compan
|
|||
import com.tangem.domain.tokens.model.analytics.TokenSwapPromoAnalyticsEvent
|
||||
import com.tangem.domain.transaction.error.AssociateAssetError
|
||||
import com.tangem.domain.transaction.error.IncompleteTransactionError
|
||||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
import com.tangem.domain.transaction.usecase.AssociateAssetUseCase
|
||||
import com.tangem.domain.transaction.usecase.DismissIncompleteTransactionUseCase
|
||||
import com.tangem.domain.transaction.usecase.RetryIncompleteTransactionUseCase
|
||||
|
|
@ -874,14 +876,26 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
currency = cryptoCurrency,
|
||||
).fold(
|
||||
ifLeft = { e ->
|
||||
when (e) {
|
||||
is IncompleteTransactionError.DataError -> {
|
||||
internalUiState.value = stateFactory.getStateWithErrorDialog(
|
||||
stringReference(e.message.orEmpty()),
|
||||
)
|
||||
Timber.e(e.message)
|
||||
val message = when (e) {
|
||||
is IncompleteTransactionError.DataError -> e.message.orEmpty()
|
||||
is IncompleteTransactionError.SendError -> {
|
||||
when (val error = e.error) {
|
||||
is SendTransactionError.UserCancelledError,
|
||||
is SendTransactionError.CreateAccountUnderfunded,
|
||||
is SendTransactionError.TangemSdkError,
|
||||
is SendTransactionError.DemoCardError,
|
||||
-> null
|
||||
is SendTransactionError.DataError -> error.message
|
||||
is SendTransactionError.BlockchainSdkError -> error.message
|
||||
is SendTransactionError.NetworkError -> error.message
|
||||
is SendTransactionError.UnknownError -> error.ex?.localizedMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
message?.let {
|
||||
internalUiState.value = stateFactory.getStateWithErrorDialog(stringReference(it))
|
||||
Timber.e(it)
|
||||
}
|
||||
},
|
||||
ifRight = {
|
||||
internalUiState.value = stateFactory.getStateWithRemovedKaspaIncompleteTransactionNotification()
|
||||
|
|
@ -903,14 +917,10 @@ internal class TokenDetailsViewModel @Inject constructor(
|
|||
currency = cryptoCurrency,
|
||||
).fold(
|
||||
ifLeft = { e ->
|
||||
when (e) {
|
||||
is IncompleteTransactionError.DataError -> {
|
||||
internalUiState.value = stateFactory.getStateWithErrorDialog(
|
||||
stringReference(e.message.orEmpty()),
|
||||
)
|
||||
Timber.e(e.message)
|
||||
}
|
||||
}
|
||||
internalUiState.value = stateFactory.getStateWithErrorDialog(
|
||||
stringReference(e.message.orEmpty()),
|
||||
)
|
||||
Timber.e(e.message)
|
||||
},
|
||||
ifRight = {
|
||||
internalUiState.value = stateFactory.getStateWithRemovedKaspaIncompleteTransactionNotification()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue