Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Bitkit/Services/CoreService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

var isConfirmed = false
var confirmedTimestamp: UInt64?
if case let .confirmed(blockHash, height, timestamp) = txStatus {

Check warning on line 74 in Bitkit/Services/CoreService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'height' was never used; consider replacing with '_' or removing it

Check warning on line 74 in Bitkit/Services/CoreService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'blockHash' was never used; consider replacing with '_' or removing it
isConfirmed = true
confirmedTimestamp = timestamp
}
Expand Down Expand Up @@ -143,7 +143,7 @@
print(payment)
addedCount += 1
}
} else if case let .bolt11(hash, preimage, secret, description, bolt11) = payment.kind {

Check warning on line 146 in Bitkit/Services/CoreService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'secret' was never used; consider replacing with '_' or removing it

Check warning on line 146 in Bitkit/Services/CoreService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'hash' was never used; consider replacing with '_' or removing it
// Skip pending inbound payments, just means they created an invoice
guard !(payment.status == .pending && payment.direction == .inbound) else { continue }

Expand Down Expand Up @@ -216,6 +216,31 @@
}
}

func findActivity(byPaymentId paymentId: String) async throws -> Activity {
guard !paymentId.isEmpty else {
throw AppError(message: "Payment ID is empty", debugMessage: nil)
}

let activities = try await get(filter: .all, limit: 50)
let activity = activities.first { activity in
switch activity {
case let .lightning(ln):
return ln.id == paymentId
case let .onchain(on):
return on.txId == paymentId
}
}

guard let activity else {
throw AppError(
message: "Activity not found",
debugMessage: "Could not find activity for payment ID: \(paymentId)"
)
}

return activity
}

func update(id: String, activity: Activity) async throws {
try await ServiceQueue.background(.core) {
try updateActivity(activityId: id, activity: activity)
Expand Down
12 changes: 11 additions & 1 deletion Bitkit/ViewModels/AppViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,17 @@ extension AppViewModel {
func handleLdkNodeEvent(_ event: Event) {
switch event {
case let .paymentReceived(paymentId, paymentHash, amountMsat, customRecords):
sheetViewModel.showSheet(.receivedTx, data: ReceivedTxSheetDetails(type: .lightning, sats: amountMsat / 1000))
// TODO: Temporary fix while ldk-node bug is not fixed
Task {
do {
let _ = try await coreService.activity.findActivity(byPaymentId: paymentHash)
Logger.debug("Activity already exists for payment \(paymentHash), skipping sheet")
} catch {
await MainActor.run {
sheetViewModel.showSheet(.receivedTx, data: ReceivedTxSheetDetails(type: .lightning, sats: amountMsat / 1000))
}
}
}
case .channelPending(channelId: _, userChannelId: _, formerTemporaryChannelId: _, counterpartyNodeId: _, fundingTxo: _):
// Only relevant for channels to external nodes
break
Expand Down
Loading