Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ class AppViewModel @Inject constructor(
_sendUiState.update { it.copy(isAddressInputValid = true) }
}

private fun validateOnChainAddress(invoice: OnChainInvoice) {
private suspend fun validateOnChainAddress(invoice: OnChainInvoice) {
val validatedAddress = runCatching { validateBitcoinAddress(invoice.address) }
.getOrElse {
showAddressValidationError(
Expand All @@ -778,6 +778,22 @@ class AppViewModel @Inject constructor(
return
}

// Check if this is a unified invoice with Lightning available
val lnInvoice: LightningInvoice? = invoice.params?.get("lightning")?.let { bolt11 ->
runCatching { decode(bolt11) }.getOrNull()
?.let { it as? Scanner.Lightning }
?.invoice
?.takeIf { lnInv ->
!lnInv.isExpired && lightningRepo.canSend(lnInv.amountSatoshis.coerceAtLeast(1u))
}
}

// If Lightning path is available, accept the unified invoice
if (lnInvoice != null) {
_sendUiState.update { it.copy(isAddressInputValid = true) }
return
}

val maxSendOnchain = walletRepo.balanceState.value.maxSendOnchainSats

if (maxSendOnchain == 0uL) {
Expand Down
Loading