Updated on 2026-08-14

This commit is contained in:
Tangem 2025-07-10 22:47:25 +07:00
parent 67457f0746
commit 63a718d771
25 changed files with 186 additions and 85 deletions

View file

@ -16,6 +16,8 @@ dependencies {
implementation(projects.domain.tokens.models)
implementation(projects.domain.wallets.models)
implementation(projects.domain.walletConnect.models)
implementation(projects.domain.transaction)
implementation(projects.domain.transaction.models)
/* Project - Core */
implementation(projects.core.analytics)
@ -25,4 +27,5 @@ dependencies {
/* Tangem libraries */
implementation(tangemDeps.blockchain)
implementation(tangemDeps.card.core)
}

View file

@ -11,6 +11,7 @@ dependencies {
implementation(projects.domain.wallets.models)
implementation(projects.domain.tokens.models)
implementation(projects.domain.blockaid.models)
implementation(projects.domain.transaction.models)
/* Other */
implementation(deps.moshi)

View file

@ -0,0 +1,56 @@
package com.tangem.domain.walletconnect.model
import com.tangem.domain.transaction.error.SendTransactionError
sealed class WcRequestError {
data class WrappedSendError(
val sendTransactionError: SendTransactionError,
) : WcRequestError()
data class WcRespondError(
val code: Int,
val message: String,
) : WcRequestError()
data class UnknownError(val ex: Throwable? = null) : WcRequestError()
companion object {
fun WcRequestError.message(): String? = when (this) {
is UnknownError -> ex?.message
is WcRespondError -> message
is WrappedSendError -> sendTransactionError.message()
}
fun WcRequestError.code(): String? = when (this) {
is UnknownError -> null
is WcRespondError -> this.code.toString()
is WrappedSendError -> sendTransactionError.code()
}
private fun SendTransactionError.code(): String? = when (this) {
is SendTransactionError.BlockchainSdkError -> code.toString()
is SendTransactionError.NetworkError -> code
is SendTransactionError.TangemSdkError -> code.toString()
is SendTransactionError.DataError,
SendTransactionError.DemoCardError,
is SendTransactionError.UnknownError,
SendTransactionError.UserCancelledError,
is SendTransactionError.CreateAccountUnderfunded,
-> null
}
private fun SendTransactionError.message(): String? = when (this) {
is SendTransactionError.BlockchainSdkError -> message
is SendTransactionError.NetworkError -> message
is SendTransactionError.DataError -> message
is SendTransactionError.UnknownError -> ex?.message
is SendTransactionError.TangemSdkError,
SendTransactionError.DemoCardError,
SendTransactionError.UserCancelledError,
is SendTransactionError.CreateAccountUnderfunded,
-> null
}
}
}

View file

@ -0,0 +1,16 @@
package com.tangem.domain.walletconnect.error
import com.tangem.blockchain.common.BlockchainSdkError
import com.tangem.common.core.TangemError
import com.tangem.domain.transaction.error.SendTransactionError
import com.tangem.domain.transaction.error.parseWrappedError
import com.tangem.domain.walletconnect.model.WcRequestError
fun parseSendError(error: SendTransactionError): WcRequestError.WrappedSendError {
return WcRequestError.WrappedSendError(error)
}
fun parseTangemSdkError(error: TangemError): WcRequestError.WrappedSendError {
val sendError = parseWrappedError(BlockchainSdkError.WrappedTangemError(error))
return parseSendError(sendError)
}

View file

@ -1,11 +1,12 @@
package com.tangem.domain.walletconnect.usecase.method
import arrow.core.Either
import com.tangem.domain.walletconnect.model.WcRequestError
interface WcAddNetworkUseCase :
WcMethodUseCase,
WcMethodContext {
suspend fun approve(): Either<Throwable, Unit>
suspend fun approve(): Either<WcRequestError, String>
fun reject()
}

View file

@ -3,6 +3,7 @@ package com.tangem.domain.walletconnect.usecase.method
import arrow.core.Either
import com.tangem.domain.models.network.Network
import com.tangem.domain.walletconnect.model.WcMethod
import com.tangem.domain.walletconnect.model.WcRequestError
import com.tangem.domain.walletconnect.model.WcSession
import com.tangem.domain.walletconnect.model.sdkcopy.WcSdkSessionRequest
import com.tangem.domain.wallets.models.UserWallet
@ -38,5 +39,5 @@ data class WcSignState<SignModel>(
sealed interface WcSignStep {
data object PreSign : WcSignStep
data object Signing : WcSignStep
data class Result(val result: Either<Throwable, Unit>) : WcSignStep
data class Result(val result: Either<WcRequestError, String>) : WcSignStep
}