11package to.bitkit.ui.screens.wallets.receive
22
3- import org.lightningdevkit.ldknode.ChannelDetails
43import 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}
0 commit comments