From 466b6e578b8f9281db53c1035235f942320e4584 Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 10 Dec 2024 18:52:29 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../tokenlist/model/OnrampTokenListModel.kt | 29 ++++++++++++------ .../tangem/feature/swap/router/SwapRouter.kt | 6 ++-- .../WalletCurrencyActionsClickIntents.kt | 30 +------------------ 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt index b8050d2cfb..6568ab9e04 100644 --- a/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt +++ b/features/onramp/impl/src/main/kotlin/com/tangem/features/onramp/tokenlist/model/OnrampTokenListModel.kt @@ -25,6 +25,9 @@ import com.tangem.features.onramp.utils.UpdateSearchBarActiveStateTransformer import com.tangem.features.onramp.utils.UpdateSearchBarCallbacksTransformer import com.tangem.features.onramp.utils.UpdateSearchQueryTransformer import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import javax.inject.Inject @@ -133,17 +136,25 @@ internal class OnrampTokenListModel @Inject constructor( } private suspend fun List.filterByAvailability(): Map> { - return groupBy { status -> - val isAvailable = checkAvailabilityByOperation(status = status) - val isNotMissedDerivation = status.value !is CryptoCurrencyStatus.MissedDerivation + return coroutineScope { + map { status -> + async { + val isAvailable = checkAvailabilityByOperation(status = status) + val isNotMissedDerivation = status.value !is CryptoCurrencyStatus.MissedDerivation + val isNotLoading = status.value !is CryptoCurrencyStatus.Loading - val isNotUnreachable = when (params.filterOperation) { - OnrampOperation.BUY -> true // unreachable state is available for Buy operation - OnrampOperation.SELL -> status.value !is CryptoCurrencyStatus.Unreachable - OnrampOperation.SWAP -> status.value !is CryptoCurrencyStatus.Unreachable + val isNotUnreachable = when (params.filterOperation) { + OnrampOperation.BUY -> true // unreachable state is available for Buy operation + OnrampOperation.SELL -> status.value !is CryptoCurrencyStatus.Unreachable + OnrampOperation.SWAP -> status.value !is CryptoCurrencyStatus.Unreachable + } + + status to (isAvailable && isNotMissedDerivation && isNotLoading && isNotUnreachable) + } } - - isAvailable && isNotMissedDerivation && isNotUnreachable + .awaitAll() + .groupBy(Pair::second) + .mapValues { it.value.map(Pair::first) } } } diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt index dad11a62e1..c260e1bac4 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/router/SwapRouter.kt @@ -30,9 +30,7 @@ internal class SwapRouter( * If select token screen is not in stack, then just pop to previous screen. * Otherwise, pop to previous screen that was before select token screen. */ - if (selectTokensIndex == null) { - router.pop() - } else { + if (currentScreen == SwapNavScreen.Success && selectTokensIndex != null) { // find previous screen that was before select token val prevRoute = router.stack.getOrNull(index = selectTokensIndex - 1) @@ -41,6 +39,8 @@ internal class SwapRouter( } else { router.pop() } + } else { + router.pop() } } } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt index 531c4507b0..85cd2a7a03 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletCurrencyActionsClickIntents.kt @@ -47,7 +47,6 @@ import com.tangem.feature.wallet.presentation.wallet.domain.unwrap import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController import com.tangem.feature.wallet.presentation.wallet.state.model.* import com.tangem.feature.wallet.presentation.wallet.state.transformers.CloseBottomSheetTransformer -import com.tangem.feature.wallet.presentation.wallet.state.transformers.DisableActionTransformer import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletEventSender import com.tangem.utils.coroutines.CoroutineDispatcherProvider import dagger.hilt.android.scopes.ViewModelScoped @@ -59,7 +58,6 @@ import kotlinx.coroutines.flow.take import kotlinx.coroutines.launch import java.math.BigDecimal import javax.inject.Inject -import kotlin.reflect.KClass interface WalletCurrencyActionsClickIntents { @@ -456,8 +454,6 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( val userCountry = getUserCountryUseCase().getOrNull() if (userCountry is UserCountry.Russia) { handleError( - userWalletId = userWalletId, - actionKClass = WalletManageButton.Sell::class, alertState = WalletAlertState.SellingRegionalRestriction, eventCreator = MainScreenAnalyticsEvent::ButtonSell, ) @@ -468,8 +464,6 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( val selectedWallet = stateHolder.getSelectedWallet().walletCardState as? WalletCardState.Content if (selectedWallet?.isZeroBalance == true) { handleError( - userWalletId = userWalletId, - actionKClass = WalletManageButton.Sell::class, alertState = WalletAlertState.InsufficientBalanceForSelling, eventCreator = MainScreenAnalyticsEvent::ButtonSell, ) @@ -478,10 +472,8 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( } onMultiWalletActionClick( - userWalletId = userWalletId, statusFlow = rampStateManager.getSellInitializationStatus(), route = AppRoute.SellCrypto(userWalletId = userWalletId), - actionKClass = WalletManageButton.Sell::class, eventCreator = MainScreenAnalyticsEvent::ButtonSell, ) } @@ -493,8 +485,6 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( if (tokenListState.items.count { it is TokensListItemUM.Token } < 2) { handleError( - userWalletId = userWalletId, - actionKClass = WalletManageButton.Swap::class, alertState = WalletAlertState.InsufficientTokensCountForSwapping, eventCreator = MainScreenAnalyticsEvent::ButtonSwap, ) @@ -503,20 +493,16 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( } onMultiWalletActionClick( - userWalletId = userWalletId, statusFlow = rampStateManager.getSwapInitializationStatus(userWalletId), route = AppRoute.SwapCrypto(userWalletId = userWalletId), - actionKClass = WalletManageButton.Swap::class, eventCreator = MainScreenAnalyticsEvent::ButtonSwap, ) } override fun onMultiWalletBuyClick(userWalletId: UserWalletId) { onMultiWalletActionClick( - userWalletId = userWalletId, statusFlow = rampStateManager.getBuyInitializationStatus(), route = AppRoute.BuyCrypto(userWalletId = userWalletId), - actionKClass = WalletManageButton.Buy::class, eventCreator = MainScreenAnalyticsEvent::ButtonBuy, ) } @@ -620,22 +606,14 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( } private fun onMultiWalletActionClick( - userWalletId: UserWalletId, statusFlow: Flow>, route: AppRoute, - actionKClass: KClass, eventCreator: (AnalyticsParam.Status) -> MainScreenAnalyticsEvent, ) { viewModelScope.launch { statusFlow.foldStatus( onContent = { handleContent(route, eventCreator) }, - onError = { - handleError( - userWalletId = userWalletId, - actionKClass = actionKClass, - eventCreator = eventCreator, - ) - }, + onError = { handleError(eventCreator = eventCreator) }, onLoading = { handleLoading(eventCreator) }, ) } @@ -662,17 +640,11 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor( } private fun handleError( - userWalletId: UserWalletId, - actionKClass: KClass, alertState: WalletAlertState = WalletAlertState.UnavailableOperation, eventCreator: (AnalyticsParam.Status) -> MainScreenAnalyticsEvent, ) { analyticsEventHandler.send(event = eventCreator(AnalyticsParam.Status.Error)) - stateHolder.update( - transformer = DisableActionTransformer(userWalletId = userWalletId, actionClass = actionKClass), - ) - walletEventSender.send(event = WalletEvent.ShowAlert(state = alertState)) }