Skip to content

Commit 477575a

Browse files
committed
fix: hw wallets 2-column grid on home
1 parent 51b3898 commit 477575a

2 files changed

Lines changed: 106 additions & 27 deletions

File tree

app/src/main/java/to/bitkit/ui/components/WalletBalanceView.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fun RowScope.WalletBalanceView(
4545
icon: Painter,
4646
modifier: Modifier = Modifier,
4747
currencies: CurrencyState = LocalCurrencies.current,
48+
titleTrailing: @Composable RowScope.() -> Unit = {},
4849
) {
4950
val isPreview = LocalInspectionMode.current
5051
if (isPreview) {
@@ -63,6 +64,7 @@ fun RowScope.WalletBalanceView(
6364
primaryDisplay = PrimaryDisplay.BITCOIN,
6465
displayUnit = BitcoinDisplayUnit.MODERN,
6566
hideBalance = false,
67+
titleTrailing = titleTrailing,
6668
)
6769
}
6870

@@ -83,6 +85,7 @@ fun RowScope.WalletBalanceView(
8385
primaryDisplay = primaryDisplay,
8486
displayUnit = displayUnit,
8587
hideBalance = hideBalance,
88+
titleTrailing = titleTrailing,
8689
)
8790
}
8891

@@ -95,16 +98,20 @@ private fun RowScope.Content(
9598
primaryDisplay: PrimaryDisplay,
9699
displayUnit: BitcoinDisplayUnit,
97100
hideBalance: Boolean,
101+
titleTrailing: @Composable RowScope.() -> Unit = {},
98102
) {
99103
Column(
100104
modifier = Modifier
101105
.weight(1f)
102106
.then(modifier)
103107
) {
104-
Text13Up(
105-
text = title,
106-
color = Colors.White64,
107-
)
108+
Row(verticalAlignment = Alignment.CenterVertically) {
109+
Text13Up(
110+
text = title,
111+
color = Colors.White64,
112+
)
113+
titleTrailing()
114+
}
108115
VerticalSpacer(8.dp)
109116

110117
converted?.let { converted ->

app/src/main/java/to/bitkit/ui/screens/wallets/HomeScreen.kt

Lines changed: 95 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import androidx.compose.foundation.layout.BoxWithConstraints
1717
import androidx.compose.foundation.layout.Column
1818
import androidx.compose.foundation.layout.IntrinsicSize
1919
import androidx.compose.foundation.layout.Row
20+
import androidx.compose.foundation.layout.RowScope
2021
import androidx.compose.foundation.layout.WindowInsets
2122
import androidx.compose.foundation.layout.asPaddingValues
2223
import androidx.compose.foundation.layout.fillMaxSize
@@ -131,6 +132,7 @@ import to.bitkit.ui.components.AppStatus
131132
import to.bitkit.ui.components.BalanceHeaderView
132133
import to.bitkit.ui.components.EmptyStateView
133134
import to.bitkit.ui.components.FillHeight
135+
import to.bitkit.ui.components.FillWidth
134136
import to.bitkit.ui.components.Headline24
135137
import to.bitkit.ui.components.HorizontalSpacer
136138
import to.bitkit.ui.components.PubkyImage
@@ -729,32 +731,44 @@ private fun BalancesSection(
729731
)
730732
}
731733

732-
hardwareWallets.forEach { wallet ->
734+
// Hardware wallets flow into a 2-column grid: a second device fills the
735+
// bottom-right column, additional devices wrap onto new rows.
736+
hardwareWallets.chunked(2).forEach { rowWallets ->
733737
VerticalSpacer(16.dp)
734-
HardwareWalletRow(wallet = wallet, onClick = onClickHardwareWallet)
738+
Row(
739+
modifier = Modifier
740+
.fillMaxWidth()
741+
.height(IntrinsicSize.Min)
742+
) {
743+
HardwareWalletCell(wallet = rowWallets[0], onClick = onClickHardwareWallet)
744+
VerticalDivider(color = Colors.Gray4)
745+
HorizontalSpacer(16.dp)
746+
val second = rowWallets.getOrNull(1)
747+
if (second != null) {
748+
HardwareWalletCell(wallet = second, onClick = onClickHardwareWallet)
749+
} else {
750+
FillWidth()
751+
}
752+
}
735753
}
736754
}
737755
}
738756

739757
@Composable
740-
private fun HardwareWalletRow(
758+
private fun RowScope.HardwareWalletCell(
741759
wallet: HwWallet,
742760
onClick: () -> Unit,
743761
) {
744-
Row(
745-
verticalAlignment = Alignment.CenterVertically,
762+
WalletBalanceView(
763+
title = wallet.name,
764+
sats = wallet.balanceSats.toLong(),
765+
icon = painterResource(id = R.drawable.ic_btc_circle_blue),
746766
modifier = Modifier
747-
.fillMaxWidth()
748-
.height(IntrinsicSize.Min)
749767
.clickableAlpha(onClick = onClick)
750768
.padding(vertical = 4.dp)
751769
.testTag("ActivityHardware")
752770
) {
753-
WalletBalanceView(
754-
title = wallet.name,
755-
sats = wallet.balanceSats.toLong(),
756-
icon = painterResource(id = R.drawable.ic_btc_circle_blue),
757-
)
771+
HorizontalSpacer(4.dp)
758772
Icon(
759773
painter = painterResource(
760774
id = when (wallet.transportType) {
@@ -1455,16 +1469,32 @@ private val previewWeather = WeatherModel(
14551469
private val previewLatestActivities = previewActivityItems.take(3).toImmutableList()
14561470
private val previewBanners = ActivityBannerType.entries.map { BannerItem(type = it, title = "") }.toImmutableList()
14571471
private val previewSuggestions = Suggestion.entries.take(4).toImmutableList()
1458-
private val previewHardwareWallets = persistentListOf(
1459-
HwWallet(
1460-
id = "trezor-1",
1461-
name = "Trezor Safe 5",
1462-
model = "Safe 5",
1463-
transportType = KnownDeviceTransportType.BLUETOOTH,
1464-
isConnected = true,
1465-
balanceSats = 10_562_411uL,
1466-
activities = persistentListOf(),
1467-
),
1472+
private val previewHardwareWalletBt = HwWallet(
1473+
id = "trezor-1",
1474+
name = "Trezor Safe 5",
1475+
model = "Safe 5",
1476+
transportType = KnownDeviceTransportType.BLUETOOTH,
1477+
isConnected = true,
1478+
balanceSats = 10_562_411uL,
1479+
activities = persistentListOf(),
1480+
)
1481+
private val previewHardwareWalletUsb = HwWallet(
1482+
id = "trezor-2",
1483+
name = "Trezor Model T",
1484+
model = "Model T",
1485+
transportType = KnownDeviceTransportType.USB,
1486+
isConnected = false,
1487+
balanceSats = 2_735_180uL,
1488+
activities = persistentListOf(),
1489+
)
1490+
private val previewHardwareWalletThird = HwWallet(
1491+
id = "trezor-3",
1492+
name = "Trezor Safe 3",
1493+
model = "Safe 3",
1494+
transportType = KnownDeviceTransportType.BLUETOOTH,
1495+
isConnected = true,
1496+
balanceSats = 500_000uL,
1497+
activities = persistentListOf(),
14681498
)
14691499

14701500
@Preview(showSystemUi = true)
@@ -1494,7 +1524,7 @@ private fun PreviewWithHardwareWallet() {
14941524
Content(
14951525
isRefreshing = false,
14961526
homeUiState = HomeUiState(
1497-
hardwareWallets = previewHardwareWallets,
1527+
hardwareWallets = persistentListOf(previewHardwareWalletBt),
14981528
),
14991529
drawerState = rememberDrawerState(initialValue = DrawerValue.Closed),
15001530
latestActivities = previewLatestActivities,
@@ -1505,6 +1535,48 @@ private fun PreviewWithHardwareWallet() {
15051535
}
15061536
}
15071537

1538+
@Preview(showSystemUi = true)
1539+
@Composable
1540+
private fun PreviewWithTwoHardwareWallets() {
1541+
AppThemeSurface {
1542+
Box {
1543+
Content(
1544+
isRefreshing = false,
1545+
homeUiState = HomeUiState(
1546+
hardwareWallets = persistentListOf(previewHardwareWalletBt, previewHardwareWalletUsb),
1547+
),
1548+
drawerState = rememberDrawerState(initialValue = DrawerValue.Closed),
1549+
latestActivities = previewLatestActivities,
1550+
balances = previewBalances.copy(totalHardwareSats = 13_297_591uL),
1551+
)
1552+
TabBar()
1553+
}
1554+
}
1555+
}
1556+
1557+
@Preview(showSystemUi = true)
1558+
@Composable
1559+
private fun PreviewWithThreeHardwareWallets() {
1560+
AppThemeSurface {
1561+
Box {
1562+
Content(
1563+
isRefreshing = false,
1564+
homeUiState = HomeUiState(
1565+
hardwareWallets = persistentListOf(
1566+
previewHardwareWalletBt,
1567+
previewHardwareWalletUsb,
1568+
previewHardwareWalletThird,
1569+
),
1570+
),
1571+
drawerState = rememberDrawerState(initialValue = DrawerValue.Closed),
1572+
latestActivities = previewLatestActivities,
1573+
balances = previewBalances.copy(totalHardwareSats = 13_797_591uL),
1574+
)
1575+
TabBar()
1576+
}
1577+
}
1578+
}
1579+
15081580
@Preview(showSystemUi = true)
15091581
@Composable
15101582
private fun PreviewEmpty() {

0 commit comments

Comments
 (0)