@@ -226,7 +226,7 @@ class AppViewModel @Inject constructor(
226226
227227 launch(bgDispatcher) { walletRepo.syncNodeAndWallet() }
228228 runCatching {
229- when (event) { // TODO Create individual sheet for each type of event
229+ when (event) {
230230 is Event .PaymentReceived -> {
231231 showNewTransactionSheet(
232232 NewTransactionSheetDetails (
@@ -235,7 +235,7 @@ class AppViewModel @Inject constructor(
235235 paymentHashOrTxId = event.paymentHash,
236236 sats = (event.amountMsat / 1000u ).toLong(),
237237 ),
238- event = event
238+ event,
239239 )
240240 }
241241
@@ -250,7 +250,7 @@ class AppViewModel @Inject constructor(
250250 direction = NewTransactionSheetDirection .RECEIVED ,
251251 sats = amount,
252252 ),
253- event = event
253+ event,
254254 )
255255 activityRepo.insertActivityFromCjit(cjitEntry = cjitEntry, channel = channel)
256256 } else {
@@ -267,7 +267,7 @@ class AppViewModel @Inject constructor(
267267
268268 is Event .PaymentSuccessful -> {
269269 val paymentHash = event.paymentHash
270- // TODO Temporary solution while LDK node don 't returns the sent value in the event
270+ // TODO Temporary solution while LDK node doesn 't return the sent value in the event
271271 activityRepo.findActivityByPaymentId(
272272 paymentHashOrTxId = paymentHash,
273273 type = ActivityFilter .LIGHTNING ,
@@ -283,13 +283,37 @@ class AppViewModel @Inject constructor(
283283 ),
284284 )
285285 }.onFailure { e ->
286- Logger .warn(" Failed displaying sheet for event: $Event " , e)
286+ Logger .warn(" Failed displaying sheet for event: $event " , e)
287287 }
288288 }
289289
290290 is Event .PaymentClaimable -> Unit
291291 is Event .PaymentFailed -> Unit
292292 is Event .PaymentForwarded -> Unit
293+
294+ is Event .OnchainTransactionReceived -> {
295+ showNewTransactionSheet(
296+ NewTransactionSheetDetails (
297+ type = NewTransactionSheetType .ONCHAIN ,
298+ direction = NewTransactionSheetDirection .RECEIVED ,
299+ paymentHashOrTxId = event.txid,
300+ sats = event.details.amountSats.toLong(),
301+ ),
302+ event,
303+ )
304+ }
305+
306+ is Event .OnchainTransactionConfirmed -> Unit
307+ is Event .SyncProgress -> Unit
308+ is Event .SyncCompleted -> Unit
309+ is Event .BalanceChanged -> Unit
310+
311+ is Event .OnchainTransactionEvicted ,
312+ is Event .OnchainTransactionReorged ,
313+ is Event .OnchainTransactionReplaced ,
314+ -> {
315+ // TODO handle activity removed from mempool UI & toast
316+ }
293317 }
294318 }.onFailure { e ->
295319 Logger .error(" LDK event handler error" , e, context = TAG )
@@ -1324,18 +1348,14 @@ class AppViewModel @Inject constructor(
13241348 // endregion
13251349
13261350 // region TxSheet
1327- var isNewTransactionSheetEnabled = true
1328- private set
1329-
1351+ private var _isNewTransactionSheetEnabled = true
13301352 private val _showNewTransaction = MutableStateFlow (false )
13311353 val showNewTransaction: StateFlow <Boolean > = _showNewTransaction .asStateFlow()
13321354
13331355 private val _newTransaction = MutableStateFlow (
13341356 NewTransactionSheetDetails (
13351357 type = NewTransactionSheetType .LIGHTNING ,
13361358 direction = NewTransactionSheetDirection .RECEIVED ,
1337- paymentHashOrTxId = null ,
1338- sats = 0
13391359 )
13401360 )
13411361
@@ -1345,25 +1365,23 @@ class AppViewModel @Inject constructor(
13451365 NewTransactionSheetDetails (
13461366 type = NewTransactionSheetType .LIGHTNING ,
13471367 direction = NewTransactionSheetDirection .SENT ,
1348- paymentHashOrTxId = null ,
1349- sats = 0
13501368 )
13511369 )
13521370
13531371 val successSendUiState = _successSendUiState .asStateFlow()
13541372
13551373 fun setNewTransactionSheetEnabled (enabled : Boolean ) {
1356- isNewTransactionSheetEnabled = enabled
1374+ _isNewTransactionSheetEnabled = enabled
13571375 }
13581376
13591377 fun showNewTransactionSheet (
13601378 details : NewTransactionSheetDetails ,
1361- event : Event ? ,
1379+ event : Event ? = null ,
13621380 ) = viewModelScope.launch {
13631381 if (backupRepo.isRestoring.value) return @launch
13641382
1365- if (! isNewTransactionSheetEnabled ) {
1366- Logger .debug (" NewTransactionSheet display blocked by isNewTransactionSheetEnabled=false" , context = TAG )
1383+ if (! _isNewTransactionSheetEnabled ) {
1384+ Logger .verbose (" NewTransactionSheet blocked by isNewTransactionSheetEnabled=false" , context = TAG )
13671385 return @launch
13681386 }
13691387
@@ -1385,13 +1403,11 @@ class AppViewModel @Inject constructor(
13851403
13861404 hideSheet()
13871405
1406+ _showNewTransaction .update { true }
13881407 _newTransaction .update { details }
1389- _showNewTransaction .value = true
13901408 }
13911409
1392- fun hideNewTransactionSheet () {
1393- _showNewTransaction .value = false
1394- }
1410+ fun hideNewTransactionSheet () = _showNewTransaction .update { false }
13951411 // endregion
13961412
13971413 // region Sheets
0 commit comments