Updated on 2026-08-14

This commit is contained in:
Tangem 2024-11-26 14:54:02 +03:00
parent 40e083ffad
commit b0694b6798
12 changed files with 66 additions and 22 deletions

View file

@ -30,6 +30,7 @@ internal class ErrorsDataConverter(
2270 -> ExpressDataError.ExchangeNotEnoughBalanceError(code = error.code)
2280 -> ExpressDataError.ExchangeInvalidAddressError(code = error.code)
2290 -> tryParseExchangeInvalidFromDecimalsError(error = error)
2320 -> tryParseProviderDifferentAmountError(error = error)
else -> ExpressDataError.UnknownErrorWithCode(error.code)
}
} catch (e: Exception) {
@ -79,4 +80,20 @@ internal class ErrorsDataConverter(
expressFromDecimals = expressFromDecimals,
)
}
private fun tryParseProviderDifferentAmountError(error: ExpressError): ExpressDataError {
val decimals = error.value?.decimals ?: return ExpressDataError.UnknownErrorWithCode(error.code)
val fromAmount = error.value?.fromAmount?.toBigDecimalOrNull()
?: return ExpressDataError.UnknownErrorWithCode(error.code)
val fromAmountProvider = error.value?.fromAmountProvider?.toBigDecimalOrNull()
?: return ExpressDataError.UnknownErrorWithCode(error.code)
return ExpressDataError.ProviderDifferentAmountError(
code = error.code,
decimals = decimals,
fromAmount = fromAmount,
fromProviderAmount = fromAmountProvider,
)
}
}

View file

@ -39,6 +39,13 @@ sealed class ExpressDataError {
val expressFromDecimals: Int,
) : ExpressDataError()
data class ProviderDifferentAmountError(
override val code: Int,
val fromAmount: BigDecimal,
val fromProviderAmount: BigDecimal,
val decimals: Int,
) : ExpressDataError()
data class UnknownErrorWithCode(override val code: Int) : ExpressDataError()
data class InvalidSignatureError(override val code: Int = 990) : ExpressDataError()

View file

@ -10,10 +10,7 @@ import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.event.consumedEvent
import com.tangem.core.ui.event.triggeredEvent
import com.tangem.core.ui.extensions.*
import com.tangem.core.ui.format.bigdecimal.anyDecimals
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.format.bigdecimal.uncapped
import com.tangem.core.ui.format.bigdecimal.*
import com.tangem.core.ui.utils.BigDecimalFormatter
import com.tangem.core.ui.utils.parseBigDecimal
import com.tangem.domain.appcurrency.model.AppCurrency
@ -777,6 +774,19 @@ internal class StateBuilder(
iconResId = R.drawable.ic_alert_circle_24,
),
)
is ExpressDataError.ProviderDifferentAmountError -> SwapWarning.GeneralError(
notificationConfig = NotificationConfig(
title = resourceReference(id = R.string.common_error),
subtitle = resourceReference(
R.string.express_error_provider_amount_roundup,
formatArgs = wrappedList(
expressDataError.code,
expressDataError.fromProviderAmount.format { simple(decimals = expressDataError.decimals) },
),
),
iconResId = R.drawable.ic_alert_circle_24,
),
)
else -> SwapWarning.GeneralWarning(
notificationConfig = NotificationConfig(
title = providerErrorTitle,

View file

@ -28,6 +28,13 @@ internal fun getExpressErrorMessage(expressDataError: ExpressDataError): TextRef
id = R.string.express_error_swap_pair_unavailable,
formatArgs = wrappedList(expressDataError.code),
)
is ExpressDataError.ProviderDifferentAmountError -> resourceReference(
R.string.express_error_provider_amount_roundup,
formatArgs = wrappedList(
expressDataError.code,
expressDataError.fromProviderAmount.format { simple(decimals = expressDataError.decimals) },
),
)
else -> resourceReference(R.string.express_error_code, wrappedList(expressDataError.code.toString()))
}
}