Updated on 2026-08-14
This commit is contained in:
parent
62f8b1dbf1
commit
73028360f4
10 changed files with 80 additions and 10 deletions
|
|
@ -75,6 +75,8 @@ class GetCryptoCurrencyActionsUseCase(
|
|||
} else {
|
||||
add(TokenActionsState.ActionState.Buy(false))
|
||||
}
|
||||
|
||||
addFirst(TokenActionsState.ActionState.CopyAddress(true))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ data class TokenActionsState(
|
|||
|
||||
data class Buy(override val enabled: Boolean) : ActionState()
|
||||
|
||||
data class CopyAddress(override val enabled: Boolean) : ActionState()
|
||||
|
||||
data class Sell(override val enabled: Boolean) : ActionState()
|
||||
|
||||
data class Receive(override val enabled: Boolean) : ActionState()
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ internal class TokenDetailsActionButtonsConverter(
|
|||
|
||||
private fun List<TokenActionsState.ActionState>.mapToManageButtons(): ImmutableList<TokenDetailsActionButton> {
|
||||
return this
|
||||
.map { action ->
|
||||
.mapNotNull { action ->
|
||||
when (action) {
|
||||
is TokenActionsState.ActionState.Buy -> {
|
||||
TokenDetailsActionButton.Buy(enabled = action.enabled, onClick = clickIntents::onBuyClick)
|
||||
|
|
@ -40,6 +40,9 @@ internal class TokenDetailsActionButtonsConverter(
|
|||
is TokenActionsState.ActionState.Swap -> {
|
||||
TokenDetailsActionButton.Swap(enabled = action.enabled, onClick = clickIntents::onSwapClick)
|
||||
}
|
||||
else -> {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
.toImmutableList()
|
||||
|
|
|
|||
|
|
@ -9,4 +9,8 @@ internal sealed class WalletEvent {
|
|||
data class ChangeWallet(val index: Int) : WalletEvent()
|
||||
|
||||
data class ShowError(val text: TextReference) : WalletEvent()
|
||||
|
||||
data class ShowToast(val text: TextReference) : WalletEvent()
|
||||
|
||||
data class CopyAddress(val address: String) : WalletEvent()
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.state.factory
|
||||
|
||||
import com.tangem.common.extensions.isZero
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
|
|
@ -22,14 +23,21 @@ internal class TokenActionsProvider(private val clickIntents: WalletClickIntents
|
|||
|
||||
fun provideActions(tokenActions: TokenActionsState): ImmutableList<TokenActionButtonConfig> {
|
||||
return tokenActions.states
|
||||
.map { mapTokenActionState(it, tokenActions.cryptoCurrencyStatus) }
|
||||
.mapNotNull {
|
||||
mapTokenActionState(it, tokenActions.cryptoCurrencyStatus)
|
||||
}
|
||||
.toImmutableList()
|
||||
}
|
||||
|
||||
private fun mapTokenActionState(
|
||||
actionsState: TokenActionsState.ActionState,
|
||||
cryptoCurrencyStatus: CryptoCurrencyStatus,
|
||||
): TokenActionButtonConfig {
|
||||
): TokenActionButtonConfig? {
|
||||
if (actionsState is TokenActionsState.ActionState.Send &&
|
||||
cryptoCurrencyStatus.value.amount?.isZero() == true
|
||||
) {
|
||||
return null
|
||||
}
|
||||
val title: TextReference
|
||||
val icon: Int
|
||||
val action: () -> Unit
|
||||
|
|
@ -59,6 +67,11 @@ internal class TokenActionsProvider(private val clickIntents: WalletClickIntents
|
|||
icon = R.drawable.ic_exchange_horizontal_24
|
||||
action = { clickIntents.onSwapClick(cryptoCurrencyStatus) }
|
||||
}
|
||||
is TokenActionsState.ActionState.CopyAddress -> {
|
||||
title = resourceReference(R.string.common_copy_address)
|
||||
icon = R.drawable.ic_copy_24
|
||||
action = { clickIntents.onCopyAddressClick(cryptoCurrencyStatus) }
|
||||
}
|
||||
}
|
||||
return TokenActionButtonConfig(
|
||||
text = title,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ internal class WalletCryptoCurrencyActionsConverter(
|
|||
onClick = { clickIntents.onSingleCurrencySendClick(cryptoCurrencyStatus) },
|
||||
)
|
||||
}
|
||||
is TokenActionsState.ActionState.Swap -> null
|
||||
else -> {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
.toPersistentList()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.ui
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import com.tangem.core.ui.event.EventEffect
|
||||
import com.tangem.core.ui.event.StateEvent
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
|
|
@ -16,7 +19,9 @@ internal fun WalletEventEffect(
|
|||
event: StateEvent<WalletEvent>,
|
||||
onAutoScrollSet: () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val resources = LocalContext.current.resources
|
||||
val clipboardManager = LocalClipboardManager.current
|
||||
EventEffect(
|
||||
event = event,
|
||||
onTrigger = { value ->
|
||||
|
|
@ -28,6 +33,12 @@ internal fun WalletEventEffect(
|
|||
is WalletEvent.ShowError -> {
|
||||
snackbarHostState.showSnackbar(message = value.text.resolveReference(resources))
|
||||
}
|
||||
is WalletEvent.ShowToast -> {
|
||||
Toast.makeText(context, value.text.resolveReference(resources), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
is WalletEvent.CopyAddress -> {
|
||||
clipboardManager.setText(AnnotatedString(value.address))
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -38,12 +38,14 @@ private fun ActionsBottomSheetContent(actions: ImmutableList<TokenActionButtonCo
|
|||
modifier = Modifier.background(TangemTheme.colors.background.primary),
|
||||
) {
|
||||
actions.forEach { action ->
|
||||
SimpleSettingsRow(
|
||||
title = action.text.resolveReference(),
|
||||
icon = action.iconResId,
|
||||
enabled = action.enabled,
|
||||
onItemsClick = action.onClick,
|
||||
)
|
||||
if (action.enabled) {
|
||||
SimpleSettingsRow(
|
||||
title = action.text.resolveReference(),
|
||||
icon = action.iconResId,
|
||||
enabled = action.enabled,
|
||||
onItemsClick = action.onClick,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ internal interface WalletClickIntents {
|
|||
|
||||
fun onReceiveClick(cryptoCurrencyStatus: CryptoCurrencyStatus)
|
||||
|
||||
fun onCopyAddressClick(cryptoCurrencyStatus: CryptoCurrencyStatus)
|
||||
|
||||
fun onSellClick(cryptoCurrencyStatus: CryptoCurrencyStatus)
|
||||
|
||||
fun onManageTokensClick()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import androidx.paging.cachedIn
|
|||
import arrow.core.getOrElse
|
||||
import com.tangem.blockchain.blockchains.cardano.CardanoUtils
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.address.AddressType
|
||||
import com.tangem.common.Provider
|
||||
import com.tangem.common.card.EllipticCurve
|
||||
import com.tangem.common.doOnFailure
|
||||
|
|
@ -16,6 +17,7 @@ import com.tangem.core.navigation.AppScreen
|
|||
import com.tangem.core.ui.components.bottomsheets.tokenreceive.AddressModel
|
||||
import com.tangem.core.ui.components.bottomsheets.tokenreceive.TokenReceiveBottomSheetConfig
|
||||
import com.tangem.core.ui.components.marketprice.MarketPriceBlockState
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
|
|
@ -45,6 +47,7 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
|
|||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.domain.wallets.usecase.*
|
||||
import com.tangem.feature.wallet.impl.R
|
||||
import com.tangem.feature.wallet.presentation.common.state.TokenItemState
|
||||
import com.tangem.feature.wallet.presentation.router.InnerWalletRouter
|
||||
import com.tangem.feature.wallet.presentation.wallet.analytics.PortfolioEvent
|
||||
|
|
@ -595,6 +598,32 @@ internal class WalletViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onCopyAddressClick(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
val state = uiState as? WalletState.ContentState ?: return
|
||||
|
||||
viewModelScope.launch(dispatchers.main) {
|
||||
val userWallet = getWallet(index = state.walletsListConfig.selectedWalletIndex)
|
||||
|
||||
val defaultAddress = walletManagersFacade.getAddress(
|
||||
userWalletId = userWallet.walletId,
|
||||
network = cryptoCurrencyStatus.currency.network,
|
||||
).find { it.type == AddressType.Default }
|
||||
|
||||
defaultAddress?.value?.let { address ->
|
||||
uiState = stateFactory.getStateAndTriggerEvent(
|
||||
state = uiState,
|
||||
event = WalletEvent.CopyAddress(address),
|
||||
setUiState = { uiState = it },
|
||||
)
|
||||
uiState = stateFactory.getStateAndTriggerEvent(
|
||||
state = uiState,
|
||||
event = WalletEvent.ShowToast(resourceReference(R.string.wallet_notification_address_copied)),
|
||||
setUiState = { uiState = it },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSellClick(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
reduxStateHolder.dispatch(
|
||||
TradeCryptoAction.New.Sell(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue