Skip to content

Commit c334b3d

Browse files
committed
refactor: share hw wallet icon
1 parent cd799ce commit c334b3d

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.BoxWithConstraints
55
import androidx.compose.foundation.layout.BoxWithConstraintsScope
66
import androidx.compose.foundation.layout.offset
77
import androidx.compose.foundation.layout.size
8+
import androidx.compose.material3.Icon
89
import androidx.compose.runtime.Composable
910
import androidx.compose.ui.Alignment
1011
import androidx.compose.ui.Modifier
@@ -14,6 +15,8 @@ import androidx.compose.ui.res.painterResource
1415
import androidx.compose.ui.unit.Dp
1516
import androidx.compose.ui.unit.dp
1617
import to.bitkit.R
18+
import to.bitkit.models.TransportType
19+
import to.bitkit.ui.theme.Colors
1720

1821
// Device illustration proportions, taken from the Figma hardware wallet frames.
1922
private const val HW_DEVICE_IMAGE_SIZE_RATIO = 256f / 375f
@@ -35,6 +38,26 @@ fun HwDeviceIllustrations(modifier: Modifier = Modifier) {
3538
}
3639
}
3740

41+
@Composable
42+
fun HwWalletConnectionIcon(
43+
transportType: TransportType,
44+
isConnected: Boolean,
45+
modifier: Modifier = Modifier,
46+
contentDescription: String? = null,
47+
) {
48+
Icon(
49+
painter = painterResource(
50+
id = when (transportType) {
51+
TransportType.BLUETOOTH -> R.drawable.ic_bluetooth_connected
52+
TransportType.USB -> R.drawable.ic_usb_connected
53+
}
54+
),
55+
contentDescription = contentDescription,
56+
tint = if (isConnected) Colors.Green else Colors.Gray1,
57+
modifier = modifier
58+
)
59+
}
60+
3861
@Composable
3962
private fun BoxWithConstraintsScope.TrezorImage(
4063
imageSize: Dp,

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ import to.bitkit.ui.components.FillHeight
137137
import to.bitkit.ui.components.FillWidth
138138
import to.bitkit.ui.components.Headline24
139139
import to.bitkit.ui.components.HorizontalSpacer
140+
import to.bitkit.ui.components.HwWalletConnectionIcon
140141
import to.bitkit.ui.components.PubkyImage
141142
import to.bitkit.ui.components.Sheet
142143
import to.bitkit.ui.components.StatusBarSpacer
@@ -779,15 +780,9 @@ private fun RowScope.HwDeviceCell(
779780
.testTag("ActivityHardware")
780781
) {
781782
HorizontalSpacer(4.dp)
782-
Icon(
783-
painter = painterResource(
784-
id = when (wallet.transportType) {
785-
TransportType.BLUETOOTH -> R.drawable.ic_bluetooth_connected
786-
TransportType.USB -> R.drawable.ic_usb_connected
787-
}
788-
),
789-
contentDescription = null,
790-
tint = if (wallet.isConnected) Colors.Green else Colors.Gray1,
783+
HwWalletConnectionIcon(
784+
transportType = wallet.transportType,
785+
isConnected = wallet.isConnected,
791786
modifier = Modifier.size(16.dp)
792787
)
793788
}

app/src/main/java/to/bitkit/ui/settings/general/HardwareWalletsSettingsScreen.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import to.bitkit.ui.components.BodyM
4040
import to.bitkit.ui.components.Display
4141
import to.bitkit.ui.components.HorizontalSpacer
4242
import to.bitkit.ui.components.HwDeviceIllustrations
43+
import to.bitkit.ui.components.HwWalletConnectionIcon
4344
import to.bitkit.ui.components.MoneySSB
4445
import to.bitkit.ui.components.PrimaryButton
4546
import to.bitkit.ui.components.VerticalSpacer
@@ -237,15 +238,10 @@ private fun HwConnectionBadge(
237238
.clip(CircleShape)
238239
.background(if (isConnected) Colors.Green16 else Colors.White16)
239240
) {
240-
Icon(
241-
painter = painterResource(
242-
id = when (transportType) {
243-
TransportType.BLUETOOTH -> R.drawable.ic_bluetooth_connected
244-
TransportType.USB -> R.drawable.ic_usb_connected
245-
}
246-
),
241+
HwWalletConnectionIcon(
242+
transportType = transportType,
243+
isConnected = isConnected,
247244
contentDescription = contentDescription,
248-
tint = if (isConnected) Colors.Green else Colors.White64,
249245
modifier = Modifier.size(16.dp)
250246
)
251247
}

0 commit comments

Comments
 (0)