Skip to content
Closed
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions app/src/main/java/to/bitkit/repositories/LightningRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,15 @@ class LightningRepo @Inject constructor(
fun canSend(amountSats: ULong): Boolean =
_lightningState.value.nodeLifecycleState.isRunning() && lightningService.canSend(amountSats)

suspend fun canSendAsync(amountSats: ULong): Result<Boolean> = executeWhenNodeRunning("canSendAsync") {
withTimeoutOrNull(3.seconds) {
while (_lightningState.value.channels.isEmpty()) {
delay(1.seconds)
}
}
Result.success(lightningService.canSend(amountSats))
}

fun getSyncFlow(): Flow<Unit> = lightningService.syncFlow()

fun getNodeId(): String? =
Expand Down
21 changes: 14 additions & 7 deletions app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,6 @@
runCatching { decode(bolt11) }.getOrNull()
?.let { it as? Scanner.Lightning }
?.invoice
?.takeIf { invoice ->
val canSend = lightningRepo.canSend(invoice.amountSatoshis.coerceAtLeast(1u))
if (!canSend) {
Logger.debug("Cannot pay unified invoice using LN, defaulting to onchain-only", context = TAG)
}
return@takeIf canSend
}
}
_sendUiState.update {
it.copy(
Expand Down Expand Up @@ -583,9 +576,23 @@
} else {
setSendEffect(SendEffect.NavigateToAmount)
}

lightningRepo.canSendAsync(invoice.amountSatoshis.coerceAtLeast(1u)).onSuccess { canSend ->
if (!canSend) {
Logger.debug("Cannot pay unified invoice using LN, defaulting to onchain-only", context = TAG)
_sendUiState.update {
it.copy(
isUnified = false,
decodedInvoice = null,
payMethod = SendMethod.ONCHAIN,
)
}
}
}
}

private suspend fun onScanLightning(invoice: LightningInvoice, scanResult: String) {
//TODO HANDLE NODE STILL RUNNING

Check warning

Code scanning / detekt

Checks if comments have the right spacing Warning

Missing space after //
if (invoice.isExpired) {
toast(
type = Toast.ToastType.ERROR,
Expand Down