From a6a5d5e1452a8f266983189e4ee1fc58fe166702 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 27 Feb 2026 15:14:05 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../SwapTransactionErrorStateConverter.kt | 6 +++--- .../tangem/feature/swap/model/SwapModel.kt | 20 +++++++++++-------- .../tangem/feature/swap/models/SwapAlertUM.kt | 11 +++++++++- .../tangem/feature/swap/ui/StateBuilder.kt | 20 +++++++++++++++++-- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/converters/SwapTransactionErrorStateConverter.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/converters/SwapTransactionErrorStateConverter.kt index 646e3a3218..dc6c9cfbb0 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/converters/SwapTransactionErrorStateConverter.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/converters/SwapTransactionErrorStateConverter.kt @@ -17,7 +17,7 @@ internal class SwapTransactionErrorStateConverter( is SwapTransactionState.Error.TransactionError -> { when (val error = value.error) { is SendTransactionError.UserCancelledError -> return null - null -> SwapAlertUM.GenericError(onDismiss) + null -> SwapAlertUM.DefaultError(onDismiss) else -> TransactionErrorAlertConverter(onDismiss, onSupportClick).convert(error) } } @@ -27,8 +27,8 @@ internal class SwapTransactionErrorStateConverter( onConfirmClick = { onSupportClick(value.error.code.toString()) }, ) } - SwapTransactionState.Error.UnknownError -> SwapAlertUM.GenericError(onDismiss) - is SwapTransactionState.Error.TangemPayWithdrawalError -> SwapAlertUM.GenericError( + SwapTransactionState.Error.UnknownError -> SwapAlertUM.DefaultError(onDismiss) + is SwapTransactionState.Error.TangemPayWithdrawalError -> SwapAlertUM.SupportError( onConfirmClick = { onSupportClick(value.txId) }, ) } diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt index 2727fa50c7..64a9dc67b1 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt @@ -342,7 +342,7 @@ internal class SwapModel @Inject constructor( } if (fromAccountStatus == null) { - uiState = stateBuilder.addAlert(uiState = uiState, onDismiss = swapRouter::back) + uiState = stateBuilder.addDefaultAlert(uiState = uiState, onDismiss = swapRouter::back) } else { fromAccountCurrencyStatus = fromAccountStatus toAccountCurrencyStatus = toAccountStatus @@ -360,7 +360,7 @@ internal class SwapModel @Inject constructor( } if (fromStatus == null) { - uiState = stateBuilder.addAlert(uiState = uiState, onDismiss = swapRouter::back) + uiState = stateBuilder.addDefaultAlert(uiState = uiState, onDismiss = swapRouter::back) } else { initialFromStatus = fromStatus initialToStatus = toStatus @@ -1020,7 +1020,7 @@ internal class SwapModel @Inject constructor( val fee = getSelectedFee() if (fee == null && tangemPayInput?.isWithdrawal != true) { - makeDefaultAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) + makeSupportAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) modelScope.launch { delay(SWAP_IN_PROGRESS_DELAY) startLoadingQuotesFromLastState() @@ -1046,7 +1046,7 @@ internal class SwapModel @Inject constructor( when (swapTransactionState) { is SwapTransactionState.TxSent -> { if (fee == null) { - makeDefaultAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) + makeSupportAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) return@onSuccess } sendSuccessSwapEvent( @@ -1205,7 +1205,7 @@ internal class SwapModel @Inject constructor( } val feeForPermission = when (val fee = approveDataModel.fee) { TxFeeState.Empty -> { - makeDefaultAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) + makeSupportAlert(resourceReference(R.string.swapping_fee_estimation_error_text)) Timber.e("Fee should not be Empty") return@launch } @@ -1658,11 +1658,15 @@ internal class SwapModel @Inject constructor( } private fun makeDefaultAlert() { - uiState = stateBuilder.addAlert(uiState) + uiState = stateBuilder.addDefaultAlert(uiState = uiState) } - private fun makeDefaultAlert(message: TextReference) { - uiState = stateBuilder.addAlert(uiState, message) + private fun makeSupportAlert(message: TextReference) { + uiState = stateBuilder.addSupportAlert( + uiState = uiState, + message = message, + onSupportClick = { onFailedTxEmailClick("Fee calculation error") }, + ) } @Suppress("LongMethod", "CyclomaticComplexMethod") diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapAlertUM.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapAlertUM.kt index bb84996732..bb7763f928 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapAlertUM.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/models/SwapAlertUM.kt @@ -7,7 +7,16 @@ import com.tangem.core.ui.extensions.resourceReference sealed class SwapAlertUM : AlertUM { - data class GenericError( + data class DefaultError( + override val onConfirmClick: (() -> Unit), + override val message: TextReference = resourceReference(R.string.common_unknown_error), + ) : SwapAlertUM() { + override val title: TextReference? = null + override val confirmButtonText: TextReference = + resourceReference(id = R.string.common_ok) + } + + data class SupportError( override val onConfirmClick: (() -> Unit), override val message: TextReference = resourceReference(R.string.common_unknown_error), ) : SwapAlertUM() { diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt index 52bc5915e7..6e0f5f520a 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt @@ -1069,7 +1069,7 @@ internal class StateBuilder( ) } - fun addAlert( + fun addDefaultAlert( uiState: SwapStateHolder, message: TextReference = resourceReference(R.string.common_unknown_error), onDismiss: () -> Unit = { clearAlert(uiState) }, @@ -1077,7 +1077,23 @@ internal class StateBuilder( return uiState.copy( event = triggeredEvent( SwapEvent.ShowAlert( - SwapAlertUM.GenericError(onDismiss, message), + SwapAlertUM.DefaultError(onDismiss, message), + ), + onConsume = onDismiss, + ), + ) + } + + fun addSupportAlert( + uiState: SwapStateHolder, + message: TextReference = resourceReference(R.string.common_unknown_error), + onDismiss: () -> Unit = { clearAlert(uiState) }, + onSupportClick: () -> Unit, + ): SwapStateHolder { + return uiState.copy( + event = triggeredEvent( + SwapEvent.ShowAlert( + SwapAlertUM.SupportError(onSupportClick, message), ), onConsume = onDismiss, ),