From 5f338d293bb24459f78682b165e233313a6dac4c Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 26 Aug 2024 22:26:45 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../impl/ui/AddToPortfolioBottomSheet.kt | 4 +- .../markets/portfolio/impl/ui/MyPortfolio.kt | 4 +- .../impl/ui/TokenActionsBottomSheet.kt | 10 +- .../impl/ui/WalletSelectorBottomSheet.kt | 142 ++++++++++++++++++ .../PreviewAddToPortfolioBSContentProvider.kt | 44 +++--- .../ui/state/AddToPortfolioBSContentUM.kt | 3 + .../portfolio/impl/ui/state/MyPortfolioUM.kt | 8 + ...SContent.kt => TokenActionsBSContentUM.kt} | 2 +- .../ui/state/WalletSelectorBSContentUM.kt | 11 ++ 9 files changed, 202 insertions(+), 26 deletions(-) create mode 100644 features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WalletSelectorBottomSheet.kt rename features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/{TokenActionsBSContent.kt => TokenActionsBSContentUM.kt} (95%) create mode 100644 features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/WalletSelectorBSContentUM.kt diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/AddToPortfolioBottomSheet.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/AddToPortfolioBottomSheet.kt index e9b760f529..422bcdb678 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/AddToPortfolioBottomSheet.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/AddToPortfolioBottomSheet.kt @@ -55,8 +55,10 @@ internal fun AddToPortfolioBottomSheet(config: TangemBottomSheetConfig) { ) { Content( modifier = Modifier.fillMaxWidth(), - state = config.content as AddToPortfolioBSContentUM, + state = it, ) + + WalletSelectorBottomSheet(it.walletSelectorConfig) } } diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/MyPortfolio.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/MyPortfolio.kt index 2acf18d893..88436fa864 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/MyPortfolio.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/MyPortfolio.kt @@ -69,6 +69,8 @@ internal fun MyPortfolio(state: MyPortfolioUM, modifier: Modifier = Modifier) { MyPortfolioUM.Unavailable -> UnavailableContent() } } + + AddToPortfolioBottomSheet(state.addToPortfolioBS) } @Composable @@ -112,7 +114,7 @@ private fun AddFirstTokenContent(state: MyPortfolioUM.AddFirstToken, modifier: M verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing12), ) { Text( - text = "To start buying, exchanging or receiving this asset, add this token to at least 1 network", + text = "To start buying, exchanging or receiving this asset, add this token to at least 1 network", // FIXME style = TangemTheme.typography.body2, color = TangemTheme.colors.text.tertiary, ) diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/TokenActionsBottomSheet.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/TokenActionsBottomSheet.kt index cfc6c814d1..bc725d98f3 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/TokenActionsBottomSheet.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/TokenActionsBottomSheet.kt @@ -18,12 +18,12 @@ import com.tangem.core.ui.components.inputrow.inner.DividerContainer import com.tangem.core.ui.components.rows.CornersToRound import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview -import com.tangem.features.markets.portfolio.impl.ui.state.TokenActionsBSContent +import com.tangem.features.markets.portfolio.impl.ui.state.TokenActionsBSContentUM import kotlinx.collections.immutable.toImmutableList @Composable fun TokenActionsBottomSheet(config: TangemBottomSheetConfig) { - TangemBottomSheet( + TangemBottomSheet( config = config, title = { content -> TangemBottomSheetTitle(content.title) @@ -34,7 +34,7 @@ fun TokenActionsBottomSheet(config: TangemBottomSheetConfig) { } @Composable -private fun Content(content: TokenActionsBSContent) { +private fun Content(content: TokenActionsBSContentUM) { Column( modifier = Modifier .padding( @@ -78,9 +78,9 @@ private fun Preview() { TangemBottomSheetConfig( isShow = true, onDismissRequest = {}, - content = TokenActionsBSContent( + content = TokenActionsBSContentUM( title = "Wallet 1", - actions = TokenActionsBSContent.Action.entries.toImmutableList(), + actions = TokenActionsBSContentUM.Action.entries.toImmutableList(), onActionClick = {}, ), ), diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WalletSelectorBottomSheet.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WalletSelectorBottomSheet.kt new file mode 100644 index 0000000000..a9e190928f --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/WalletSelectorBottomSheet.kt @@ -0,0 +1,142 @@ +package com.tangem.features.markets.portfolio.impl.ui + +import android.content.res.Configuration +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll +import androidx.compose.runtime.Composable +import androidx.compose.runtime.key +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.tooling.preview.Preview +import com.tangem.common.ui.userwallet.UserWalletItem +import com.tangem.common.ui.userwallet.state.UserWalletItemUM +import com.tangem.core.ui.components.SpacerH +import com.tangem.core.ui.components.appbar.TangemTopAppBar +import com.tangem.core.ui.components.appbar.TangemTopAppBarHeight +import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM +import com.tangem.core.ui.components.block.BlockCard +import com.tangem.core.ui.components.block.TangemBlockCardColors +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.extensions.resourceReference +import com.tangem.core.ui.res.TangemTheme +import com.tangem.core.ui.res.TangemThemePreview +import com.tangem.features.markets.impl.R +import com.tangem.features.markets.portfolio.impl.ui.preview.PreviewAddToPortfolioBSContentProvider +import com.tangem.features.markets.portfolio.impl.ui.state.WalletSelectorBSContentUM +import kotlinx.collections.immutable.persistentListOf + +@Composable +internal fun WalletSelectorBottomSheet(config: TangemBottomSheetConfig) { + TangemBottomSheet( + config = config, + containerColor = TangemTheme.colors.background.tertiary, + addBottomInsets = false, + title = { content -> + TangemTopAppBar( + title = resourceReference(R.string.manage_tokens_wallet_selector_title), + titleAlignment = Alignment.CenterHorizontally, + startButton = TopAppBarButtonUM.Back(content.onBack), + height = TangemTopAppBarHeight.BOTTOM_SHEET, + ) + }, + ) { content -> + Content( + modifier = Modifier + .fillMaxSize() + .padding( + horizontal = TangemTheme.dimens.spacing16, + vertical = TangemTheme.dimens.spacing8, + ), + state = content, + ) + } +} + +@Composable +private fun Content(state: WalletSelectorBSContentUM, modifier: Modifier = Modifier) { + val bottomBarHeight = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() } + + Column( + modifier = modifier + .verticalScroll(rememberScrollState()), + ) { + BlockCard( + modifier = Modifier.fillMaxSize(), + colors = TangemBlockCardColors.copy( + containerColor = TangemTheme.colors.background.action, + disabledContainerColor = TangemTheme.colors.background.action, + ), + ) { + state.userWallets.forEach { state -> + key(state.id) { + UserWalletItem( + modifier = Modifier.fillMaxWidth(), + blockColors = TangemBlockCardColors.copy( + containerColor = TangemTheme.colors.background.action, + disabledContainerColor = TangemTheme.colors.background.action, + ), + state = state, + ) + } + } + } + SpacerH(bottomBarHeight) + } +} + +@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun Preview() { + TangemThemePreview { + WalletSelectorBottomSheet( + config = TangemBottomSheetConfig( + isShow = true, + onDismissRequest = {}, + content = WalletSelectorBSContentUM( + userWallets = persistentListOf( + PreviewAddToPortfolioBSContentProvider().userWallet.copy( + endIcon = UserWalletItemUM.EndIcon.None, + ), + PreviewAddToPortfolioBSContentProvider().userWallet.copy( + endIcon = UserWalletItemUM.EndIcon.Checkmark, + ), + PreviewAddToPortfolioBSContentProvider().userWallet.copy( + endIcon = UserWalletItemUM.EndIcon.None, + ), + ), + onBack = {}, + onWalletSelected = {}, + ), + ), + ) + } +} + +@Preview +@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) +@Composable +private fun PreviewContent() { + TangemThemePreview { + Content( + state = WalletSelectorBSContentUM( + userWallets = persistentListOf( + PreviewAddToPortfolioBSContentProvider().userWallet.copy( + endIcon = UserWalletItemUM.EndIcon.None, + ), + PreviewAddToPortfolioBSContentProvider().userWallet.copy( + endIcon = UserWalletItemUM.EndIcon.Checkmark, + ), + PreviewAddToPortfolioBSContentProvider().userWallet.copy( + endIcon = UserWalletItemUM.EndIcon.None, + ), + ), + onBack = {}, + onWalletSelected = {}, + ), + ) + } +} \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/preview/PreviewAddToPortfolioBSContentProvider.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/preview/PreviewAddToPortfolioBSContentProvider.kt index d184d3aac6..d218f4f8db 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/preview/PreviewAddToPortfolioBSContentProvider.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/preview/PreviewAddToPortfolioBSContentProvider.kt @@ -2,6 +2,8 @@ package com.tangem.features.markets.portfolio.impl.ui.preview import androidx.compose.ui.tooling.preview.PreviewParameterProvider import com.tangem.common.ui.userwallet.state.UserWalletItemUM +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent import com.tangem.core.ui.components.rows.model.BlockchainRowUM import com.tangem.core.ui.extensions.stringReference import com.tangem.domain.wallets.models.UserWalletId @@ -20,18 +22,20 @@ internal class PreviewAddToPortfolioBSContentProvider : PreviewParameterProvider isSelected = false, ) + val userWallet = UserWalletItemUM( + id = UserWalletId("1"), + name = stringReference("Wallet 1"), + information = stringReference("3 cards, 10,123$"), + imageUrl = "", + isEnabled = true, + endIcon = UserWalletItemUM.EndIcon.Arrow, + onClick = {}, + ) + override val values: Sequence get() = sequenceOf( AddToPortfolioBSContentUM( - selectedWallet = UserWalletItemUM( - id = UserWalletId("1"), - name = stringReference("Wallet 1"), - information = stringReference("3 cards, 10,123$"), - imageUrl = "", - isEnabled = true, - endIcon = UserWalletItemUM.EndIcon.Arrow, - onClick = {}, - ), + selectedWallet = userWallet, selectNetworkUM = SelectNetworkUM( tokenId = "etherium", tokenName = "Etherium", @@ -51,17 +55,15 @@ internal class PreviewAddToPortfolioBSContentProvider : PreviewParameterProvider isScanCardNotificationVisible = true, continueButtonEnabled = true, onContinueButtonClick = {}, + walletSelectorConfig = TangemBottomSheetConfig( + isShow = false, + onDismissRequest = {}, + content = TangemBottomSheetConfigContent.Empty, + ), + onWalletClick = {}, ), AddToPortfolioBSContentUM( - selectedWallet = UserWalletItemUM( - id = UserWalletId("1"), - name = stringReference("Wallet 1"), - information = stringReference("3 cards, 10,123$"), - imageUrl = "", - isEnabled = true, - endIcon = UserWalletItemUM.EndIcon.Arrow, - onClick = {}, - ), + selectedWallet = userWallet, selectNetworkUM = SelectNetworkUM( tokenId = "etherium", tokenName = "Etherium", @@ -81,6 +83,12 @@ internal class PreviewAddToPortfolioBSContentProvider : PreviewParameterProvider isScanCardNotificationVisible = true, continueButtonEnabled = false, onContinueButtonClick = {}, + walletSelectorConfig = TangemBottomSheetConfig( + isShow = false, + onDismissRequest = {}, + content = TangemBottomSheetConfigContent.Empty, + ), + onWalletClick = {}, ), ) } \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/AddToPortfolioBSContentUM.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/AddToPortfolioBSContentUM.kt index 6b708502ce..7369b5cf69 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/AddToPortfolioBSContentUM.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/AddToPortfolioBSContentUM.kt @@ -1,6 +1,7 @@ package com.tangem.features.markets.portfolio.impl.ui.state import com.tangem.common.ui.userwallet.state.UserWalletItemUM +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent internal data class AddToPortfolioBSContentUM( @@ -9,4 +10,6 @@ internal data class AddToPortfolioBSContentUM( val isScanCardNotificationVisible: Boolean, val continueButtonEnabled: Boolean, val onContinueButtonClick: () -> Unit, + val onWalletClick: () -> Unit, + val walletSelectorConfig: TangemBottomSheetConfig, ) : TangemBottomSheetConfigContent \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/MyPortfolioUM.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/MyPortfolioUM.kt index 7fa4c11a4a..c4f8d45a46 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/MyPortfolioUM.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/MyPortfolioUM.kt @@ -1,11 +1,19 @@ package com.tangem.features.markets.portfolio.impl.ui.state import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent import kotlinx.collections.immutable.ImmutableList @Immutable internal sealed class MyPortfolioUM { + val addToPortfolioBS: TangemBottomSheetConfig = TangemBottomSheetConfig( + isShow = false, + onDismissRequest = {}, + content = TangemBottomSheetConfigContent.Empty, + ) + data class Tokens( val tokens: ImmutableList, val buttonState: AddButtonState, diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/TokenActionsBSContent.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/TokenActionsBSContentUM.kt similarity index 95% rename from features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/TokenActionsBSContent.kt rename to features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/TokenActionsBSContentUM.kt index 2252b38f70..7b2a115f54 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/TokenActionsBSContent.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/TokenActionsBSContentUM.kt @@ -7,7 +7,7 @@ import com.tangem.core.ui.extensions.resourceReference import com.tangem.features.markets.impl.R import kotlinx.collections.immutable.ImmutableList -internal data class TokenActionsBSContent( +internal data class TokenActionsBSContentUM( val title: String, val actions: ImmutableList, val onActionClick: (Action) -> Unit, diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/WalletSelectorBSContentUM.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/WalletSelectorBSContentUM.kt new file mode 100644 index 0000000000..ee727b3608 --- /dev/null +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/ui/state/WalletSelectorBSContentUM.kt @@ -0,0 +1,11 @@ +package com.tangem.features.markets.portfolio.impl.ui.state + +import com.tangem.common.ui.userwallet.state.UserWalletItemUM +import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent +import kotlinx.collections.immutable.ImmutableList + +internal data class WalletSelectorBSContentUM( + val userWallets: ImmutableList, + val onWalletSelected: (UserWalletItemUM) -> Unit, + val onBack: () -> Unit, +) : TangemBottomSheetConfigContent \ No newline at end of file