Updated on 2026-08-14

This commit is contained in:
Tangem 2026-01-09 16:44:30 +03:00
parent 3a9bdb16ad
commit aa621dd48f
10 changed files with 78 additions and 36 deletions

View file

@ -105,7 +105,6 @@ internal class SendConfirmComponent(
analyticsCategoryName = params.analyticsCategoryName,
userWalletId = params.userWallet.walletId,
cryptoCurrencyStatus = params.cryptoCurrencyStatus,
feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus,
appCurrency = params.appCurrency,
callback = model,
notificationData = NotificationData(
@ -116,6 +115,7 @@ internal class SendConfirmComponent(
isIgnoreReduce = model.confirmData.isIgnoreReduce,
fee = model.confirmData.fee,
feeError = model.confirmData.feeError,
feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus,
),
),
)

View file

@ -5,6 +5,7 @@ import androidx.compose.runtime.Stable
import arrow.core.getOrElse
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.transaction.Fee
import com.tangem.common.routing.AppRouter
import com.tangem.common.ui.amountScreen.converters.AmountReduceByTransformer
import com.tangem.common.ui.amountScreen.models.AmountState
@ -29,6 +30,7 @@ import com.tangem.domain.feedback.SendFeedbackEmailUseCase
import com.tangem.domain.feedback.models.BlockchainErrorInfo
import com.tangem.domain.feedback.models.FeedbackEmailType
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.currency.CryptoCurrencyStatus
import com.tangem.domain.settings.IsSendTapHelpEnabledUseCase
import com.tangem.domain.settings.NeverShowTapHelpUseCase
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
@ -155,10 +157,7 @@ internal class SendConfirmModel @Inject constructor(
internal var feeStateConfiguration: FeeStateConfiguration = FeeStateConfiguration.None
init {
modelScope.launch {
isAmountSubtractAvailable =
isAmountSubtractAvailableUseCase(userWallet.walletId, cryptoCurrency).getOrElse { false }
}
updateAmountSubtractAvailability()
configConfirmNavigation()
subscribeOnNotificationsUpdateTrigger()
subscribeOnCheckFeeResultUpdates()
@ -357,7 +356,7 @@ internal class SendConfirmModel @Inject constructor(
val receivingAmount = checkAndCalculateSubtractedAmount(
isAmountSubtractAvailable = isAmountSubtractAvailable,
cryptoCurrencyStatus = cryptoCurrencyStatus,
cryptoCurrencyStatus = getCurrencyStatusForFeePayment(),
amountValue = amountValue,
feeValue = feeValue,
reduceAmountBy = confirmData.reduceAmountBy.orZero(),
@ -392,7 +391,9 @@ internal class SendConfirmModel @Inject constructor(
private suspend fun sendTransaction(txData: TransactionData.Uncompiled) {
val feeExtended = feeUMV2?.feeExtraInfo?.transactionFeeExtended
val result = if (feeExtended != null) {
val isFeeInTokenCurrency = feeExtended?.transactionFee?.normal is Fee.Ethereum.TokenCurrency
val result = if (isFeeInTokenCurrency) {
createAndSendGaslessTransactionUseCase(
userWallet = userWallet,
transactionData = txData,
@ -439,6 +440,16 @@ internal class SendConfirmModel @Inject constructor(
)
}
private fun getCurrencyStatusForFeePayment(): CryptoCurrencyStatus {
val feeExtended = feeUMV2?.feeExtraInfo?.transactionFeeExtended
val isFeeInTokenCurrency = feeExtended?.transactionFee?.normal is Fee.Ethereum.TokenCurrency
return if (isFeeInTokenCurrency) {
feeUMV2?.feeExtraInfo?.feeCryptoCurrencyStatus ?: cryptoCurrencyStatus
} else {
params.feeCryptoCurrencyStatus
}
}
private fun addTokenToWalletIfNeeded() {
if (cryptoCurrency !is CryptoCurrency.Token) return
val wallets = destinationUM?.wallets ?: return
@ -509,6 +520,7 @@ internal class SendConfirmModel @Inject constructor(
isIgnoreReduce = confirmData.isIgnoreReduce,
fee = confirmData.fee,
feeError = confirmData.feeError,
feeCryptoCurrencyStatus = getCurrencyStatusForFeePayment(),
),
)
_uiState.update { state ->
@ -610,9 +622,23 @@ internal class SendConfirmModel @Inject constructor(
override fun onFeeResult(feeSelectorUM: FeeSelectorUMRedesigned) {
sendIdleTimer = SystemClock.elapsedRealtime()
_uiState.update { it.copy(feeSelectorUM = feeSelectorUM) }
updateAmountSubtractAvailability()
updateConfirmNotifications()
}
private fun updateAmountSubtractAvailability() {
modelScope.launch {
val isGaslessEthTx =
feeUMV2?.feeExtraInfo?.transactionFeeExtended?.transactionFee?.normal is Fee.Ethereum.TokenCurrency
isAmountSubtractAvailable =
isAmountSubtractAvailableUseCase(
userWalletId = userWallet.walletId,
currency = cryptoCurrency,
isGaslessEthTx = isGaslessEthTx,
).getOrElse { false }
}
}
private companion object {
const val CHECK_FEE_UPDATE_DELAY = 10_000L
}

View file

@ -102,7 +102,6 @@ internal class NFTSendConfirmComponent @AssistedInject constructor(
analyticsCategoryName = params.analyticsCategoryName,
userWalletId = params.userWallet.walletId,
cryptoCurrencyStatus = params.cryptoCurrencyStatus,
feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus,
appCurrency = params.appCurrency,
callback = model,
notificationData = SendNotificationsComponent.Params.NotificationData(
@ -113,6 +112,7 @@ internal class NFTSendConfirmComponent @AssistedInject constructor(
isIgnoreReduce = false,
fee = model.confirmData.fee,
feeError = model.confirmData.feeError,
feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus,
),
),
)

View file

@ -350,6 +350,7 @@ internal class NFTSendConfirmModel @Inject constructor(
isIgnoreReduce = false,
fee = confirmData.fee,
feeError = confirmData.feeError,
feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus, // TODO change when gasless implement
),
)
}

View file

@ -79,7 +79,7 @@ internal class NotificationsModel @Inject constructor(
private val analyticsCategoryName = params.analyticsCategoryName
private val userWalletId = params.userWalletId
private val cryptoCurrencyStatus = params.cryptoCurrencyStatus
private val feeCryptoCurrencyStatus = params.feeCryptoCurrencyStatus
private val feeCryptoCurrencyStatus = params.notificationData.feeCryptoCurrencyStatus
private val currency = cryptoCurrencyStatus.currency
private val appCurrency = params.appCurrency
@ -92,7 +92,10 @@ internal class NotificationsModel @Inject constructor(
init {
subscribeToNotificationUpdateTrigger()
checkIfSubtractAvailable()
modelScope.launch {
checkIfSubtractAvailable()
buildNotifications()
}
incrementNotificationsShowCount()
}
@ -102,11 +105,12 @@ internal class NotificationsModel @Inject constructor(
.launchIn(modelScope)
}
private fun checkIfSubtractAvailable() {
modelScope.launch {
isAmountSubtractAvailable = isAmountSubtractAvailableUseCase(userWalletId, currency).getOrElse { false }
buildNotifications()
}
private suspend fun checkIfSubtractAvailable() {
isAmountSubtractAvailable = isAmountSubtractAvailableUseCase(
userWalletId = userWalletId,
currency = currency,
isGaslessEthTx = notificationData.fee is Fee.Ethereum.TokenCurrency,
).getOrElse { false }
}
private fun incrementNotificationsShowCount() {
@ -115,16 +119,19 @@ internal class NotificationsModel @Inject constructor(
}
}
private suspend fun updateState(data: NotificationData) {
private fun updateState(data: NotificationData) {
notificationData = data
buildNotifications()
modelScope.launch {
checkIfSubtractAvailable()
buildNotifications()
}
}
private suspend fun buildNotifications() = with(notificationData) {
val feeValue = fee?.amount?.value
val sendingAmount = checkAndCalculateSubtractedAmount(
isAmountSubtractAvailable = isAmountSubtractAvailable,
cryptoCurrencyStatus = cryptoCurrencyStatus,
cryptoCurrencyStatus = getCurrencyStatusForFeePayment(),
amountValue = amountValue,
feeValue = feeValue,
reduceAmountBy = reduceAmountBy,
@ -369,6 +376,15 @@ internal class NotificationsModel @Inject constructor(
}
}
private fun getCurrencyStatusForFeePayment(): CryptoCurrencyStatus {
val isFeeInTokenCurrency = notificationData.fee is Fee.Ethereum.TokenCurrency
return if (isFeeInTokenCurrency) {
notificationData.feeCryptoCurrencyStatus
} else {
cryptoCurrencyStatus
}
}
companion object {
const val TRON_FEE_NOTIFICATION_MAX_SHOW_COUNT = 3
}