Updated on 2026-08-14
This commit is contained in:
parent
0f1a926cc4
commit
5421e5eb69
3 changed files with 44 additions and 0 deletions
|
|
@ -3,6 +3,8 @@ package com.tangem.features.onramp.alloffers.model
|
|||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.model.ParamsContainer
|
||||
import com.tangem.core.decompose.ui.UiMessageSender
|
||||
import com.tangem.domain.demo.IsDemoCardUseCase
|
||||
import com.tangem.domain.onramp.GetOnrampAllOffersUseCase
|
||||
import com.tangem.domain.onramp.analytics.OnrampAnalyticsEvent
|
||||
import com.tangem.domain.onramp.model.OnrampProviderWithQuote
|
||||
|
|
@ -13,6 +15,7 @@ import com.tangem.features.onramp.alloffers.entity.AllOffersPaymentMethodUM
|
|||
import com.tangem.features.onramp.alloffers.entity.AllOffersStateFactory
|
||||
import com.tangem.features.onramp.alloffers.entity.AllOffersStateUM
|
||||
import com.tangem.features.onramp.main.entity.OnrampOfferAdvantagesUM
|
||||
import com.tangem.features.onramp.utils.showDemoModeWarningIfNeeded
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.Job
|
||||
|
|
@ -24,10 +27,13 @@ import kotlinx.coroutines.launch
|
|||
import com.tangem.utils.logging.TangemLogger
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
internal class AllOffersModel @Inject constructor(
|
||||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
private val analyticsEventHandler: AnalyticsEventHandler,
|
||||
private val getOnrampAllOffersUseCase: GetOnrampAllOffersUseCase,
|
||||
private val isDemoCardUseCase: IsDemoCardUseCase,
|
||||
private val messageSender: UiMessageSender,
|
||||
paramsContainer: ParamsContainer,
|
||||
) : Model(), AllOffersIntents {
|
||||
|
||||
|
|
@ -92,6 +98,8 @@ internal class AllOffersModel @Inject constructor(
|
|||
analyticsEventHandler.send(event)
|
||||
}
|
||||
|
||||
if (messageSender.showDemoModeWarningIfNeeded(params.userWallet, isDemoCardUseCase)) return
|
||||
|
||||
dismiss()
|
||||
params.openRedirectPage(quote)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ import com.tangem.core.analytics.api.AnalyticsEventHandler
|
|||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.model.ParamsContainer
|
||||
import com.tangem.core.decompose.navigation.Router
|
||||
import com.tangem.core.decompose.ui.UiMessageSender
|
||||
import com.tangem.core.ui.components.fields.InputManager
|
||||
import com.tangem.domain.demo.IsDemoCardUseCase
|
||||
import com.tangem.domain.onramp.*
|
||||
import com.tangem.domain.onramp.analytics.OnrampAnalyticsEvent
|
||||
import com.tangem.domain.onramp.model.OnrampAvailability
|
||||
|
|
@ -21,6 +23,7 @@ import com.tangem.features.onramp.main.entity.factory.OnrampAmountStateFactory
|
|||
import com.tangem.features.onramp.main.entity.factory.OnrampOffersStateFactory
|
||||
import com.tangem.features.onramp.main.entity.factory.OnrampStateFactory
|
||||
import com.tangem.features.onramp.utils.sendOnrampErrorEvent
|
||||
import com.tangem.features.onramp.utils.showDemoModeWarningIfNeeded
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import com.tangem.utils.coroutines.PeriodicTask
|
||||
|
|
@ -45,6 +48,8 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
private val fetchPairsUseCase: OnrampFetchPairsUseCase,
|
||||
private val amountInputManager: InputManager,
|
||||
private val getOnrampOffersUseCase: GetOnrampOffersUseCase,
|
||||
private val isDemoCardUseCase: IsDemoCardUseCase,
|
||||
private val messageSender: UiMessageSender,
|
||||
paramsContainer: ParamsContainer,
|
||||
getWalletsUseCase: GetWalletsUseCase,
|
||||
) : Model(), OnrampIntents {
|
||||
|
|
@ -146,6 +151,7 @@ internal class OnrampMainComponentModel @Inject constructor(
|
|||
onrampOfferAdvantagesUM = onrampOfferAdvantagesUM,
|
||||
categoryUM = categoryUM,
|
||||
)
|
||||
if (messageSender.showDemoModeWarningIfNeeded(userWallet, isDemoCardUseCase)) return
|
||||
params.openRedirectPage(quote)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package com.tangem.features.onramp.utils
|
||||
|
||||
import com.tangem.core.decompose.ui.UiMessageSender
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.message.DialogMessage
|
||||
import com.tangem.domain.demo.IsDemoCardUseCase
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.features.onramp.impl.R
|
||||
|
||||
/**
|
||||
* Onramp (buy) is disabled for demo cards. When [userWallet] is a demo cold wallet, shows the
|
||||
* demo-mode warning dialog and returns `true` — callers MUST abort the buy action in that case.
|
||||
*
|
||||
* Returns `false` for any non-demo wallet, so the caller can proceed.
|
||||
*/
|
||||
internal fun UiMessageSender.showDemoModeWarningIfNeeded(
|
||||
userWallet: UserWallet,
|
||||
isDemoCardUseCase: IsDemoCardUseCase,
|
||||
): Boolean {
|
||||
val isDemo = userWallet is UserWallet.Cold && isDemoCardUseCase(cardId = userWallet.cardId)
|
||||
if (isDemo) {
|
||||
send(
|
||||
DialogMessage(
|
||||
title = resourceReference(id = R.string.warning_demo_mode_title),
|
||||
message = resourceReference(id = R.string.warning_demo_mode_message),
|
||||
),
|
||||
)
|
||||
}
|
||||
return isDemo
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue