Updated on 2026-08-14

This commit is contained in:
Tangem 2024-09-16 14:31:21 +05:00
parent da409f11ce
commit bc7cb0abe8
4 changed files with 67 additions and 12 deletions

View file

@ -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)

View file

@ -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,
)
}

View file

@ -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<AppCurrency>,
@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

View file

@ -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,
)
}