diff --git a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt index 398c5f4ff..a76db343c 100644 --- a/app/src/main/java/to/bitkit/repositories/LightningRepo.kt +++ b/app/src/main/java/to/bitkit/repositories/LightningRepo.kt @@ -205,6 +205,7 @@ class LightningRepo @Inject constructor( // Initial state sync syncState() + updateGeoBlockState() // Perform post-startup tasks connectToTrustedPeers().onFailure { e -> @@ -238,6 +239,15 @@ class LightningRepo @Inject constructor( } } + /**Updates the shouldBlockLightning state and returns the current value*/ + private suspend fun updateGeoBlockState(): Boolean { + val shouldBlock = coreService.shouldBlockLightning() + _lightningState.update { + it.copy(shouldBlockLightning = shouldBlock) + } + return shouldBlock + } + fun setInitNodeLifecycleState() { _lightningState.update { it.copy(nodeLifecycleState = NodeLifecycleState.Initializing) } } @@ -414,7 +424,7 @@ class LightningRepo @Inject constructor( description: String, expirySeconds: UInt = 86_400u, ): Result = executeWhenNodeRunning("Create invoice") { - if (coreService.shouldBlockLightning()) { + if (updateGeoBlockState()) { return@executeWhenNodeRunning Result.failure(ServiceError.GeoBlocked) } @@ -661,7 +671,6 @@ class LightningRepo @Inject constructor( nodeStatus = getStatus(), peers = getPeers().orEmpty(), channels = getChannels().orEmpty(), - shouldBlockLightning = coreService.shouldBlockLightning() ) } } diff --git a/app/src/main/java/to/bitkit/services/CoreService.kt b/app/src/main/java/to/bitkit/services/CoreService.kt index 5776a3738..879ed3c8e 100644 --- a/app/src/main/java/to/bitkit/services/CoreService.kt +++ b/app/src/main/java/to/bitkit/services/CoreService.kt @@ -145,8 +145,6 @@ class CoreService @Inject constructor( suspend fun hasExternalNode() = getConnectedPeers().any { connectedPeer -> connectedPeer !in getLspPeers() } - // TODO this is business logic, should be moved to the domain layer in the future - // TODO this spams network calls too often, it needs a caching mechanism suspend fun shouldBlockLightning() = checkGeoStatus() == true && !hasExternalNode() }