From 1e85dbe6f75186d5e060ef26802b4b88f59c06b5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 5 Sep 2024 09:18:09 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../core/ui/components/rows/BlockchainRow.kt | 24 +++++++++++--- .../core/ui/components/rows/RowComponents.kt | 13 ++++++-- .../components/rows/model/BlockchainRowUM.kt | 1 + .../model/AddToPortfolioBSContentUMFactory.kt | 32 ++++++++----------- .../impl/model/BlockchainRowUMConverter.kt | 17 ++++++++-- .../impl/model/MarketsPortfolioModel.kt | 8 ++--- .../impl/model/MyPortfolioUMFactory.kt | 6 +--- .../impl/model/SelectNetworkUMConverter.kt | 6 +++- .../impl/ui/AddToPortfolioBottomSheet.kt | 8 +++-- 9 files changed, 73 insertions(+), 42 deletions(-) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt index 70150328ce..df2cdf37a9 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/BlockchainRow.kt @@ -10,6 +10,7 @@ import androidx.compose.material3.Icon import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter @@ -20,6 +21,8 @@ import com.tangem.core.ui.components.rows.model.BlockchainRowUM import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemThemePreview +private const val DISABLED_ICON_ALPHA = 0.4f + /** * [Figma Component](https://www.figma.com/design/14ISV23YB1yVW1uNVwqrKv/Android?node-id=2737-2800&t=ewlXfWwbDnRhjw4B-4) * */ @@ -36,8 +39,9 @@ fun BlockchainRow(model: BlockchainRowUM, action: @Composable BoxScope.() -> Uni icon = { RowIcon( resId = model.iconResId, - isColored = model.isSelected, + isColored = model.isSelected && model.isEnabled, showAccentBadge = model.isMainNetwork, + isEnabled = model.isEnabled, ) }, text = { @@ -46,6 +50,7 @@ fun BlockchainRow(model: BlockchainRowUM, action: @Composable BoxScope.() -> Uni secondText = model.type, accentMainText = model.isSelected, accentSecondText = model.isMainNetwork, + isEnabled = model.isEnabled, ) }, action = action, @@ -58,10 +63,9 @@ private fun RowIcon( isColored: Boolean, showAccentBadge: Boolean, modifier: Modifier = Modifier, + isEnabled: Boolean = true, ) { - Box( - modifier = modifier.size(TangemTheme.dimens.size24), - ) { + Box(modifier = modifier.size(TangemTheme.dimens.size24)) { if (isColored) { Image( modifier = Modifier @@ -78,6 +82,7 @@ private fun RowIcon( color = TangemTheme.colors.button.secondary, shape = CircleShape, ) + .alpha(if (isEnabled) 1f else DISABLED_ICON_ALPHA) .size(TangemTheme.dimens.size22), painter = painterResource(id = resId), tint = TangemTheme.colors.icon.informative, @@ -126,7 +131,7 @@ private fun Preview_BlockchainRow(@PreviewParameter(BlockchainRowParameterProvid BlockchainRow( model = state, action = { - TangemSwitch(onCheckedChange = { }, checked = true) + TangemSwitch(onCheckedChange = { }, checked = true, enabled = state.isEnabled) }, ) }, @@ -160,6 +165,15 @@ private class BlockchainRowParameterProvider : CollectionPreviewParameterProvide isMainNetwork = false, isSelected = false, ), + BlockchainRowUM( + id = "2", + name = "BNB BEACON CHAIN", + type = "1234567890111213141516171819", + iconResId = R.drawable.ic_bsc_16, + isMainNetwork = false, + isSelected = false, + isEnabled = false, + ), ), ) // endregion Preview \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt index ede73396a0..258a153de4 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/RowComponents.kt @@ -53,6 +53,7 @@ internal fun RowText( accentSecondText: Boolean, modifier: Modifier = Modifier, subtitle: TextReference? = null, + isEnabled: Boolean = true, ) { Column( modifier = modifier, @@ -67,7 +68,11 @@ internal fun RowText( modifier = Modifier.weight(weight = 10f, fill = false), text = mainText, style = TangemTheme.typography.subtitle2, - color = if (accentMainText) TangemTheme.colors.text.primary1 else TangemTheme.colors.text.secondary, + color = if (isEnabled) { + if (accentMainText) TangemTheme.colors.text.primary1 else TangemTheme.colors.text.secondary + } else { + TangemTheme.colors.text.disabled + }, maxLines = 1, overflow = TextOverflow.Ellipsis, ) @@ -76,7 +81,11 @@ internal fun RowText( modifier = Modifier.weight(weight = 4f, fill = false), text = secondText, style = TangemTheme.typography.body2, - color = if (accentSecondText) TangemTheme.colors.text.accent else TangemTheme.colors.text.secondary, + color = if (isEnabled) { + if (accentSecondText) TangemTheme.colors.text.accent else TangemTheme.colors.text.secondary + } else { + TangemTheme.colors.text.disabled + }, maxLines = 1, overflow = TextOverflow.Ellipsis, ) diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt b/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt index 700b4bc377..6cba8925ee 100644 --- a/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/rows/model/BlockchainRowUM.kt @@ -10,4 +10,5 @@ data class BlockchainRowUM( val iconResId: Int, val isMainNetwork: Boolean, val isSelected: Boolean, + val isEnabled: Boolean = true, ) \ No newline at end of file diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/AddToPortfolioBSContentUMFactory.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/AddToPortfolioBSContentUMFactory.kt index 761d567f41..c1b58bdbf6 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/AddToPortfolioBSContentUMFactory.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/AddToPortfolioBSContentUMFactory.kt @@ -30,28 +30,22 @@ internal class AddToPortfolioBSContentUMFactory( private val onWalletSelectorVisibilityChange: (Boolean) -> Unit, private val onNetworkSwitchClick: (String, Boolean) -> Unit, private val onWalletSelect: (UserWalletId) -> Unit, - private val onContinueClick: ( - selectedWalletId: UserWalletId, - addedNetworks: Set, - removedNetworks: Set, - ) -> Unit, + private val onContinueClick: (selectedWalletId: UserWalletId, addedNetworks: Set) -> Unit, ) { /** * Create [TangemBottomSheetConfig] * - * @param portfolioData portfolio data - * @param portfolioUIData portfolio bottom sheet visibility model - * @param selectedWallet selected wallet - * @param networksWithToggle networks with toggle - * @param isUserChangedNetworks flag indicates if user changed networks + * @param portfolioData portfolio data + * @param portfolioUIData portfolio bottom sheet visibility model + * @param selectedWallet selected wallet + * @param alreadyAddedNetworks already added networks */ fun create( portfolioData: PortfolioData, portfolioUIData: PortfolioUIData, selectedWallet: UserWallet, - networksWithToggle: Map, - isUserChangedNetworks: Boolean, + alreadyAddedNetworks: Set, ): TangemBottomSheetConfig { return TangemBottomSheetConfig( isShow = portfolioUIData.portfolioBSVisibilityModel.addToPortfolioBSVisibility, @@ -59,11 +53,17 @@ internal class AddToPortfolioBSContentUMFactory( content = AddToPortfolioBSContentUM( selectedWallet = selectedWallet.toSelectedUserWalletItemUM(), selectNetworkUM = SelectNetworkUMConverter( - networksWithToggle = networksWithToggle, + networksWithToggle = portfolioUIData.addToPortfolioData.associateWithToggle( + userWalletId = selectedWallet.walletId, + alreadyAddedNetworkIds = alreadyAddedNetworks, + ), + alreadyAddedNetworks = alreadyAddedNetworks, onNetworkSwitchClick = onNetworkSwitchClick, ).convert(value = token), isScanCardNotificationVisible = portfolioUIData.hasMissedDerivations, - continueButtonEnabled = isUserChangedNetworks, + continueButtonEnabled = portfolioUIData.addToPortfolioData.isUserChangedNetworks( + userWalletId = selectedWallet.walletId, + ), onContinueButtonClick = { val alreadyAddedNetworkIds = portfolioData.walletsWithCurrencies[selectedWallet].orEmpty() .map { it.status.currency.network.backendId } @@ -75,10 +75,6 @@ internal class AddToPortfolioBSContentUMFactory( userWalletId = selectedWallet.walletId, alreadyAddedNetworkIds = alreadyAddedNetworkIds, ), - portfolioUIData.addToPortfolioData.getRemovedNetworks( - userWalletId = selectedWallet.walletId, - alreadyAddedNetworkIds = alreadyAddedNetworkIds, - ), ) }, walletSelectorConfig = crateWalletSelectorBSConfig( diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/BlockchainRowUMConverter.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/BlockchainRowUMConverter.kt index b80d71c2d1..09be6a8976 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/BlockchainRowUMConverter.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/BlockchainRowUMConverter.kt @@ -10,9 +10,13 @@ import com.tangem.utils.converter.Converter /** * Converter from [TokenMarketInfo.Network] to [BlockchainRowUM] * + * @property alreadyAddedNetworks set of already added networks + * [REDACTED_AUTHOR] */ -internal object BlockchainRowUMConverter : Converter, BlockchainRowUM> { +internal class BlockchainRowUMConverter( + private val alreadyAddedNetworks: Set, +) : Converter, BlockchainRowUM> { override fun convert(value: Pair): BlockchainRowUM { val (network, isSelected) = value @@ -22,17 +26,24 @@ internal object BlockchainRowUMConverter : Converter, - removedNetworks: Set, - ) { + private fun onContinueClick(userWalletId: UserWalletId, addedNetworks: Set) { modelScope.launch { saveMarketTokensUseCase( userWalletId = userWalletId, tokenMarketParams = params.token, addedNetworks = addedNetworks, - removedNetworks = removedNetworks, + removedNetworks = emptySet(), ) onAddToPortfolioBSVisibilityChange(isShow = false) diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MyPortfolioUMFactory.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MyPortfolioUMFactory.kt index e9b8527b12..7cc596fc95 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MyPortfolioUMFactory.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/MyPortfolioUMFactory.kt @@ -95,11 +95,7 @@ internal class MyPortfolioUMFactory( portfolioData = portfolioData, portfolioUIData = portfolioUIData, selectedWallet = selectedWallet, - networksWithToggle = portfolioUIData.addToPortfolioData.associateWithToggle( - userWalletId = selectedWallet.walletId, - alreadyAddedNetworkIds = alreadyAddedNetworks, - ), - isUserChangedNetworks = portfolioUIData.addToPortfolioData.isUserChangedNetworks(selectedWallet.walletId), + alreadyAddedNetworks = alreadyAddedNetworks, ) } diff --git a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/SelectNetworkUMConverter.kt b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/SelectNetworkUMConverter.kt index ea02d5c805..d7d84b6bcb 100644 --- a/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/SelectNetworkUMConverter.kt +++ b/features/markets/impl/src/main/kotlin/com/tangem/features/markets/portfolio/impl/model/SelectNetworkUMConverter.kt @@ -10,12 +10,14 @@ import kotlinx.collections.immutable.toImmutableList * Converter from [TokenMarketParams] to [SelectNetworkUM] * * @property networksWithToggle map of networks with toggles + * @property alreadyAddedNetworks already added networks * @property onNetworkSwitchClick callback is called when network switch is clicked * [REDACTED_AUTHOR] */ internal class SelectNetworkUMConverter( private val networksWithToggle: Map, + private val alreadyAddedNetworks: Set, private val onNetworkSwitchClick: (String, Boolean) -> Unit, ) : Converter { @@ -25,7 +27,9 @@ internal class SelectNetworkUMConverter( iconUrl = value.imageUrl, tokenName = value.name, tokenCurrencySymbol = value.symbol, - networks = BlockchainRowUMConverter.convertList(networksWithToggle.toList()).toImmutableList(), + networks = BlockchainRowUMConverter(alreadyAddedNetworks) + .convertList(networksWithToggle.toList()) + .toImmutableList(), onNetworkSwitchClick = { um, isChecked -> onNetworkSwitchClick(um.id, isChecked) }, ) } 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 19080cb275..524c8bfd4f 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 @@ -224,9 +224,13 @@ private fun NetworkSelection(state: SelectNetworkUM, modifier: Modifier = Modifi action = { TangemSwitch( checked = network.isSelected, - onCheckedChange = { - state.onNetworkSwitchClick(network, it) + checkedColor = if (network.isEnabled) { + TangemTheme.colors.control.checked + } else { + TangemTheme.colors.icon.inactive }, + onCheckedChange = { state.onNetworkSwitchClick(network, it) }, + enabled = network.isEnabled, ) }, )