Skip to content

Commit d0f514d

Browse files
committed
refactor: only sync after the node starts with success
1 parent eb337da commit d0f514d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,21 @@ class WalletViewModel @Inject constructor(
8181
syncState()
8282
refreshBip21ForEvent(event)
8383
}.onFailure { error ->
84-
_uiState.update { it.copy(nodeLifecycleState = NodeLifecycleState.ErrorStarting(error)) }
8584
Logger.error("Node startup error", error)
8685
throw error
87-
}
86+
}.onSuccess {
87+
syncState()
8888

89-
_uiState.update { it.copy(nodeLifecycleState = NodeLifecycleState.Running) }
90-
syncState()
89+
lightningRepository.connectToTrustedPeers().onFailure { e ->
90+
Logger.error("Failed to connect to trusted peers", e)
91+
}
9192

92-
// Connect to trusted peers
93-
lightningRepository.connectToTrustedPeers().onFailure { e ->
94-
Logger.error("Failed to connect to trusted peers", e)
93+
// Refresh BIP21 and sync
94+
launch(bgDispatcher) { refreshBip21() }
95+
launch(bgDispatcher) { sync() }
96+
launch(bgDispatcher) { registerForNotificationsIfNeeded() }
97+
launch(bgDispatcher) { observeDbConfig() }
9598
}
96-
97-
// Refresh BIP21 and sync
98-
launch(bgDispatcher) { refreshBip21() }
99-
launch(bgDispatcher) { sync() }
100-
launch(bgDispatcher) { registerForNotificationsIfNeeded() }
101-
launch(bgDispatcher) { observeDbConfig() }
10299
}
103100
}
104101

0 commit comments

Comments
 (0)