Skip to content

Commit b9eea05

Browse files
committed
fix: insufficient savings error returned to unified invoice even with spending balance
1 parent eee3800 commit b9eea05

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ class AppViewModel @Inject constructor(
758758
_sendUiState.update { it.copy(isAddressInputValid = true) }
759759
}
760760

761-
private fun validateOnChainAddress(invoice: OnChainInvoice) {
761+
private suspend fun validateOnChainAddress(invoice: OnChainInvoice) {
762762
val validatedAddress = runCatching { validateBitcoinAddress(invoice.address) }
763763
.getOrElse {
764764
showAddressValidationError(
@@ -778,6 +778,22 @@ class AppViewModel @Inject constructor(
778778
return
779779
}
780780

781+
// Check if this is a unified invoice with Lightning available
782+
val lnInvoice: LightningInvoice? = invoice.params?.get("lightning")?.let { bolt11 ->
783+
runCatching { decode(bolt11) }.getOrNull()
784+
?.let { it as? Scanner.Lightning }
785+
?.invoice
786+
?.takeIf { lnInv ->
787+
!lnInv.isExpired && lightningRepo.canSend(lnInv.amountSatoshis.coerceAtLeast(1u))
788+
}
789+
}
790+
791+
// If Lightning path is available, accept the unified invoice
792+
if (lnInvoice != null) {
793+
_sendUiState.update { it.copy(isAddressInputValid = true) }
794+
return
795+
}
796+
781797
val maxSendOnchain = walletRepo.balanceState.value.maxSendOnchainSats
782798

783799
if (maxSendOnchain == 0uL) {

0 commit comments

Comments
 (0)