From 8a46d815b9fb0947f6e13213c5bd94c05dfe07f5 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 13 Jul 2023 08:59:18 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../marketprice/MarketPriceBlock.kt | 56 ++++++++++--------- .../marketprice/MarketPriceBlockState.kt | 17 ++++++ .../marketprice/PriceChangeConfig.kt | 9 +++ .../presentation/common/WalletPreviewData.kt | 21 ++++--- .../common/component/TokenItem.kt | 2 +- .../common/state/PriceChangeConfig.kt | 15 ----- .../common/state/TokenItemState.kt | 1 + .../state/WalletMarketplaceBlockState.kt | 33 ----------- .../wallet/state/WalletStateHolder.kt | 5 +- .../presentation/wallet/ui/WalletScreen.kt | 6 +- 10 files changed, 74 insertions(+), 91 deletions(-) rename features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/WalletMarketplaceBlock.kt => core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt (74%) create mode 100644 core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlockState.kt create mode 100644 core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeConfig.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/PriceChangeConfig.kt delete mode 100644 features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMarketplaceBlockState.kt diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/WalletMarketplaceBlock.kt b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt similarity index 74% rename from features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/WalletMarketplaceBlock.kt rename to core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt index 7033b42c61..d7f217308c 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/components/singlecurrency/WalletMarketplaceBlock.kt +++ b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlock.kt @@ -1,4 +1,4 @@ -package com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency +package com.tangem.core.ui.components.marketprice import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -17,22 +17,17 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import androidx.compose.ui.unit.Dp +import com.tangem.core.ui.R import com.tangem.core.ui.components.RectangleShimmer import com.tangem.core.ui.res.TangemTheme -import com.tangem.feature.wallet.impl.R -import com.tangem.feature.wallet.presentation.common.WalletPreviewData -import com.tangem.feature.wallet.presentation.common.state.PriceChangeConfig -import com.tangem.feature.wallet.presentation.wallet.state.WalletMarketplaceBlockState /** - * Wallet marketplace block - * - * @param state state - * -[REDACTED_AUTHOR] + * @see Figma component */ @Composable -internal fun WalletMarketplaceBlock(state: WalletMarketplaceBlockState, modifier: Modifier = Modifier) { +fun MarketPriceBlock(state: MarketPriceBlockState, modifier: Modifier = Modifier) { var rootWidth by remember { mutableStateOf(value = 0) } Column( modifier = modifier @@ -54,12 +49,12 @@ internal fun WalletMarketplaceBlock(state: WalletMarketplaceBlockState, modifier ) when (state) { - is WalletMarketplaceBlockState.Loading -> { + is MarketPriceBlockState.Loading -> { RectangleShimmer( modifier = Modifier.size(width = TangemTheme.dimens.size158, height = TangemTheme.dimens.size20), ) } - is WalletMarketplaceBlockState.Content -> { + is MarketPriceBlockState.Content -> { Price( config = state, priceWidthDp = with(LocalDensity.current) { rootWidth.div(other = 2).toDp() }, @@ -70,7 +65,7 @@ internal fun WalletMarketplaceBlock(state: WalletMarketplaceBlockState, modifier } @Composable -private fun Price(config: WalletMarketplaceBlockState.Content, priceWidthDp: Dp) { +private fun Price(config: MarketPriceBlockState.Content, priceWidthDp: Dp) { Row( modifier = Modifier, verticalAlignment = Alignment.CenterVertically, @@ -124,35 +119,44 @@ private fun PriceChangeInPercent(config: PriceChangeConfig) { @Preview @Composable -private fun Preview_MarketplaceBlock_Light( - @PreviewParameter(WalletMarketplaceStateProvider::class) - state: WalletMarketplaceBlockState, +private fun Preview_MarketPriceBlock_Light( + @PreviewParameter(WalletMarketPriceBlockStateProvider::class) + state: MarketPriceBlockState, ) { TangemTheme(isDark = false) { - WalletMarketplaceBlock(state = state) + MarketPriceBlock(state = state) } } @Preview @Composable -private fun Preview_MarketplaceBlock_Dark( - @PreviewParameter(WalletMarketplaceStateProvider::class) - state: WalletMarketplaceBlockState, +private fun Preview_MarketPriceBlock_Dark( + @PreviewParameter(WalletMarketPriceBlockStateProvider::class) + state: MarketPriceBlockState, ) { TangemTheme(isDark = true) { - WalletMarketplaceBlock(state = state) + MarketPriceBlock(state = state) } } -private class WalletMarketplaceStateProvider : CollectionPreviewParameterProvider( +private class WalletMarketPriceBlockStateProvider : CollectionPreviewParameterProvider( collection = listOf( - WalletPreviewData.marketplaceBlockContent, - WalletPreviewData.marketplaceBlockContent.copy( + MarketPriceBlockState.Content( + currencyName = "BTC", + price = "98900", priceChangeConfig = PriceChangeConfig( valueInPercent = "5.16%", type = PriceChangeConfig.Type.DOWN, ), ), - WalletMarketplaceBlockState.Loading(currencyName = "BTC"), + MarketPriceBlockState.Content( + currencyName = "BTC", + price = "98900", + priceChangeConfig = PriceChangeConfig( + valueInPercent = "10.89%", + type = PriceChangeConfig.Type.UP, + ), + ), + MarketPriceBlockState.Loading(currencyName = "BTC"), ), ) \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlockState.kt b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlockState.kt new file mode 100644 index 0000000000..ae59401aa9 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/MarketPriceBlockState.kt @@ -0,0 +1,17 @@ +package com.tangem.core.ui.components.marketprice + +import androidx.compose.runtime.Immutable + +@Immutable +sealed interface MarketPriceBlockState { + + val currencyName: String + + data class Loading(override val currencyName: String) : MarketPriceBlockState + + data class Content( + override val currencyName: String, + val price: String, + val priceChangeConfig: PriceChangeConfig, + ) : MarketPriceBlockState +} \ No newline at end of file diff --git a/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeConfig.kt b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeConfig.kt new file mode 100644 index 0000000000..60af2367e5 --- /dev/null +++ b/core/ui/src/main/java/com/tangem/core/ui/components/marketprice/PriceChangeConfig.kt @@ -0,0 +1,9 @@ +package com.tangem.core.ui.components.marketprice + +data class PriceChangeConfig(val valueInPercent: String, val type: Type) { + + /** Price changing type */ + enum class Type { + UP, DOWN + } +} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt index 6f6b726f82..c89bcc47ee 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/WalletPreviewData.kt @@ -1,8 +1,9 @@ package com.tangem.feature.wallet.presentation.common import com.tangem.core.ui.R +import com.tangem.core.ui.components.marketprice.MarketPriceBlockState +import com.tangem.core.ui.components.marketprice.PriceChangeConfig import com.tangem.core.ui.components.transactions.TransactionState -import com.tangem.feature.wallet.presentation.common.state.PriceChangeConfig import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.common.state.TokenItemState.TokenOptionsState import com.tangem.feature.wallet.presentation.organizetokens.DraggableItem @@ -204,15 +205,6 @@ internal object WalletPreviewData { WalletManageButton.CopyAddress(onClick = {}), ) - val marketplaceBlockContent = WalletMarketplaceBlockState.Content( - currencyName = "BTC", - price = "0.11$", - priceChangeConfig = PriceChangeConfig( - valueInPercent = "5.16%", - type = PriceChangeConfig.Type.UP, - ), - ) - val multicurrencyWalletScreenState = WalletStateHolder.MultiCurrencyContent( onBackClick = {}, topBarConfig = walletTopBarConfig, @@ -300,6 +292,13 @@ internal object WalletPreviewData { ), notifications = persistentListOf(WalletNotification.LikeTangemApp(onClick = {})), buttons = manageButtons, - marketplaceBlockState = marketplaceBlockContent, + marketPriceBlockState = MarketPriceBlockState.Content( + currencyName = "BTC", + price = "98900.12$", + priceChangeConfig = PriceChangeConfig( + valueInPercent = "5.16%", + type = PriceChangeConfig.Type.UP, + ), + ), ) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt index 62b877549a..5c4cb19fb7 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/TokenItem.kt @@ -28,11 +28,11 @@ import androidx.constraintlayout.compose.Dimension import coil.compose.SubcomposeAsyncImage import coil.request.ImageRequest import com.tangem.core.ui.components.* +import com.tangem.core.ui.components.marketprice.PriceChangeConfig import com.tangem.core.ui.res.TangemTheme import com.tangem.core.ui.res.TangemTypography import com.tangem.feature.wallet.impl.R import com.tangem.feature.wallet.presentation.common.WalletPreviewData -import com.tangem.feature.wallet.presentation.common.state.PriceChangeConfig import com.tangem.feature.wallet.presentation.common.state.TokenItemState import com.tangem.feature.wallet.presentation.common.state.TokenItemState.TokenOptionsState import org.burnoutcrew.reorderable.ReorderableLazyListState diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/PriceChangeConfig.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/PriceChangeConfig.kt deleted file mode 100644 index 9d6b4989ee..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/PriceChangeConfig.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.tangem.feature.wallet.presentation.common.state - -/** - * Price changing config - * - * @property valueInPercent value in percent - * @property type type [Type] - */ -internal data class PriceChangeConfig(val valueInPercent: String, val type: Type) { - - /** Price changing type */ - enum class Type { - UP, DOWN - } -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt index 5489b5e602..b1c8417e9e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/state/TokenItemState.kt @@ -2,6 +2,7 @@ package com.tangem.feature.wallet.presentation.common.state import androidx.annotation.DrawableRes import androidx.compose.runtime.Immutable +import com.tangem.core.ui.components.marketprice.PriceChangeConfig /** Token item state */ @Immutable diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMarketplaceBlockState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMarketplaceBlockState.kt deleted file mode 100644 index 591c548d9e..0000000000 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletMarketplaceBlockState.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.tangem.feature.wallet.presentation.wallet.state - -import com.tangem.feature.wallet.presentation.common.state.PriceChangeConfig - -/** - * Wallet marketplace component state - * - * @property currencyName currency name - * -[REDACTED_AUTHOR] - */ -internal sealed class WalletMarketplaceBlockState(open val currencyName: String) { - - /** - * Loading state - * - * @property currencyName currency name - */ - data class Loading(override val currencyName: String) : WalletMarketplaceBlockState(currencyName = currencyName) - - /** - * Content state - * - * @property currencyName currency name - * @property price price - * @property priceChangeConfig price change config - */ - data class Content( - override val currencyName: String, - val price: String, - val priceChangeConfig: PriceChangeConfig, - ) : WalletMarketplaceBlockState(currencyName = currencyName) -} \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt index 02b9d37a3d..b9b216a198 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/WalletStateHolder.kt @@ -1,5 +1,6 @@ package com.tangem.feature.wallet.presentation.wallet.state +import com.tangem.core.ui.components.marketprice.MarketPriceBlockState import kotlinx.collections.immutable.ImmutableList /** @@ -49,7 +50,7 @@ internal sealed class WalletStateHolder( * @property contentItems content items * @property notifications notifications * @property buttons manage buttons - * @property marketplaceBlockState marketplace block state + * @property marketPriceBlockState market price block state */ data class SingleCurrencyContent( override val onBackClick: () -> Unit, @@ -58,6 +59,6 @@ internal sealed class WalletStateHolder( override val contentItems: ImmutableList, override val notifications: ImmutableList, val buttons: ImmutableList, - val marketplaceBlockState: WalletMarketplaceBlockState, + val marketPriceBlockState: MarketPriceBlockState, ) : WalletStateHolder(onBackClick, topBarConfig, walletsListConfig, contentItems, notifications) } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt index 438aaf5d32..b89486d90e 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/ui/WalletScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider import com.tangem.core.ui.components.buttons.actions.ActionButtonConfig import com.tangem.core.ui.components.buttons.actions.RoundedActionButton +import com.tangem.core.ui.components.marketprice.MarketPriceBlock import com.tangem.core.ui.components.notifications.Notification import com.tangem.core.ui.components.transactions.Transaction import com.tangem.core.ui.res.TangemTheme @@ -33,7 +34,6 @@ import com.tangem.feature.wallet.presentation.wallet.ui.components.WalletsList import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.TransactionsBlockGroupTitle import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.TransactionsBlockTitle import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.WalletManageButtons -import com.tangem.feature.wallet.presentation.wallet.ui.components.singlecurrency.WalletMarketplaceBlock import com.tangem.feature.wallet.presentation.wallet.ui.decorations.walletContentItemDecoration import com.tangem.feature.wallet.presentation.wallet.ui.utils.changeWalletAnimator @@ -94,8 +94,8 @@ internal fun WalletScreen(state: WalletStateHolder) { if (state is WalletStateHolder.SingleCurrencyContent) { item { - WalletMarketplaceBlock( - state = state.marketplaceBlockState, + MarketPriceBlock( + state = state.marketPriceBlockState, modifier = changeableItemModifier .padding(top = TangemTheme.dimens.spacing14) .padding(horizontal = TangemTheme.dimens.spacing16),