Skip to content

Commit 28a59aa

Browse files
authored
Merge pull request #180 from synonymdev/fix/cjit-activity
Display CJIT activities
2 parents 1d5933c + e6218f9 commit 28a59aa

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

Bitkit/Services/CoreService.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,17 @@ class BlocktankService {
594594
}
595595
}
596596

597+
func getCjit(channel: ChannelDetails) async -> IcJitEntry? {
598+
do {
599+
let orders = try await cjitOrders()
600+
return orders.first { order in
601+
order.channelSizeSat == channel.channelValueSats && order.lspNode.pubkey == channel.counterpartyNodeId
602+
}
603+
} catch {
604+
return nil
605+
}
606+
}
607+
597608
func newOrder(
598609
lspBalanceSat: UInt64,
599610
channelExpiryWeeks: UInt32,

Bitkit/ViewModels/AppViewModel.swift

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)