From bc7cb0abe858dd38b2be8295fe1cd6c17721e579 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 16 Sep 2024 14:31:21 +0500 Subject: [PATCH] Updated on 2026-08-14 --- features/markets/impl/build.gradle.kts | 1 + .../impl/model/MarketsPortfolioModel.kt | 16 +++------ .../impl/model/TokenActionsHandler.kt | 35 +++++++++++++++++++ .../portfolio/impl/ui/WarningDialog.kt | 27 ++++++++++++++ 4 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WarningDialog.kt diff --git a/features/markets/impl/build.gradle.kts b/features/markets/impl/build.gradle.kts index 055d5172a9..a6e62fdf7c 100644 --- a/features/markets/impl/build.gradle.kts +++ b/features/markets/impl/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { implementation(projects.domain.balanceHiding) implementation(projects.domain.balanceHiding.models) implementation(projects.domain.card) + implementation(projects.domain.demo) implementation(projects.domain.manageTokens) implementation(projects.domain.markets) implementation(projects.domain.staking.models) diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MarketsPortfolioModel.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MarketsPortfolioModel.kt index 59a9e16805..fa57001e94 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MarketsPortfolioModel.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MarketsPortfolioModel.kt @@ -1,16 +1,12 @@ package com.tangem.features.markets.portfolio.impl.model import androidx.compose.runtime.Stable -import androidx.compose.ui.res.stringResource import arrow.core.getOrElse import com.tangem.core.decompose.di.ComponentScoped import com.tangem.core.decompose.model.Model import com.tangem.core.decompose.model.ParamsContainer import com.tangem.core.decompose.ui.UiMessageSender -import com.tangem.core.ui.components.BasicDialog -import com.tangem.core.ui.components.DialogButtonUM import com.tangem.core.ui.components.rows.model.BlockchainRowUM -import com.tangem.core.ui.extensions.resolveReference import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.extensions.wrappedList @@ -29,6 +25,7 @@ import com.tangem.domain.wallets.usecase.GetSelectedWalletUseCase import com.tangem.features.markets.impl.R import com.tangem.features.markets.portfolio.api.MarketsPortfolioComponent import com.tangem.features.markets.portfolio.impl.loader.PortfolioDataLoader +import com.tangem.features.markets.portfolio.impl.ui.WarningDialog import com.tangem.features.markets.portfolio.impl.ui.state.MyPortfolioUM import com.tangem.utils.Provider import com.tangem.utils.coroutines.CoroutineDispatcherProvider @@ -225,8 +222,7 @@ internal class MarketsPortfolioModel @Inject constructor( private fun showUnsupportedWarning(unsupportedState: CurrencyUnsupportedState) { val message = ContentMessage { onDismiss -> - BasicDialog( - title = resourceReference(R.string.common_warning).resolveReference(), + WarningDialog( message = when (unsupportedState) { is CurrencyUnsupportedState.Token.NetworkTokensUnsupported -> resourceReference( id = R.string.alert_manage_tokens_unsupported_message, @@ -240,12 +236,8 @@ internal class MarketsPortfolioModel @Inject constructor( id = R.string.alert_manage_tokens_unsupported_curve_message, formatArgs = wrappedList(unsupportedState.networkName), ) - }.resolveReference(), - confirmButton = DialogButtonUM( - title = stringResource(R.string.common_ok), - onClick = onDismiss, - ), - onDismissDialog = onDismiss, + }, + onDismiss = onDismiss, ) } diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/TokenActionsHandler.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/TokenActionsHandler.kt index 8b8d8ffa82..b43dc3b16f 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/TokenActionsHandler.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/TokenActionsHandler.kt @@ -9,13 +9,17 @@ import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig import com.tangem.core.ui.components.bottomsheets.tokenreceive.mapToAddressModels import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.message.ContentMessage import com.tangem.core.ui.message.SnackbarMessage import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.demo.IsDemoCardUseCase import com.tangem.domain.redux.ReduxStateHolder import com.tangem.domain.tokens.legacy.TradeCryptoAction import com.tangem.domain.tokens.model.TokenActionsState +import com.tangem.domain.wallets.models.UserWallet import com.tangem.features.markets.impl.R import com.tangem.features.markets.portfolio.impl.loader.PortfolioData +import com.tangem.features.markets.portfolio.impl.ui.WarningDialog import com.tangem.features.markets.portfolio.impl.ui.state.TokenActionsBSContentUM import com.tangem.utils.Provider import dagger.assisted.Assisted @@ -34,9 +38,18 @@ internal class TokenActionsHandler @AssistedInject constructor( private val currentAppCurrency: Provider, @Assisted("updateTokenReceiveBSConfig") private val updateTokenReceiveBSConfig: ((TangemBottomSheetConfig) -> TangemBottomSheetConfig) -> Unit, + private val isDemoCardUseCase: IsDemoCardUseCase, + private val messageSender: UiMessageSender, ) { + private val disabledActionsInDemoMode = setOf( + TokenActionsBSContentUM.Action.Buy, + TokenActionsBSContentUM.Action.Sell, + ) + fun handle(action: TokenActionsBSContentUM.Action, cryptoCurrencyData: PortfolioData.CryptoCurrencyData) { + if (handleDemoMode(action, cryptoCurrencyData.userWallet)) return + when (action) { TokenActionsBSContentUM.Action.Buy -> onBuyClick(cryptoCurrencyData) TokenActionsBSContentUM.Action.Exchange -> onExchangeClick(cryptoCurrencyData) @@ -48,6 +61,28 @@ internal class TokenActionsHandler @AssistedInject constructor( } } + private fun handleDemoMode(action: TokenActionsBSContentUM.Action, userWallet: UserWallet): Boolean { + val demoCard = isDemoCardUseCase.invoke(userWallet.cardId) + val needShowDemoWarning = demoCard && disabledActionsInDemoMode.contains(action) + + if (needShowDemoWarning) { + showDemoModeWarning() + } + + return needShowDemoWarning + } + + private fun showDemoModeWarning() { + val message = ContentMessage { onDismiss -> + WarningDialog( + message = resourceReference(R.string.alert_demo_feature_disabled), + onDismiss = onDismiss, + ) + } + + messageSender.send(message) + } + private fun onReceiveClick(cryptoCurrencyData: PortfolioData.CryptoCurrencyData) { val cryptoCurrencyStatus = cryptoCurrencyData.status val currency = cryptoCurrencyStatus.currency diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WarningDialog.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WarningDialog.kt new file mode 100644 index 0000000000..70e52d864c --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WarningDialog.kt @@ -0,0 +1,27 @@ +package com.tangem.features.markets.portfolio.impl.ui + +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import com.tangem.core.ui.components.BasicDialog +import com.tangem.core.ui.components.DialogButtonUM +import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.extensions.resolveReference +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.features.markets.impl.R + +@Composable +internal fun WarningDialog( + message: TextReference, + onDismiss: () -> Unit, + title: TextReference = resourceReference(R.string.common_warning), +) { + BasicDialog( + title = title.resolveReference(), + message = message.resolveReference(), + confirmButton = DialogButtonUM( + title = stringResource(R.string.common_ok), + onClick = onDismiss, + ), + onDismissDialog = onDismiss, + ) +} \ No newline at end of file