Updated on 2026-08-14

This commit is contained in:
Tangem 2025-04-17 18:49:40 +05:00
commit 10acf6d245
7 changed files with 59 additions and 8 deletions

View file

@ -201,7 +201,7 @@ internal class DefaultSendComponent @AssistedInject constructor(
params = SendConfirmComponent.Params(
state = model.uiState.value,
userWallet = model.userWallet,
currentRoute = currentRoute.filterIsInstance<SendRoute.Confirm>(),
currentRoute = currentRoute,
isBalanceHidingFlow = model.isBalanceHiddenFlow,
analyticsCategoryName = SendAnalyticEvents.SEND_CATEGORY,
cryptoCurrencyStatus = model.cryptoCurrencyStatus,

View file

@ -140,7 +140,7 @@ internal class SendConfirmComponent(
val feeCryptoCurrencyStatus: CryptoCurrencyStatus,
val appCurrency: AppCurrency,
val callback: ModelCallback,
val currentRoute: Flow<SendRoute.Confirm>,
val currentRoute: Flow<SendRoute>,
val isBalanceHidingFlow: StateFlow<Boolean>,
val predefinedValues: PredefinedValues,
) {

View file

@ -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(

View file

@ -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) {

View file

@ -25,14 +25,33 @@ interface SendAmountReduceListener {
val ignoreReduceTriggerFlow: Flow<Unit>
}
/**
* 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<String>
}
@Singleton
internal class DefaultSendAmountReduceTrigger @Inject constructor() :
SendAmountReduceTrigger,
SendAmountReduceListener {
SendAmountReduceListener,
SendAmountUpdateQRTrigger,
SendAmountUpdateQRListener {
override val reduceToTriggerFlow = MutableSharedFlow<BigDecimal>()
override val reduceByTriggerFlow = MutableSharedFlow<ReduceByData>()
override val ignoreReduceTriggerFlow = MutableSharedFlow<Unit>()
override val updateAmountTriggerFlow = MutableSharedFlow<String>()
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)
}
}

View file

@ -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
}

View file

@ -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)