Skip to content

Commit 379deee

Browse files
committed
fix: sync exception not caught
1 parent 55a99a3 commit 379deee

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

app/src/main/java/to/bitkit/repositories/LightningRepo.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ class LightningRepo @Inject constructor(
321321
do {
322322
syncPending.set(false)
323323
_lightningState.update { it.copy(isSyncingWallet = true) }
324-
lightningService.sync()
324+
runCatching {
325+
lightningService.sync()
326+
}.onFailure {
327+
return@executeWhenNodeRunning Result.failure(it)
328+
}
325329
refreshChannelCache()
326330
syncState()
327331
if (syncPending.get()) delay(MS_SYNC_LOOP_DEBOUNCE)

app/src/main/java/to/bitkit/viewmodels/WalletViewModel.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,15 @@ class WalletViewModel @Inject constructor(
276276
walletRepo.syncNodeAndWallet()
277277
.onFailure {
278278
Logger.error("Failed to refresh state: ${it.message}", it)
279-
if (it is CancellationException || it.isTxSyncTimeout()) return@onFailure
279+
if (it is CancellationException) return@onFailure
280+
if (it.isTxSyncTimeout()) {
281+
ToastEventBus.send(
282+
type = Toast.ToastType.ERROR,
283+
title = context.getString(R.string.wallet__ldk_sync_error_title),
284+
description = context.getString(R.string.wallet__ldk_sync_error_body),
285+
)
286+
return@onFailure
287+
}
280288
ToastEventBus.send(it)
281289
}
282290
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@
10991099
<string name="wallet__filter_title">Select Range</string>
11001100
<string name="wallet__instant_payment_received">Received Instant Bitcoin</string>
11011101
<string name="wallet__ldk_start_error_title">Lightning Startup Error</string>
1102+
<string name="wallet__ldk_sync_error_body">Unable to sync with the network. Please try again later.</string>
11021103
<string name="wallet__ldk_sync_error_title">Lightning Sync Error</string>
11031104
<string name="wallet__lnurl_p_max">Maximum amount</string>
11041105
<string name="wallet__lnurl_p_title">Pay Bitcoin</string>

0 commit comments

Comments
 (0)