Updated on 2026-08-14
This commit is contained in:
parent
f5eaca92f6
commit
dea7034aad
26 changed files with 349 additions and 716 deletions
|
|
@ -1,56 +0,0 @@
|
|||
package com.tangem.common.ui.alerts
|
||||
|
||||
import com.tangem.common.ui.alerts.models.AlertDemoModeUM
|
||||
import com.tangem.common.ui.alerts.models.AlertTransactionErrorUM
|
||||
import com.tangem.common.ui.alerts.models.AlertUM
|
||||
import com.tangem.core.ui.R
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
import com.tangem.utils.converter.Converter
|
||||
|
||||
class TransactionErrorAlertConverter(
|
||||
private val popBackStack: () -> Unit,
|
||||
private val onFailedTxEmailClick: (String) -> Unit,
|
||||
) : Converter<SendTransactionError, AlertUM?> {
|
||||
override fun convert(value: SendTransactionError): AlertUM? {
|
||||
return when (value) {
|
||||
is SendTransactionError.DemoCardError -> AlertDemoModeUM(
|
||||
onConfirmClick = popBackStack,
|
||||
)
|
||||
is SendTransactionError.TangemSdkError -> AlertTransactionErrorUM(
|
||||
code = value.code.toString(),
|
||||
cause = null,
|
||||
causeTextReference = resourceReference(value.messageRes, wrappedList(value.args)),
|
||||
onConfirmClick = { onFailedTxEmailClick(value.code.toString()) },
|
||||
)
|
||||
is SendTransactionError.BlockchainSdkError -> AlertTransactionErrorUM(
|
||||
code = value.code.toString(),
|
||||
cause = value.message,
|
||||
onConfirmClick = { onFailedTxEmailClick("${value.code}: ${value.message.orEmpty()}") },
|
||||
)
|
||||
is SendTransactionError.DataError -> AlertTransactionErrorUM(
|
||||
code = "",
|
||||
cause = value.message,
|
||||
onConfirmClick = { onFailedTxEmailClick(value.message.orEmpty()) },
|
||||
)
|
||||
is SendTransactionError.NetworkError -> AlertTransactionErrorUM(
|
||||
code = value.code.orEmpty(),
|
||||
cause = value.message.orEmpty(),
|
||||
onConfirmClick = { onFailedTxEmailClick(value.message.orEmpty()) },
|
||||
)
|
||||
is SendTransactionError.UnknownError -> AlertTransactionErrorUM(
|
||||
code = "",
|
||||
cause = value.ex?.localizedMessage,
|
||||
onConfirmClick = { onFailedTxEmailClick(value.ex?.localizedMessage.orEmpty()) },
|
||||
)
|
||||
is SendTransactionError.CreateAccountUnderfunded -> AlertTransactionErrorUM(
|
||||
code = "",
|
||||
cause = null,
|
||||
causeTextReference = resourceReference(R.string.no_account_polkadot, wrappedList(value.amount)),
|
||||
onConfirmClick = popBackStack,
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.tangem.common.ui.alerts
|
||||
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
import com.tangem.core.ui.message.DialogMessage
|
||||
import com.tangem.core.ui.message.EventMessageAction
|
||||
import com.tangem.domain.transaction.error.SendTransactionError
|
||||
import javax.inject.Inject
|
||||
|
||||
class TransactionErrorDialogFactory @Inject constructor() {
|
||||
|
||||
fun create(
|
||||
error: SendTransactionError,
|
||||
popBackStack: () -> Unit,
|
||||
onFailedTxEmailClick: (String) -> Unit,
|
||||
): DialogMessage? {
|
||||
return when (error) {
|
||||
is SendTransactionError.DemoCardError -> demoModeDialog(popBackStack)
|
||||
is SendTransactionError.TangemSdkError -> transactionErrorDialog(
|
||||
causeTextReference = resourceReference(error.messageRes, wrappedList(error.args)),
|
||||
code = error.code.toString(),
|
||||
onConfirmClick = { onFailedTxEmailClick(error.code.toString()) },
|
||||
)
|
||||
is SendTransactionError.BlockchainSdkError -> transactionErrorDialog(
|
||||
cause = error.message,
|
||||
code = error.code.toString(),
|
||||
onConfirmClick = { onFailedTxEmailClick("${error.code}: ${error.message.orEmpty()}") },
|
||||
)
|
||||
is SendTransactionError.DataError -> transactionErrorDialog(
|
||||
cause = error.message,
|
||||
code = "",
|
||||
onConfirmClick = { onFailedTxEmailClick(error.message.orEmpty()) },
|
||||
)
|
||||
is SendTransactionError.NetworkError -> transactionErrorDialog(
|
||||
cause = error.message.orEmpty(),
|
||||
code = error.code.orEmpty(),
|
||||
onConfirmClick = { onFailedTxEmailClick(error.message.orEmpty()) },
|
||||
)
|
||||
is SendTransactionError.UnknownError -> transactionErrorDialog(
|
||||
cause = error.ex?.localizedMessage,
|
||||
code = "",
|
||||
onConfirmClick = { onFailedTxEmailClick(error.ex?.localizedMessage.orEmpty()) },
|
||||
)
|
||||
is SendTransactionError.CreateAccountUnderfunded -> transactionErrorDialog(
|
||||
causeTextReference = resourceReference(
|
||||
R.string.no_account_polkadot,
|
||||
wrappedList(error.amount),
|
||||
),
|
||||
code = "",
|
||||
onConfirmClick = popBackStack,
|
||||
)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun demoModeDialog(onConfirmClick: () -> Unit): DialogMessage = DialogMessage(
|
||||
title = resourceReference(id = R.string.warning_demo_mode_title),
|
||||
message = resourceReference(id = R.string.warning_demo_mode_message),
|
||||
firstAction = EventMessageAction(
|
||||
title = resourceReference(id = R.string.common_ok),
|
||||
onClick = onConfirmClick,
|
||||
),
|
||||
)
|
||||
|
||||
private fun transactionErrorDialog(
|
||||
cause: String? = null,
|
||||
causeTextReference: TextReference? = null,
|
||||
code: String,
|
||||
onConfirmClick: () -> Unit,
|
||||
): DialogMessage = DialogMessage(
|
||||
title = resourceReference(id = R.string.send_alert_transaction_failed_title),
|
||||
message = resourceReference(
|
||||
id = R.string.send_alert_transaction_failed_text,
|
||||
formatArgs = wrappedList(causeTextReference ?: cause.orEmpty(), code),
|
||||
),
|
||||
firstAction = EventMessageAction(
|
||||
title = resourceReference(id = R.string.common_support),
|
||||
onClick = onConfirmClick,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
package com.tangem.common.ui.alerts.models
|
||||
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
|
||||
data class AlertDemoModeUM(
|
||||
override val onConfirmClick: () -> Unit,
|
||||
) : AlertUM {
|
||||
override val confirmButtonText: TextReference = resourceReference(id = R.string.common_ok)
|
||||
override val title: TextReference = resourceReference(id = R.string.warning_demo_mode_title)
|
||||
override val message: TextReference = resourceReference(id = R.string.warning_demo_mode_message)
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
package com.tangem.common.ui.alerts.models
|
||||
|
||||
import com.tangem.common.ui.R
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.wrappedList
|
||||
|
||||
data class AlertTransactionErrorUM(
|
||||
val code: String,
|
||||
val cause: String?,
|
||||
val causeTextReference: TextReference? = null,
|
||||
override val onConfirmClick: () -> Unit,
|
||||
) : AlertUM {
|
||||
override val title: TextReference = resourceReference(id = R.string.send_alert_transaction_failed_title)
|
||||
override val message: TextReference = resourceReference(
|
||||
id = R.string.send_alert_transaction_failed_text,
|
||||
formatArgs = wrappedList(causeTextReference ?: cause.orEmpty(), code),
|
||||
)
|
||||
override val confirmButtonText: TextReference =
|
||||
resourceReference(id = R.string.common_support)
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.tangem.common.ui.alerts.models
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
|
||||
@Immutable
|
||||
interface AlertUM {
|
||||
val title: TextReference?
|
||||
val message: TextReference
|
||||
val confirmButtonText: TextReference
|
||||
val onConfirmClick: (() -> Unit)?
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue