Skip to content

Commit d900a2c

Browse files
committed
feat: boosted parents ui on activity explore screen
1 parent 827c023 commit d900a2c

File tree

5 files changed

+67
-36
lines changed

5 files changed

+67
-36
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,21 @@ fun Activity.isFinished() = when (this) {
4343
is Activity.Lightning -> v1.status != PaymentState.PENDING
4444
}
4545

46+
fun Activity.isSent() = when (this) {
47+
is Activity.Lightning -> v1.txType == PaymentType.SENT
48+
is Activity.Onchain -> v1.txType == PaymentType.SENT
49+
}
50+
4651
fun Activity.matchesPaymentId(paymentHashOrTxId: String): Boolean = when (this) {
4752
is Activity.Lightning -> paymentHashOrTxId == v1.id
4853
is Activity.Onchain -> paymentHashOrTxId == v1.txId
4954
}
5055

5156
fun Activity.isTransfer() = this is Activity.Onchain && this.v1.isTransfer
57+
58+
fun Activity.Onchain.boostType() = when (this.v1.txType) {
59+
PaymentType.SENT -> BoostType.RBF
60+
PaymentType.RECEIVED -> BoostType.CPFP
61+
}
62+
63+
enum class BoostType { RBF, CPFP }

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import to.bitkit.R
4444
import to.bitkit.ext.canBeBoosted
4545
import to.bitkit.ext.ellipsisMiddle
4646
import to.bitkit.ext.isBoosted
47+
import to.bitkit.ext.isSent
4748
import to.bitkit.ext.isTransfer
4849
import to.bitkit.ext.rawId
4950
import to.bitkit.ext.toActivityItemDate
@@ -187,10 +188,7 @@ private fun ActivityDetailContent(
187188
) {
188189
val isLightning = item is Activity.Lightning
189190
val accentColor = if (isLightning) Colors.Purple else Colors.Brand
190-
val isSent = when (item) {
191-
is Activity.Lightning -> item.v1.txType == PaymentType.SENT
192-
is Activity.Onchain -> item.v1.txType == PaymentType.SENT
193-
}
191+
val isSent = item.isSent()
194192
val amountPrefix = if (isSent) "-" else "+"
195193
val timestamp = when (item) {
196194
is Activity.Lightning -> item.v1.timestamp

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

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ import com.synonym.bitkitcore.OnchainActivity
3636
import com.synonym.bitkitcore.PaymentState
3737
import com.synonym.bitkitcore.PaymentType
3838
import to.bitkit.R
39+
import to.bitkit.ext.BoostType
40+
import to.bitkit.ext.boostType
3941
import to.bitkit.ext.ellipsisMiddle
42+
import to.bitkit.ext.isBoosted
43+
import to.bitkit.ext.isSent
4044
import to.bitkit.ext.rawId
4145
import to.bitkit.ext.totalValue
4246
import to.bitkit.models.Toast
@@ -70,8 +74,7 @@ fun ActivityExploreScreen(
7074
onCloseClick: () -> Unit,
7175
) {
7276
val activities by listViewModel.filteredActivities.collectAsStateWithLifecycle()
73-
val item = activities?.find { it.rawId() == route.id }
74-
?: return
77+
val item = activities?.find { it.rawId() == route.id } ?: return
7578

7679
val app = appViewModel ?: return
7780
val context = LocalContext.current
@@ -113,6 +116,13 @@ fun ActivityExploreScreen(
113116
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
114117
context.startActivity(intent)
115118
},
119+
onClickParent = { id ->
120+
app.toast(
121+
type = Toast.ToastType.WARNING,
122+
title = "TODO",
123+
description = "Navigate to Activity Detail for: $id",
124+
)
125+
},
116126
)
117127
}
118128
}
@@ -123,28 +133,23 @@ private fun ActivityExploreContent(
123133
txDetails: TxDetails? = null,
124134
onCopy: (String) -> Unit = {},
125135
onClickExplore: (String) -> Unit = {},
136+
onClickParent: (String) -> Unit = {},
126137
) {
127138
Column(
128139
modifier = Modifier
129140
.fillMaxHeight()
130141
.padding(16.dp)
131142
.verticalScroll(rememberScrollState())
132143
) {
133-
// Header
134144
Row(
135145
verticalAlignment = Alignment.Bottom,
136146
modifier = Modifier
137147
.fillMaxWidth()
138148
.padding(vertical = 16.dp)
139149
) {
140-
val isSent = when (item) {
141-
is Activity.Lightning -> item.v1.txType == PaymentType.SENT
142-
is Activity.Onchain -> item.v1.txType == PaymentType.SENT
143-
}
144-
val amountPrefix = if (isSent) "-" else "+"
145150
BalanceHeaderView(
146151
sats = item.totalValue().toLong(),
147-
prefix = amountPrefix,
152+
prefix = if (item.isSent()) "-" else "+",
148153
showBitcoinSymbol = false,
149154
modifier = Modifier.weight(1f),
150155
)
@@ -155,7 +160,12 @@ private fun ActivityExploreContent(
155160

156161
when (item) {
157162
is Activity.Onchain -> {
158-
OnchainDetails(onchain = item, onCopy = onCopy, txDetails = txDetails)
163+
OnchainDetails(
164+
onchain = item,
165+
onCopy = onCopy,
166+
txDetails = txDetails,
167+
onClickParent = onClickParent,
168+
)
159169
Spacer(modifier = Modifier.weight(1f))
160170
PrimaryButton(
161171
text = stringResource(R.string.wallet__activity_explorer),
@@ -187,8 +197,7 @@ private fun LightningDetails(
187197
modifier = Modifier.clickableAlpha(
188198
onClick = copyToClipboard(preimage) {
189199
onCopy(preimage)
190-
}
191-
),
200+
}),
192201
)
193202
}
194203
Section(
@@ -197,17 +206,15 @@ private fun LightningDetails(
197206
modifier = Modifier.clickableAlpha(
198207
onClick = copyToClipboard(paymentHash) {
199208
onCopy(paymentHash)
200-
}
201-
),
209+
}),
202210
)
203211
Section(
204212
title = stringResource(R.string.wallet__activity_invoice),
205213
value = invoice,
206214
modifier = Modifier.clickableAlpha(
207215
onClick = copyToClipboard(invoice) {
208216
onCopy(invoice)
209-
}
210-
),
217+
}),
211218
)
212219
}
213220

@@ -216,19 +223,16 @@ private fun ColumnScope.OnchainDetails(
216223
onchain: Activity.Onchain,
217224
onCopy: (String) -> Unit,
218225
txDetails: TxDetails?,
226+
onClickParent: (String) -> Unit,
219227
) {
220228
val txId = onchain.v1.txId
221229
Section(
222-
title = stringResource(R.string.wallet__activity_tx_id),
223-
value = txId,
224-
modifier = Modifier
230+
title = stringResource(R.string.wallet__activity_tx_id), value = txId, modifier = Modifier
225231
.clickableAlpha(
226232
onClick = copyToClipboard(txId) {
227233
onCopy(txId)
228-
}
229-
)
230-
.testTag("TXID")
231-
)
234+
})
235+
.testTag("TXID"))
232236
if (txDetails != null) {
233237
Section(
234238
title = localizedPlural(R.string.wallet__activity_input, mapOf("count" to txDetails.vin.size)),
@@ -256,12 +260,31 @@ private fun ColumnScope.OnchainDetails(
256260
CircularProgressIndicator(
257261
strokeWidth = 2.dp,
258262
modifier = Modifier
259-
.size(16.dp)
260263
.padding(vertical = 16.dp)
261-
.align(Alignment.CenterHorizontally),
264+
.size(16.dp)
265+
.align(Alignment.CenterHorizontally)
262266
)
267+
} // TODO use real boosted parents from bitkit-core/ldk-node when available
268+
val boostedParents = listOfNotNull(
269+
"todo_first_parent_txid".takeIf { onchain.isBoosted() && !onchain.v1.confirmed },
270+
"todo_second_parent_txid".takeIf { onchain.isBoosted() && onchain.v1.confirmed },
271+
)
272+
273+
boostedParents.forEachIndexed { index, parent ->
274+
val isRbf = onchain.boostType() == BoostType.RBF
275+
Section(
276+
title = stringResource(
277+
if (isRbf) R.string.wallet__activity_boosted_rbf else R.string.wallet__activity_boosted_cpfp
278+
).replace("{num}", "${index + 1}"), valueContent = {
279+
Column {
280+
BodySSB(text = parent, maxLines = 1, overflow = TextOverflow.MiddleEllipsis)
281+
}
282+
}, modifier = Modifier
283+
.clickableAlpha {
284+
onClickParent(parent)
285+
}
286+
.testTag(if (isRbf) "RBFBoosted" else "CPFPBoosted"))
263287
}
264-
// TODO add boosted parents info if boosted
265288
}
266289

267290
@Composable

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.synonym.bitkitcore.PaymentType
2626
import to.bitkit.R
2727
import to.bitkit.ext.DatePattern
2828
import to.bitkit.ext.formatted
29+
import to.bitkit.ext.isSent
2930
import to.bitkit.ext.isTransfer
3031
import to.bitkit.ext.rawId
3132
import to.bitkit.ext.totalValue
@@ -65,7 +66,7 @@ fun ActivityRow(
6566
is Activity.Lightning -> item.v1.txType
6667
is Activity.Onchain -> item.v1.txType
6768
}
68-
val isSent = txType == PaymentType.SENT
69+
val isSent = item.isSent()
6970
val amountPrefix = if (isSent) "-" else "+"
7071
val confirmed: Boolean? = when (item) {
7172
is Activity.Lightning -> null

app/src/main/java/to/bitkit/ui/utils/ActivityItems.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package to.bitkit.ui.utils
22

33
import com.synonym.bitkitcore.Activity
4-
import com.synonym.bitkitcore.PaymentType
54
import to.bitkit.R
5+
import to.bitkit.ext.isSent
66
import to.bitkit.ext.isTransfer
77

88
fun Activity.getScreenTitleRes(): Int {
9-
val isSent = when (this) {
10-
is Activity.Lightning -> v1.txType == PaymentType.SENT
11-
is Activity.Onchain -> v1.txType == PaymentType.SENT
12-
}
9+
val isSent = this.isSent()
1310

1411
var resId = when {
1512
isSent -> R.string.wallet__activity_bitcoin_sent

0 commit comments

Comments
 (0)