Skip to content

Commit 1bad750

Browse files
authored
Merge pull request #110 from synonymdev/fix/copy-address-slider-adjustments
Copy address slider adjustments
2 parents b8ee55b + 74a1264 commit 1bad750

File tree

7 files changed

+49
-17
lines changed

7 files changed

+49
-17
lines changed

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ class LightningService @Inject constructor(
311311
return ServiceQueue.LDK.background {
312312
if (sat != null) {
313313
Logger.debug("Creating bolt11 for $sat sats")
314-
node.bolt11Payment().receive(sat.millis, description, expirySecs)
314+
node.bolt11Payment().receive(sat.millis, description.ifBlank { "Bitkit" }, expirySecs)
315315
} else {
316316
Logger.debug("Creating bolt11 for variable amount")
317-
node.bolt11Payment().receiveVariableAmount(description, expirySecs)
317+
node.bolt11Payment().receiveVariableAmount(description.ifBlank { "Bitkit" }, expirySecs)
318318
}
319319
}
320320
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.height
1010
import androidx.compose.foundation.layout.imePadding
1111
import androidx.compose.foundation.layout.padding
1212
import androidx.compose.foundation.layout.size
13+
import androidx.compose.foundation.layout.width
1314
import androidx.compose.foundation.pager.rememberPagerState
1415
import androidx.compose.material3.Card
1516
import androidx.compose.material3.CardDefaults
@@ -395,7 +396,14 @@ private fun CopyAddressCard(
395396
.fillMaxWidth()
396397
.padding(24.dp)
397398
) {
398-
Caption13Up(text = title, color = Colors.White64)
399+
Row {
400+
Caption13Up(text = title, color = Colors.White64)
401+
402+
Spacer(modifier = Modifier.width(3.dp))
403+
404+
val iconRes = if (type == CopyAddressType.ONCHAIN) R.drawable.ic_bitcoin else R.drawable.ic_lightning_alt
405+
Icon(painter = painterResource(iconRes), contentDescription = null, tint = Colors.White64)
406+
}
399407
Spacer(modifier = Modifier.height(16.dp))
400408
BodyS(text = address.truncate(32).uppercase())
401409
Spacer(modifier = Modifier.height(16.dp))

app/src/main/java/to/bitkit/utils/Bip21Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Bip21Utils {
66
bitcoinAddress: String,
77
amountSats: ULong? = null,
88
label: String? = null,
9-
message: String? = null,
9+
message: String? = "Bitkit",
1010
lightningInvoice: String? = null
1111
): String {
1212
val builder = StringBuilder("bitcoin:$bitcoinAddress")

app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class WalletViewModel @Inject constructor(
278278
}
279279
}
280280

281-
updateBip21Invoice(description = "Bitkit")
281+
updateBip21Invoice()
282282
}
283283

284284
fun disconnectPeer(peer: LnPeer) {
@@ -307,7 +307,7 @@ class WalletViewModel @Inject constructor(
307307

308308
fun updateBip21Invoice(
309309
amountSats: ULong? = null,
310-
description: String
310+
description: String = ""
311311
) {
312312
viewModelScope.launch(Dispatchers.IO) {
313313
val hasChannels = lightningService.channels.hasChannels()
@@ -321,7 +321,7 @@ class WalletViewModel @Inject constructor(
321321
val newBip21 = Bip21Utils.buildBip21Url(
322322
bitcoinAddress = _onchainAddress,
323323
amountSats = amountSats,
324-
message = description.ifBlank { "Bitkit" },
324+
message = description.ifBlank { DEFAULT_INVOICE_MESSAGE },
325325
lightningInvoice = _bolt11
326326
)
327327
_bip21 = newBip21
@@ -336,7 +336,7 @@ class WalletViewModel @Inject constructor(
336336
description: String,
337337
expirySeconds: UInt = 86_400u, // 1 day
338338
): String {
339-
return lightningService.receive(amountSats, description, expirySeconds)
339+
return lightningService.receive(amountSats, description.ifBlank { DEFAULT_INVOICE_MESSAGE }, expirySeconds)
340340
}
341341

342342
fun openChannel() {
@@ -517,6 +517,10 @@ class WalletViewModel @Inject constructor(
517517
}
518518

519519
private fun List<ChannelDetails>?.hasChannels() = this?.isNotEmpty() == true
520+
521+
private companion object {
522+
const val DEFAULT_INVOICE_MESSAGE = "Bitkit"
523+
}
520524
}
521525

522526
// region state
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="17dp"
4+
android:viewportWidth="16"
5+
android:viewportHeight="17">
6+
<path
7+
android:pathData="M13.05,7.128C13.27,5.657 12.15,4.866 10.618,4.339L11.115,2.346L9.902,2.044L9.418,3.984C9.099,3.905 8.772,3.83 8.446,3.755L8.933,1.802L7.721,1.5L7.224,3.492C6.96,3.432 6.701,3.373 6.449,3.31L6.45,3.304L4.778,2.886L4.455,4.182C4.455,4.182 5.355,4.388 5.336,4.401C5.827,4.524 5.916,4.849 5.901,5.106L5.335,7.377C5.369,7.385 5.413,7.397 5.461,7.417C5.421,7.407 5.378,7.396 5.333,7.385L4.54,10.565C4.48,10.715 4.327,10.939 3.984,10.853C3.996,10.871 3.102,10.633 3.102,10.633L2.5,12.022L4.078,12.415C4.372,12.489 4.66,12.566 4.943,12.638L4.442,14.654L5.653,14.956L6.15,12.962C6.482,13.052 6.803,13.135 7.117,13.213L6.622,15.198L7.835,15.5L8.337,13.488C10.406,13.88 11.961,13.722 12.616,11.851C13.143,10.345 12.59,9.476 11.501,8.909C12.294,8.726 12.891,8.205 13.05,7.128ZM10.279,11.015C9.904,12.521 7.368,11.707 6.545,11.502L7.211,8.832C8.033,9.037 10.67,9.444 10.279,11.015ZM10.653,7.107C10.312,8.477 8.201,7.781 7.516,7.61L8.12,5.188C8.804,5.359 11.01,5.677 10.653,7.107Z"
8+
android:fillColor="#ffffff"
9+
android:fillAlpha="0.64"/>
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="16dp"
3+
android:height="16dp"
4+
android:viewportWidth="16"
5+
android:viewportHeight="16">
6+
<path
7+
android:pathData="M3.998,9.234H7.694L5.759,14.232C5.485,14.919 6.225,15.287 6.698,14.726L12.659,7.643C12.771,7.504 12.833,7.372 12.833,7.221C12.833,6.956 12.622,6.763 12.336,6.763H8.64L10.575,1.765C10.842,1.078 10.108,0.717 9.635,1.271L3.674,8.354C3.556,8.493 3.5,8.626 3.5,8.776C3.5,9.042 3.712,9.234 3.998,9.234Z"
8+
android:fillColor="#ffffff"
9+
android:fillAlpha="0.64"/>
10+
</vector>

app/src/test/java/to/bitkit/utils/Bip21UrlBuilderTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,31 @@ class Bip21UrlBuilderTest {
1818
@Test
1919
fun `basic address without parameters`() {
2020
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
21-
val expected = "bitcoin:$address"
21+
val expected = "bitcoin:$address?message=Bitkit"
2222
Assert.assertEquals(expected, buildBip21Url(address))
2323
}
2424

2525
@Test
2626
fun `address with amount in sats`() {
2727
val address = "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
2828
val amount = 100000uL // 0.001 BTC
29-
val expected = "bitcoin:$address?amount=0.001"
29+
val expected = "bitcoin:$address?amount=0.001&message=Bitkit"
3030
Assert.assertEquals(expected, buildBip21Url(address, amount))
3131
}
3232

3333
@Test
3434
fun `amount with exact 1 BTC`() {
3535
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
3636
val amount = 100000000uL
37-
val expected = "bitcoin:$address?amount=1"
37+
val expected = "bitcoin:$address?amount=1&message=Bitkit"
3838
Assert.assertEquals(expected, buildBip21Url(address, amount))
3939
}
4040

4141
@Test
4242
fun `amount with fractional sats rounds correctly`() {
4343
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
4444
val amount = 12345678uL
45-
val expected = "bitcoin:$address?amount=0.12345678"
45+
val expected = "bitcoin:$address?amount=0.12345678&message=Bitkit"
4646
Assert.assertEquals(expected, buildBip21Url(address, amount))
4747
}
4848

@@ -64,7 +64,7 @@ class Bip21UrlBuilderTest {
6464
fun `address with lightning parameter`() {
6565
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
6666
val invoice = "lnbc500n1p3k9v3pp5kzmj..."
67-
val expected = "bitcoin:$address?lightning=${invoice.encodeToUrl()}"
67+
val expected = "bitcoin:$address?message=Bitkit&lightning=${invoice.encodeToUrl()}"
6868
Assert.assertEquals(expected, buildBip21Url(address, lightningInvoice = invoice))
6969
}
7070

@@ -105,23 +105,23 @@ class Bip21UrlBuilderTest {
105105
fun `zero sats is handled correctly`() {
106106
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
107107
val amount = 0uL
108-
val expected = "bitcoin:$address?amount=0"
108+
val expected = "bitcoin:$address?amount=0&message=Bitkit"
109109
Assert.assertEquals(expected, buildBip21Url(address, amount))
110110
}
111111

112112
@Test
113113
fun `maximum ULong value is handled correctly`() {
114114
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
115115
val amount = ULong.MAX_VALUE
116-
val expected = "bitcoin:$address?amount=184467440737.09551615"
116+
val expected = "bitcoin:$address?amount=184467440737.09551615&message=Bitkit"
117117
Assert.assertEquals(expected, buildBip21Url(address, amount))
118118
}
119119

120120
@Test
121121
fun `lightning parameter without other parameters`() {
122122
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
123123
val invoice = "lnbc100n1p3k9v3pp5kzmj..."
124-
val expected = "bitcoin:$address?lightning=${invoice.encodeToUrl()}"
124+
val expected = "bitcoin:$address?message=Bitkit&lightning=${invoice.encodeToUrl()}"
125125
Assert.assertEquals(expected, buildBip21Url(address, lightningInvoice = invoice))
126126
}
127127

@@ -130,7 +130,7 @@ class Bip21UrlBuilderTest {
130130
val address = "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"
131131
val amount = 10000uL
132132
val invoice = "lnbc100n1p3k9v3pp5kzmj..."
133-
val expected = "bitcoin:$address?amount=0.0001&lightning=${invoice.encodeToUrl()}"
133+
val expected = "bitcoin:$address?amount=0.0001&message=Bitkit&lightning=${invoice.encodeToUrl()}"
134134
Assert.assertEquals(expected, buildBip21Url(address, amount, lightningInvoice = invoice))
135135
}
136136
}

0 commit comments

Comments
 (0)