Skip to content

Commit 85d7c54

Browse files
authored
Merge pull request #360 from synonymdev/fix/send-unified-wo-ln
fix(send): avoid unified flow when LN invoice can't be paid
2 parents 9a2d2ae + cfcdb52 commit 85d7c54

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,24 @@ class AppViewModel @Inject constructor(
535535

536536
private suspend fun onScanOnchain(invoice: OnChainInvoice, scanResult: String) {
537537
val lnInvoice: LightningInvoice? = invoice.params?.get("lightning")?.let { bolt11 ->
538-
val decoded = runCatching { decode(bolt11) }.getOrNull()
539-
(decoded as? Scanner.Lightning)?.invoice
538+
runCatching { decode(bolt11) }.getOrNull()
539+
?.let { it as? Scanner.Lightning }
540+
?.invoice
541+
?.takeIf { invoice ->
542+
val canSend = lightningRepo.canSend(invoice.amountSatoshis.coerceAtLeast(1u))
543+
if (!canSend) {
544+
Logger.debug("Cannot pay unified invoice using LN, defaulting to onchain-only", context = TAG)
545+
}
546+
return@takeIf canSend
547+
}
540548
}
541549
_sendUiState.update {
542550
it.copy(
543551
address = invoice.address,
544552
addressInput = scanResult,
545553
isAddressInputValid = true,
546554
amount = invoice.amountSatoshis,
547-
isUnified = invoice.params?.containsKey("lightning") == true,
555+
isUnified = lnInvoice != null,
548556
decodedInvoice = lnInvoice,
549557
payMethod = lnInvoice?.let { SendMethod.LIGHTNING } ?: SendMethod.ONCHAIN,
550558
)

0 commit comments

Comments
 (0)