Updated on 2026-08-14

This commit is contained in:
Tangem 2024-02-09 17:39:45 +03:00
commit 8b0e75064b
8 changed files with 85 additions and 13 deletions

View file

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

View file

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

View file

@ -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<EllipticCurve> = 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
}
}
}
}

View file

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

View file

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

View file

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

View file

@ -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<AppCurrency> {
return getSelectedAppCurrencyUseCase()
.map { maybeAppCurrency ->

View file

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