@@ -62,7 +62,7 @@ import kotlin.time.Duration
6262import kotlin.time.Duration.Companion.minutes
6363import kotlin.time.Duration.Companion.seconds
6464
65- private const val SYNC_TIMEOUT_MS = 10_000L
65+ private const val SYNC_TIMEOUT_MS = 15_000L
6666
6767@Singleton
6868class LightningRepo @Inject constructor(
@@ -246,12 +246,11 @@ class LightningRepo @Inject constructor(
246246 }
247247
248248 /* *Updates the shouldBlockLightning state and returns the current value*/
249- private suspend fun updateGeoBlockState (): Boolean {
250- val shouldBlock = coreService.shouldBlockLightning ()
249+ suspend fun updateGeoBlockState () {
250+ val (isGeoBlocked, shouldBlockLightning) = coreService.checkGeoBlock ()
251251 _lightningState .update {
252- it.copy(shouldBlockLightning = shouldBlock )
252+ it.copy(shouldBlockLightning = shouldBlockLightning, isGeoBlocked = isGeoBlocked )
253253 }
254- return shouldBlock
255254 }
256255
257256 fun setInitNodeLifecycleState () {
@@ -409,7 +408,9 @@ class LightningRepo @Inject constructor(
409408 }
410409
411410 suspend fun connectPeer (peer : LnPeer ): Result <Unit > = executeWhenNodeRunning(" connectPeer" ) {
412- lightningService.connectPeer(peer)
411+ lightningService.connectPeer(peer).onFailure { e ->
412+ return @executeWhenNodeRunning Result .failure(e)
413+ }
413414 syncState()
414415 Result .success(Unit )
415416 }
@@ -430,7 +431,8 @@ class LightningRepo @Inject constructor(
430431 description : String ,
431432 expirySeconds : UInt = 86_400u,
432433 ): Result <String > = executeWhenNodeRunning(" Create invoice" ) {
433- if (updateGeoBlockState()) {
434+ updateGeoBlockState()
435+ if (lightningState.value.shouldBlockLightning) {
434436 return @executeWhenNodeRunning Result .failure(ServiceError .GeoBlocked )
435437 }
436438
@@ -682,8 +684,13 @@ class LightningRepo @Inject constructor(
682684 }
683685 }
684686
685- fun canSend (amountSats : ULong ): Boolean =
686- _lightningState .value.nodeLifecycleState.isRunning() && lightningService.canSend(amountSats)
687+ suspend fun canSend (amountSats : ULong , fallbackToCachedBalance : Boolean = true): Boolean {
688+ return if (! _lightningState .value.nodeLifecycleState.isRunning() && fallbackToCachedBalance) {
689+ amountSats <= (cacheStore.data.first().balance?.maxSendLightningSats ? : 0u )
690+ } else {
691+ lightningService.canSend(amountSats)
692+ }
693+ }
687694
688695 fun getSyncFlow (): Flow <Unit > = lightningService.syncFlow()
689696
@@ -850,4 +857,5 @@ data class LightningState(
850857 val channels : List <ChannelDetails > = emptyList(),
851858 val isSyncingWallet : Boolean = false ,
852859 val shouldBlockLightning : Boolean = false ,
860+ val isGeoBlocked : Boolean = false ,
853861)
0 commit comments