Skip to content

Commit 98645c1

Browse files
committed
revert: Disable bolt11 cache for now since it breaks send
1 parent 29b7e0f commit 98645c1

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

app/src/main/java/to/bitkit/di/HttpModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object HttpModule {
4444
}
4545
install(Logging) {
4646
logger = Logger.ANDROID
47-
level = LogLevel.BODY
47+
level = LogLevel.INFO
4848
}
4949
install(ContentNegotiation) {
5050
json(json = json)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,10 @@ class LightningService @Inject constructor(
310310

311311
return ServiceQueue.LDK.background {
312312
if (sat != null) {
313+
Logger.debug("Creating bolt11 for $sat sats")
313314
node.bolt11Payment().receive(sat.millis, description, expirySecs)
314315
} else {
316+
Logger.debug("Creating bolt11 for variable amount")
315317
node.bolt11Payment().receiveVariableAmount(description, expirySecs)
316318
}
317319
}

app/src/main/java/to/bitkit/ui/shared/Payments.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.runtime.Composable
2020
import androidx.compose.runtime.getValue
2121
import androidx.compose.runtime.mutableStateOf
2222
import androidx.compose.runtime.remember
23+
import androidx.compose.runtime.rememberCoroutineScope
2324
import androidx.compose.runtime.setValue
2425
import androidx.compose.ui.Alignment
2526
import androidx.compose.ui.Modifier
@@ -28,13 +29,15 @@ import androidx.compose.ui.res.stringResource
2829
import androidx.compose.ui.text.AnnotatedString
2930
import androidx.compose.ui.text.input.KeyboardType
3031
import androidx.compose.ui.unit.dp
32+
import kotlinx.coroutines.launch
3133
import to.bitkit.R
3234
import to.bitkit.viewmodels.WalletViewModel
3335

3436
@Composable
3537
fun Payments(
3638
viewModel: WalletViewModel,
3739
) {
40+
val scope = rememberCoroutineScope()
3841
Column {
3942
OutlinedCard {
4043
Text(
@@ -86,9 +89,11 @@ fun Payments(
8689
val clipboard = LocalClipboardManager.current
8790
FullWidthTextButton(
8891
onClick = {
89-
amountToReceive.toULongOrNull()?.let {
90-
val bolt11 = viewModel.createInvoice(amountSats = it, description = "Bitkit")
91-
clipboard.setText(AnnotatedString(bolt11))
92+
scope.launch {
93+
amountToReceive.toULongOrNull()?.let {
94+
val bolt11 = viewModel.createInvoice(amountSats = it, description = "Bitkit")
95+
clipboard.setText(AnnotatedString(bolt11))
96+
}
9297
}
9398
},
9499
enabled = amountToReceive.toULongOrNull() != null,

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

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class WalletViewModel @Inject constructor(
265265
get() = lightningService.channels?.sumOf { it.inboundCapacityMsat / 1000u }
266266

267267
suspend fun refreshBip21() {
268+
Logger.debug("Refreshing bip21", context = "WalletViewModel")
268269
if (_onchainAddress.isEmpty()) {
269270
_onchainAddress = lightningService.newAddress()
270271
} else {
@@ -282,16 +283,20 @@ class WalletViewModel @Inject constructor(
282283

283284
val hasChannels = lightningService.channels?.isNotEmpty() == true
284285
if (hasChannels) {
285-
if (_bolt11.isEmpty()) {
286-
_bolt11 = this.createInvoice(description = "Bitkit")
287-
} else {
288-
// Check if existing invoice has expired and create a new one if so
289-
decode(invoice = _bolt11).let { decoded ->
290-
if (decoded is Scanner.Lightning && decoded.invoice.isExpired) {
291-
_bolt11 = this.createInvoice(description = "Bitkit")
292-
}
293-
}
294-
}
286+
287+
// TODO: check current bolt11 for expiry (fix payments not working with commented code & rm next line):
288+
_bolt11 = createInvoice(description = "Bitkit")
289+
290+
// if (_bolt11.isEmpty()) {
291+
// _bolt11 = createInvoice(description = "Bitkit")
292+
// } else {
293+
// // Check if existing invoice has expired and create a new one if so
294+
// decode(invoice = _bolt11).let { decoded ->
295+
// if (decoded is Scanner.Lightning && decoded.invoice.isExpired) {
296+
// _bolt11 = createInvoice(description = "Bitkit")
297+
// }
298+
// }
299+
// }
295300
} else {
296301
_bolt11 = ""
297302
}
@@ -329,12 +334,12 @@ class WalletViewModel @Inject constructor(
329334
}
330335
}
331336

332-
fun createInvoice(
337+
suspend fun createInvoice(
333338
amountSats: ULong? = null,
334339
description: String,
335340
expirySeconds: UInt = 86_400u, // 1 day
336341
): String {
337-
return runBlocking { lightningService.receive(amountSats, description, expirySeconds) }
342+
return lightningService.receive(amountSats, description, expirySeconds)
338343
}
339344

340345
fun openChannel() {

0 commit comments

Comments
 (0)