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

@ -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)
}