Skip to content

Commit db352d1

Browse files
committed
chore: simplify onchain address extraction
1 parent 0eb4fcb commit db352d1

File tree

2 files changed

+6
-44
lines changed

2 files changed

+6
-44
lines changed
Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,6 @@
11
package to.bitkit.ui.screens.wallets.receive
22

3-
import org.lightningdevkit.ldknode.ChannelDetails
43
import to.bitkit.R
5-
import to.bitkit.models.NodeLifecycleState
6-
7-
/**
8-
* Strips the Lightning invoice parameter from a BIP21 URI, returning pure onchain address.
9-
*
10-
* Example:
11-
* Input: "bitcoin:bc1q...?amount=0.001&lightning=lnbc..."
12-
* Output: "bitcoin:bc1q...?amount=0.001"
13-
*
14-
* @param bip21 The full BIP21 URI
15-
* @return BIP21 URI without lightning parameter
16-
*/
17-
fun stripLightningFromBip21(bip21: String): String {
18-
if (bip21.isEmpty()) return bip21
19-
20-
// Remove lightning parameter and its value
21-
// Pattern: &lightning=... or ?lightning=...
22-
val lightningParamRegex = Regex("[?&]lightning=[^&]*")
23-
var result = bip21.replace(lightningParamRegex, "")
24-
25-
// If we removed the first param (started with ?), convert & to ?
26-
if (result.contains("&") && !result.contains("?")) {
27-
result = result.replaceFirst("&", "?")
28-
}
29-
30-
// Clean up trailing ? or &
31-
result = result.trimEnd('?', '&')
32-
33-
return result
34-
}
354

365
/**
376
* Returns the appropriate invoice/address for the selected tab.
@@ -53,9 +22,7 @@ fun getInvoiceForTab(
5322
): String {
5423
return when (tab) {
5524
ReceiveTab.SAVINGS -> {
56-
// Pure onchain: strip lightning from BIP21
57-
val strippedBip21 = stripLightningFromBip21(bip21)
58-
strippedBip21.ifEmpty { onchainAddress }
25+
onchainAddress
5926
}
6027

6128
ReceiveTab.AUTO -> {
@@ -77,15 +44,10 @@ fun getInvoiceForTab(
7744
* @param hasCjit Whether a CJIT invoice is active
7845
* @return Drawable resource ID for QR logo
7946
*/
80-
fun getQrLogoResource(tab: ReceiveTab, hasCjit: Boolean): Int {
47+
fun getQrLogoResource(tab: ReceiveTab): Int {
8148
return when (tab) {
8249
ReceiveTab.SAVINGS -> R.drawable.ic_btc_circle
83-
ReceiveTab.AUTO -> {
84-
// Unified logo if CJIT or standard unified
85-
if (hasCjit) R.drawable.ic_unified_circle
86-
else R.drawable.ic_unified_circle
87-
}
88-
50+
ReceiveTab.AUTO -> R.drawable.ic_unified_circle
8951
ReceiveTab.SPENDING -> R.drawable.ic_ln_circle
9052
}
9153
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fun ReceiveQrScreen(
8989
// Dynamic tab visibility
9090
val visibleTabs = remember(walletState, lightningState) {
9191
buildList {
92-
add(ReceiveTab.SAVINGS) // Always visible
92+
add(ReceiveTab.SAVINGS)
9393
if (walletState.channels.isNotEmpty()) {
9494
add(ReceiveTab.AUTO)
9595
}
@@ -117,8 +117,8 @@ fun ReceiveQrScreen(
117117
}
118118

119119
// QR logo based on selected tab
120-
val qrLogoRes = remember(selectedTab, cjitInvoice.value) {
121-
getQrLogoResource(selectedTab, cjitInvoice.value != null)
120+
val qrLogoRes = remember(selectedTab) {
121+
getQrLogoResource(selectedTab)
122122
}
123123

124124
Column(

0 commit comments

Comments
 (0)