Skip to content
Merged
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
13 changes: 11 additions & 2 deletions app/src/main/java/to/bitkit/repositories/LightningRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class LightningRepo @Inject constructor(

// Initial state sync
syncState()
updateGeoBlockState()

// Perform post-startup tasks
connectToTrustedPeers().onFailure { e ->
Expand Down Expand Up @@ -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) }
}
Expand Down Expand Up @@ -414,7 +424,7 @@ class LightningRepo @Inject constructor(
description: String,
expirySeconds: UInt = 86_400u,
): Result<String> = executeWhenNodeRunning("Create invoice") {
if (coreService.shouldBlockLightning()) {
if (updateGeoBlockState()) {
return@executeWhenNodeRunning Result.failure(ServiceError.GeoBlocked)
}

Expand Down Expand Up @@ -661,7 +671,6 @@ class LightningRepo @Inject constructor(
nodeStatus = getStatus(),
peers = getPeers().orEmpty(),
channels = getChannels().orEmpty(),
shouldBlockLightning = coreService.shouldBlockLightning()
)
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/to/bitkit/services/CoreService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down