Updated on 2026-08-14
This commit is contained in:
parent
4b72ca5252
commit
8611aca9e0
8 changed files with 80 additions and 7 deletions
|
|
@ -13,6 +13,8 @@ import com.tangem.tap.domain.TangemSdkManager
|
|||
import com.tangem.tap.domain.tokens.UserTokensRepository
|
||||
import com.tangem.tap.domain.walletStores.WalletStoresManager
|
||||
import com.tangem.tap.features.wallet.redux.WalletState
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import org.rekotlin.Store
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -23,6 +25,15 @@ import javax.inject.Inject
|
|||
class AppStateHolder @Inject constructor() : WalletsStateHolder, NavigationStateHolder {
|
||||
|
||||
override var userWalletsListManager: UserWalletsListManager? = null
|
||||
set(value) {
|
||||
field = value
|
||||
_userWalletsListManagerFlow.value = value
|
||||
}
|
||||
|
||||
override val userWalletListManagerFlow: Flow<UserWalletsListManager?>
|
||||
get() = _userWalletsListManagerFlow
|
||||
|
||||
private val _userWalletsListManagerFlow = MutableStateFlow<UserWalletsListManager?>(null)
|
||||
|
||||
@Deprecated("Use scan response from selected user wallet")
|
||||
var scanResponse: ScanResponse? = null
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import dagger.Module
|
|||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.*
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
|
|
@ -58,8 +60,15 @@ class ProxyModule {
|
|||
@Singleton
|
||||
fun provideLear2earnDependencies(appStateHolder: AppStateHolder): Learn2earnDependencyProvider {
|
||||
return object : Learn2earnDependencyProvider {
|
||||
override fun getCardTypeResolver(): CardTypesResolver? {
|
||||
return appStateHolder.userWalletsListManager?.selectedUserWalletSync?.scanResponse?.cardTypesResolver
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
override fun getCardTypeResolverFlow(): Flow<CardTypesResolver?> {
|
||||
return appStateHolder.userWalletListManagerFlow
|
||||
.flatMapLatest { manager ->
|
||||
manager?.selectedUserWallet
|
||||
?.map { it.scanResponse.cardTypesResolver }
|
||||
?: flowOf(null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLocaleProvider(): () -> String = { Locale.current.language }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
package com.tangem.domain.wallets.legacy
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
interface WalletsStateHolder {
|
||||
|
||||
val userWalletsListManager: UserWalletsListManager?
|
||||
|
||||
val userWalletListManagerFlow: Flow<UserWalletsListManager?>
|
||||
}
|
||||
|
|
@ -16,6 +16,14 @@ import com.tangem.feature.learn2earn.domain.models.toDomainError
|
|||
import com.tangem.lib.crypto.DerivationManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.lib.crypto.models.Currency
|
||||
import com.tangem.utils.coroutines.AppCoroutineDispatcherProvider
|
||||
import com.tangem.utils.coroutines.FeatureCoroutineExceptionHandler
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -29,12 +37,19 @@ internal class DefaultLearn2earnInteractor(
|
|||
private val analytics: AnalyticsEventHandler,
|
||||
private val demoModeDatasource: DemoModeDatasource,
|
||||
private val dependencyProvider: Learn2earnDependencyProvider,
|
||||
dispatchers: AppCoroutineDispatcherProvider,
|
||||
) : Learn2earnInteractor {
|
||||
|
||||
override var webViewResultHandler: WebViewResultHandler? = null
|
||||
|
||||
private lateinit var promotion: Promotion
|
||||
|
||||
private val scope = CoroutineScope(Job() + dispatchers.io + FeatureCoroutineExceptionHandler.create("mainScope"))
|
||||
|
||||
private val isTangemWalletFlow = MutableStateFlow(false)
|
||||
private var isTangemWalletFlowJob: Job? = null
|
||||
private var isTangemWalletFlowSync = false
|
||||
|
||||
private val webViewUriBuilder: WebViewUriBuilder by lazy {
|
||||
WebViewUriBuilder(
|
||||
authCredentialsProvider = dependencyProvider.getWebViewAuthCredentialsProvider(),
|
||||
|
|
@ -51,6 +66,8 @@ internal class DefaultLearn2earnInteractor(
|
|||
initPromotionInfo()
|
||||
}
|
||||
|
||||
override fun getIsTangemWalletFlow(): Flow<Boolean> = isTangemWalletFlow
|
||||
|
||||
override fun isUserHadPromoCode(): Boolean {
|
||||
return repository.getUserData().promoCode != null
|
||||
}
|
||||
|
|
@ -223,6 +240,8 @@ internal class DefaultLearn2earnInteractor(
|
|||
}
|
||||
|
||||
override fun isPromotionActive(): Boolean {
|
||||
subscribeToCardTypeResolverFlow()
|
||||
|
||||
val isActive = when {
|
||||
demoModeDatasource.isDemoModeActive -> false
|
||||
!featureToggleManager.isLearn2earnEnabled -> false
|
||||
|
|
@ -242,11 +261,9 @@ internal class DefaultLearn2earnInteractor(
|
|||
}
|
||||
|
||||
override fun isPromotionActiveOnMain(): Boolean {
|
||||
val cardTypesResolver = dependencyProvider.getCardTypeResolver() ?: return false
|
||||
|
||||
return when {
|
||||
!isPromotionActive() -> false
|
||||
!cardTypesResolver.isTangemWallet() -> false
|
||||
!isTangemWalletFlowSync -> false
|
||||
else -> promotion.getPromotionInfo().oldCard.status == PromotionInfoResponse.Status.ACTIVE
|
||||
}
|
||||
}
|
||||
|
|
@ -308,6 +325,17 @@ internal class DefaultLearn2earnInteractor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun subscribeToCardTypeResolverFlow() {
|
||||
if (isTangemWalletFlowJob == null || isTangemWalletFlowJob?.isCancelled == true) {
|
||||
isTangemWalletFlowJob = dependencyProvider.getCardTypeResolverFlow()
|
||||
.onEach {
|
||||
isTangemWalletFlowSync = it?.isTangemWallet() ?: false
|
||||
isTangemWalletFlow.emit(isTangemWalletFlowSync)
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Promotion.PromotionInfo.getData(promoCode: String?): PromotionInfoResponse.Data {
|
||||
return if (promoCode == null) {
|
||||
oldCard
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.feature.learn2earn.domain.api
|
||||
|
||||
import com.tangem.domain.common.CardTypesResolver
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
* Interface, a wrapper that allows us to get values from the AppStateHolder located in the app module
|
||||
|
|
@ -9,7 +10,7 @@ import com.tangem.domain.common.CardTypesResolver
|
|||
*/
|
||||
interface Learn2earnDependencyProvider {
|
||||
|
||||
fun getCardTypeResolver(): CardTypesResolver?
|
||||
fun getCardTypeResolverFlow(): Flow<CardTypesResolver?>
|
||||
|
||||
fun getLocaleProvider(): () -> String
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tangem.feature.learn2earn.domain.api
|
|||
|
||||
import android.net.Uri
|
||||
import com.tangem.feature.learn2earn.domain.models.PromotionError
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -12,6 +13,8 @@ interface Learn2earnInteractor : WebViewRedirectHandler {
|
|||
|
||||
suspend fun init()
|
||||
|
||||
fun getIsTangemWalletFlow(): Flow<Boolean>
|
||||
|
||||
fun isUserHadPromoCode(): Boolean
|
||||
|
||||
fun isPromotionActive(): Boolean
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import com.tangem.feature.learn2earn.domain.api.WebViewRedirectHandler
|
|||
import com.tangem.feature.learn2earn.presentation.Learn2earnRouter
|
||||
import com.tangem.lib.crypto.DerivationManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.utils.coroutines.AppCoroutineDispatcherProvider
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
|
|
@ -47,6 +48,7 @@ internal class Learn2earnDomainModule {
|
|||
analyticsEventHandler: AnalyticsEventHandler,
|
||||
derivationManager: DerivationManager,
|
||||
demoModeDatasource: DemoModeDatasource,
|
||||
dispatchers: AppCoroutineDispatcherProvider,
|
||||
): Learn2earnInteractor {
|
||||
return DefaultLearn2earnInteractor(
|
||||
featureToggleManager = featureToggleManager,
|
||||
|
|
@ -56,6 +58,7 @@ internal class Learn2earnDomainModule {
|
|||
analytics = analyticsEventHandler,
|
||||
demoModeDatasource = demoModeDatasource,
|
||||
dependencyProvider = dependencyProvider,
|
||||
dispatchers = dispatchers,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,11 +44,25 @@ class Learn2earnViewModel @Inject constructor(
|
|||
private set
|
||||
|
||||
init {
|
||||
subscribeToWalletChanges()
|
||||
uiState = uiState
|
||||
.updateStoriesVisibility(isVisible = interactor.isPromotionActiveOnStories())
|
||||
.updateGetBonusVisibility(isVisible = interactor.isPromotionActiveOnMain())
|
||||
}
|
||||
|
||||
private fun subscribeToWalletChanges() {
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
interactor.getIsTangemWalletFlow()
|
||||
.collect { isTangemWallet ->
|
||||
updateUi {
|
||||
uiState
|
||||
.updateGetBonusVisibility(isVisible = isTangemWallet)
|
||||
.changeGetBounsDescription(getBonusDescription())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onMainScreenCreated() {
|
||||
updateMainScreenViews()
|
||||
}
|
||||
|
|
@ -137,7 +151,7 @@ class Learn2earnViewModel @Inject constructor(
|
|||
onSuccess = {
|
||||
analytics.send(Learn2earnEvents.MainScreen.NoticeClaimSuccess())
|
||||
val onHideDialog = {
|
||||
uiState = uiState.updateGetBonusVisibility(isVisible = false)
|
||||
uiState = uiState.updateViewsVisibility(isVisible = false)
|
||||
.hideDialog()
|
||||
}
|
||||
val successDialog = MainScreenState.Dialog.Claimed(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue