diff --git a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt index b406f013fb..75b3107ff5 100644 --- a/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt +++ b/features/swap-v2/impl/src/main/java/com/tangem/features/swap/v2/impl/amount/model/SwapAmountModel.kt @@ -58,6 +58,7 @@ import com.tangem.utils.coroutines.SingleTaskScheduler import com.tangem.utils.extensions.orZero import com.tangem.utils.isNullOrZero import com.tangem.utils.transformer.update +import kotlinx.coroutines.Job import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.flow.* @@ -110,6 +111,8 @@ internal class SwapAmountModel @Inject constructor( private var isShowBestRateAnimation: Boolean = false + private var autoUpdateSubscriberJob: Job? = null + val uiState: StateFlow field = MutableStateFlow(params.amountUM) @@ -132,7 +135,6 @@ internal class SwapAmountModel @Inject constructor( subscribeOnAmountIgnoreReduceTriggerUpdates() subscribeOnReloadQuotesTriggerUpdates() subscribeOnBalanceHiddenUpdates() - subscribeOnAutoupdateEnabling() } fun onStart() { @@ -140,10 +142,12 @@ internal class SwapAmountModel @Inject constructor( scope = modelScope, task = loadQuotesTask(), ) + subscribeOnAutoupdateEnabling() } fun onStop() { quoteTaskScheduler.cancelTask() + autoUpdateSubscriberJob?.cancel() } override fun onDestroy() { @@ -484,7 +488,7 @@ internal class SwapAmountModel @Inject constructor( } private fun subscribeOnAutoupdateEnabling() { - swapAmountUpdateListener.autoUpdateTriggerFlow + autoUpdateSubscriberJob = swapAmountUpdateListener.autoUpdateTriggerFlow .distinctUntilChanged() .onEach { isEnabled -> if (isEnabled) {