Updated on 2026-08-14
This commit is contained in:
parent
f426a1f922
commit
909ff3be7c
17 changed files with 104 additions and 21 deletions
|
|
@ -0,0 +1,19 @@
|
|||
package com.tangem.features.send.impl.presentation.errors
|
||||
|
||||
import com.tangem.domain.transaction.error.GetFeeError
|
||||
import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState
|
||||
|
||||
internal class FeeErrorStateMapper {
|
||||
|
||||
fun getFeeError(loadFeeError: GetFeeError?, tokenName: String): FeeSelectorState.Error {
|
||||
return when (loadFeeError) {
|
||||
GetFeeError.BlockchainErrors.TronActivationError -> FeeSelectorState.Error.TronAccountActivationError(
|
||||
tokenName,
|
||||
)
|
||||
is GetFeeError.DataError,
|
||||
GetFeeError.UnknownError,
|
||||
null,
|
||||
-> FeeSelectorState.Error.NetworkError
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -157,6 +157,14 @@ internal sealed class SendNotification(val config: NotificationConfig) {
|
|||
),
|
||||
)
|
||||
|
||||
data class TronAccountNotActivated(val tokenName: String) : Warning(
|
||||
title = resourceReference(R.string.send_fee_unreachable_error_title),
|
||||
subtitle = resourceReference(
|
||||
R.string.send_tron_account_activation_error,
|
||||
wrappedList(tokenName),
|
||||
),
|
||||
)
|
||||
|
||||
data class FeeCoverageNotification(val cryptoAmount: String, val fiatAmount: String) : Warning(
|
||||
title = resourceReference(R.string.send_network_fee_warning_title),
|
||||
subtitle = resourceReference(
|
||||
|
|
|
|||
|
|
@ -126,8 +126,18 @@ internal class SendNotificationFactory(
|
|||
}
|
||||
|
||||
private fun MutableList<SendNotification>.addFeeUnreachableNotification(feeSelectorState: FeeSelectorState) {
|
||||
if (feeSelectorState is FeeSelectorState.Error) {
|
||||
add(SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload))
|
||||
when (feeSelectorState) {
|
||||
is FeeSelectorState.Error.TronAccountActivationError -> add(
|
||||
SendNotification.Warning.TronAccountNotActivated(
|
||||
feeSelectorState.tokenName,
|
||||
),
|
||||
)
|
||||
is FeeSelectorState.Error.NetworkError -> add(
|
||||
SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload),
|
||||
)
|
||||
else -> {
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.tangem.features.send.impl.presentation.state.fee
|
||||
|
||||
import com.tangem.features.send.impl.presentation.state.*
|
||||
import com.tangem.features.send.impl.presentation.state.SendNotification
|
||||
import com.tangem.features.send.impl.presentation.state.SendUiState
|
||||
import com.tangem.features.send.impl.presentation.state.SendUiStateType
|
||||
import com.tangem.features.send.impl.presentation.state.StateRouter
|
||||
import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents
|
||||
import com.tangem.utils.Provider
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
|
@ -21,13 +24,25 @@ internal class FeeNotificationFactory(
|
|||
val state = currentStateProvider()
|
||||
val feeState = state.getFeeState(stateRouterProvider().isEditState) ?: return@map persistentListOf()
|
||||
buildList {
|
||||
addFeeUnreachableNotification(feeState.feeSelectorState)
|
||||
addFeeUnreachableNotification(
|
||||
feeState.feeSelectorState,
|
||||
)
|
||||
}.toImmutableList()
|
||||
}
|
||||
|
||||
private fun MutableList<SendNotification>.addFeeUnreachableNotification(feeSelectorState: FeeSelectorState) {
|
||||
if (feeSelectorState is FeeSelectorState.Error) {
|
||||
add(SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload))
|
||||
when (feeSelectorState) {
|
||||
is FeeSelectorState.Error.TronAccountActivationError -> add(
|
||||
SendNotification.Warning.TronAccountNotActivated(
|
||||
feeSelectorState.tokenName,
|
||||
),
|
||||
)
|
||||
is FeeSelectorState.Error.NetworkError -> add(
|
||||
SendNotification.Warning.NetworkFeeUnreachable(clickIntents::feeReload),
|
||||
)
|
||||
else -> {
|
||||
/* do nothing */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,10 @@ internal sealed class FeeSelectorState {
|
|||
|
||||
data object Loading : FeeSelectorState()
|
||||
|
||||
data object Error : FeeSelectorState()
|
||||
sealed class Error : FeeSelectorState() {
|
||||
data object NetworkError : Error()
|
||||
data class TronAccountActivationError(val tokenName: String) : Error()
|
||||
}
|
||||
}
|
||||
|
||||
enum class FeeType {
|
||||
|
|
|
|||
|
|
@ -99,13 +99,13 @@ internal class FeeStateFactory(
|
|||
)
|
||||
}
|
||||
|
||||
fun onFeeOnErrorState(): SendUiState {
|
||||
fun onFeeOnErrorState(feeError: FeeSelectorState.Error): SendUiState {
|
||||
val state = currentStateProvider()
|
||||
val isEditState = stateRouterProvider().isEditState
|
||||
return state.copyWrapped(
|
||||
isEditState = isEditState,
|
||||
feeState = state.getFeeState(isEditState)?.copy(
|
||||
feeSelectorState = FeeSelectorState.Error,
|
||||
feeSelectorState = feeError,
|
||||
),
|
||||
sendState = state.sendState?.copy(
|
||||
isPrimaryButtonEnabled = false,
|
||||
|
|
|
|||
|
|
@ -102,6 +102,6 @@ internal object FeeStatePreviewData {
|
|||
)
|
||||
|
||||
val errorFeeState = feeState.copy(
|
||||
feeSelectorState = FeeSelectorState.Error,
|
||||
feeSelectorState = FeeSelectorState.Error.NetworkError,
|
||||
)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ private fun FeeError(feeSelectorState: FeeSelectorState) {
|
|||
Row {
|
||||
SpacerWMax()
|
||||
AnimatedVisibility(
|
||||
visible = feeSelectorState == FeeSelectorState.Error,
|
||||
visible = feeSelectorState is FeeSelectorState.Error,
|
||||
label = "Fee Error State Change",
|
||||
modifier = Modifier.align(Alignment.CenterVertically),
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ private fun BoxScope.FeeError(feeSelectorState: FeeSelectorState) {
|
|||
label = "Fee Error State Change",
|
||||
modifier = Modifier.align(Alignment.CenterEnd),
|
||||
) {
|
||||
if (it == FeeSelectorState.Error) {
|
||||
if (it is FeeSelectorState.Error) {
|
||||
Text(
|
||||
text = BigDecimalFormatter.EMPTY_BALANCE_SIGN,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import com.tangem.features.send.impl.presentation.analytics.SendAnalyticEvents
|
|||
import com.tangem.features.send.impl.presentation.analytics.SendScreenSource
|
||||
import com.tangem.features.send.impl.presentation.analytics.utils.SendScreenAnalyticSender
|
||||
import com.tangem.features.send.impl.presentation.domain.AvailableWallet
|
||||
import com.tangem.features.send.impl.presentation.errors.FeeErrorStateMapper
|
||||
import com.tangem.features.send.impl.presentation.state.*
|
||||
import com.tangem.features.send.impl.presentation.state.amount.AmountStateFactory
|
||||
import com.tangem.features.send.impl.presentation.state.confirm.SendNotificationFactory
|
||||
|
|
@ -120,6 +121,8 @@ internal class SendViewModel @Inject constructor(
|
|||
var stateRouter: StateRouter by Delegates.notNull()
|
||||
private set
|
||||
|
||||
private val feeErrorHandler = FeeErrorStateMapper()
|
||||
|
||||
private val stateFactory = SendStateFactory(
|
||||
clickIntents = this,
|
||||
stateRouterProvider = Provider { stateRouter },
|
||||
|
|
@ -711,20 +714,24 @@ internal class SendViewModel @Inject constructor(
|
|||
uiState.value = feeStateFactory.onFeeOnLoadedState(it)
|
||||
sendIdleTimer = SystemClock.elapsedRealtime()
|
||||
},
|
||||
ifLeft = {
|
||||
onFeeLoadFailed(isShowStatus)
|
||||
ifLeft = { loadFeeError ->
|
||||
onFeeLoadFailed(isShowStatus, loadFeeError)
|
||||
},
|
||||
)
|
||||
if (result == null) {
|
||||
onFeeLoadFailed(isShowStatus)
|
||||
onFeeLoadFailed(isShowStatus, null)
|
||||
}
|
||||
updateNotifications()
|
||||
updateFeeNotifications()
|
||||
}.saveIn(feeJobHolder)
|
||||
}
|
||||
|
||||
private fun onFeeLoadFailed(isShowStatus: Boolean) {
|
||||
if (isShowStatus) uiState.value = feeStateFactory.onFeeOnErrorState()
|
||||
private fun onFeeLoadFailed(isShowStatus: Boolean, loadFeeError: GetFeeError?) {
|
||||
if (isShowStatus) {
|
||||
uiState.value = feeStateFactory.onFeeOnErrorState(
|
||||
feeErrorHandler.getFeeError(loadFeeError, cryptoCurrency.name),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkIfSubtractAvailable() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue