Updated on 2026-08-14
This commit is contained in:
parent
e803ab0d7d
commit
955da46b07
7 changed files with 59 additions and 21 deletions
|
|
@ -7,6 +7,7 @@ import com.arkivanov.essenty.lifecycle.doOnResume
|
|||
import com.tangem.core.decompose.context.AppComponentContext
|
||||
import com.tangem.core.ui.decompose.ComposableBottomSheetComponent
|
||||
import com.tangem.features.send.v2.api.FeeSelectorBlockComponent
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM
|
||||
import com.tangem.features.send.v2.api.params.FeeSelectorParams
|
||||
import com.tangem.features.walletconnect.transaction.entity.common.WcTransactionFeeState
|
||||
import com.tangem.features.walletconnect.transaction.model.WcSendTransactionModel
|
||||
|
|
@ -58,6 +59,7 @@ internal class WcSendTransactionComponent(
|
|||
WcSendTransactionModalBottomSheet(
|
||||
state = state,
|
||||
feeSelectorBlockComponent = feeSelectorBlock,
|
||||
feeSelectorUM = content?.feeSelectorUM ?: FeeSelectorUM.Loading,
|
||||
onClickTransactionRequest = model::showTransactionRequest,
|
||||
onBack = router::pop,
|
||||
onDismiss = ::dismiss,
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ internal class WcSendTransactionUMConverter @Inject constructor(
|
|||
) : Converter<WcSendTransactionUMConverter.Input, WcSendTransactionUM?> {
|
||||
|
||||
override fun convert(value: Input): WcSendTransactionUM? {
|
||||
val feeExceedsBalance = notificationsFactory.createFeeExceedsBalance(
|
||||
val feeErrorNotification = notificationsFactory.createFeeNotifications(
|
||||
cryptoCurrencyStatus = value.cryptoCurrencyStatus,
|
||||
feeSelectorUM = value.feeSelectorUM,
|
||||
onFeeReload = value.onFeeReload,
|
||||
)
|
||||
return when (value.context.method) {
|
||||
is WcEthMethod.SendTransaction,
|
||||
|
|
@ -51,8 +52,8 @@ internal class WcSendTransactionUMConverter @Inject constructor(
|
|||
estimatedWalletChanges = WcSendReceiveTransactionCheckResultsUM(),
|
||||
isLoading = value.signState.domainStep == WcSignStep.Signing,
|
||||
address = WcAddressConverter.convert(value.context.derivationState),
|
||||
sendEnabled = value.feeSelectorUM is FeeSelectorUM.Content && feeExceedsBalance == null,
|
||||
feeExceedsBalanceNotification = feeExceedsBalance,
|
||||
sendEnabled = value.feeSelectorUM is FeeSelectorUM.Content && feeErrorNotification == null,
|
||||
feeErrorNotification = feeErrorNotification,
|
||||
),
|
||||
feeSelectorUM = value.feeSelectorUM ?: FeeSelectorUM.Loading,
|
||||
transactionRequestInfo = WcTransactionRequestInfoUM(
|
||||
|
|
@ -77,5 +78,6 @@ internal class WcSendTransactionUMConverter @Inject constructor(
|
|||
val actions: WcTransactionActionsUM,
|
||||
val feeSelectorUM: FeeSelectorUM?,
|
||||
val cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
val onFeeReload: () -> Unit,
|
||||
)
|
||||
}
|
||||
|
|
@ -28,6 +28,6 @@ internal data class WcSendTransactionItemUM(
|
|||
val networkInfo: WcNetworkInfoUM,
|
||||
val address: String?,
|
||||
val sendEnabled: Boolean,
|
||||
val feeExceedsBalanceNotification: NotificationUM.Info?,
|
||||
val feeErrorNotification: NotificationUM.Info?,
|
||||
val isLoading: Boolean = false,
|
||||
) : TangemBottomSheetConfigContent
|
||||
|
|
@ -142,7 +142,7 @@ internal class WcSendTransactionModel @Inject constructor(
|
|||
feeReloadState.value = false
|
||||
modelScope.launch {
|
||||
feeSelectorReloadTrigger.triggerUpdate(
|
||||
feeData = FeeSelectorData(removeSuggestedFee = true),
|
||||
FeeSelectorData(removeSuggestedFee = feeStateConfiguration !is FeeStateConfiguration.Suggestion),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -161,16 +161,17 @@ internal class WcSendTransactionModel @Inject constructor(
|
|||
* Also handles fee results from FeeSelectorBlockComponent
|
||||
*/
|
||||
fun updateFee(feeSelectorUM: FeeSelectorUM) {
|
||||
val feeExceedsBalance = notificationsFactory.createFeeExceedsBalance(
|
||||
val feeErrorNotification = notificationsFactory.createFeeNotifications(
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
onFeeReload = ::triggerFeeReload,
|
||||
)
|
||||
_uiState.update {
|
||||
it?.copy(
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
transaction = it.transaction.copy(
|
||||
sendEnabled = feeSelectorUM is FeeSelectorUM.Content && feeExceedsBalance == null,
|
||||
feeExceedsBalanceNotification = feeExceedsBalance,
|
||||
sendEnabled = feeSelectorUM is FeeSelectorUM.Content && feeErrorNotification == null,
|
||||
feeErrorNotification = feeErrorNotification,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -237,6 +238,7 @@ internal class WcSendTransactionModel @Inject constructor(
|
|||
actions = actions,
|
||||
feeSelectorUM = uiState.value?.feeSelectorUM,
|
||||
cryptoCurrencyStatus = cryptoCurrencyStatus,
|
||||
onFeeReload = ::triggerFeeReload,
|
||||
),
|
||||
)
|
||||
transactionUM = transactionUM?.copy(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.tangem.core.ui.components.divider.DividerWithPadding
|
|||
import com.tangem.core.ui.extensions.clickableSingle
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.features.send.v2.api.FeeSelectorBlockComponent
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM
|
||||
import com.tangem.features.walletconnect.transaction.entity.common.WcNetworkInfoUM
|
||||
import com.tangem.features.walletconnect.transaction.entity.common.WcTransactionFeeState
|
||||
|
||||
|
|
@ -25,14 +26,15 @@ internal fun WcSendTransactionItems(
|
|||
networkInfo: WcNetworkInfoUM,
|
||||
feeState: WcTransactionFeeState,
|
||||
feeSelectorBlockComponent: FeeSelectorBlockComponent?,
|
||||
feeExceedsBalance: Boolean,
|
||||
feeSelectorUM: FeeSelectorUM,
|
||||
address: String?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val onFeeBlockClicked = remember(feeState) {
|
||||
when (feeState) {
|
||||
WcTransactionFeeState.None -> null
|
||||
is WcTransactionFeeState.Success -> feeState.onClick
|
||||
val onFeeBlockClicked = remember(feeState, feeSelectorUM) {
|
||||
if (feeState is WcTransactionFeeState.Success && feeSelectorUM is FeeSelectorUM.Content) {
|
||||
feeState.onClick
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
Column(
|
||||
|
|
@ -64,7 +66,7 @@ internal fun WcSendTransactionItems(
|
|||
address = address,
|
||||
)
|
||||
}
|
||||
if (feeState != WcTransactionFeeState.None && !feeExceedsBalance) {
|
||||
if (feeState != WcTransactionFeeState.None) {
|
||||
DividerWithPadding(start = 40.dp, end = 12.dp)
|
||||
feeSelectorBlockComponent?.Content(
|
||||
modifier = if (onFeeBlockClicked != null) {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import com.tangem.core.ui.extensions.stringReference
|
|||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.features.send.v2.api.FeeSelectorBlockComponent
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM
|
||||
import com.tangem.features.walletconnect.connections.entity.VerifiedDAppState
|
||||
import com.tangem.features.walletconnect.connections.ui.WcAppInfoItem
|
||||
import com.tangem.features.walletconnect.impl.R
|
||||
|
|
@ -54,6 +55,7 @@ import kotlinx.collections.immutable.persistentListOf
|
|||
internal fun WcSendTransactionModalBottomSheet(
|
||||
state: WcSendTransactionItemUM,
|
||||
feeSelectorBlockComponent: FeeSelectorBlockComponent?,
|
||||
feeSelectorUM: FeeSelectorUM,
|
||||
onClickTransactionRequest: () -> Unit,
|
||||
onBack: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
|
|
@ -112,14 +114,15 @@ internal fun WcSendTransactionModalBottomSheet(
|
|||
networkInfo = state.networkInfo,
|
||||
feeState = state.feeState,
|
||||
feeSelectorBlockComponent = feeSelectorBlockComponent,
|
||||
feeExceedsBalance = state.feeExceedsBalanceNotification != null,
|
||||
feeSelectorUM = feeSelectorUM,
|
||||
address = state.address,
|
||||
)
|
||||
if (state.feeExceedsBalanceNotification != null) {
|
||||
if (state.feeErrorNotification != null) {
|
||||
Notification(
|
||||
modifier = Modifier.padding(top = 14.dp),
|
||||
config = state.feeExceedsBalanceNotification.config,
|
||||
config = state.feeErrorNotification.config,
|
||||
iconTint = TangemTheme.colors.icon.warning,
|
||||
containerColor = TangemTheme.colors.button.disabled,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -169,6 +172,7 @@ private fun WcSendTransactionBottomSheetPreview(
|
|||
onBack = {},
|
||||
onDismiss = {},
|
||||
onClickAllowToSpend = {},
|
||||
feeSelectorUM = FeeSelectorUM.Loading,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
|
@ -215,7 +219,7 @@ private class WcSendTransactionStateProvider : CollectionPreviewParameterProvide
|
|||
feeState = WcTransactionFeeState.Success(dAppFee = null, onClick = {}),
|
||||
address = null,
|
||||
sendEnabled = true,
|
||||
feeExceedsBalanceNotification = null,
|
||||
feeErrorNotification = null,
|
||||
),
|
||||
WcSendTransactionItemUM(
|
||||
onDismiss = {},
|
||||
|
|
@ -254,7 +258,7 @@ private class WcSendTransactionStateProvider : CollectionPreviewParameterProvide
|
|||
feeState = WcTransactionFeeState.Success(dAppFee = null, onClick = {}),
|
||||
address = "0xdac17f958d2ee523a2206206994597c13d831ec7",
|
||||
sendEnabled = true,
|
||||
feeExceedsBalanceNotification = NotificationUM.Info(
|
||||
feeErrorNotification = NotificationUM.Info(
|
||||
title = stringReference("Insufficient Ethereum"),
|
||||
subtitle = stringReference("Top up your balance to cover the network fee"),
|
||||
),
|
||||
|
|
@ -296,7 +300,7 @@ private class WcSendTransactionStateProvider : CollectionPreviewParameterProvide
|
|||
feeState = WcTransactionFeeState.None,
|
||||
address = null,
|
||||
sendEnabled = false,
|
||||
feeExceedsBalanceNotification = NotificationUM.Info(
|
||||
feeErrorNotification = NotificationUM.Info(
|
||||
title = stringReference("Insufficient Ethereum"),
|
||||
subtitle = stringReference("Top up your balance to cover the network fee"),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -2,15 +2,30 @@ package com.tangem.features.walletconnect.utils
|
|||
|
||||
import com.tangem.blockchain.common.transaction.TransactionFee
|
||||
import com.tangem.common.ui.notifications.NotificationUM
|
||||
import com.tangem.core.ui.components.notifications.NotificationConfig
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.features.send.v2.api.entity.FeeSelectorUM
|
||||
import com.tangem.features.send.v2.api.subcomponents.feeSelector.utils.FeeCalculationUtils
|
||||
import com.tangem.features.walletconnect.impl.R
|
||||
import javax.inject.Inject
|
||||
|
||||
internal class WcNotificationsFactory @Inject constructor() {
|
||||
|
||||
fun createFeeExceedsBalance(
|
||||
fun createFeeNotifications(
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
feeSelectorUM: FeeSelectorUM?,
|
||||
onFeeReload: () -> Unit,
|
||||
): NotificationUM.Info? {
|
||||
return when (feeSelectorUM) {
|
||||
is FeeSelectorUM.Content -> createFeeExceedsBalance(cryptoCurrencyStatus, feeSelectorUM)
|
||||
is FeeSelectorUM.Error -> createFeeErrorNotification(onFeeReload)
|
||||
FeeSelectorUM.Loading, null -> null
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFeeExceedsBalance(
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
feeSelectorUM: FeeSelectorUM?,
|
||||
): NotificationUM.Info? {
|
||||
|
|
@ -21,6 +36,17 @@ internal class WcNotificationsFactory @Inject constructor() {
|
|||
).takeIf { isFeeExceedsBalance(cryptoCurrencyStatus = cryptoCurrencyStatus, feeSelectorUM = feeSelectorUM) }
|
||||
}
|
||||
|
||||
private fun createFeeErrorNotification(onFeeReload: () -> Unit): NotificationUM.Info {
|
||||
return NotificationUM.Info(
|
||||
title = resourceReference(R.string.send_fee_unreachable_error_title),
|
||||
subtitle = resourceReference(R.string.send_fee_unreachable_error_text),
|
||||
buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig(
|
||||
text = resourceReference(R.string.warning_button_refresh),
|
||||
onClick = onFeeReload,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun isFeeExceedsBalance(
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
feeSelectorUM: FeeSelectorUM?,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue