From 8a76ba376b9ed91e7e5b11b76458435fe15070fc Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 19 Oct 2023 21:33:27 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../tokenreceive/TokenReceiveBottomSheet.kt | 2 ++ .../tangem/domain/common/CardTypesResolver.kt | 2 ++ .../domain/common/TangemCardTypesResolver.kt | 2 ++ .../state/factory/TokenActionsProvider.kt | 31 ++++++++++++++----- .../state/factory/WalletStateFactory.kt | 2 +- .../presentation/wallet/ui/WalletScreen.kt | 1 + .../SingleCurrencyControlButtons.kt | 13 +++++--- .../wallet/viewmodels/WalletViewModel.kt | 8 ++--- 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/tokenreceive/TokenReceiveBottomSheet.kt b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/tokenreceive/TokenReceiveBottomSheet.kt index 417b9fcb35..15f594db35 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/tokenreceive/TokenReceiveBottomSheet.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/bottomsheets/tokenreceive/TokenReceiveBottomSheet.kt @@ -1,5 +1,6 @@ package com.tangem.core.ui.components.bottomsheets.tokenreceive +import android.widget.Toast import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -79,6 +80,7 @@ private fun TokenReceiveBottomSheetContent(content: TokenReceiveBottomSheetConfi content.onCopyClick.invoke() hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress) clipboardManager.setText(AnnotatedString(selectedAddress.value)) + Toast.makeText(context, R.string.wallet_notification_address_copied, Toast.LENGTH_SHORT).show() }, ) SecondaryButtonIconStart( diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/CardTypesResolver.kt b/domain/legacy/src/main/java/com/tangem/domain/common/CardTypesResolver.kt index 4b409286eb..2793156b1f 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/common/CardTypesResolver.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/common/CardTypesResolver.kt @@ -21,6 +21,8 @@ interface CardTypesResolver { fun isDevKit(): Boolean + fun isSingleWalletWithToken(): Boolean + fun isMultiwalletAllowed(): Boolean fun getBlockchain(): Blockchain diff --git a/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt b/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt index 35164b37d6..a6fe702b8a 100644 --- a/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/common/TangemCardTypesResolver.kt @@ -43,6 +43,8 @@ internal class TangemCardTypesResolver( override fun isDevKit(): Boolean = card.batchId == DEV_KIT_CARD_BATCH_ID + override fun isSingleWalletWithToken(): Boolean = walletData?.token != null && !isMultiwalletAllowed() + override fun isMultiwalletAllowed(): Boolean { return !isTangemTwins() && !card.isStart2Coin && !isTangemNote() && (multiWalletAvailable() || card.wallets.firstOrNull()?.curve == EllipticCurve.Secp256k1) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt index 9c671a6549..6c3bf9805f 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/TokenActionsProvider.kt @@ -1,9 +1,12 @@ package com.tangem.feature.wallet.presentation.wallet.state.factory +import com.tangem.common.Provider import com.tangem.core.ui.extensions.TextReference import com.tangem.core.ui.extensions.resourceReference +import com.tangem.domain.common.util.cardTypesResolver import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.TokenActionsState +import com.tangem.domain.wallets.models.UserWallet import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.wallet.state.TokenActionButtonConfig @@ -15,27 +18,39 @@ import kotlinx.collections.immutable.toImmutableList /** * Converter from loaded [TokenItemState.Content] to ImmutableList<[TokenActionButtonConfig]> * - * @property clickIntents screen click intents - * + * @property currentWalletProvider current wallet provider + * @property clickIntents screen click intents */ -@Suppress("UnusedPrivateMember") // will be used in next PRs -internal class TokenActionsProvider(private val clickIntents: WalletClickIntents) { +internal class TokenActionsProvider( + private val currentWalletProvider: Provider, + private val clickIntents: WalletClickIntents, +) { fun provideActions(tokenActions: TokenActionsState): ImmutableList { return tokenActions.states + .filterIfNodl() .mapNotNull { - mapTokenActionState(it, tokenActions.cryptoCurrencyStatus) + mapTokenActionState( + actionsState = it, + cryptoCurrencyStatus = tokenActions.cryptoCurrencyStatus, + ) } .toImmutableList() } + private fun List.filterIfNodl(): List { + return if (currentWalletProvider().scanResponse.cardTypesResolver.isSingleWalletWithToken()) { + filter { it !is TokenActionsState.ActionState.HideToken } + } else { + this + } + } + private fun mapTokenActionState( actionsState: TokenActionsState.ActionState, cryptoCurrencyStatus: CryptoCurrencyStatus, ): TokenActionButtonConfig? { - if (actionsState is TokenActionsState.ActionState.Send && - cryptoCurrencyStatus.value.amount.isNullOrZero() - ) { + if (actionsState is TokenActionsState.ActionState.Send && cryptoCurrencyStatus.value.amount.isNullOrZero()) { return null } val title: TextReference diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt index 961c4078dd..bcf2170eef 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/factory/WalletStateFactory.kt @@ -48,7 +48,7 @@ internal class WalletStateFactory( private val clickIntents: WalletClickIntents, ) { - private val tokenActionsProvider by lazy { TokenActionsProvider(clickIntents) } + private val tokenActionsProvider by lazy { TokenActionsProvider(currentWalletProvider, clickIntents) } private val skeletonConverter by lazy { WalletSkeletonStateConverter( diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt index 7cef25b9ea..8ef88e4498 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt @@ -137,6 +137,7 @@ private fun WalletContent( if (state is WalletSingleCurrencyState) { controlButtons( configs = state.buttons, + selectedWalletIndex = state.walletsListConfig.selectedWalletIndex, modifier = movableItemModifier.padding(top = betweenItemsPadding), ) } diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt index 4843bd9dc4..af4d8c17ae 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/SingleCurrencyControlButtons.kt @@ -15,14 +15,19 @@ private const val CONTROL_BUTTONS_CONTENT_TYPE = "ControlButtons" /** * Single currency control buttons. Like, "Buy", "Sell", etc * - * @param configs list of buttons - * @param modifier modifier + * @param configs list of buttons + * @param selectedWalletIndex selected wallet index for creating a unique key + * @param modifier modifier * [REDACTED_AUTHOR] */ @OptIn(ExperimentalFoundationApi::class) -internal fun LazyListScope.controlButtons(configs: ImmutableList, modifier: Modifier = Modifier) { - item(key = CONTROL_BUTTONS_CONTENT_TYPE, contentType = CONTROL_BUTTONS_CONTENT_TYPE) { +internal fun LazyListScope.controlButtons( + configs: ImmutableList, + selectedWalletIndex: Int, + modifier: Modifier = Modifier, +) { + item(key = CONTROL_BUTTONS_CONTENT_TYPE + selectedWalletIndex, contentType = CONTROL_BUTTONS_CONTENT_TYPE) { HorizontalActionChips( buttons = configs.map(WalletManageButton::config).toImmutableList(), modifier = modifier.animateItemPlacement(), diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 8dbd1e55da..7aa35eae77 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -581,7 +581,7 @@ internal class WalletViewModel @Inject constructor( viewModelScope.launch(dispatchers.main) { val wallet = getWallet(walletIndex) - val maybeFetchResult = if (isSingleWalletWithTokens(wallet)) { + val maybeFetchResult = if (wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken()) { fetchCardTokenListUseCase(userWalletId = wallet.walletId, refresh = true) } else { fetchTokenListUseCase(userWalletId = wallet.walletId, refresh = true) @@ -998,7 +998,7 @@ internal class WalletViewModel @Inject constructor( uiState = stateFactory.getLockedState() } wallet.isMultiCurrency -> getMultiCurrencyContent(wallet, index) - isSingleWalletWithTokens(wallet) -> getSingleCurrencyWithTokenContent(index) + wallet.scanResponse.cardTypesResolver.isSingleWalletWithToken() -> getSingleCurrencyWithTokenContent(index) !wallet.isMultiCurrency -> getSingleCurrencyContent(index) } } @@ -1075,10 +1075,6 @@ internal class WalletViewModel @Inject constructor( ) } - private fun isSingleWalletWithTokens(userWallet: UserWallet): Boolean { - return userWallet.scanResponse.walletData?.token != null && !userWallet.isMultiCurrency - } - private fun List.isAllCurrenciesLoaded(): Boolean { return !this.any { it.value is CryptoCurrencyStatus.Loading } }