Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-14 14:56:12 +02:00
commit 7547bb9e55
6 changed files with 64 additions and 42 deletions

View file

@ -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<CryptoCurrencyWarning?> {
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
}

View file

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

View file

@ -51,7 +51,7 @@ internal fun PushNotificationsScreen(
},
),
secondaryButton = ShowcaseButtonModel(
buttonText = resourceReference(R.string.common_cancel),
buttonText = resourceReference(R.string.common_later),
onClick = onNeverRequest,
),
modifier = Modifier.systemBarsPadding(),

View file

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

View file

@ -76,7 +76,7 @@ private fun PushNotificationsSheetContent(content: PushNotificationsBottomSheetC
),
) {
SecondaryButton(
text = stringResource(R.string.common_cancel),
text = stringResource(R.string.common_later),
onClick = {
content.onNeverRequest()
onDismiss()

View file

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