Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-28 23:01:32 +02:00
parent 78497e41a8
commit 474cd50820
7 changed files with 22 additions and 26 deletions

View file

@ -15,7 +15,7 @@ sealed class ApiResponseError : Exception() {
data class HttpException(
val code: Code,
override val message: String?,
val errorBody: String?
val errorBody: String?,
) : ApiResponseError() {
// region Error Codes

View file

@ -2,7 +2,6 @@ package com.tangem.datasource.api.express.models.response
import com.squareup.moshi.Json
import java.math.BigDecimal
import java.math.BigInteger
data class ExpressErrorResponse(
@Json(name = "error")

View file

@ -1,6 +1,5 @@
package com.tangem.feature.swap
import com.squareup.moshi.Moshi
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.Approver
import com.tangem.blockchain.common.Blockchain
@ -304,7 +303,7 @@ internal class SwapRepositoryImpl @Inject constructor(
)
}
private fun getDataError(ex: Exception) : DataError {
private fun getDataError(ex: Exception): DataError {
return if (ex is ApiResponseError.HttpException) {
errorsDataConverter.convert(ex.errorBody ?: "")
} else {

View file

@ -10,6 +10,7 @@ internal class ErrorsDataConverter(
private val jsonAdapter: JsonAdapter<ExpressErrorResponse>,
) : Converter<String, DataError> {
@Suppress("MagicNumber")
override fun convert(errorBody: String): DataError {
try {
val errorResponse = jsonAdapter.fromJson(errorBody)
@ -26,18 +27,19 @@ internal class ErrorsDataConverter(
code = error.code,
amount = SwapAmount(
requireNotNull(error.value?.minAmount),
requireNotNull(error.value?.decimals)
)
requireNotNull(error.value?.decimals),
),
)
2260 -> DataError.ExchangeNotEnoughAllowanceError(
code = error.code,
currentAllowance = requireNotNull(error.value?.currentAllowance)
currentAllowance = requireNotNull(error.value?.currentAllowance),
)
2270 -> DataError.ExchangeNotEnoughBalanceError(code = error.code)
2280 -> DataError.ExchangeInvalidAddressError(code = error.code)
2290 -> DataError.ExchangeInvalidFromDecimalsError(code = error.code,
2290 -> DataError.ExchangeInvalidFromDecimalsError(
code = error.code,
receivedFromDecimals = requireNotNull(error.value?.receivedFromDecimals),
expressFromDecimals = requireNotNull(error.value?.expressFromDecimals)
expressFromDecimals = requireNotNull(error.value?.expressFromDecimals),
)
else -> DataError.UnknownError()
}

View file

@ -11,7 +11,6 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.legacy.WalletsStateHolder
import com.tangem.feature.swap.SwapRepositoryImpl
import com.tangem.feature.swap.converters.ErrorsDataConverter
import com.tangem.feature.swap.converters.ExpressDataConverter
import com.tangem.feature.swap.domain.SwapRepository
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.Module
@ -50,9 +49,7 @@ internal class SwapDataModule {
@Provides
@Singleton
internal fun provideErrorsConverter(
@NetworkMoshi moshi: Moshi
) : ErrorsDataConverter {
internal fun provideErrorsConverter(@NetworkMoshi moshi: Moshi): ErrorsDataConverter {
val jsonAdapter = moshi.adapter(ExpressErrorResponse::class.java)
return ErrorsDataConverter(jsonAdapter)
}

View file

@ -14,7 +14,6 @@ import com.tangem.domain.wallets.legacy.WalletsStateHolder
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
import com.tangem.feature.swap.domain.*
import com.tangem.feature.swap.domain.cache.SwapDataCacheImpl
import com.tangem.features.wallet.featuretoggles.WalletFeatureToggles
import com.tangem.lib.crypto.TransactionManager
import com.tangem.lib.crypto.UserWalletManager
import com.tangem.utils.coroutines.CoroutineDispatcherProvider

View file

@ -8,27 +8,27 @@ sealed class DataError {
data class BadRequest(override val code: Int) : DataError()
data class ExchangeProviderNotFoundError(override val code: Int): DataError()
data class ExchangeProviderNotFoundError(override val code: Int) : DataError()
data class ExchangeProviderNotActiveError(override val code: Int): DataError()
data class ExchangeProviderNotActiveError(override val code: Int) : DataError()
data class ExchangeProviderNotAvailableError(override val code: Int): DataError()
data class ExchangeProviderNotAvailableError(override val code: Int) : DataError()
data class ExchangeNotPossibleError(override val code: Int): DataError()
data class ExchangeNotPossibleError(override val code: Int) : DataError()
data class ExchangeTooSmallAmountError(override val code: Int, val amount: SwapAmount): DataError()
data class ExchangeTooSmallAmountError(override val code: Int, val amount: SwapAmount) : DataError()
data class ExchangeNotEnoughAllowanceError(override val code: Int, val currentAllowance: BigDecimal): DataError()
data class ExchangeNotEnoughAllowanceError(override val code: Int, val currentAllowance: BigDecimal) : DataError()
data class ExchangeNotEnoughBalanceError(override val code: Int): DataError()
data class ExchangeNotEnoughBalanceError(override val code: Int) : DataError()
data class ExchangeInvalidAddressError(override val code: Int): DataError()
data class ExchangeInvalidAddressError(override val code: Int) : DataError()
data class ExchangeInvalidFromDecimalsError(
override val code: Int,
val receivedFromDecimals: Int,
val expressFromDecimals: Int
): DataError()
val expressFromDecimals: Int,
) : DataError()
data class UnknownError(override val code: Int = -1): DataError()
}
data class UnknownError(override val code: Int = -1) : DataError()
}