Updated on 2026-08-14
This commit is contained in:
parent
0c56df0075
commit
535bb9b8c3
44 changed files with 128 additions and 1038 deletions
|
|
@ -1,11 +0,0 @@
|
|||
package com.tangem.features.onramp
|
||||
|
||||
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
|
||||
|
||||
internal class DefaultOnrampFeatureToggles(
|
||||
private val featureTogglesManager: FeatureTogglesManager,
|
||||
) : OnrampFeatureToggles {
|
||||
|
||||
override val isFeatureEnabled: Boolean
|
||||
get() = featureTogglesManager.isFeatureEnabled(name = "ONRAMP_ENABLED")
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
package com.tangem.features.onramp
|
||||
|
||||
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
internal object OnrampFeatureModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideFeatureToggles(featureTogglesManager: FeatureTogglesManager): OnrampFeatureToggles {
|
||||
return DefaultOnrampFeatureToggles(featureTogglesManager)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
package com.tangem.features.onramp.deeplink
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.domain.tokens.GetCryptoCurrencyUseCase
|
||||
import com.tangem.domain.tokens.model.analytics.TokenScreenAnalyticsEvent
|
||||
import com.tangem.domain.wallets.models.isMultiCurrency
|
||||
import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase
|
||||
import com.tangem.features.onramp.OnrampFeatureToggles
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
import dagger.assisted.AssistedInject
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultBuyRedirectDeepLinkHandler @AssistedInject constructor(
|
||||
@Assisted scope: CoroutineScope,
|
||||
onrampFeatureToggles: OnrampFeatureToggles,
|
||||
getSelectedWalletSyncUseCase: GetSelectedWalletSyncUseCase,
|
||||
getCryptoCurrencyUseCase: GetCryptoCurrencyUseCase,
|
||||
analyticsEventHandler: AnalyticsEventHandler,
|
||||
) : BuyRedirectDeepLinkHandler {
|
||||
|
||||
init {
|
||||
// It is okay here, we are navigating from outside, and there is no other way to getting UserWallet
|
||||
getSelectedWalletSyncUseCase().fold(
|
||||
ifLeft = {
|
||||
Timber.e("Error on getting user wallet: $it")
|
||||
},
|
||||
ifRight = { userWallet ->
|
||||
if (!onrampFeatureToggles.isFeatureEnabled && !userWallet.isMultiCurrency) {
|
||||
scope.launch {
|
||||
val cryptoCurrency = getCryptoCurrencyUseCase(userWallet.walletId).getOrElse {
|
||||
Timber.e("Error on getting cryptoCurrency: $it")
|
||||
return@launch
|
||||
}
|
||||
analyticsEventHandler.send(TokenScreenAnalyticsEvent.Bought(cryptoCurrency.symbol))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory : BuyRedirectDeepLinkHandler.Factory {
|
||||
override fun create(coroutineScope: CoroutineScope): DefaultBuyRedirectDeepLinkHandler
|
||||
}
|
||||
}
|
||||
|
|
@ -19,12 +19,6 @@ internal interface OnrampDeeplinkModule {
|
|||
@Singleton
|
||||
fun bindOnrampDeepLinkHandlerFactory(impl: DefaultOnrampDeepLinkHandler.Factory): OnrampDeepLinkHandler.Factory
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindBuyRedirectDeepLinkHandler(
|
||||
impl: DefaultBuyRedirectDeepLinkHandler.Factory,
|
||||
): BuyRedirectDeepLinkHandler.Factory
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
fun bindBuyDeepLinkHandler(impl: DefaultBuyDeepLinkHandler.Factory): BuyDeepLinkHandler.Factory
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.features.onramp.selecttoken.model
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.common.routing.AppRouter
|
||||
import com.tangem.common.ui.alerts.models.AlertDemoModeUM
|
||||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
|
|
@ -23,7 +24,6 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
|||
import com.tangem.domain.tokens.model.ScenarioUnavailabilityReason
|
||||
import com.tangem.domain.wallets.models.requireColdWallet
|
||||
import com.tangem.domain.wallets.usecase.GetWalletsUseCase
|
||||
import com.tangem.features.onramp.OnrampFeatureToggles
|
||||
import com.tangem.features.onramp.impl.R
|
||||
import com.tangem.features.onramp.selecttoken.OnrampOperationComponent.Params
|
||||
import com.tangem.features.onramp.selecttoken.entity.OnrampOperationUM
|
||||
|
|
@ -46,7 +46,6 @@ internal class OnrampOperationModel @Inject constructor(
|
|||
private val reduxStateHolder: ReduxStateHolder,
|
||||
private val isDemoCardUseCase: IsDemoCardUseCase,
|
||||
private val messageSender: UiMessageSender,
|
||||
private val onrampFeatureToggles: OnrampFeatureToggles,
|
||||
private val rampStateManager: RampStateManager,
|
||||
) : Model() {
|
||||
|
||||
|
|
@ -100,7 +99,7 @@ internal class OnrampOperationModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun selectTokenIfDemoModeOff(status: CryptoCurrencyStatus) {
|
||||
if (params is Params.Sell || !onrampFeatureToggles.isFeatureEnabled) {
|
||||
if (params is Params.Sell) {
|
||||
showErrorIfDemoModeOrElse { selectToken(status) }
|
||||
} else {
|
||||
selectToken(status)
|
||||
|
|
@ -109,14 +108,25 @@ internal class OnrampOperationModel @Inject constructor(
|
|||
|
||||
private fun selectToken(status: CryptoCurrencyStatus) {
|
||||
modelScope.launch {
|
||||
val appCurrencyCode = getSelectedAppCurrencyUseCase.invokeSync().getOrElse { AppCurrency.Default }.code
|
||||
when (params) {
|
||||
is Params.Buy -> {
|
||||
router.push(
|
||||
AppRoute.Onramp(
|
||||
userWalletId = selectedUserWallet.walletId,
|
||||
currency = status.currency,
|
||||
source = OnrampSource.ACTION_BUTTONS,
|
||||
),
|
||||
)
|
||||
}
|
||||
is Params.Sell -> {
|
||||
val appCurrencyCode = getSelectedAppCurrencyUseCase.invokeSync()
|
||||
.getOrElse { AppCurrency.Default }.code
|
||||
|
||||
reduxStateHolder.dispatch(
|
||||
action = when (params) {
|
||||
is Params.Buy -> getBuyAction(status, appCurrencyCode)
|
||||
is Params.Sell -> TradeCryptoAction.Sell(status, appCurrencyCode)
|
||||
},
|
||||
)
|
||||
reduxStateHolder.dispatch(
|
||||
action = TradeCryptoAction.Sell(status, appCurrencyCode),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -144,15 +154,6 @@ internal class OnrampOperationModel @Inject constructor(
|
|||
router.pop()
|
||||
}
|
||||
|
||||
private fun getBuyAction(status: CryptoCurrencyStatus, appCurrencyCode: String): TradeCryptoAction {
|
||||
return TradeCryptoAction.Buy(
|
||||
userWallet = selectedUserWallet,
|
||||
cryptoCurrencyStatus = status,
|
||||
source = OnrampSource.ACTION_BUTTONS,
|
||||
appCurrencyCode = appCurrencyCode,
|
||||
)
|
||||
}
|
||||
|
||||
private fun showErrorIfDemoModeOrElse(action: () -> Unit) {
|
||||
if (isDemoCardUseCase(cardId = selectedUserWallet.cardId)) {
|
||||
val alertUM = AlertDemoModeUM(onConfirmClick = {})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue