diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt index c9736b29ad..64817ff69e 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotification.kt @@ -23,12 +23,12 @@ internal sealed class SendNotification(val config: NotificationConfig) { ), ) { - object TotalExceedsBalance : Error( + data object TotalExceedsBalance : Error( title = resourceReference(R.string.send_notification_exceed_balance_title), subtitle = resourceReference(R.string.send_notification_exceed_balance_text), ) - object InvalidAmount : Error( + data object InvalidAmount : Error( title = resourceReference(R.string.send_notification_invalid_amount_title), subtitle = resourceReference(R.string.send_notification_invalid_amount_text), ) @@ -94,17 +94,6 @@ internal sealed class SendNotification(val config: NotificationConfig) { subtitle = resourceReference(R.string.send_notification_existential_deposit_text, wrappedList(deposit)), ) - data class NetworkCoverage( - val amountReducedBy: String, - val amountReduced: String, - ) : Warning( - title = resourceReference(id = R.string.send_network_fee_warning_title), - subtitle = resourceReference( - id = R.string.send_network_fee_warning_content, - formatArgs = wrappedList(amountReducedBy, amountReduced), - ), - ) - data object FeeTooLow : Warning( title = resourceReference(id = R.string.send_notification_transaction_delay_title), subtitle = resourceReference(id = R.string.send_notification_transaction_delay_text), diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt index 20ad57bca1..426ddab71a 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendNotificationFactory.kt @@ -52,7 +52,6 @@ internal class SendNotificationFactory( addDustWarningNotification(feeAmount, sendAmount) addTransactionLimitErrorNotification(feeAmount, sendAmount) // warnings - addFeeCoverageNotification(sendState.isSubtract, sendAmount) addExistentialWarningNotification(feeAmount, sendAmount) addHighFeeWarningNotification(sendAmount, sendState.ignoreAmountReduce) addTooLowNotification(feeState) @@ -257,29 +256,6 @@ internal class SendNotificationFactory( } } - private fun MutableList.addFeeCoverageNotification( - isSubtract: Boolean, - amountValue: BigDecimal, - ) { - val state = currentStateProvider() - val cryptoCurrency = cryptoCurrencyStatusProvider().currency - val feeAmount = state.feeState?.fee?.amount?.value ?: BigDecimal.ZERO - - val amountReducedValue = amountValue.minus(feeAmount) - val amountReducedByValue = amountValue.minus(amountReducedValue) - val amountReducedBy = BigDecimalFormatter.formatCryptoAmount( - cryptoAmount = amountReducedByValue, - cryptoCurrency = cryptoCurrency, - ) - val amountReduced = BigDecimalFormatter.formatCryptoAmount( - cryptoAmount = amountReducedValue, - cryptoCurrency = cryptoCurrency, - ) - if (isSubtract) { - add(SendNotification.Warning.NetworkCoverage(amountReducedBy, amountReduced)) - } - } - private fun MutableList.addTooLowNotification(feeState: SendStates.FeeState) { val feeSelectorState = feeState.feeSelectorState as? FeeSelectorState.Content ?: return val multipleFees = feeSelectorState.fees as? TransactionFee.Choosable ?: return diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt index 53f1815f01..0b45a8adda 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/SendStateFactory.kt @@ -5,6 +5,7 @@ import com.tangem.blockchain.common.TransactionData import com.tangem.core.ui.components.currency.tokenicon.converter.CryptoCurrencyToIconStateConverter import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.utils.parseBigDecimal import com.tangem.domain.appcurrency.model.AppCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.txhistory.models.TxHistoryItem @@ -215,9 +216,20 @@ internal class SendStateFactory( //endregion //region send - fun onSubtractSelect(isSubtract: Boolean): SendUiState { + fun onSubtractSelect(isSubtract: Boolean, isAmountSubtractAvailable: Boolean): SendUiState { val state = currentStateProvider() + val fee = state.feeState?.fee ?: return state + val amountState = state.amountState ?: return state + val amount = amountState.amountTextField.cryptoAmount + val amountValue = amount.value ?: return state + val amountToSend = if (isSubtract && isAmountSubtractAvailable) { + val feeValue = fee.amount.value ?: return state + amountValue.minus(feeValue) + } else { + amountValue + } return state.copy( + amountState = amountStateConverter.convert(amountToSend.parseBigDecimal(amount.decimals)), sendState = state.sendState.copy(isSubtract = isSubtract), ) } diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 30b3e00367..93d739cd4b 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -430,7 +430,7 @@ internal class SendViewModel @Inject constructor( ) return } else { - uiState = stateFactory.onSubtractSelect(false) + uiState = stateFactory.onSubtractSelect(false, isAmountSubtractAvailable) analyticsEventHandler.send(SendAnalyticEvents.SubtractFromAmount(false)) } if (checkIfFeeTooLow(uiState)) { @@ -569,7 +569,7 @@ internal class SendViewModel @Inject constructor( } override fun onSubtractSelect() { - uiState = stateFactory.onSubtractSelect(true) + uiState = stateFactory.onSubtractSelect(true, isAmountSubtractAvailable) stateRouter.showSend() analyticsEventHandler.send(SendAnalyticEvents.SubtractFromAmount(true)) } @@ -676,16 +676,10 @@ internal class SendViewModel @Inject constructor( val fee = feeState.fee ?: return val memo = uiState.recipientState?.memoTextField?.value val amountValue = uiState.amountState?.amountTextField?.cryptoAmount?.value ?: return - val amountToSend = if (uiState.sendState.isSubtract && isAmountSubtractAvailable) { - val feeValue = fee.amount.value ?: return - amountValue.minus(feeValue) - } else { - amountValue - } viewModelScope.launch(dispatchers.main) { createTransactionUseCase( - amount = amountToSend.convertToAmount(cryptoCurrency), + amount = amountValue.convertToAmount(cryptoCurrency), fee = fee, memo = memo, destination = recipient,