Updated on 2026-08-14
This commit is contained in:
parent
5e1c63c252
commit
8a76ba376b
8 changed files with 42 additions and 19 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ interface CardTypesResolver {
|
|||
|
||||
fun isDevKit(): Boolean
|
||||
|
||||
fun isSingleWalletWithToken(): Boolean
|
||||
|
||||
fun isMultiwalletAllowed(): Boolean
|
||||
|
||||
fun getBlockchain(): Blockchain
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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<UserWallet>,
|
||||
private val clickIntents: WalletClickIntents,
|
||||
) {
|
||||
|
||||
fun provideActions(tokenActions: TokenActionsState): ImmutableList<TokenActionButtonConfig> {
|
||||
return tokenActions.states
|
||||
.filterIfNodl()
|
||||
.mapNotNull {
|
||||
mapTokenActionState(it, tokenActions.cryptoCurrencyStatus)
|
||||
mapTokenActionState(
|
||||
actionsState = it,
|
||||
cryptoCurrencyStatus = tokenActions.cryptoCurrencyStatus,
|
||||
)
|
||||
}
|
||||
.toImmutableList()
|
||||
}
|
||||
|
||||
private fun List<TokenActionsState.ActionState>.filterIfNodl(): List<TokenActionsState.ActionState> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ private fun WalletContent(
|
|||
if (state is WalletSingleCurrencyState) {
|
||||
controlButtons(
|
||||
configs = state.buttons,
|
||||
selectedWalletIndex = state.walletsListConfig.selectedWalletIndex,
|
||||
modifier = movableItemModifier.padding(top = betweenItemsPadding),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<WalletManageButton>, modifier: Modifier = Modifier) {
|
||||
item(key = CONTROL_BUTTONS_CONTENT_TYPE, contentType = CONTROL_BUTTONS_CONTENT_TYPE) {
|
||||
internal fun LazyListScope.controlButtons(
|
||||
configs: ImmutableList<WalletManageButton>,
|
||||
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(),
|
||||
|
|
|
|||
|
|
@ -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<CryptoCurrencyStatus>.isAllCurrenciesLoaded(): Boolean {
|
||||
return !this.any { it.value is CryptoCurrencyStatus.Loading }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue