@@ -330,12 +330,35 @@ extension AppViewModel {
330330 // Only relevant for channels to external nodes
331331 break
332332 case . channelReady( let channelId, userChannelId: _, counterpartyNodeId: _) :
333- // TODO: handle ONLY cjit as payment received. This makes it look like any channel confirmed is a received payment.
334333 if let channel = lightningService. channels? . first ( where: { $0. channelId == channelId } ) {
335- let amount = channel. spendableBalanceSats
336- sheetViewModel. showSheet ( . receivedTx, data: ReceivedTxSheetDetails ( type: . lightning, sats: amount) )
334+ Task {
335+ let cjitOrder = try await CoreService . shared. blocktank. getCjit ( channel: channel)
336+ if cjitOrder != nil {
337+ let amount = channel. spendableBalanceSats
338+ sheetViewModel. showSheet ( . receivedTx, data: ReceivedTxSheetDetails ( type: . lightning, sats: amount) )
339+ let now = UInt64 ( Date ( ) . timeIntervalSince1970)
340+
341+ let ln = LightningActivity (
342+ id: channel. fundingTxo? . txid ?? " " ,
343+ txType: . received,
344+ status: . succeeded,
345+ value: amount,
346+ fee: 0 ,
347+ invoice: cjitOrder? . invoice. request ?? " " ,
348+ message: " " ,
349+ timestamp: now,
350+ preimage: nil ,
351+ createdAt: now,
352+ updatedAt: nil
353+ )
354+
355+ try await CoreService . shared. activity. insert ( . lightning( ln) )
356+ } else {
357+ toast ( type: . lightning, title: t ( " lightning__channel_opened_title " ) , description: t ( " lightning__channel_opened_msg " ) )
358+ }
359+ }
337360 } else {
338- toast ( type: . error , title: " Channel opened " , description: " Ready to send " )
361+ toast ( type: . lightning , title: t ( " lightning__channel_opened_title " ) , description: t ( " lightning__channel_opened_msg " ) )
339362 }
340363 case . channelClosed( channelId: _, userChannelId: _, counterpartyNodeId: _, reason: _) :
341364 break
0 commit comments