From 69c477269e5e3f60959ee9614202228caf9cb377 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 17 Apr 2025 17:21:04 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../send/v2/send/DefaultSendComponent.kt | 2 +- .../v2/send/confirm/SendConfirmComponent.kt | 2 +- .../v2/send/confirm/model/SendConfirmModel.kt | 2 +- .../features/send/v2/send/model/SendModel.kt | 12 ++++++++- .../amount/SendAmountReduceTrigger.kt | 25 ++++++++++++++++++- .../amount/di/SendAmountModule.kt | 11 ++++++-- .../amount/model/SendAmountModel.kt | 13 +++++++++- 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt index 3ce42734fc..e7ae73cb18 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/DefaultSendComponent.kt @@ -201,7 +201,7 @@ internal class DefaultSendComponent @AssistedInject constructor( params = SendConfirmComponent.Params( state = model.uiState.value, userWallet = model.userWallet, - currentRoute = currentRoute.filterIsInstance(), + currentRoute = currentRoute, isBalanceHidingFlow = model.isBalanceHiddenFlow, analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY, cryptoCurrencyStatus = model.cryptoCurrencyStatus, diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt index ff6ba04840..943e48d31f 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/SendConfirmComponent.kt @@ -140,7 +140,7 @@ internal class SendConfirmComponent( val feeCryptoCurrencyStatus: CryptoCurrencyStatus, val appCurrency: AppCurrency, val callback: ModelCallback, - val currentRoute: Flow, + val currentRoute: Flow, val isBalanceHidingFlow: StateFlow, val predefinedValues: PredefinedValues, ) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt index cfd1b22477..daf5df6be6 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/confirm/model/SendConfirmModel.kt @@ -490,7 +490,7 @@ internal class SendConfirmModel @Inject constructor( flow = uiState, flow2 = params.currentRoute, transform = { state, route -> state to route }, - ).onEach { (state, _) -> + ).filter { it.second is SendRoute.Confirm }.onEach { (state, _) -> val amountUM = state.amountUM as? AmountState.Data val confirmUM = state.confirmUM params.callback.onResult( diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt index a1d123dc42..2e22376c66 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/send/model/SendModel.kt @@ -31,11 +31,12 @@ import com.tangem.domain.wallets.usecase.GetUserWalletUseCase import com.tangem.features.send.v2.api.SendComponent import com.tangem.features.send.v2.common.NavigationUM import com.tangem.features.send.v2.send.SendRoute -import com.tangem.features.send.v2.send.confirm.model.SendConfirmAlertFactory import com.tangem.features.send.v2.send.confirm.SendConfirmComponent +import com.tangem.features.send.v2.send.confirm.model.SendConfirmAlertFactory import com.tangem.features.send.v2.send.confirm.ui.state.ConfirmUM import com.tangem.features.send.v2.send.ui.state.SendUM import com.tangem.features.send.v2.subcomponents.amount.SendAmountComponent +import com.tangem.features.send.v2.subcomponents.amount.SendAmountUpdateQRTrigger import com.tangem.features.send.v2.subcomponents.destination.SendDestinationComponent import com.tangem.features.send.v2.subcomponents.destination.model.transformers.SendDestinationInitialStateTransformer import com.tangem.features.send.v2.subcomponents.destination.ui.state.DestinationUM @@ -74,6 +75,7 @@ internal class SendModel @Inject constructor( private val getCardInfoUseCase: GetCardInfoUseCase, private val sendFeedbackEmailUseCase: SendFeedbackEmailUseCase, private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, + private val sendAmountUpdateQRTrigger: SendAmountUpdateQRTrigger, ) : Model(), SendComponentCallback { private val params: SendComponent.Params = paramsContainer.require() @@ -110,6 +112,7 @@ internal class SendModel @Inject constructor( } override fun onAmountResult(amountUM: AmountState) { + predefinedAmountValue = null // reset predefined amount _uiState.update { it.copy(amountUM = amountUM) } } @@ -118,6 +121,7 @@ internal class SendModel @Inject constructor( } override fun onResult(sendUM: SendUM) { + predefinedAmountValue = null // reset predefined amount _uiState.update { sendUM } } @@ -227,7 +231,13 @@ internal class SendModel @Inject constructor( private fun onQrCodeScanned(address: String) { val parsedQrCode = parseQrCodeUseCase(address, cryptoCurrency).getOrNull() + // Decompose component can be active or inactive depending on its state and navigation stack + // If it is in inactive state use parameter to pass value to amount component predefinedAmountValue = parsedQrCode?.amount?.parseBigDecimal(cryptoCurrency.decimals) + // If it is in active state use flow to update value in amount component + modelScope.launch { + predefinedAmountValue?.let { sendAmountUpdateQRTrigger.triggerUpdateAmount(it) } + } } private fun onFailedTxEmailClick(errorMessage: String? = null) { diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountReduceTrigger.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountReduceTrigger.kt index 901ee1f0df..459994ffcf 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountReduceTrigger.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/SendAmountReduceTrigger.kt @@ -25,14 +25,33 @@ interface SendAmountReduceListener { val ignoreReduceTriggerFlow: Flow } +/** + * Trigger amount change from another component. + * Different from another triggers because it takes raw string instead of BigDecimal + */ +interface SendAmountUpdateQRTrigger { + suspend fun triggerUpdateAmount(amountValue: String) +} + +/** + * Trigger amount change from another component. + * Different from another triggers because it takes raw string instead of BigDecimal + */ +interface SendAmountUpdateQRListener { + val updateAmountTriggerFlow: Flow +} + @Singleton internal class DefaultSendAmountReduceTrigger @Inject constructor() : SendAmountReduceTrigger, - SendAmountReduceListener { + SendAmountReduceListener, + SendAmountUpdateQRTrigger, + SendAmountUpdateQRListener { override val reduceToTriggerFlow = MutableSharedFlow() override val reduceByTriggerFlow = MutableSharedFlow() override val ignoreReduceTriggerFlow = MutableSharedFlow() + override val updateAmountTriggerFlow = MutableSharedFlow() override suspend fun triggerReduceBy(reduceBy: ReduceByData) { reduceByTriggerFlow.emit(reduceBy) @@ -45,4 +64,8 @@ internal class DefaultSendAmountReduceTrigger @Inject constructor() : override suspend fun triggerIgnoreReduce() { ignoreReduceTriggerFlow.emit(Unit) } + + override suspend fun triggerUpdateAmount(amountValue: String) { + updateAmountTriggerFlow.emit(amountValue) + } } \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/di/SendAmountModule.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/di/SendAmountModule.kt index b486aeaeae..c88ca068c2 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/di/SendAmountModule.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/di/SendAmountModule.kt @@ -1,8 +1,7 @@ package com.tangem.features.send.v2.subcomponents.amount.di +import com.tangem.features.send.v2.subcomponents.amount.* import com.tangem.features.send.v2.subcomponents.amount.DefaultSendAmountReduceTrigger -import com.tangem.features.send.v2.subcomponents.amount.SendAmountReduceListener -import com.tangem.features.send.v2.subcomponents.amount.SendAmountReduceTrigger import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -20,4 +19,12 @@ internal interface SendAmountModule { @Singleton @Binds fun provideSendAmountReduceListener(impl: DefaultSendAmountReduceTrigger): SendAmountReduceListener + + @Singleton + @Binds + fun provideSendAmountUpdateQRListener(impl: DefaultSendAmountReduceTrigger): SendAmountUpdateQRListener + + @Singleton + @Binds + fun provideSendAmountUpdateQRTrigger(impl: DefaultSendAmountReduceTrigger): SendAmountUpdateQRTrigger } \ No newline at end of file diff --git a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt index 67bac1cf20..3c137c1bb4 100644 --- a/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt +++ b/features/send-v2/impl/src/main/java/com/tangem/features/send/v2/subcomponents/amount/model/SendAmountModel.kt @@ -27,6 +27,7 @@ import com.tangem.features.send.v2.send.analytics.SendAnalyticEvents.SendScreenS import com.tangem.features.send.v2.send.ui.state.ButtonsUM import com.tangem.features.send.v2.subcomponents.amount.SendAmountComponentParams import com.tangem.features.send.v2.subcomponents.amount.SendAmountReduceListener +import com.tangem.features.send.v2.subcomponents.amount.SendAmountUpdateQRListener import com.tangem.features.send.v2.subcomponents.amount.analytics.SendAmountAnalyticEvents import com.tangem.features.send.v2.subcomponents.amount.analytics.SendAmountAnalyticEvents.SelectedCurrencyType import com.tangem.features.send.v2.subcomponents.fee.SendFeeData @@ -50,6 +51,7 @@ internal class SendAmountModel @Inject constructor( private val getMinimumTransactionAmountSyncUseCase: GetMinimumTransactionAmountSyncUseCase, private val sendAmountReduceListener: SendAmountReduceListener, private val feeReloadTrigger: SendFeeReloadTrigger, + private val sendAmountUpdateQRListener: SendAmountUpdateQRListener, private val analyticsEventHandler: AnalyticsEventHandler, ) : Model(), AmountScreenClickIntents { @@ -71,6 +73,7 @@ internal class SendAmountModel @Inject constructor( subscribeOnAmountReduceByTriggerUpdates() subscribeOnAmountReduceToTriggerUpdates() subscribeOnAmountIgnoreReduceTriggerUpdates() + subscribeOnAmountUpdateQRTriggerUpdates() } private fun initMinBoundary() { @@ -105,8 +108,8 @@ internal class SendAmountModel @Inject constructor( ), ) } - params.predefinedAmountValue?.let(::onAmountValueChange) } + params.predefinedAmountValue?.let(::onAmountValueChange) } fun updateState(amountUM: AmountState) { @@ -215,6 +218,14 @@ internal class SendAmountModel @Inject constructor( .launchIn(modelScope) } + private fun subscribeOnAmountUpdateQRTriggerUpdates() { + sendAmountUpdateQRListener.updateAmountTriggerFlow + .onEach { amount -> + onAmountValueChange(amount) + saveResult() + }.launchIn(modelScope) + } + private fun saveResult() { val params = params as? SendAmountComponentParams.AmountParams ?: return params.callback.onAmountResult(uiState.value)