Updated on 2026-08-14
This commit is contained in:
parent
cad4da6f19
commit
2c259cb036
9 changed files with 79 additions and 37 deletions
|
|
@ -304,7 +304,7 @@ internal object WalletPreviewData {
|
|||
onDismissRequest = {},
|
||||
actions = listOf(
|
||||
TokenActionButtonConfig(
|
||||
text = "Send",
|
||||
text = TextReference.Str("Send"),
|
||||
iconResId = R.drawable.ic_share_24,
|
||||
onClick = {},
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.state
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
|
||||
/**
|
||||
* Action button config
|
||||
|
|
@ -11,7 +12,7 @@ import androidx.annotation.DrawableRes
|
|||
* @property enabled enabled
|
||||
*/
|
||||
data class TokenActionButtonConfig(
|
||||
val text: String,
|
||||
val text: TextReference,
|
||||
@DrawableRes val iconResId: Int,
|
||||
val onClick: () -> Unit,
|
||||
val enabled: Boolean = true,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.state.factory
|
||||
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.domain.tokens.model.TokenActionsState
|
||||
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
|
||||
|
|
@ -14,35 +16,57 @@ import kotlinx.collections.immutable.toImmutableList
|
|||
* @property clickIntents screen click intents
|
||||
*
|
||||
*/
|
||||
@Suppress("UnusedPrivateMember") // will be used in next PRs
|
||||
internal class TokenActionsProvider(private val clickIntents: WalletClickIntents) {
|
||||
|
||||
fun provideActions(cryptoCurrencyStatus: CryptoCurrencyStatus): ImmutableList<TokenActionButtonConfig> {
|
||||
// TODO: [REDACTED_JIRA]
|
||||
return mockTokenActionButtonConfig(cryptoCurrencyStatus).toImmutableList()
|
||||
fun provideActions(tokenActions: TokenActionsState): ImmutableList<TokenActionButtonConfig> {
|
||||
return convertTokenActionsState(tokenActions)
|
||||
}
|
||||
|
||||
private fun mockTokenActionButtonConfig(cryptoCurrencyStatus: CryptoCurrencyStatus): List<TokenActionButtonConfig> {
|
||||
return listOf(
|
||||
TokenActionButtonConfig(
|
||||
text = "Send",
|
||||
iconResId = R.drawable.ic_plus_24,
|
||||
onClick = { clickIntents.onMultiCurrencySendClick(cryptoCurrencyStatus) },
|
||||
),
|
||||
TokenActionButtonConfig(
|
||||
text = "Buy",
|
||||
iconResId = R.drawable.ic_plus_24,
|
||||
onClick = {},
|
||||
),
|
||||
TokenActionButtonConfig(
|
||||
text = "Sell",
|
||||
iconResId = R.drawable.ic_plus_24,
|
||||
onClick = {},
|
||||
),
|
||||
TokenActionButtonConfig(
|
||||
text = "Swap",
|
||||
iconResId = R.drawable.ic_plus_24,
|
||||
onClick = {},
|
||||
),
|
||||
private fun convertTokenActionsState(
|
||||
tokenActionsState: TokenActionsState,
|
||||
): ImmutableList<TokenActionButtonConfig> {
|
||||
return tokenActionsState.states
|
||||
.map(::tokenActionStateMapper)
|
||||
.toImmutableList()
|
||||
}
|
||||
|
||||
private fun tokenActionStateMapper(actionsState: TokenActionsState.ActionState): TokenActionButtonConfig {
|
||||
val title: TextReference
|
||||
val icon: Int
|
||||
val action: () -> Unit
|
||||
when (actionsState) {
|
||||
is TokenActionsState.ActionState.Buy -> {
|
||||
title = resourceReference(R.string.common_buy)
|
||||
icon = R.drawable.ic_plus_24
|
||||
action = { }
|
||||
}
|
||||
is TokenActionsState.ActionState.Receive -> {
|
||||
title = resourceReference(R.string.common_receive)
|
||||
icon = R.drawable.ic_arrow_down_24
|
||||
action = { }
|
||||
}
|
||||
is TokenActionsState.ActionState.Sell -> {
|
||||
title = resourceReference(R.string.common_sell)
|
||||
icon = R.drawable.ic_currency_24
|
||||
action = { }
|
||||
}
|
||||
is TokenActionsState.ActionState.Send -> {
|
||||
title = resourceReference(R.string.common_send)
|
||||
icon = R.drawable.ic_arrow_up_24
|
||||
action = { }
|
||||
}
|
||||
is TokenActionsState.ActionState.Swap -> {
|
||||
title = resourceReference(R.string.common_swap)
|
||||
icon = R.drawable.ic_exchange_horizontal_24
|
||||
action = { }
|
||||
}
|
||||
}
|
||||
return TokenActionButtonConfig(
|
||||
text = title,
|
||||
iconResId = icon,
|
||||
onClick = action,
|
||||
enabled = actionsState.enabled,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -199,16 +199,15 @@ internal class WalletStateFactory(
|
|||
bottomSheetConfig = state.bottomSheetConfig?.copy(isShow = false),
|
||||
)
|
||||
is WalletSingleCurrencyState.Locked -> state.copy(isBottomSheetShow = false)
|
||||
else -> state
|
||||
}
|
||||
}
|
||||
|
||||
fun getStateWithTokenActionBottomSheet(currencyStatus: CryptoCurrencyStatus): WalletState {
|
||||
fun getStateWithTokenActionBottomSheet(tokenActions: TokenActionsState): WalletState {
|
||||
return when (val state = currentStateProvider() as WalletState.ContentState) {
|
||||
is WalletMultiCurrencyState.Content -> state.copy(
|
||||
tokenActionsBottomSheet = ActionsBottomSheetConfig(
|
||||
isShow = true,
|
||||
actions = tokenActionsProvider.provideActions(currencyStatus),
|
||||
actions = tokenActionsProvider.provideActions(tokenActions),
|
||||
onDismissRequest = clickIntents::onDismissActionsBottomSheet,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
|
||||
import com.tangem.core.ui.components.SimpleSettingsRow
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
|
||||
import com.tangem.feature.wallet.presentation.wallet.state.ActionsBottomSheetConfig
|
||||
|
|
@ -38,7 +39,7 @@ private fun ActionsBottomSheetContent(actions: ImmutableList<TokenActionButtonCo
|
|||
) {
|
||||
actions.forEach { action ->
|
||||
SimpleSettingsRow(
|
||||
title = action.text,
|
||||
title = action.text.resolveReference(),
|
||||
icon = action.iconResId,
|
||||
enabled = action.enabled,
|
||||
onItemsClick = action.onClick,
|
||||
|
|
|
|||
|
|
@ -496,7 +496,16 @@ internal class WalletViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onTokenItemLongClick(cryptoCurrencyStatus: CryptoCurrencyStatus) {
|
||||
uiState = stateFactory.getStateWithTokenActionBottomSheet(cryptoCurrencyStatus)
|
||||
val state = uiState as? WalletState.ContentState ?: return
|
||||
val userWallet = getWallet(state.walletsListConfig.selectedWalletIndex)
|
||||
viewModelScope.launch(dispatchers.io) {
|
||||
getCryptoCurrencyActionsUseCase
|
||||
.invoke(userWallet.walletId, cryptoCurrencyStatus.currency)
|
||||
.take(count = 1)
|
||||
.collectLatest {
|
||||
uiState = stateFactory.getStateWithTokenActionBottomSheet(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRenameClick(userWalletId: UserWalletId, name: String) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue