Skip to content

Commit 77e679e

Browse files
authored
feat(lightning): show route fee for probe results (#622)
1 parent 03ac820 commit 77e679e

9 files changed

Lines changed: 35 additions & 32 deletions

File tree

Bitkit.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@
11931193
repositoryURL = "https://github.com/synonymdev/ldk-node";
11941194
requirement = {
11951195
kind = exactVersion;
1196-
version = "0.7.0-rc.39";
1196+
version = "0.7.0-rc.53";
11971197
};
11981198
};
11991199
96DEA0382DE8BBA1009932BF /* XCRemoteSwiftPackageReference "bitkit-core" */ = {

Bitkit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Bitkit/Services/LightningService.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,12 +1249,14 @@ extension LightningService {
12491249
Logger.info(
12501250
"🫰 Payment claimable: paymentId: \(paymentId) paymentHash: \(paymentHash) claimableAmountMsat: \(claimableAmountMsat)"
12511251
)
1252-
case let .probeSuccessful(paymentId, paymentHash):
1253-
Logger.info("🤑 Probe successful: paymentId: \(paymentId) paymentHash: \(paymentHash)")
1254-
case let .probeFailed(paymentId, paymentHash, shortChannelId):
1252+
case let .probeSuccessful(paymentId, paymentHash, routeFeeMsat):
1253+
let routeFeeText = routeFeeMsat.map(String.init) ?? "unknown"
1254+
Logger.info("🤑 Probe successful: paymentId: \(paymentId) paymentHash: \(paymentHash) routeFeeMsat: \(routeFeeText)")
1255+
case let .probeFailed(paymentId, paymentHash, shortChannelId, routeFeeMsat):
1256+
let routeFeeText = routeFeeMsat.map(String.init) ?? "unknown"
12551257
Logger
12561258
.info(
1257-
"❌ Probe failed: paymentId: \(paymentId) paymentHash: \(paymentHash) shortChannelId: \(String(describing: shortChannelId))"
1259+
"❌ Probe failed: paymentId: \(paymentId) paymentHash: \(paymentHash) shortChannelId: \(String(describing: shortChannelId)) routeFeeMsat: \(routeFeeText)"
12581260
)
12591261
// Payment claimable doesn't need activity update - it's still pending
12601262
// The payment will be updated when it succeeds or fails via paymentSuccessful/paymentFailed events

Bitkit/ViewModels/AppViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,9 @@ extension AppViewModel {
954954
break
955955
case .paymentForwarded:
956956
break
957-
case .probeSuccessful(paymentId: _, paymentHash: _):
957+
case .probeSuccessful(paymentId: _, paymentHash: _, routeFeeMsat: _):
958958
break
959-
case .probeFailed(paymentId: _, paymentHash: _, shortChannelId: _):
959+
case .probeFailed(paymentId: _, paymentHash: _, shortChannelId: _, routeFeeMsat: _):
960960
break
961961

962962
// MARK: New Onchain Transaction Events

Bitkit/ViewModels/WalletViewModel.swift

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,21 @@ class WalletViewModel: ObservableObject {
182182

183183
// Handle specific events for targeted UI updates
184184
switch event {
185-
case let .probeSuccessful(paymentId, paymentHash: paymentHash):
185+
case let .probeSuccessful(paymentId, paymentHash: paymentHash, routeFeeMsat: routeFeeMsat):
186186
self.cacheProbeOutcome(
187187
success: true,
188188
paymentId: paymentId,
189189
paymentHash: paymentHash,
190-
shortChannelId: nil
190+
shortChannelId: nil,
191+
routeFeeMsat: routeFeeMsat
191192
)
192-
case let .probeFailed(paymentId, paymentHash: paymentHash, shortChannelId: shortChannelId):
193+
case let .probeFailed(paymentId, paymentHash: paymentHash, shortChannelId: shortChannelId, routeFeeMsat: routeFeeMsat):
193194
self.cacheProbeOutcome(
194195
success: false,
195196
paymentId: paymentId,
196197
paymentHash: paymentHash,
197-
shortChannelId: shortChannelId
198+
shortChannelId: shortChannelId,
199+
routeFeeMsat: routeFeeMsat
198200
)
199201
case let .paymentReceived(_, paymentHash, _, _):
200202
self.bolt11 = ""
@@ -680,6 +682,7 @@ class WalletViewModel: ObservableObject {
680682
let paymentId: PaymentId
681683
let paymentHash: PaymentHash
682684
let shortChannelId: UInt64?
685+
let routeFeeMsat: UInt64?
683686
}
684687

685688
/// Waits for probe results that match one of the returned probe `paymentId`s.
@@ -704,23 +707,25 @@ class WalletViewModel: ObservableObject {
704707
addOnEvent(id: eventId) { event in
705708
guard !resumed else { return }
706709
switch event {
707-
case let .probeSuccessful(paymentId, paymentHash: paymentHash):
710+
case let .probeSuccessful(paymentId, paymentHash: paymentHash, routeFeeMsat: routeFeeMsat):
708711
guard pendingPaymentIds.contains(paymentId) else { return }
709712
resumed = true
710713
self.removeOnEvent(id: eventId)
711714
continuation.resume(returning: .init(
712715
success: true,
713716
paymentId: paymentId,
714717
paymentHash: paymentHash,
715-
shortChannelId: nil
718+
shortChannelId: nil,
719+
routeFeeMsat: routeFeeMsat
716720
))
717-
case let .probeFailed(paymentId, paymentHash: paymentHash, shortChannelId: shortChannelId):
721+
case let .probeFailed(paymentId, paymentHash: paymentHash, shortChannelId: shortChannelId, routeFeeMsat: routeFeeMsat):
718722
guard pendingPaymentIds.remove(paymentId) != nil else { return }
719723
lastFailure = .init(
720724
success: false,
721725
paymentId: paymentId,
722726
paymentHash: paymentHash,
723-
shortChannelId: shortChannelId
727+
shortChannelId: shortChannelId,
728+
routeFeeMsat: routeFeeMsat
724729
)
725730
if pendingPaymentIds.isEmpty, let lastFailure {
726731
resumed = true
@@ -734,12 +739,13 @@ class WalletViewModel: ObservableObject {
734739
}
735740
}
736741

737-
private func cacheProbeOutcome(success: Bool, paymentId: PaymentId, paymentHash: PaymentHash, shortChannelId: UInt64?) {
742+
private func cacheProbeOutcome(success: Bool, paymentId: PaymentId, paymentHash: PaymentHash, shortChannelId: UInt64?, routeFeeMsat: UInt64?) {
738743
probeOutcomes[paymentId] = ProbeOutcome(
739744
success: success,
740745
paymentId: paymentId,
741746
paymentHash: paymentHash,
742-
shortChannelId: shortChannelId
747+
shortChannelId: shortChannelId,
748+
routeFeeMsat: routeFeeMsat
743749
)
744750
}
745751

Bitkit/Views/Settings/ProbingTool/ProbeResult.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import Foundation
33
struct ProbeResult {
44
let success: Bool
55
let durationMs: Int
6-
let estimatedFeeSats: UInt64?
6+
let routeFeeMsat: UInt64?
77
let errorMessage: String?
88
}

Bitkit/Views/Settings/ProbingTool/ProbeResultSectionView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ struct ProbeResultSectionView: View {
2727
}
2828
.font(.subheadline)
2929

30-
if let fee = result.estimatedFeeSats {
30+
if let fee = result.routeFeeMsat {
3131
HStack {
3232
Image(systemName: "bitcoinsign.circle")
3333
.foregroundStyle(.secondary)
34-
Text("Estimated Fee")
34+
Text("Route Fee")
3535
Spacer()
36-
Text("\(fee) sats")
36+
Text("\(fee) msat")
3737
.foregroundStyle(.secondary)
3838
}
3939
.font(.subheadline)

Bitkit/Views/Settings/ProbingTool/ProbingToolScreen.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,11 @@ struct ProbingToolScreen: View {
249249
let durationMs = Int(Date().timeIntervalSince(start) * 1000)
250250

251251
if resolved.success {
252-
let estimatedFee: UInt64? = switch target {
253-
case let .invoice(bolt11, _):
254-
try? await lightningService.estimateRoutingFees(bolt11: bolt11, amountSats: amountSatsValue)
255-
case .nodeId:
256-
nil
257-
}
258252
await MainActor.run {
259253
probeResult = ProbeResult(
260254
success: true,
261255
durationMs: durationMs,
262-
estimatedFeeSats: estimatedFee,
256+
routeFeeMsat: resolved.routeFeeMsat,
263257
errorMessage: nil
264258
)
265259
}
@@ -271,7 +265,7 @@ struct ProbingToolScreen: View {
271265
probeResult = ProbeResult(
272266
success: false,
273267
durationMs: durationMs,
274-
estimatedFeeSats: nil,
268+
routeFeeMsat: resolved.routeFeeMsat,
275269
errorMessage: message
276270
)
277271
}
@@ -283,7 +277,7 @@ struct ProbingToolScreen: View {
283277
probeResult = ProbeResult(
284278
success: false,
285279
durationMs: durationMs,
286-
estimatedFeeSats: nil,
280+
routeFeeMsat: nil,
287281
errorMessage: error.localizedDescription
288282
)
289283
}

changelog.d/next/622.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved Lightning probe route fee reporting.

0 commit comments

Comments
 (0)