Skip to content

Commit e0fc9c1

Browse files
committed
chore: lint
1 parent 8cd39ac commit e0fc9c1

File tree

9 files changed

+167
-150
lines changed

9 files changed

+167
-150
lines changed

app/src/main/java/to/bitkit/domain/commands/NotifyPaymentReceived.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ sealed interface NotifyPaymentReceived {
3434

3535
is Event.OnchainTransactionReceived -> {
3636
val amountSats = event.details.amountSats
37-
if (amountSats <= 0) null
38-
else Onchain(
37+
Onchain(
3938
sats = amountSats.toULong(),
4039
paymentId = event.txid,
4140
includeNotification = includeNotification,
42-
)
41+
).takeIf {
42+
amountSats > 0
43+
}
4344
}
4445

4546
else -> null

app/src/main/java/to/bitkit/ext/Activities.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ fun Activity.isFinished() = when (this) {
4848
is Activity.Lightning -> v1.status != PaymentState.PENDING
4949
}
5050

51+
fun Activity.isBoosting(): Boolean = isBoosted() && !isFinished() && doesExist()
52+
5153
fun Activity.isSent() = when (this) {
5254
is Activity.Lightning -> v1.txType == PaymentType.SENT
5355
is Activity.Onchain -> v1.txType == PaymentType.SENT
@@ -62,6 +64,11 @@ fun Activity.isTransfer() = this is Activity.Onchain && this.v1.isTransfer
6264

6365
fun Activity.doesExist() = this is Activity.Onchain && this.v1.doesExist
6466

67+
fun Activity.paymentState(): PaymentState? = when (this) {
68+
is Activity.Lightning -> this.v1.status
69+
is Activity.Onchain -> null
70+
}
71+
6572
fun Activity.Onchain.boostType() = when (this.v1.txType) {
6673
PaymentType.SENT -> BoostType.RBF
6774
PaymentType.RECEIVED -> BoostType.CPFP

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ import androidx.compose.material.icons.filled.Close
2626
import androidx.compose.material3.Icon
2727
import androidx.compose.material3.IconButton
2828
import androidx.compose.runtime.Composable
29+
import androidx.compose.runtime.ReadOnlyComposable
2930
import androidx.compose.ui.Alignment
3031
import androidx.compose.ui.Modifier
3132
import androidx.compose.ui.graphics.Brush.Companion.verticalGradient
3233
import androidx.compose.ui.graphics.Color
33-
import androidx.compose.ui.res.stringResource
3434
import androidx.compose.ui.platform.testTag
35+
import androidx.compose.ui.res.stringResource
3536
import androidx.compose.ui.tooling.preview.Preview
3637
import androidx.compose.ui.unit.dp
3738
import to.bitkit.R
3839
import to.bitkit.models.Toast
40+
import to.bitkit.ui.scaffold.ScreenColumn
3941
import to.bitkit.ui.theme.AppThemeSurface
4042
import to.bitkit.ui.theme.Colors
4143

@@ -44,21 +46,8 @@ fun ToastView(
4446
toast: Toast,
4547
onDismiss: () -> Unit,
4648
) {
47-
val tintColor = when (toast.type) {
48-
Toast.ToastType.SUCCESS -> Colors.Green
49-
Toast.ToastType.INFO -> Colors.Blue
50-
Toast.ToastType.LIGHTNING -> Colors.Purple
51-
Toast.ToastType.WARNING -> Colors.Brand
52-
Toast.ToastType.ERROR -> Colors.Red
53-
}
54-
55-
val gradientColor = when (toast.type) {
56-
Toast.ToastType.SUCCESS -> Color(0XFF1D2F1C)
57-
Toast.ToastType.INFO -> Color(0XFF032E56)
58-
Toast.ToastType.LIGHTNING -> Color(0XFF2B1637)
59-
Toast.ToastType.WARNING -> Color(0XFF3C1001)
60-
Toast.ToastType.ERROR -> Color(0XFF491F25)
61-
}
49+
val tintColor = toast.tintColor()
50+
val gradientColor = toast.gradientColor()
6251

6352
Box(
6453
contentAlignment = Alignment.CenterStart,
@@ -140,7 +129,7 @@ fun ToastOverlay(
140129
@Composable
141130
private fun ToastViewPreview() {
142131
AppThemeSurface {
143-
Column(
132+
ScreenColumn(
144133
verticalArrangement = Arrangement.spacedBy(16.dp),
145134
) {
146135
ToastView(
@@ -189,3 +178,24 @@ private fun ToastViewPreview() {
189178
}
190179
}
191180
}
181+
182+
@Suppress("MagicNumber")
183+
@ReadOnlyComposable
184+
@Composable
185+
private fun Toast.gradientColor(): Color = when (type) {
186+
Toast.ToastType.SUCCESS -> Color(0XFF1D2F1C)
187+
Toast.ToastType.INFO -> Color(0XFF032E56)
188+
Toast.ToastType.LIGHTNING -> Color(0XFF2B1637)
189+
Toast.ToastType.WARNING -> Color(0XFF3C1001)
190+
Toast.ToastType.ERROR -> Color(0XFF491F25)
191+
}
192+
193+
@ReadOnlyComposable
194+
@Composable
195+
private fun Toast.tintColor(): Color = when (type) {
196+
Toast.ToastType.SUCCESS -> Colors.Green
197+
Toast.ToastType.INFO -> Colors.Blue
198+
Toast.ToastType.LIGHTNING -> Colors.Purple
199+
Toast.ToastType.WARNING -> Colors.Brand
200+
Toast.ToastType.ERROR -> Colors.Red
201+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ fun ActivityDetailScreen(
189189
}
190190
}
191191

192+
@Suppress("CyclomaticComplexMethod")
192193
@Composable
193194
private fun ActivityDetailContent(
194195
item: Activity,

app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/ActivityIcon.kt

Lines changed: 65 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import com.synonym.bitkitcore.PaymentState
2525
import com.synonym.bitkitcore.PaymentType
2626
import to.bitkit.R
2727
import to.bitkit.ext.doesExist
28-
import to.bitkit.ext.isBoosted
29-
import to.bitkit.ext.isFinished
28+
import to.bitkit.ext.isBoosting
3029
import to.bitkit.ext.isTransfer
30+
import to.bitkit.ext.paymentState
3131
import to.bitkit.ext.txType
3232
import to.bitkit.ui.theme.AppThemeSurface
3333
import to.bitkit.ui.theme.Colors
@@ -39,15 +39,13 @@ fun ActivityIcon(
3939
modifier: Modifier = Modifier,
4040
) {
4141
val isLightning = activity is Activity.Lightning
42-
val status: PaymentState? = when (activity) {
43-
is Activity.Lightning -> activity.v1.status
44-
is Activity.Onchain -> null
45-
}
46-
val txType: PaymentType = activity.txType()
42+
val isBoosting = activity.isBoosting()
43+
val status = activity.paymentState()
44+
val txType = activity.txType()
4745
val arrowIcon = painterResource(if (txType == PaymentType.SENT) R.drawable.ic_sent else R.drawable.ic_received)
4846

4947
when {
50-
activity.isBoosted() && !activity.isFinished() && activity.doesExist() -> {
48+
isBoosting -> {
5149
CircularIcon(
5250
icon = painterResource(R.drawable.ic_timer_alt),
5351
iconColor = Colors.Yellow,
@@ -57,57 +55,71 @@ fun ActivityIcon(
5755
)
5856
}
5957

60-
isLightning -> {
61-
when (status) {
62-
PaymentState.FAILED -> {
63-
CircularIcon(
64-
icon = painterResource(R.drawable.ic_x),
65-
iconColor = Colors.Purple,
66-
backgroundColor = Colors.Purple16,
67-
size = size,
68-
modifier = modifier,
69-
)
70-
}
58+
isLightning -> ActivityIconLightning(status, size, arrowIcon, modifier)
59+
else -> ActivityIconOnchain(activity, arrowIcon, size, modifier)
60+
}
61+
}
7162

72-
PaymentState.PENDING -> {
73-
CircularIcon(
74-
icon = painterResource(R.drawable.ic_hourglass_simple),
75-
iconColor = Colors.Purple,
76-
backgroundColor = Colors.Purple16,
77-
size = size,
78-
modifier = modifier,
79-
)
80-
}
63+
@Composable
64+
private fun ActivityIconOnchain(
65+
activity: Activity,
66+
arrowIcon: Painter,
67+
size: Dp,
68+
modifier: Modifier = Modifier,
69+
) {
70+
val isTransfer = activity.isTransfer()
71+
val isTransferFromSpending = isTransfer && activity.txType() == PaymentType.RECEIVED
72+
val transferIconColor = if (isTransferFromSpending) Colors.Purple else Colors.Brand
73+
val transferBackgroundColor = if (isTransferFromSpending) Colors.Purple16 else Colors.Brand16
8174

82-
else -> {
83-
CircularIcon(
84-
icon = arrowIcon,
85-
iconColor = Colors.Purple,
86-
backgroundColor = Colors.Purple16,
87-
size = size,
88-
modifier = modifier,
89-
)
90-
}
91-
}
75+
CircularIcon(
76+
icon = when {
77+
!activity.doesExist() -> painterResource(R.drawable.ic_x)
78+
isTransfer -> painterResource(R.drawable.ic_transfer)
79+
else -> arrowIcon
80+
},
81+
iconColor = if (isTransfer) transferIconColor else Colors.Brand,
82+
backgroundColor = if (isTransfer) transferBackgroundColor else Colors.Brand16,
83+
size = size,
84+
modifier = modifier.testTag(if (isTransfer) "TransferIcon" else "ActivityIcon"),
85+
)
86+
}
87+
88+
@Composable
89+
private fun ActivityIconLightning(
90+
status: PaymentState?,
91+
size: Dp,
92+
arrowIcon: Painter,
93+
modifier: Modifier = Modifier,
94+
) {
95+
when (status) {
96+
PaymentState.FAILED -> {
97+
CircularIcon(
98+
icon = painterResource(R.drawable.ic_x),
99+
iconColor = Colors.Purple,
100+
backgroundColor = Colors.Purple16,
101+
size = size,
102+
modifier = modifier,
103+
)
92104
}
93105

94-
// onchain
95-
else -> {
96-
val isTransfer = activity.isTransfer()
97-
val isTransferFromSpending = isTransfer && activity.txType() == PaymentType.RECEIVED
98-
val transferIconColor = if (isTransferFromSpending) Colors.Purple else Colors.Brand
99-
val transferBackgroundColor = if (isTransferFromSpending) Colors.Purple16 else Colors.Brand16
106+
PaymentState.PENDING -> {
107+
CircularIcon(
108+
icon = painterResource(R.drawable.ic_hourglass_simple),
109+
iconColor = Colors.Purple,
110+
backgroundColor = Colors.Purple16,
111+
size = size,
112+
modifier = modifier,
113+
)
114+
}
100115

116+
else -> {
101117
CircularIcon(
102-
icon = when {
103-
!activity.doesExist() -> painterResource(R.drawable.ic_x)
104-
isTransfer -> painterResource(R.drawable.ic_transfer)
105-
else -> arrowIcon
106-
},
107-
iconColor = if (isTransfer) transferIconColor else Colors.Brand,
108-
backgroundColor = if (isTransfer) transferBackgroundColor else Colors.Brand16,
118+
icon = arrowIcon,
119+
iconColor = Colors.Purple,
120+
backgroundColor = Colors.Purple16,
109121
size = size,
110-
modifier = modifier.testTag(if (isTransfer) "TransferIcon" else "ActivityIcon"),
122+
modifier = modifier,
111123
)
112124
}
113125
}
@@ -122,7 +134,7 @@ fun CircularIcon(
122134
modifier: Modifier = Modifier,
123135
) {
124136
Box(
125-
contentAlignment = Alignment.Companion.Center,
137+
contentAlignment = Alignment.Center,
126138
modifier = modifier
127139
.size(size)
128140
.background(backgroundColor, CircleShape)

app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/EmptyActivityRow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fun EmptyActivityRow(
2727
modifier: Modifier = Modifier,
2828
) {
2929
Row(
30-
verticalAlignment = Alignment.Companion.CenterVertically,
30+
verticalAlignment = Alignment.CenterVertically,
3131
modifier = modifier
3232
.fillMaxWidth()
3333
.padding(vertical = 16.dp)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fun SendRecipientScreen(
119119
Image(
120120
painter = painterResource(R.drawable.coin_stack_logo),
121121
contentDescription = null,
122-
contentScale = ContentScale.Companion.FillWidth,
122+
contentScale = ContentScale.FillWidth,
123123
modifier = Modifier.fillMaxWidth()
124124
)
125125
}

0 commit comments

Comments
 (0)