From 8459eb743b50563b9d075d6dd7390f7e73bf2c0a Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 26 Feb 2025 15:43:23 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/tap/features/main/MainViewModel.kt | 32 +++++++++++++------ .../data/promo/DefaultPromoRepository.kt | 6 ++-- .../domain/promo/GetStoryContentUseCase.kt | 4 +-- .../tangem/domain/promo/PromoRepository.kt | 2 +- .../stories/impl/analytics/StoriesEvents.kt | 11 ------- .../stories/impl/model/StoriesModel.kt | 12 ------- .../feature/swap/analytics/StoriesEvents.kt | 2 -- .../tangem/feature/swap/model/SwapModel.kt | 15 +-------- 8 files changed, 30 insertions(+), 54 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt b/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt index a21fee2f05..143a8d92a4 100644 --- a/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt +++ b/app/src/main/java/com/tangem/tap/features/main/MainViewModel.kt @@ -29,6 +29,7 @@ import com.tangem.domain.settings.IncrementAppLaunchCounterUseCase import com.tangem.domain.settings.usercountry.FetchUserCountryUseCase import com.tangem.domain.staking.FetchStakingTokensUseCase import com.tangem.domain.wallets.legacy.UserWalletsListManager +import com.tangem.feature.swap.analytics.StoriesEvents import com.tangem.features.onramp.OnrampFeatureToggles import com.tangem.features.swap.SwapFeatureToggles import com.tangem.tap.common.extensions.setContext @@ -300,19 +301,32 @@ internal class MainViewModel @Inject constructor( private fun preloadImages() { try { viewModelScope.launch { - val swapStories = if (swapFeatureToggles.isPromoStoriesEnabled) { - getStoryContentUseCase.invokeSync(StoryContentIds.STORY_FIRST_TIME_SWAP.id) - .getOrNull() - } else { - null - } + if (swapFeatureToggles.isPromoStoriesEnabled) { + val swapStories = getStoryContentUseCase.invokeSync( + id = StoryContentIds.STORY_FIRST_TIME_SWAP.id, + refresh = true, + ).getOrNull() - val storiesImages = swapStories?.getImageUrls() - // try to preload images for stories - storiesImages?.forEach(imagePreloader::preload) + if (swapStories == null) { + analyticsEventHandler.send( + StoriesEvents.Error( + type = StoryContentIds.STORY_FIRST_TIME_SWAP.analyticType, + ), + ) + } else { + val storiesImages = swapStories.getImageUrls() + // try to preload images for stories + storiesImages.forEach(imagePreloader::preload) + } + } } } catch (ex: Exception) { Timber.e(ex.message) + analyticsEventHandler.send( + StoriesEvents.Error( + type = StoryContentIds.STORY_FIRST_TIME_SWAP.analyticType, + ), + ) } } } \ No newline at end of file diff --git a/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt b/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt index 1e0f94e8f0..5b14b75e9a 100644 --- a/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt +++ b/data/promo/src/main/java/com/tangem/data/promo/DefaultPromoRepository.kt @@ -44,15 +44,15 @@ internal class DefaultPromoRepository( } override fun getStoryById(id: String): Flow = isReadyToShowStories(id).mapLatest { - getStoryByIdSync(id) + getStoryByIdSync(id = id, refresh = false) } - override suspend fun getStoryByIdSync(id: String): StoryContent? = withContext(dispatchers.io) { + override suspend fun getStoryByIdSync(id: String, refresh: Boolean): StoryContent? = withContext(dispatchers.io) { if (!isReadyToShowStoriesSync(id)) return@withContext null val storedPromo = promoStoriesStore.getSyncOrNull(storyId = id) // Get last stored promo by id if possible or get from network - val story = if (storedPromo == null) { + val story = if (storedPromo == null && refresh) { val storyContent = runCatching { // Important to return withTimeoutOrNull(STORIES_LOAD_DELAY) { diff --git a/domain/promo/src/main/java/com/tangem/domain/promo/GetStoryContentUseCase.kt b/domain/promo/src/main/java/com/tangem/domain/promo/GetStoryContentUseCase.kt index 1964bb9b6e..786f1e9552 100644 --- a/domain/promo/src/main/java/com/tangem/domain/promo/GetStoryContentUseCase.kt +++ b/domain/promo/src/main/java/com/tangem/domain/promo/GetStoryContentUseCase.kt @@ -18,7 +18,7 @@ class GetStoryContentUseCase( .catch { emit(it.left()) } .onEmpty { emit(null.right()) } - suspend fun invokeSync(id: String): Either = Either.catch { - promoRepository.getStoryByIdSync(id) + suspend fun invokeSync(id: String, refresh: Boolean = false): Either = Either.catch { + promoRepository.getStoryByIdSync(id, refresh) } } \ No newline at end of file diff --git a/domain/promo/src/main/java/com/tangem/domain/promo/PromoRepository.kt b/domain/promo/src/main/java/com/tangem/domain/promo/PromoRepository.kt index d785801863..4db7b9bf87 100644 --- a/domain/promo/src/main/java/com/tangem/domain/promo/PromoRepository.kt +++ b/domain/promo/src/main/java/com/tangem/domain/promo/PromoRepository.kt @@ -18,7 +18,7 @@ interface PromoRepository { // region Stories fun getStoryById(id: String): Flow - suspend fun getStoryByIdSync(id: String): StoryContent? + suspend fun getStoryByIdSync(id: String, refresh: Boolean): StoryContent? fun isReadyToShowStories(storyId: String): Flow diff --git a/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/analytics/StoriesEvents.kt b/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/analytics/StoriesEvents.kt index bfab83d626..54644cf01f 100644 --- a/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/analytics/StoriesEvents.kt +++ b/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/analytics/StoriesEvents.kt @@ -19,15 +19,4 @@ sealed class StoriesEvents( WATCHED to watchCount, ), ) - - data class Error( - val source: String, - val type: String, - ) : StoriesEvents( - event = "Error", - params = mapOf( - AnalyticsParam.SOURCE to source, - AnalyticsParam.TYPE to type, - ), - ) } \ No newline at end of file diff --git a/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/model/StoriesModel.kt b/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/model/StoriesModel.kt index c47bd9c1b6..1d3c2f06b6 100644 --- a/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/model/StoriesModel.kt +++ b/features/stories/impl/src/main/java/com/tangem/feature/stories/impl/model/StoriesModel.kt @@ -53,22 +53,10 @@ internal class StoriesModel @Inject constructor( getStoryContentUseCase.invokeSync(params.storyId).fold( ifLeft = { Timber.e("Unable to load stories for ${StoryContentIds.STORY_FIRST_TIME_SWAP.id}") - analyticsEventHandler.send( - StoriesEvents.Error( - source = params.screenSource, - type = StoryContentIds.STORY_FIRST_TIME_SWAP.analyticType, - ), - ) openScreen(hideStories = false) // Fallback to target screen }, ifRight = { swapStory -> if (swapStory == null) { - analyticsEventHandler.send( - StoriesEvents.Error( - source = params.screenSource, - type = StoryContentIds.STORY_FIRST_TIME_SWAP.analyticType, - ), - ) openScreen(hideStories = false) // Fallback to target screen } else { _state.update { diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/StoriesEvents.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/StoriesEvents.kt index 6123fa2876..b7f89e9288 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/StoriesEvents.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/analytics/StoriesEvents.kt @@ -21,12 +21,10 @@ sealed class StoriesEvents( ) data class Error( - val source: String, val type: String, ) : StoriesEvents( event = "Error", params = mapOf( - AnalyticsParam.SOURCE to source, AnalyticsParam.TYPE to type, ), ) diff --git a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt index 1207f32248..f5a23e89f8 100644 --- a/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt +++ b/features/swap/impl/src/main/java/com/tangem/feature/swap/model/SwapModel.kt @@ -82,7 +82,6 @@ internal class SwapModel @Inject constructor( override val dispatchers: CoroutineDispatcherProvider, private val blockchainInteractor: BlockchainInteractor, private val analyticsEventHandler: AnalyticsEventHandler, - private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, private val getSelectedAppCurrencyUseCase: GetSelectedAppCurrencyUseCase, private val getCryptoCurrencyStatusUseCase: GetCryptoCurrencyStatusSyncUseCase, private val updateDelayedCurrencyStatusUseCase: UpdateDelayedNetworkStatusUseCase, @@ -96,6 +95,7 @@ internal class SwapModel @Inject constructor( private val shouldShowStoriesUseCase: ShouldShowStoriesUseCase, private val getStoryContentUseCase: GetStoryContentUseCase, private val featureToggles: SwapFeatureToggles, + getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase, swapInteractorFactory: SwapInteractor.Factory, private val urlOpener: UrlOpener, router: AppRouter, @@ -278,23 +278,10 @@ internal class SwapModel @Inject constructor( getStoryContentUseCase.invokeSync(StoryContentIds.STORY_FIRST_TIME_SWAP.id).fold( ifLeft = { Timber.e("Unable to load stories for ${StoryContentIds.STORY_FIRST_TIME_SWAP.id}") - analyticsEventHandler.send( - StoriesEvents.Error( - source = params.screenSource, - type = StoryContentIds.STORY_FIRST_TIME_SWAP.analyticType, - ), - ) }, ifRight = { story -> if (story != null) { uiState = stateBuilder.createStoriesState(uiState, story) - } else { - analyticsEventHandler.send( - StoriesEvents.Error( - source = params.screenSource, - type = StoryContentIds.STORY_FIRST_TIME_SWAP.analyticType, - ), - ) } }, )