Skip to content

Commit 77cb6ac

Browse files
committed
fix: activity boosting icon update
1 parent 0ead374 commit 77cb6ac

File tree

2 files changed

+112
-40
lines changed

2 files changed

+112
-40
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package to.bitkit.ext
22

33
import com.synonym.bitkitcore.Activity
4+
import com.synonym.bitkitcore.PaymentState
45
import com.synonym.bitkitcore.PaymentType
56

67
fun Activity.rawId(): String = when (this) {
@@ -19,7 +20,7 @@ fun Activity.rawId(): String = when (this) {
1920
*
2021
* @return The total value as an `ULong`.
2122
*/
22-
fun Activity.totalValue() = when(this) {
23+
fun Activity.totalValue() = when (this) {
2324
is Activity.Lightning -> v1.value + (v1.fee ?: 0u)
2425
is Activity.Onchain -> when (v1.txType) {
2526
PaymentType.SENT -> v1.value + v1.fee
@@ -37,6 +38,11 @@ fun Activity.isBoosted() = when (this) {
3738
else -> false
3839
}
3940

41+
fun Activity.isFinished() = when (this) {
42+
is Activity.Onchain -> v1.confirmed
43+
is Activity.Lightning -> v1.status != PaymentState.PENDING
44+
}
45+
4046
fun Activity.matchesPaymentId(paymentHashOrTxId: String): Boolean = when (this) {
4147
is Activity.Lightning -> paymentHashOrTxId == v1.id
4248
is Activity.Onchain -> paymentHashOrTxId == v1.txId

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

Lines changed: 105 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import com.synonym.bitkitcore.OnchainActivity
2323
import com.synonym.bitkitcore.PaymentState
2424
import com.synonym.bitkitcore.PaymentType
2525
import to.bitkit.R
26+
import to.bitkit.ext.isBoosted
27+
import to.bitkit.ext.isFinished
2628
import to.bitkit.ui.theme.AppThemeSurface
2729
import to.bitkit.ui.theme.Colors
2830

@@ -43,49 +45,63 @@ fun ActivityIcon(
4345
}
4446
val arrowIcon = painterResource(if (txType == PaymentType.SENT) R.drawable.ic_sent else R.drawable.ic_received)
4547

46-
if (isLightning) {
47-
when (status) {
48-
PaymentState.FAILED -> {
49-
CircularIcon(
50-
icon = painterResource(R.drawable.ic_x),
51-
iconColor = Colors.Purple,
52-
backgroundColor = Colors.Purple16,
53-
size = size,
54-
modifier = modifier,
55-
)
56-
}
48+
when {
49+
activity.isBoosted() && !activity.isFinished() -> {
50+
CircularIcon(
51+
icon = painterResource(R.drawable.ic_timer_alt),
52+
iconColor = Colors.Yellow,
53+
backgroundColor = Colors.Yellow16,
54+
size = size,
55+
modifier = modifier,
56+
)
57+
}
5758

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

68-
else -> {
69-
CircularIcon(
70-
icon = arrowIcon,
71-
iconColor = Colors.Purple,
72-
backgroundColor = Colors.Purple16,
73-
size = size,
74-
modifier = modifier,
75-
)
71+
PaymentState.PENDING -> {
72+
CircularIcon(
73+
icon = painterResource(R.drawable.ic_hourglass_simple),
74+
iconColor = Colors.Purple,
75+
backgroundColor = Colors.Purple16,
76+
size = size,
77+
modifier = modifier,
78+
)
79+
}
80+
81+
else -> {
82+
CircularIcon(
83+
icon = arrowIcon,
84+
iconColor = Colors.Purple,
85+
backgroundColor = Colors.Purple16,
86+
size = size,
87+
modifier = modifier,
88+
)
89+
}
7690
}
7791
}
78-
} else {
79-
val isTransfer = (activity as? Activity.Onchain)?.v1?.isTransfer == true
80-
val onChainIcon = if (isTransfer) painterResource(R.drawable.ic_transfer) else arrowIcon
81-
82-
CircularIcon(
83-
icon = onChainIcon,
84-
iconColor = Colors.Brand,
85-
backgroundColor = Colors.Brand16,
86-
size = size,
87-
modifier = modifier,
88-
)
92+
93+
else -> {
94+
val isTransfer = (activity as? Activity.Onchain)?.v1?.isTransfer == true
95+
val onChainIcon = if (isTransfer) painterResource(R.drawable.ic_transfer) else arrowIcon
96+
97+
CircularIcon(
98+
icon = onChainIcon,
99+
iconColor = Colors.Brand,
100+
backgroundColor = Colors.Brand16,
101+
size = size,
102+
modifier = modifier,
103+
)
104+
}
89105
}
90106
}
91107

@@ -202,6 +218,56 @@ private fun Preview() {
202218
)
203219
)
204220

221+
// Onchain BOOST CPFP
222+
ActivityIcon(
223+
activity = Activity.Onchain(
224+
v1 = OnchainActivity(
225+
id = "test-onchain-1",
226+
txType = PaymentType.RECEIVED,
227+
txId = "abc123",
228+
value = 100000uL,
229+
fee = 500uL,
230+
feeRate = 8uL,
231+
address = "bc1...",
232+
confirmed = false,
233+
timestamp = (System.currentTimeMillis() / 1000).toULong(),
234+
isBoosted = true,
235+
isTransfer = false,
236+
doesExist = true,
237+
confirmTimestamp = (System.currentTimeMillis() / 1000).toULong(),
238+
channelId = null,
239+
transferTxId = null,
240+
createdAt = null,
241+
updatedAt = null,
242+
)
243+
)
244+
)
245+
246+
// Onchain BOOST RBF
247+
ActivityIcon(
248+
activity = Activity.Onchain(
249+
v1 = OnchainActivity(
250+
id = "test-onchain-1",
251+
txType = PaymentType.SENT,
252+
txId = "abc123",
253+
value = 100000uL,
254+
fee = 500uL,
255+
feeRate = 8uL,
256+
address = "bc1...",
257+
confirmed = false,
258+
timestamp = (System.currentTimeMillis() / 1000).toULong(),
259+
isBoosted = true,
260+
isTransfer = false,
261+
doesExist = true,
262+
confirmTimestamp = (System.currentTimeMillis() / 1000).toULong(),
263+
channelId = null,
264+
transferTxId = null,
265+
createdAt = null,
266+
updatedAt = null,
267+
)
268+
)
269+
)
270+
205271
// Onchain Transfer
206272
ActivityIcon(
207273
activity = Activity.Onchain(

0 commit comments

Comments
 (0)