Updated on 2026-08-14

This commit is contained in:
Tangem 2024-12-12 16:48:30 +04:00
parent ed6970db05
commit 207fe02586
15 changed files with 433 additions and 253 deletions

View file

@ -1,52 +0,0 @@
package com.tangem.feature.wallet.presentation.wallet.subscribers
import com.tangem.domain.core.lce.Lce
import com.tangem.domain.exchange.RampStateManager
import com.tangem.domain.wallets.models.UserWallet
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
import com.tangem.feature.wallet.presentation.wallet.state.transformers.UpdateMultiWalletActionsTransformer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.onEach
/**
* Multi-currency wallet subscriber for actions state updating
*
* @property userWallet user wallet
* @property rampStateManager ramp state manager
* @property stateController state controller
*
[REDACTED_AUTHOR]
*/
internal class MultiWalletActionsSubscriber(
private val userWallet: UserWallet,
private val rampStateManager: RampStateManager,
private val stateController: WalletStateController,
) : WalletSubscriber() {
override fun create(coroutineScope: CoroutineScope): Flow<*> {
return combine(
flow = rampStateManager.getBuyInitializationStatus(),
flow2 = rampStateManager.getSellInitializationStatus(),
flow3 = rampStateManager.getSwapInitializationStatus(userWalletId = userWallet.walletId),
transform = ::RampStatuses,
)
.onEach { statuses ->
stateController.update(
UpdateMultiWalletActionsTransformer(
userWalletId = userWallet.walletId,
buyStatus = statuses.buy,
sellStatus = statuses.sell,
swapStatus = statuses.swap,
),
)
}
}
private data class RampStatuses(
val buy: Lce<Throwable, Any>,
val sell: Lce<Throwable, Any>,
val swap: Lce<Throwable, Any>,
)
}

View file

@ -18,6 +18,7 @@ import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState
import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetRefreshStateTransformer
import com.tangem.feature.wallet.presentation.wallet.state.transformers.SetTokenListErrorTransformer
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.CoroutineScope
@ -46,6 +47,7 @@ internal class WalletClickIntents @Inject constructor(
private val neverToShowWalletsScrollPreview: NeverToShowWalletsScrollPreview,
private val rampStateManager: RampStateManager,
private val dispatchers: CoroutineDispatcherProvider,
private val onrampFeatureToggles: OnrampFeatureToggles,
) : BaseWalletClickIntents(),
WalletCardClickIntents by walletCardClickIntentsImplementor,
WalletWarningsClickIntents by warningsClickIntentsImplementer,
@ -120,10 +122,13 @@ internal class WalletClickIntents @Inject constructor(
fetchTokenListUseCase(userWalletId = userWallet.walletId, mode = RefreshMode.FULL)
}
listOf(
async { rampStateManager.fetchBuyServiceData() },
async { rampStateManager.fetchSellServiceData() },
)
buildList {
if (!onrampFeatureToggles.isFeatureEnabled) {
async { rampStateManager.fetchBuyServiceData() }.let(::add)
}
async { rampStateManager.fetchSellServiceData() }.let(::add)
}
.awaitAll()
maybeFetchResult.onLeft {

View file

@ -48,6 +48,7 @@ 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.utils.WalletEventSender
import com.tangem.features.onramp.OnrampFeatureToggles
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.collections.immutable.toImmutableList
@ -119,6 +120,7 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
private val appRouter: AppRouter,
private val rampStateManager: RampStateManager,
private val getUserCountryUseCase: GetUserCountryUseCase,
private val onrampFeatureToggles: OnrampFeatureToggles,
) : BaseWalletClickIntents(), WalletCurrencyActionsClickIntents {
override fun onSendClick(
@ -493,7 +495,7 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
}
onMultiWalletActionClick(
statusFlow = rampStateManager.getSwapInitializationStatus(userWalletId),
statusFlow = rampStateManager.getExpressInitializationStatus(userWalletId),
route = AppRoute.SwapCrypto(userWalletId = userWalletId),
eventCreator = MainScreenAnalyticsEvent::ButtonSwap,
)
@ -501,7 +503,11 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
override fun onMultiWalletBuyClick(userWalletId: UserWalletId) {
onMultiWalletActionClick(
statusFlow = rampStateManager.getBuyInitializationStatus(),
statusFlow = if (onrampFeatureToggles.isFeatureEnabled) {
rampStateManager.getExpressInitializationStatus(userWalletId)
} else {
rampStateManager.getBuyInitializationStatus()
},
route = AppRoute.BuyCrypto(userWalletId = userWalletId),
eventCreator = MainScreenAnalyticsEvent::ButtonBuy,
)