Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-27 18:53:26 +05:00
parent d13c10328b
commit 5603059bb8
7 changed files with 29 additions and 10 deletions

View file

@ -62,7 +62,14 @@ internal class AmountStateFactory(
fun getOnAmountValueChange(value: String) = amountFieldChangeConverter.convert(value)
fun getOnAmountReduceByState(reduceAmountBy: BigDecimal) = amountReduceByConverter.convert(reduceAmountBy)
fun getOnAmountReduceByState(reduceAmountBy: BigDecimal, reduceAmountByDiff: BigDecimal) =
amountReduceByConverter.convert(
SendAmountReduceByConverter.ReduceByData(
reduceAmountBy = reduceAmountBy,
reduceAmountByDiff = reduceAmountByDiff,
),
)
fun getOnAmountReduceToState(reduceAmountTo: BigDecimal) = amountReduceToConverter.convert(reduceAmountTo)
fun getOnMaxAmountClick(): SendUiState {

View file

@ -16,8 +16,8 @@ internal class SendAmountReduceByConverter(
private val stateRouterProvider: Provider<StateRouter>,
private val currentStateProvider: Provider<SendUiState>,
private val cryptoCurrencyStatusProvider: Provider<CryptoCurrencyStatus>,
) : Converter<BigDecimal, SendUiState> {
override fun convert(value: BigDecimal): SendUiState {
) : Converter<SendAmountReduceByConverter.ReduceByData, SendUiState> {
override fun convert(value: ReduceByData): SendUiState {
val state = currentStateProvider()
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val isEditState = stateRouterProvider().isEditState
@ -27,7 +27,7 @@ internal class SendAmountReduceByConverter(
val fiatDecimals = amountTextField.fiatAmount.decimals
val amountValue = amountState.amountTextField.cryptoAmount.value ?: return state
val decimalCryptoValue = amountValue.minus(value)
val decimalCryptoValue = amountValue.minus(value.reduceAmountByDiff)
val cryptoValue = decimalCryptoValue.parseBigDecimal(cryptoDecimals)
val (fiatValue, decimalFiatValue) = cryptoValue.getFiatValue(
fiatRate = cryptoCurrencyStatus.value.fiatRate,
@ -41,7 +41,7 @@ internal class SendAmountReduceByConverter(
return state.copyWrapped(
isEditState = isEditState,
sendState = state.sendState?.copy(
reduceAmountBy = value,
reduceAmountBy = value.reduceAmountBy,
),
amountState = amountState.copy(
isPrimaryButtonEnabled = !isExceedBalance && !isZero,
@ -59,4 +59,9 @@ internal class SendAmountReduceByConverter(
),
)
}
internal data class ReduceByData(
val reduceAmountBy: BigDecimal,
val reduceAmountByDiff: BigDecimal,
)
}

View file

@ -213,7 +213,8 @@ internal class SendNotificationFactory(
),
onConfirmClick = {
clickIntents.onAmountReduceClick(
reduceAmountBy = currencyDeposit.minus(diff),
reduceAmountByDiff = currencyDeposit.minus(diff),
reduceAmountBy = currencyDeposit,
clazz = SendNotification.Error.ExistentialDeposit::class.java,
)
},

View file

@ -29,7 +29,7 @@ internal fun checkAndCalculateSubtractedAmount(
return if (isFeeCoverage) {
balance.minus(reduceAmountBy).minus(feeValue)
} else {
amountValue.minus(reduceAmountBy)
amountValue
}
}
@ -44,8 +44,8 @@ internal fun checkFeeCoverage(
reduceAmountBy: BigDecimal?,
): Boolean {
if (!isSubtractAvailable) return false
val amountWithReduced = (reduceAmountBy ?: BigDecimal.ZERO) + amountValue
return balance < amountWithReduced + feeValue && balance > feeValue && balance >= amountWithReduced
val reducedBy = balance - (reduceAmountBy ?: BigDecimal.ZERO)
return reducedBy < amountValue + feeValue && reducedBy > feeValue && reducedBy >= amountValue
}
/**

View file

@ -62,6 +62,7 @@ internal object SendClickIntentsStub : SendClickIntents {
override fun onAmountReduceClick(
reduceAmountBy: BigDecimal?,
reduceAmountByDiff: BigDecimal?,
reduceAmountTo: BigDecimal?,
clazz: Class<out SendNotification>,
) {}

View file

@ -69,6 +69,7 @@ internal interface SendClickIntents {
fun onAmountReduceClick(
reduceAmountBy: BigDecimal? = null,
reduceAmountByDiff: BigDecimal? = reduceAmountBy,
reduceAmountTo: BigDecimal? = null,
clazz: Class<out SendNotification>,
)

View file

@ -798,11 +798,15 @@ internal class SendViewModel @Inject constructor(
override fun onAmountReduceClick(
reduceAmountBy: BigDecimal?,
reduceAmountByDiff: BigDecimal?,
reduceAmountTo: BigDecimal?,
clazz: Class<out SendNotification>,
) {
uiState = when {
reduceAmountBy != null -> amountStateFactory.getOnAmountReduceByState(reduceAmountBy)
reduceAmountBy != null && reduceAmountByDiff != null -> amountStateFactory.getOnAmountReduceByState(
reduceAmountBy = reduceAmountBy,
reduceAmountByDiff = reduceAmountByDiff,
)
reduceAmountTo != null -> amountStateFactory.getOnAmountReduceToState(reduceAmountTo)
else -> return
}