@@ -226,32 +226,35 @@ class AppViewModel @Inject constructor(
226226 @Suppress(" CyclomaticComplexMethod" )
227227 private fun observeLdkNodeEvents () {
228228 viewModelScope.launch {
229- lightningRepo.nodeEvents.collect { event ->
230- if (! walletRepo.walletExists()) return @collect
231- Logger .debug(" LDK-node event received in $TAG : ${jsonLogOf(event)} " , context = TAG )
232- // TODO maybe use launch
233- runCatching {
234- when (event) {
235- is Event .BalanceChanged -> handleBalanceChanged()
236- is Event .ChannelClosed -> Unit
237- is Event .ChannelPending -> Unit
238- is Event .ChannelReady -> notifyChannelReady(event)
239- is Event .OnchainTransactionConfirmed -> handleOnchainTransactionConfirmed(event)
240- is Event .OnchainTransactionEvicted -> handleOnchainTransactionEvicted(event)
241- is Event .OnchainTransactionReceived -> handleOnchainTransactionReceived(event)
242- is Event .OnchainTransactionReorged -> handleOnchainTransactionReorged(event)
243- is Event .OnchainTransactionReplaced -> handleOnchainTransactionReplaced(event)
244- is Event .PaymentClaimable -> Unit
245- is Event .PaymentFailed -> handlePaymentFailed(event)
246- is Event .PaymentForwarded -> Unit
247- is Event .PaymentReceived -> handlePaymentReceived(event)
248- is Event .PaymentSuccessful -> handlePaymentSuccessful(event)
249- is Event .SyncCompleted -> handleSyncCompleted()
250- is Event .SyncProgress -> Unit
251- }
252- }.onFailure { e ->
253- Logger .error(" LDK event handler error" , e, context = TAG )
229+ lightningRepo.nodeEvents.collect { handleLdkEvent(it) }
230+ }
231+ }
232+
233+ private fun handleLdkEvent (event : Event ) {
234+ if (! walletRepo.walletExists()) return
235+ Logger .debug(" LDK-node event received in $TAG : ${jsonLogOf(event)} " , context = TAG )
236+ viewModelScope.launch {
237+ runCatching {
238+ when (event) {
239+ is Event .BalanceChanged -> handleBalanceChanged()
240+ is Event .ChannelClosed -> Unit
241+ is Event .ChannelPending -> Unit
242+ is Event .ChannelReady -> notifyChannelReady(event)
243+ is Event .OnchainTransactionConfirmed -> handleOnchainTransactionConfirmed(event)
244+ is Event .OnchainTransactionEvicted -> handleOnchainTransactionEvicted(event)
245+ is Event .OnchainTransactionReceived -> handleOnchainTransactionReceived(event)
246+ is Event .OnchainTransactionReorged -> handleOnchainTransactionReorged(event)
247+ is Event .OnchainTransactionReplaced -> handleOnchainTransactionReplaced(event)
248+ is Event .PaymentClaimable -> Unit
249+ is Event .PaymentFailed -> handlePaymentFailed(event)
250+ is Event .PaymentForwarded -> Unit
251+ is Event .PaymentReceived -> handlePaymentReceived(event)
252+ is Event .PaymentSuccessful -> handlePaymentSuccessful(event)
253+ is Event .SyncCompleted -> handleSyncCompleted()
254+ is Event .SyncProgress -> Unit
254255 }
256+ }.onFailure { e ->
257+ Logger .error(" LDK event handler error" , e, context = TAG )
255258 }
256259 }
257260 }
@@ -295,14 +298,14 @@ class AppViewModel @Inject constructor(
295298 }
296299
297300 private suspend fun handlePaymentReceived (event : Event .PaymentReceived ) {
298- event.paymentHash? .let { paymentHash ->
301+ event.paymentHash.let { paymentHash ->
299302 activityRepo.handlePaymentEvent(paymentHash)
300303 }
301304 notifyPaymentReceived(event)
302305 }
303306
304307 private suspend fun handlePaymentSuccessful (event : Event .PaymentSuccessful ) {
305- event.paymentHash? .let { paymentHash ->
308+ event.paymentHash.let { paymentHash ->
306309 activityRepo.handlePaymentEvent(paymentHash)
307310 }
308311 notifyPaymentSentOnLightning(event)
@@ -446,7 +449,7 @@ class AppViewModel @Inject constructor(
446449 is SendEvent .ConfirmAmountWarning -> onConfirmAmountWarning(it.warning)
447450 SendEvent .DismissAmountWarning -> onDismissAmountWarning()
448451 SendEvent .PayConfirmed -> onConfirmPay()
449- SendEvent .ClearPayConfirmation -> _sendUiState .update { it .copy(shouldConfirmPay = false ) }
452+ SendEvent .ClearPayConfirmation -> _sendUiState .update { s -> s .copy(shouldConfirmPay = false ) }
450453 SendEvent .BackToAmount -> setSendEffect(SendEffect .PopBack (SendRoute .Amount ))
451454 SendEvent .NavToAddress -> setSendEffect(SendEffect .NavigateToAddress )
452455 }
0 commit comments