Updated on 2026-08-14
This commit is contained in:
parent
177bdfad5a
commit
edfaa5320d
13 changed files with 347 additions and 32 deletions
|
|
@ -0,0 +1,16 @@
|
|||
package com.tangem.features.walletconnect.transaction.entity.blockaid
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
internal data class WcEstimatedWalletChangesUM(
|
||||
val items: ImmutableList<WcEstimatedWalletChangeUM>,
|
||||
)
|
||||
|
||||
internal data class WcEstimatedWalletChangeUM(
|
||||
@DrawableRes val iconRes: Int,
|
||||
val title: TextReference,
|
||||
val description: String,
|
||||
val tokenIconUrl: String,
|
||||
)
|
||||
|
|
@ -6,7 +6,6 @@ import androidx.compose.foundation.background
|
|||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
|
|
@ -14,11 +13,11 @@ import androidx.compose.ui.tooling.preview.Devices
|
|||
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 androidx.compose.ui.unit.dp
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
||||
import com.tangem.core.ui.components.bottomsheets.modal.TangemModalBottomSheet
|
||||
import com.tangem.core.ui.components.bottomsheets.modal.TangemModalBottomSheetTitle
|
||||
import com.tangem.core.ui.components.divider.DividerWithPadding
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
|
|
@ -112,18 +111,6 @@ private fun WcApproveTransactionItems(state: WcApproveTransactionItemUM) {
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DividerWithPadding(start: Dp, end: Dp) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(
|
||||
start = start,
|
||||
end = end,
|
||||
),
|
||||
thickness = TangemTheme.dimens.size1,
|
||||
color = TangemTheme.colors.stroke.primary,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO)
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
package com.tangem.features.walletconnect.transaction.ui.blockaid
|
||||
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import coil.compose.AsyncImage
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.features.walletconnect.impl.R
|
||||
import com.tangem.features.walletconnect.transaction.entity.blockaid.WcEstimatedWalletChangeUM
|
||||
|
||||
@Composable
|
||||
internal fun WcEstimatedWalletChangeRow(item: WcEstimatedWalletChangeUM, modifier: Modifier = Modifier) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = modifier
|
||||
.fillMaxWidth(),
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = item.iconRes),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
Box(
|
||||
modifier = Modifier.weight(1f),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = item.title.resolveReference(),
|
||||
style = TangemTheme.typography.body1,
|
||||
color = TangemTheme.colors.text.primary1,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
Text(
|
||||
text = item.description,
|
||||
style = TangemTheme.typography.body1,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
textAlign = TextAlign.End,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
|
||||
AsyncImage(
|
||||
model = item.tokenIconUrl,
|
||||
contentDescription = null,
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.clip(RoundedCornerShape(4.dp)),
|
||||
placeholder = painterResource(R.drawable.ic_nft_placeholder_20),
|
||||
error = painterResource(R.drawable.ic_nft_placeholder_20),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
package com.tangem.features.walletconnect.transaction.ui.blockaid
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.animation.animateContentSize
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Devices
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.graphics.vector.rememberVectorPainter
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import com.tangem.core.ui.components.divider.DividerWithPadding
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.features.walletconnect.impl.R
|
||||
import com.tangem.features.walletconnect.transaction.entity.blockaid.WcEstimatedWalletChangeUM
|
||||
import com.tangem.features.walletconnect.transaction.entity.blockaid.WcEstimatedWalletChangesUM
|
||||
import com.tangem.features.walletconnect.transaction.ui.common.WcSmallTitleItem
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
|
||||
private const val MAX_CHANGES_SIZE = 4
|
||||
|
||||
@Composable
|
||||
internal fun WcEstimatedWalletChangesItem(item: WcEstimatedWalletChangesUM, modifier: Modifier = Modifier) {
|
||||
var isExpanded by remember { mutableStateOf(false) }
|
||||
|
||||
Column(
|
||||
modifier = modifier
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(color = TangemTheme.colors.background.action)
|
||||
.fillMaxWidth()
|
||||
.animateContentSize(),
|
||||
) {
|
||||
WcSmallTitleItem(
|
||||
textRex = R.string.wc_estimated_wallet_changes,
|
||||
modifier = Modifier
|
||||
.padding(bottom = 16.dp),
|
||||
)
|
||||
|
||||
val itemsToDisplay = if (isExpanded) item.items else item.items.take(MAX_CHANGES_SIZE)
|
||||
|
||||
itemsToDisplay.forEachIndexed { idx, row ->
|
||||
key(row.hashCode()) {
|
||||
WcEstimatedWalletChangeRow(
|
||||
item = row,
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
)
|
||||
if (idx == item.items.lastIndex) {
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
} else {
|
||||
DividerWithPadding(start = 48.dp, end = 12.dp, top = 8.dp, bottom = 8.dp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (item.items.size > MAX_CHANGES_SIZE) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.clickable { isExpanded = !isExpanded }
|
||||
.padding(bottom = 12.dp, start = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(if (isExpanded) R.string.common_show_less else R.string.common_show_more),
|
||||
style = TangemTheme.typography.body1,
|
||||
color = TangemTheme.colors.text.tertiary,
|
||||
)
|
||||
Icon(
|
||||
painter = rememberVectorPainter(
|
||||
image = ImageVector.vectorResource(id = R.drawable.ic_chevron_24),
|
||||
),
|
||||
tint = TangemTheme.colors.icon.informative,
|
||||
modifier = Modifier
|
||||
.size(20.dp)
|
||||
.padding(start = 2.dp),
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO)
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
private fun EstimatedWalletChangesPreviewTwoItems(
|
||||
@PreviewParameter(EstimatedWalletChangesPreviewProviderTwoItems::class) item: WcEstimatedWalletChangesUM,
|
||||
) {
|
||||
TangemThemePreview {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(TangemTheme.colors.background.tertiary),
|
||||
) {
|
||||
WcEstimatedWalletChangesItem(item = item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO)
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
private fun EstimatedWalletChangesPreviewMoreThanFour(
|
||||
@PreviewParameter(EstimatedWalletChangesPreviewProviderManyItems::class) item: WcEstimatedWalletChangesUM,
|
||||
) {
|
||||
TangemThemePreview {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.background(TangemTheme.colors.background.tertiary),
|
||||
) {
|
||||
WcEstimatedWalletChangesItem(item = item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class EstimatedWalletChangesPreviewProviderTwoItems :
|
||||
PreviewParameterProvider<WcEstimatedWalletChangesUM> {
|
||||
override val values = sequenceOf(
|
||||
WcEstimatedWalletChangesUM(
|
||||
items = persistentListOf(
|
||||
WcEstimatedWalletChangeUM(
|
||||
iconRes = R.drawable.ic_send_new_24,
|
||||
title = resourceReference(R.string.common_send),
|
||||
description = "- 42 USDT",
|
||||
tokenIconUrl = "https://tangem.com",
|
||||
),
|
||||
WcEstimatedWalletChangeUM(
|
||||
iconRes = R.drawable.ic_recieve_new_24,
|
||||
title = resourceReference(R.string.common_receive),
|
||||
description = "+ 1,131.46 MATIC",
|
||||
tokenIconUrl = "https://tangem.com",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private class EstimatedWalletChangesPreviewProviderManyItems :
|
||||
PreviewParameterProvider<WcEstimatedWalletChangesUM> {
|
||||
override val values = sequenceOf(
|
||||
WcEstimatedWalletChangesUM(
|
||||
items = (1..6).map {
|
||||
WcEstimatedWalletChangeUM(
|
||||
iconRes = R.drawable.ic_send_new_24,
|
||||
title = resourceReference(R.string.common_send),
|
||||
description = "Nethers #1111",
|
||||
tokenIconUrl = "https://tangem.com",
|
||||
)
|
||||
}.toPersistentList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.Column
|
|||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
|
|
@ -16,11 +15,11 @@ import androidx.compose.ui.tooling.preview.Devices
|
|||
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 androidx.compose.ui.unit.dp
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
||||
import com.tangem.core.ui.components.bottomsheets.modal.TangemModalBottomSheet
|
||||
import com.tangem.core.ui.components.bottomsheets.modal.TangemModalBottomSheetTitle
|
||||
import com.tangem.core.ui.components.divider.DividerWithPadding
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
|
|
@ -109,18 +108,6 @@ private fun WcSignTransactionItems(state: WcSignTransactionItemUM) {
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DividerWithPadding(start: Dp, end: Dp) {
|
||||
HorizontalDivider(
|
||||
modifier = Modifier.padding(
|
||||
start = start,
|
||||
end = end,
|
||||
),
|
||||
thickness = 1.dp,
|
||||
color = TangemTheme.colors.stroke.primary,
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO)
|
||||
@Preview(showBackground = true, device = Devices.PIXEL_7_PRO, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue