Skip to content

Commit 8b07f97

Browse files
committed
fix(send): prefill amount from onchain invoice scan
1 parent 83f3d7c commit 8b07f97

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/src/main/java/to/bitkit/repositories/LightningRepo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class LightningRepo @Inject constructor(
512512
Result.success(paymentId)
513513
}
514514

515+
@Suppress("LongParameterList")
515516
suspend fun sendOnChain(
516517
address: Address,
517518
sats: ULong,

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,13 @@ class AppViewModel @Inject constructor(
544544
payMethod = lnInvoice?.let { SendMethod.LIGHTNING } ?: SendMethod.ONCHAIN,
545545
)
546546
}
547-
val isLnInvoiceWithAmount = lnInvoice?.amountSatoshis?.takeIf { it > 0uL } != null
548-
if (isLnInvoiceWithAmount) {
547+
548+
val lnAmountSats = lnInvoice?.amountSatoshis ?: 0u
549+
if (lnAmountSats > 0u) {
549550
Logger.info("Found amount in unified invoice, checking QuickPay conditions", context = TAG)
550551

551552
val quickPayHandled = handleQuickPayIfApplicable(
552-
amountSats = lnInvoice.amountSatoshis,
553+
amountSats = lnAmountSats,
553554
invoice = lnInvoice,
554555
)
555556
if (quickPayHandled) return
@@ -562,8 +563,14 @@ class AppViewModel @Inject constructor(
562563
}
563564
return
564565
}
565-
Logger.info("No amount found in invoice, proceeding to enter amount manually", context = TAG)
566-
resetAmountInput()
566+
567+
Logger.info(
568+
when (invoice.amountSatoshis > 0u) {
569+
true -> "Found amount in invoice, proceeding to edit amount"
570+
else -> "No amount found in invoice, proceeding to enter amount"
571+
},
572+
context = TAG,
573+
)
567574

568575
if (isMainScanner) {
569576
showSheet(Sheet.Send(SendRoute.Amount))
@@ -614,8 +621,7 @@ class AppViewModel @Inject constructor(
614621
}
615622
return
616623
}
617-
Logger.info("No amount found in invoice, proceeding to enter amount manually", context = TAG)
618-
resetAmountInput()
624+
Logger.info("No amount found in invoice, proceeding to enter amount", context = TAG)
619625

620626
if (isMainScanner) {
621627
showSheet(Sheet.Send(SendRoute.Amount))

0 commit comments

Comments
 (0)