diff --git a/app/src/test/kotlin/com/tangem/tap/domain/card/ScanResponseMockFactory.kt b/app/src/test/kotlin/com/tangem/tap/domain/card/ScanResponseMockFactory.kt index 71f1514668..da79e800f0 100644 --- a/app/src/test/kotlin/com/tangem/tap/domain/card/ScanResponseMockFactory.kt +++ b/app/src/test/kotlin/com/tangem/tap/domain/card/ScanResponseMockFactory.kt @@ -2,10 +2,7 @@ package com.tangem.tap.domain.card import com.tangem.common.card.CardWallet import com.tangem.common.card.FirmwareVersion -import com.tangem.domain.common.configs.CardConfig -import com.tangem.domain.common.configs.GenericCardConfig -import com.tangem.domain.common.configs.MultiWalletCardConfig -import com.tangem.domain.common.configs.Wallet2CardConfig +import com.tangem.domain.common.configs.* import com.tangem.domain.models.scan.CardDTO import com.tangem.domain.models.scan.KeyWalletPublicKey import com.tangem.domain.models.scan.ProductType @@ -50,6 +47,7 @@ object ScanResponseMockFactory { is GenericCardConfig -> genericFirmwareVersion MultiWalletCardConfig -> walletFirmwareVersion Wallet2CardConfig -> wallet2FirmwareVersion + EdSingleCurrencyCardConfig -> genericFirmwareVersion }, manufacturer = CardDTO.Manufacturer(name = "NEVER-MIND", manufactureDate = Date(), signature = null), issuer = CardDTO.Issuer(name = "NEVER-MIND", publicKey = ByteArray(0)), diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/configs/CardConfig.kt b/domain/legacy/src/main/java/com/tangem/domain/common/configs/CardConfig.kt index 7e3fc92045..8099ff7d09 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/common/configs/CardConfig.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/common/configs/CardConfig.kt @@ -22,6 +22,11 @@ sealed interface CardConfig { ) { return MultiWalletCardConfig } + if (cardDTO.supportedCurves.size == 1 && + cardDTO.supportedCurves.contains(EllipticCurve.Ed25519) + ) { + return EdSingleCurrencyCardConfig + } return GenericCardConfig(cardDTO.settings.maxWalletsCount) } } diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/configs/EdSingleCurrencyCardConfig.kt b/domain/legacy/src/main/java/com/tangem/domain/common/configs/EdSingleCurrencyCardConfig.kt new file mode 100644 index 0000000000..6792eeff3e --- /dev/null +++ b/domain/legacy/src/main/java/com/tangem/domain/common/configs/EdSingleCurrencyCardConfig.kt @@ -0,0 +1,22 @@ +package com.tangem.domain.common.configs + +import com.tangem.blockchain.common.Blockchain +import com.tangem.common.card.EllipticCurve +import timber.log.Timber + +object EdSingleCurrencyCardConfig : CardConfig { + + override val mandatoryCurves: List = listOf(EllipticCurve.Ed25519) + + override fun primaryCurve(blockchain: Blockchain): EllipticCurve? { + return when { + blockchain.getSupportedCurves().contains(EllipticCurve.Ed25519) -> { + EllipticCurve.Ed25519 + } + else -> { + Timber.e("Unsupported blockchain, curve not found") + null + } + } + } +} \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsTopAppBarConfig.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsTopAppBarConfig.kt index 88ecf53046..f72f09f20f 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsTopAppBarConfig.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/TokenDetailsTopAppBarConfig.kt @@ -2,5 +2,5 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state internal data class TokenDetailsTopAppBarConfig( val onBackClick: () -> Unit, - val tokenDetailsAppBarMenuConfig: TokenDetailsAppBarMenuConfig, + val tokenDetailsAppBarMenuConfig: TokenDetailsAppBarMenuConfig?, ) \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt index b4b567a444..c0e14ea621 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/state/factory/TokenDetailsStateFactory.kt @@ -11,7 +11,9 @@ import com.tangem.core.ui.components.transactions.state.TxHistoryState import com.tangem.core.ui.event.consumedEvent import com.tangem.core.ui.event.triggeredEvent import com.tangem.core.ui.extensions.TextReference +import com.tangem.core.ui.res.TangemTheme import com.tangem.domain.appcurrency.model.AppCurrency +import com.tangem.domain.common.CardTypesResolver import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus @@ -22,6 +24,7 @@ import com.tangem.domain.txhistory.models.TxHistoryItem import com.tangem.domain.txhistory.models.TxHistoryListError import com.tangem.domain.txhistory.models.TxHistoryStateError import com.tangem.feature.tokendetails.presentation.tokendetails.state.SwapTransactionsState +import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsAppBarMenuConfig import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsDialogConfig import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsLoadedTxHistoryConverter @@ -29,7 +32,9 @@ import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.t import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsLoadingTxHistoryConverter.TokenDetailsLoadingTxHistoryModel import com.tangem.feature.tokendetails.presentation.tokendetails.ui.components.exchange.ExchangeStatusBottomSheetConfig import com.tangem.feature.tokendetails.presentation.tokendetails.viewmodels.TokenDetailsClickIntents +import com.tangem.features.tokendetails.impl.R import com.tangem.utils.Provider +import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -276,4 +281,31 @@ internal class TokenDetailsStateFactory( ), ) } + + fun getStateWithUpdatedMenu(cardTypesResolver: CardTypesResolver): TokenDetailsState { + return with(currentStateProvider()) { + copy( + topAppBarConfig = topAppBarConfig.copy( + tokenDetailsAppBarMenuConfig = topAppBarConfig.tokenDetailsAppBarMenuConfig + ?.updateMenu(cardTypesResolver), + ), + ) + } + } + + private fun TokenDetailsAppBarMenuConfig.updateMenu( + cardTypesResolver: CardTypesResolver, + ): TokenDetailsAppBarMenuConfig? { + if (cardTypesResolver.isSingleWalletWithToken()) return null + + return copy( + items = persistentListOf( + TokenDetailsAppBarMenuConfig.MenuItem( + title = TextReference.Res(id = R.string.token_details_hide_token), + textColorProvider = { TangemTheme.colors.text.warning }, + onClick = clickIntents::onHideClick, + ), + ), + ) + } } \ No newline at end of file diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsTopAppBar.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsTopAppBar.kt index b5e0839679..1ed6603ba3 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsTopAppBar.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/ui/components/TokenDetailsTopAppBar.kt @@ -1,5 +1,6 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.ui.components +import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.padding @@ -38,12 +39,17 @@ internal fun TokenDetailsTopAppBar(config: TokenDetailsTopAppBarConfig) { }, title = {}, actions = { - IconButton(onClick = { showDropdownMenu = true }) { - Icon( - painter = painterResource(id = R.drawable.ic_more_vertical_24), - tint = TangemTheme.colors.icon.primary1, - contentDescription = "More", - ) + AnimatedVisibility( + visible = config.tokenDetailsAppBarMenuConfig != null && + config.tokenDetailsAppBarMenuConfig.items.isNotEmpty(), + ) { + IconButton(onClick = { showDropdownMenu = true }) { + Icon( + painter = painterResource(id = R.drawable.ic_more_vertical_24), + tint = TangemTheme.colors.icon.primary1, + contentDescription = "More", + ) + } } TangemDropdownMenu( @@ -52,7 +58,7 @@ internal fun TokenDetailsTopAppBar(config: TokenDetailsTopAppBarConfig) { onDismissRequest = { showDropdownMenu = false }, offset = DpOffset(x = TangemTheme.dimens.spacing20, y = TangemTheme.dimens.spacing10.times(-1)), content = { - config.tokenDetailsAppBarMenuConfig.items.fastForEach { + config.tokenDetailsAppBarMenuConfig?.items?.fastForEach { AppBarDropdownItem( item = it, dismissParent = { showDropdownMenu = false }, diff --git a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt index 1fba010ecc..382d9ca76e 100644 --- a/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt +++ b/features/tokendetails/impl/src/main/kotlin/com/tangem/feature/tokendetails/presentation/tokendetails/viewmodels/TokenDetailsViewModel.kt @@ -185,6 +185,7 @@ internal class TokenDetailsViewModel @Inject constructor( analyticsEventsHandler.send( event = TokenScreenAnalyticsEvent.DetailsScreenOpened(token = cryptoCurrency.symbol), ) + updateTopBarMenu() updateContent() handleBalanceHiding(owner) } @@ -339,6 +340,14 @@ internal class TokenDetailsViewModel @Inject constructor( } } + private fun updateTopBarMenu() { + viewModelScope.launch(dispatchers.main) { + val wallet = getUserWalletUseCase(userWalletId).getOrElse { return@launch } + + uiState = stateFactory.getStateWithUpdatedMenu(wallet.scanResponse.cardTypesResolver) + } + } + private fun createSelectedAppCurrencyFlow(): StateFlow { return getSelectedAppCurrencyUseCase() .map { maybeAppCurrency -> diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt index 79fef13194..2717ca2dfa 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/analytics/WalletScreenAnalyticsEvent.kt @@ -61,7 +61,7 @@ sealed class WalletScreenAnalyticsEvent { object NoticeBackupYourWalletTapped : MainScreen(event = "Notice - Backup Your Wallet Tapped") object NoticeScanYourCardTapped : MainScreen(event = "Notice - Scan Your Card Tapped") object NoticeWalletLocked : MainScreen(event = "Notice - Wallet Locked") - object WalletUnlockTapped : MainScreen(event = "Button - Wallet Unlock Tapped") + object WalletUnlockTapped : MainScreen(event = "Notice - Wallet Unlock Tapped") object NetworksUnreachable : MainScreen(event = "Notice - Networks Unreachable")