From d7cec0764ed51d45a46d08a8d5b08210b6ba9a9c Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 12 Aug 2024 16:50:29 +0300 Subject: [PATCH 1/2] Updated on 2026-08-14 --- .../api/analytics/PushNotificationAnalyticEvents.kt | 9 +++++++++ .../presentation/viewmodel/PushNotificationViewModel.kt | 2 +- .../intents/WalletPushPermissionClickIntents.kt | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt index ae6f90b7a1..fecdc9bb3d 100644 --- a/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt +++ b/features/push-notifications/api/src/main/java/com/tangem/features/pushnotifications/api/analytics/PushNotificationAnalyticEvents.kt @@ -26,6 +26,15 @@ sealed class PushNotificationAnalyticEvents( ), ) + data class ButtonLater( + val source: AnalyticsParam.ScreensSources, + ) : PushNotificationAnalyticEvents( + event = "Button - Later", + params = mapOf( + AnalyticsParam.SOURCE to source.value, + ), + ) + data class PermissionStatus( val isAllowed: Boolean, ) : PushNotificationAnalyticEvents( diff --git a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt index 5b62923bbb..b760936b5b 100644 --- a/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt +++ b/features/push-notifications/impl/src/main/java/com/tangem/features/pushnotifications/impl/presentation/viewmodel/PushNotificationViewModel.kt @@ -30,7 +30,7 @@ internal class PushNotificationViewModel @Inject constructor( override fun onNeverRequest() { analyticHandler.send( - PushNotificationAnalyticEvents.ButtonCancel(AnalyticsParam.ScreensSources.Stories), + PushNotificationAnalyticEvents.ButtonLater(AnalyticsParam.ScreensSources.Stories), ) viewModelScope.launch { neverRequestPermissionUseCase(PUSH_PERMISSION) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt index 6043a409aa..98560342e5 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/intents/WalletPushPermissionClickIntents.kt @@ -38,7 +38,7 @@ internal class WalletPushPermissionClickIntentsImplementor @Inject constructor( if (isUserDismissedDialog != isUserDismissed) return viewModelScope.launch { analyticsEventHandler.send( - PushNotificationAnalyticEvents.ButtonCancel(AnalyticsParam.ScreensSources.Main), + PushNotificationAnalyticEvents.ButtonLater(AnalyticsParam.ScreensSources.Main), ) neverRequestPermissionUseCase(PUSH_PERMISSION) } From 2a175de4e14ba79daf72896fcf4bfb40dbe7ff0e Mon Sep 17 00:00:00 2001 From: Tangem Date: Tue, 13 Aug 2024 12:12:43 +0300 Subject: [PATCH 2/2] Updated on 2026-08-14 --- .../tokens/GetCurrencyWarningsUseCase.kt | 89 +++++++++++-------- 1 file changed, 51 insertions(+), 38 deletions(-) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt index c4e96be175..03c0debc06 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetCurrencyWarningsUseCase.kt @@ -14,6 +14,7 @@ import com.tangem.feature.swap.domain.api.SwapRepository import com.tangem.feature.swap.domain.models.domain.LeastTokenInfo import com.tangem.lib.crypto.BlockchainUtils import com.tangem.utils.coroutines.CoroutineDispatcherProvider +import com.tangem.utils.coroutines.runCatching import com.tangem.utils.isNullOrZero import kotlinx.coroutines.flow.* import java.math.BigDecimal @@ -85,49 +86,61 @@ class GetCurrencyWarningsUseCase( currencyStatus: CryptoCurrencyStatus, ): Flow { val currency = currencyStatus.currency - val cryptoCurrencyStatuses = operations.getCurrenciesStatusesSync().getOrNull() ?: emptyList() + val cryptoStatuses = operations.getCurrenciesStatusesSync() val promoBanner = promoRepository.getOkxPromoBanner() - val pairs = swapRepository.getPairsOnly( - LeastTokenInfo( - contractAddress = (currency as? CryptoCurrency.Token)?.contractAddress ?: "0", - network = currency.network.backendId, - ), - cryptoCurrencyStatuses.map { it.currency }, - ).pairs return combine( - showSwapPromoTokenUseCase().conflate(), - flowOf(marketCryptoCurrencyRepository.isExchangeable(userWalletId, currency)).conflate(), + showSwapPromoTokenUseCase() + .conflate() + .distinctUntilChanged(), + flowOf(marketCryptoCurrencyRepository.isExchangeable(userWalletId, currency)) + .conflate() + .distinctUntilChanged(), ) { shouldShowSwapPromo, isExchangeable -> promoBanner ?: return@combine null - val showPromoBannerActive = promoBanner.isActive && shouldShowSwapPromo - if (showPromoBannerActive && isExchangeable && currencyStatus.value !is CryptoCurrencyStatus.Unreachable) { - val filteredCurrencies = cryptoCurrencyStatuses.filterNot { - it.currency.id == currency.id - } - val currencyPairs = pairs.filter { - it.from.network == currency.network.backendId || - it.to.network == currency.network.backendId - } - val showPromoForPair = currencyPairs.any { pair -> - val availablePair = if (currencyStatus.value.amount.isNullOrZero()) { - filteredCurrencies.filterNot { it.value.amount.isNullOrZero() } - } else { - filteredCurrencies - } - availablePair - .any { - it.currency.network.backendId == pair.to.network || - it.currency.network.backendId == pair.from.network + val showPromoBanner = promoBanner.isActive && shouldShowSwapPromo + if (showPromoBanner && isExchangeable && currencyStatus.value !is CryptoCurrencyStatus.Unreachable) { + cryptoStatuses.fold( + ifLeft = { null }, + ifRight = { cryptoCurrencyStatuses -> + val pairs = runCatching(dispatchers.io) { + swapRepository.getPairsOnly( + LeastTokenInfo( + contractAddress = (currency as? CryptoCurrency.Token)?.contractAddress ?: "0", + network = currency.network.backendId, + ), + cryptoCurrencyStatuses.map { it.currency }, + ) + }.getOrNull()?.pairs ?: emptyList() + + val filteredCurrencies = cryptoCurrencyStatuses.filterNot { + it.currency.id == currency.id } - } - if (showPromoForPair) { - CryptoCurrencyWarning.SwapPromo( - startDateTime = promoBanner.bannerState.timeline.start, - endDateTime = promoBanner.bannerState.timeline.end, - ) - } else { - null - } + val currencyPairs = pairs.filter { + it.from.network == currency.network.backendId || + it.to.network == currency.network.backendId + } + val showPromo = currencyPairs.any { pair -> + val availablePair = if (currencyStatus.value.amount.isNullOrZero()) { + filteredCurrencies.filterNot { it.value.amount.isNullOrZero() } + } else { + filteredCurrencies + } + availablePair + .any { + it.currency.network.backendId == pair.to.network || + it.currency.network.backendId == pair.from.network + } + } + if (showPromo) { + CryptoCurrencyWarning.SwapPromo( + startDateTime = promoBanner.bannerState.timeline.start, + endDateTime = promoBanner.bannerState.timeline.end, + ) + } else { + null + } + }, + ) } else { null }