Updated on 2026-08-14

This commit is contained in:
Tangem 2024-04-12 12:48:55 +05:00
parent b86da72f6e
commit ff486475ea
12 changed files with 22 additions and 21 deletions

View file

@ -69,12 +69,11 @@ internal sealed class SendAlertState {
}
data class FeeCoverage(
val amount: String,
override val onConfirmClick: (() -> Unit),
) : SendAlertState() {
override val title: TextReference? = null
override val message: TextReference =
resourceReference(id = R.string.send_alert_fee_coverage_title, wrappedList(amount))
resourceReference(id = R.string.send_alert_fee_coverage_title)
override val confirmButtonText: TextReference =
resourceReference(id = R.string.send_alert_fee_coverage_subract_text)
}

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.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.state.fee.FeeSelectorState
@ -50,18 +49,10 @@ internal class SendEventStateFactory(
}
fun getFeeCoverageAlert(onConsume: () -> Unit): SendUiState {
val state = currentStateProvider()
val amount = state.feeState?.fee?.amount ?: return state
val feeAmount = BigDecimalFormatter.formatCryptoAmount(
cryptoAmount = amount.value,
cryptoCurrency = state.cryptoCurrencySymbol,
decimals = amount.decimals,
)
return state.copy(
return currentStateProvider().copy(
event = triggeredEvent(
data = SendEvent.ShowAlert(
SendAlertState.FeeCoverage(
amount = feeAmount,
onConfirmClick = clickIntents::onSubtractSelect,
),
),

View file

@ -52,6 +52,7 @@ internal sealed class SendStates {
val notifications: ImmutableList<SendNotification>,
val appCurrencyCode: String,
val isFeeLoading: Boolean,
val subtractedFee: BigDecimal?,
) : SendStates()
/** Recipient state */

View file

@ -41,6 +41,7 @@ internal class SendAmountStateConverter(
notifications = persistentListOf(),
isFeeLoading = false,
appCurrencyCode = appCurrency.code,
subtractedFee = null,
segmentedButtonConfig = if (status.value.fiatRate.isNullOrZero()) {
persistentListOf()
} else {

View file

@ -15,14 +15,16 @@ internal class SendAmountSubtractConverter(
val state = currentStateProvider()
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val amountState = state.amountState ?: return state
val feeValue = state.feeState?.fee?.amount?.value ?: return state
val feeState = state.feeState ?: return state
val feeValue = feeState.fee?.amount?.value ?: return state
val amountTextField = amountState.amountTextField
val amountValue = amountTextField.cryptoAmount.value ?: return state
val fiatRate = cryptoCurrencyStatus.value.fiatRate
val cryptoDecimals = amountTextField.cryptoAmount.decimals
val fiatDecimals = amountTextField.fiatAmount.decimals
val decimalCryptoValue = amountValue.minus(feeValue)
val feeDiff = amountState.subtractedFee?.let { feeValue.minus(it) } ?: feeValue
val decimalCryptoValue = amountValue.minus(feeDiff)
if (decimalCryptoValue < BigDecimal.ZERO) return state
@ -33,6 +35,7 @@ internal class SendAmountSubtractConverter(
return state.copy(
sendState = state.sendState?.copy(isSubtract = true),
amountState = amountState.copy(
subtractedFee = feeValue,
amountTextField = amountTextField.copy(
value = cryptoValue,
fiatValue = fiatValue,

View file

@ -13,7 +13,7 @@ internal fun checkFeeCoverage(state: SendUiState, cryptoCurrencyStatus: CryptoCu
val balance = cryptoCurrencyStatus.value.amount ?: return false
val fee = state.feeState?.fee?.amount?.value ?: return false
val amount = state.amountState?.amountTextField?.cryptoAmount?.value ?: return false
return balance <= amount + fee
return balance < amount + fee
}
/**

View file

@ -59,8 +59,8 @@ internal class BitcoinCustomFeeConverter(
).toString(),
decimals = SATOSHI_DECIMALS,
symbol = "",
title = resourceReference(R.string.send_gas_price),
footer = resourceReference(R.string.send_gas_price_footer),
title = resourceReference(R.string.send_satoshi_per_byte_title),
footer = resourceReference(R.string.send_satoshi_per_byte_text),
onValueChange = { clickIntents.onCustomFeeValueChange(FEE_SATOSHI_INDEX, it) },
keyboardOptions = KeyboardOptions(
imeAction = if (checkExceedBalance(feeValue)) ImeAction.None else ImeAction.Done,

View file

@ -38,6 +38,7 @@ internal class SendAmountFieldChangeConverter(
return state.copy(
amountState = amountState.copy(
isPrimaryButtonEnabled = !isExceedBalance && !isZero,
subtractedFee = null,
amountTextField = amountTextField.copy(
value = cryptoValue,
fiatValue = fiatValue,

View file

@ -34,6 +34,7 @@ internal class SendAmountFieldMaxAmountConverter(
return state.copy(
amountState = amountState.copy(
isPrimaryButtonEnabled = true,
subtractedFee = null,
amountTextField = amountTextField.copy(
value = cryptoValue,
fiatValue = fiatValue,

View file

@ -25,6 +25,7 @@ internal object AmountStatePreviewData {
notifications = persistentListOf(),
isFeeLoading = false,
appCurrencyCode = "usd",
subtractedFee = null,
amountTextField = SendTextField.AmountField(
value = "123.123123123123123123",
onValueChange = {},