Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-15 12:13:02 +05:00
parent 11f32af295
commit 3e34156925
6 changed files with 38 additions and 46 deletions

View file

@ -68,13 +68,6 @@ internal sealed class SendAlertState {
override val confirmButtonText: TextReference = resourceReference(R.string.common_continue)
}
data class ReserveAmount(val amount: String) : SendAlertState() {
override val title: TextReference =
resourceReference(id = R.string.send_notification_invalid_reserve_amount_title, wrappedList(amount))
override val message: TextReference =
resourceReference(id = R.string.send_notification_invalid_reserve_amount_text)
}
data class FeeUnreachableError(
override val onConfirmClick: (() -> Unit),
) : SendAlertState() {

View file

@ -3,7 +3,6 @@ package com.tangem.features.send.impl.presentation.state
import com.tangem.blockchain.common.transaction.TransactionFee
import com.tangem.core.ui.event.consumedEvent
import com.tangem.core.ui.event.triggeredEvent
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.transaction.error.SendTransactionError
import com.tangem.features.send.impl.presentation.state.fee.FeeSelectorState
import com.tangem.features.send.impl.presentation.state.fee.FeeStateFactory
@ -22,13 +21,11 @@ import java.math.BigDecimal
internal class SendEventStateFactory(
private val stateRouterProvider: Provider<StateRouter>,
private val currentStateProvider: Provider<SendUiState>,
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
private val clickIntents: SendClickIntents,
private val feeStateFactory: FeeStateFactory,
) {
private val sendTransactionErrorConverter by lazy(LazyThreadSafetyMode.NONE) {
SendTransactionAlertConverter(
cryptoCurrencyStatusProvider = cryptoCurrencyStatusProvider,
clickIntents = clickIntents,
)
}

View file

@ -105,6 +105,14 @@ internal sealed class SendNotification(val config: NotificationConfig) {
onClick = onConfirmClick,
),
)
data class ReserveAmount(val amount: String) : Error(
title = resourceReference(
id = R.string.send_notification_invalid_reserve_amount_title,
wrappedList(amount),
),
subtitle = resourceReference(id = R.string.send_notification_invalid_reserve_amount_text),
)
}
sealed class Warning(

View file

@ -1,14 +1,10 @@
package com.tangem.features.send.impl.presentation.state
import com.tangem.core.ui.utils.BigDecimalFormatter
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.transaction.error.SendTransactionError
import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents
import com.tangem.utils.Provider
import com.tangem.utils.converter.Converter
internal class SendTransactionAlertConverter(
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
private val clickIntents: SendClickIntents,
) : Converter<SendTransactionError, SendAlertState?> {
override fun convert(value: SendTransactionError): SendAlertState? {
@ -42,12 +38,6 @@ internal class SendTransactionAlertConverter(
cause = value.ex?.localizedMessage,
onConfirmClick = { clickIntents.onFailedTxEmailClick(value.ex?.localizedMessage.orEmpty()) },
)
is SendTransactionError.CreateAccountUnderfunded -> SendAlertState.ReserveAmount(
BigDecimalFormatter.formatWithSymbol(
amount = value.amount,
symbol = cryptoCurrencyStatusProvider().currency.symbol,
),
)
else -> null
}
}

View file

@ -31,6 +31,7 @@ import com.tangem.features.send.impl.presentation.viewmodel.SendClickIntents
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.lib.crypto.BlockchainUtils.isTezos
import com.tangem.utils.Provider
import com.tangem.utils.extensions.orZero
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
@ -60,14 +61,15 @@ internal class SendNotificationFactory(
.map {
val state = currentStateProvider()
val isEditState = stateRouterProvider().isEditState
val balance = cryptoCurrencyStatusProvider().value.amount ?: BigDecimal.ZERO
val balance = cryptoCurrencyStatusProvider().value.amount.orZero()
val sendState = state.sendState ?: return@map persistentListOf()
val feeState = state.getFeeState(isEditState) ?: return@map persistentListOf()
val amountState = state.getAmountState(isEditState) as? AmountState.Data ?: return@map persistentListOf()
val amountValue = amountState.amountTextField.cryptoAmount.value ?: BigDecimal.ZERO
val feeValue = feeState.fee?.amount?.value ?: BigDecimal.ZERO
val reduceAmountBy = sendState.reduceAmountBy ?: BigDecimal.ZERO
val recipientAddress = state.recipientState?.addressTextField?.value.orEmpty()
val amountValue = amountState.amountTextField.cryptoAmount.value.orZero()
val feeValue = feeState.fee?.amount?.value.orZero()
val reduceAmountBy = sendState.reduceAmountBy.orZero()
val isFeeCoverage = checkFeeCoverage(
isSubtractAvailable = isSubtractAvailableProvider(),
balance = balance,
@ -89,6 +91,7 @@ internal class SendNotificationFactory(
addExceedsBalanceNotification(feeState.fee)
addDustWarningNotificationForSpecificBlockchains(feeValue, sendingAmount)
addTransactionLimitErrorNotification(feeValue, sendingAmount)
addReserveAmountErrorNotification(recipientAddress, sendingAmount)
// warnings
addExistentialWarningNotification(feeValue, amountValue)
@ -156,27 +159,29 @@ internal class SendNotificationFactory(
}
}
// todo temporarily disabling notification
// private suspend fun MutableList<SendNotification>.addReserveAmountErrorNotification(recipientAddress: String) {
// val userWalletId = userWalletProvider().walletId
// val cryptoCurrency = cryptoCurrencyStatusProvider().currency
// val isAccountFunded = currencyChecksRepository.checkIfAccountFunded(
// userWalletId,
// cryptoCurrency.network,
// recipientAddress,
// )
// val minimumAmount = currencyChecksRepository.getReserveAmount(userWalletId, cryptoCurrency.network)
// if (!isAccountFunded && minimumAmount != null && minimumAmount > BigDecimal.ZERO) {
// add(
// SendNotification.Error.ReserveAmountError(
// BigDecimalFormatter.formatCryptoAmount(
// cryptoAmount = minimumAmount,
// cryptoCurrency = cryptoCurrency,
// ),
// ),
// )
// }
// }
private suspend fun MutableList<SendNotification>.addReserveAmountErrorNotification(
recipientAddress: String,
sendingAmount: BigDecimal,
) {
val userWalletId = userWalletProvider().walletId
val cryptoCurrency = cryptoCurrencyStatusProvider().currency
val isAccountFunded = currencyChecksRepository.checkIfAccountFunded(
userWalletId,
cryptoCurrency.network,
recipientAddress,
)
val minimumAmount = currencyChecksRepository.getReserveAmount(userWalletId, cryptoCurrency.network)
if (!isAccountFunded && minimumAmount != null && minimumAmount > sendingAmount) {
add(
SendNotification.Error.ReserveAmount(
BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = minimumAmount,
cryptoCurrency = cryptoCurrency,
),
),
)
}
}
private suspend fun MutableList<SendNotification>.addTransactionLimitErrorNotification(
feeAmount: BigDecimal,

View file

@ -161,7 +161,6 @@ internal class SendViewModel @Inject constructor(
clickIntents = this,
stateRouterProvider = Provider { stateRouter },
currentStateProvider = Provider { uiState.value },
cryptoCurrencyStatusProvider = Provider { cryptoCurrencyStatus },
feeStateFactory = feeStateFactory,
)