Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f7fc9ae
fix: avoid msat truncation when paying invoices with built-in amounts
ben-kaufman Apr 1, 2026
548dcb1
chore: add changelog entry for msat fix
ben-kaufman Apr 1, 2026
8f01a90
Merge branch 'master' into fix/msat-invoice-precision
piotr-iohk Apr 2, 2026
617ecdc
fix: preserve msat precision for LNURL pay and withdraw callbacks
ben-kaufman Apr 3, 2026
0723c7e
chore: update changelog with LNURL msat fix
ben-kaufman Apr 3, 2026
ef88089
fix: use msat-precision invoices for fixed-amount LNURL withdraw
ben-kaufman Apr 3, 2026
851826f
fix: use satsCeil for LNURL display amounts and revert LDK Node rev
ben-kaufman Apr 3, 2026
91a35c5
fix: use ceiling division for PaymentDetails.amountSats
ben-kaufman Apr 5, 2026
36af4da
fix: use ceiling for received payment notification amount
ben-kaufman Apr 5, 2026
fd1d1f8
fix: restore LDK Node rev to v0.7.0-rc.36 and add LightningAmountConv…
ovitrif Apr 5, 2026
ec303d7
fix: link CoreBluetooth for BitkitCore iOS builds
ovitrif Apr 5, 2026
0e32c43
Merge branch 'master' into fix/msat-invoice-precision
ovitrif Apr 6, 2026
6bf7773
fix: add LightningAmountConversion to BitkitTests target
ovitrif Apr 6, 2026
c72b745
fix: add LNURL amount extensions and fix sub-sat rounding checks
ovitrif Apr 6, 2026
1274929
fix: show amount on LNURL quickpay screen
ovitrif Apr 6, 2026
e2d0056
chore: enforce single changelog entry per PR rule
ovitrif Apr 6, 2026
c17ee16
fix: show send-success amount from lnurl and invoices
piotr-iohk Apr 7, 2026
b987e7c
Merge pull request #514 from synonymdev/fix/lnurl-amount-rounding
ovitrif Apr 7, 2026
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
21 changes: 10 additions & 11 deletions Bitkit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
18D65E002EB964B500252335 /* VssRustClientFfi in Frameworks */ = {isa = PBXBuildFile; productRef = 18D65DFF2EB964B500252335 /* VssRustClientFfi */; };
18D65E022EB964BD00252335 /* VssRustClientFfi in Frameworks */ = {isa = PBXBuildFile; productRef = 18D65E012EB964BD00252335 /* VssRustClientFfi */; };
3D76260F4C9C4A53B1E4A001 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D76260E4C9C4A53B1E4A001 /* CoreBluetooth.framework */; };
3D7626104C9C4A53B1E4A001 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D76260E4C9C4A53B1E4A001 /* CoreBluetooth.framework */; };
4AAB08CA2E1FE77600BA63DF /* Lottie in Frameworks */ = {isa = PBXBuildFile; productRef = 4AAB08C92E1FE77600BA63DF /* Lottie */; };
4AFCA3702E05933800205CAE /* Zip in Frameworks */ = {isa = PBXBuildFile; productRef = 4AFCA36F2E05933800205CAE /* Zip */; };
4AFCA3722E0596D900205CAE /* Zip in Frameworks */ = {isa = PBXBuildFile; productRef = 4AFCA3712E0596D900205CAE /* Zip */; };
Expand Down Expand Up @@ -62,6 +64,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
3D76260E4C9C4A53B1E4A001 /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = System/Library/Frameworks/CoreBluetooth.framework; sourceTree = SDKROOT; };
961058DC2C355B5500E1F1D8 /* BitkitNotification.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = BitkitNotification.appex; sourceTree = BUILT_PRODUCTS_DIR; };
96FE1F612C2DE6AA006D0C8B /* Bitkit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bitkit.app; sourceTree = BUILT_PRODUCTS_DIR; };
96FE1F722C2DE6AC006D0C8B /* BitkitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = BitkitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -123,6 +126,7 @@
Utilities/Crypto.swift,
Utilities/Errors.swift,
Utilities/Keychain.swift,
Utilities/LightningAmountConversion.swift,
Utilities/Logger.swift,
Utilities/StateLocker.swift,
);
Expand All @@ -149,6 +153,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3D7626104C9C4A53B1E4A001 /* CoreBluetooth.framework in Frameworks */,
968FE1402DFB016B0053CD7F /* LDKNode in Frameworks */,
96DEA03C2DE8BBAB009932BF /* BitkitCore in Frameworks */,
4AFCA3722E0596D900205CAE /* Zip in Frameworks */,
Expand All @@ -161,6 +166,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3D76260F4C9C4A53B1E4A001 /* CoreBluetooth.framework in Frameworks */,
4AFCA3702E05933800205CAE /* Zip in Frameworks */,
968FDF162DFAFE230053CD7F /* LDKNode in Frameworks */,
18D65E002EB964B500252335 /* VssRustClientFfi in Frameworks */,
Expand Down Expand Up @@ -192,6 +198,7 @@
961058EC2C35798C00E1F1D8 /* Frameworks */ = {
isa = PBXGroup;
children = (
3D76260E4C9C4A53B1E4A001 /* CoreBluetooth.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -917,14 +924,6 @@
minimumVersion = 2.1.2;
};
};
962045C92DE998F1007BAA26 /* XCRemoteSwiftPackageReference "ldk-node" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/lightningdevkit/ldk-node";
requirement = {
branch = main;
kind = branch;
};
};
968FE13E2DFB016B0053CD7F /* XCRemoteSwiftPackageReference "ldk-node" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/synonymdev/ldk-node";
Expand All @@ -937,8 +936,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/synonymdev/bitkit-core";
requirement = {
branch = master;
kind = branch;
kind = revision;
revision = 99bd86bb60c1f14e8ce8a6356cd2ab36f222fc69;
};
};
96E20CD22CB6D91A00C24149 /* XCRemoteSwiftPackageReference "CodeScanner" */ = {
Expand Down Expand Up @@ -987,7 +986,7 @@
};
9613018B2C5022D700878183 /* LDKNode */ = {
isa = XCSwiftPackageProductDependency;
package = 962045C92DE998F1007BAA26 /* XCRemoteSwiftPackageReference "ldk-node" */;
package = 968FE13E2DFB016B0053CD7F /* XCRemoteSwiftPackageReference "ldk-node" */;
productName = LDKNode;
};
968FE13F2DFB016B0053CD7F /* LDKNode */ = {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Bitkit/Extensions/PaymentDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extension PaymentDetails {
var amountSats: UInt64? {
if let amountMsat {
return amountMsat / 1000
return LightningAmountConversion.satsCeil(fromMsats: amountMsat)

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

cannot find 'LightningAmountConversion' in scope

Check failure on line 7 in Bitkit/Extensions/PaymentDetails.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

cannot find 'LightningAmountConversion' in scope
}

return nil
Expand Down
8 changes: 6 additions & 2 deletions Bitkit/Services/LightningService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,20 @@ class LightningService {
}

func receive(amountSats: UInt64? = nil, description: String, expirySecs: UInt32 = 3600) async throws -> String {
try await receiveMsats(amountMsats: amountSats.map { $0 * 1000 }, description: description, expirySecs: expirySecs)
}

func receiveMsats(amountMsats: UInt64? = nil, description: String, expirySecs: UInt32 = 3600) async throws -> String {
guard let node else {
throw AppError(serviceError: .nodeNotSetup)
}

let bolt11 = try await ServiceQueue.background(.ldk) {
if let amountSats {
if let amountMsats {
try node
.bolt11Payment()
.receive(
amountMsat: amountSats * 1000,
amountMsat: amountMsats,
description: Bolt11InvoiceDescription.direct(description: description),
expirySecs: expirySecs
)
Expand Down
6 changes: 3 additions & 3 deletions Bitkit/Utilities/Lnurl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ struct LnurlHelper {
/// Fetches a Lightning invoice from an LNURL pay callback
/// - Parameters:
/// - callbackUrl: The LNURL callback URL
/// - amount: The amount in satoshis to pay
/// - amountMsats: The amount in millisatoshis to pay
/// - comment: Optional comment to include with the payment
/// - Returns: The bolt11 invoice string
/// - Throws: Network or parsing errors
static func fetchLnurlInvoice(
callbackUrl: String,
amount: UInt64,
amountMsats: UInt64,
comment: String? = nil
) async throws -> String {
var queryItems = [
URLQueryItem(name: "amount", value: String(amount * 1000)), // Convert to millisatoshis
URLQueryItem(name: "amount", value: String(amountMsats)),
]

// Add comment if provided
Expand Down
24 changes: 6 additions & 18 deletions Bitkit/ViewModels/AppViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,14 @@ extension AppViewModel {
}

private func handleLnurlPayInvoice(_ data: LnurlPayData) {
// Check if lightning service is running
guard lightningService.status?.isRunning == true else {
toast(type: .error, title: "Lightning not running", description: "Please try again later.")
return
}

var normalizedData = data
normalizedData.minSendable = max(1, LightningAmountConversion.satsCeil(fromMsats: normalizedData.minSendable))
normalizedData.maxSendable = max(normalizedData.minSendable, LightningAmountConversion.satsFloor(fromMsats: normalizedData.maxSendable))

// Check if user has enough lightning balance to pay the minimum amount
let minSats = max(1, LightningAmountConversion.satsCeil(fromMsats: data.minSendable))
let lightningBalance = lightningService.balances?.totalLightningBalanceSats ?? 0
if lightningBalance < normalizedData.minSendable {
if lightningBalance < minSats {
toast(
type: .warning,
title: t("other__lnurl_pay_error"),
Expand All @@ -502,11 +497,10 @@ extension AppViewModel {
}

selectedWalletToPayFrom = .lightning
lnurlPayData = normalizedData
lnurlPayData = data
Comment thread
ovitrif marked this conversation as resolved.
Comment thread
ovitrif marked this conversation as resolved.
}

private func handleLnurlWithdraw(_ data: LnurlWithdrawData) {
// Check if lightning service is running
guard lightningService.status?.isRunning == true else {
toast(type: .error, title: "Lightning not running", description: "Please try again later.")
return
Expand All @@ -515,7 +509,6 @@ extension AppViewModel {
let minMsats = data.minWithdrawable ?? Env.msatsPerSat
let maxMsats = data.maxWithdrawable

// Check if minWithdrawable > maxWithdrawable
if minMsats > maxMsats {
toast(
type: .warning,
Expand All @@ -525,13 +518,7 @@ extension AppViewModel {
return
}

var normalizedData = data
let minSats = max(1, LightningAmountConversion.satsCeil(fromMsats: minMsats))
let maxSats = max(minSats, LightningAmountConversion.satsFloor(fromMsats: maxMsats))
normalizedData.minWithdrawable = minSats
normalizedData.maxWithdrawable = maxSats

// Check if we have enough receiving capacity
let lightningBalance = lightningService.balances?.totalLightningBalanceSats ?? 0
if lightningBalance < minSats {
toast(
Expand All @@ -542,7 +529,7 @@ extension AppViewModel {
return
}

lnurlWithdrawData = normalizedData
lnurlWithdrawData = data
}

private func handleLnurlChannel(_ data: LnurlChannelData) {
Expand Down Expand Up @@ -739,7 +726,8 @@ extension AppViewModel {
}

await MainActor.run {
sheetViewModel.showSheet(.receivedTx, data: ReceivedTxSheetDetails(type: .lightning, sats: amountMsat / 1000))
let sats = LightningAmountConversion.satsCeil(fromMsats: amountMsat)
sheetViewModel.showSheet(.receivedTx, data: ReceivedTxSheetDetails(type: .lightning, sats: sats))
}
}
case .channelPending(channelId: _, userChannelId: _, formerTemporaryChannelId: _, counterpartyNodeId: _, fundingTxo: _):
Expand Down
6 changes: 6 additions & 0 deletions Bitkit/ViewModels/WalletViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ class WalletViewModel: ObservableObject {
return invoice.lowercased()
}

func createInvoiceMsats(amountMsats: UInt64, note: String, expirySecs: UInt32? = nil) async throws -> String {
let finalExpirySecs = expirySecs ?? 60 * 60 * 24
let invoice = try await lightningService.receiveMsats(amountMsats: amountMsats, description: note, expirySecs: finalExpirySecs)
return invoice.lowercased()
}

@discardableResult
func waitForNodeToRun(timeoutSeconds: Double = 10.0) async -> Bool {
guard nodeLifecycleState != .running else { return true }
Expand Down
5 changes: 3 additions & 2 deletions Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawAmount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ struct LnurlWithdrawAmount: View {
@StateObject private var amountViewModel = AmountInputViewModel()

var minAmount: Int {
Int(app.lnurlWithdrawData!.minWithdrawable ?? 1)
let minMsats = app.lnurlWithdrawData!.minWithdrawable ?? Env.msatsPerSat
return Int(max(1, LightningAmountConversion.satsCeil(fromMsats: minMsats)))
}

var maxAmount: Int {
Int(app.lnurlWithdrawData!.maxWithdrawable)
Int(LightningAmountConversion.satsFloor(fromMsats: app.lnurlWithdrawData!.maxWithdrawable))
}

var amount: UInt64 {
Expand Down
36 changes: 22 additions & 14 deletions Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawConfirm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ struct LnurlWithdrawConfirm: View {
let onFailure: (UInt64) -> Void
@State private var isLoading = false

var amount: UInt64 {
// Fixed amount
if app.lnurlWithdrawData!.maxWithdrawable == app.lnurlWithdrawData!.minWithdrawable {
return app.lnurlWithdrawData!.maxWithdrawable
}
var isFixedAmount: Bool {
app.lnurlWithdrawData!.maxWithdrawable == app.lnurlWithdrawData!.minWithdrawable
}

// For variable amount, use the amount from the previous screen
var displayAmountSats: UInt64 {
if isFixedAmount {
return LightningAmountConversion.satsCeil(fromMsats: app.lnurlWithdrawData!.maxWithdrawable)
}
return wallet.lnurlWithdrawAmount!
}

var body: some View {
VStack(spacing: 0) {
SheetHeader(title: t("wallet__lnurl_w_title"), showBackButton: true)

MoneyStack(sats: Int(amount), showSymbol: true, testIdPrefix: "WithdrawAmount")
MoneyStack(sats: Int(displayAmountSats), showSymbol: true, testIdPrefix: "WithdrawAmount")
.padding(.top, 16)
.padding(.bottom, 42)

Expand Down Expand Up @@ -58,12 +59,19 @@ struct LnurlWithdrawConfirm: View {
throw NSError(domain: "LNURL", code: -1, userInfo: [NSLocalizedDescriptionKey: "Missing LNURL withdraw data"])
}

// Create a Lightning invoice for the withdraw
let invoice = try await wallet.createInvoice(
amountSats: amount,
note: withdrawData.defaultDescription,
expirySecs: 3600
)
let invoice: String = if isFixedAmount {
try await wallet.createInvoiceMsats(
amountMsats: withdrawData.maxWithdrawable,
note: withdrawData.defaultDescription,
expirySecs: 3600
)
} else {
try await wallet.createInvoice(
amountSats: displayAmountSats,
note: withdrawData.defaultDescription,
expirySecs: 3600
)
}

// Perform the LNURL withdraw
try await LnurlHelper.handleLnurlWithdraw(
Expand All @@ -84,7 +92,7 @@ struct LnurlWithdrawConfirm: View {

} catch {
await MainActor.run {
onFailure(amount)
onFailure(displayAmountSats)
isLoading = false
}
}
Expand Down
8 changes: 4 additions & 4 deletions Bitkit/Views/Wallets/Send/LnurlPayAmount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct LnurlPayAmount: View {

var maxAmount: UInt64 {
// TODO: subtract fee
min(app.lnurlPayData!.maxSendable, UInt64(wallet.totalLightningSats))
min(LightningAmountConversion.satsFloor(fromMsats: app.lnurlPayData!.maxSendable), UInt64(wallet.totalLightningSats))
}

var amount: UInt64 {
Expand Down Expand Up @@ -80,12 +80,12 @@ struct LnurlPayAmount: View {
}

private func onContinue() {
let minSendable = app.lnurlPayData!.minSendable
let minSendableSats = max(1, LightningAmountConversion.satsCeil(fromMsats: app.lnurlPayData!.minSendable))

if amount < minSendable {
if amount < minSendableSats {
app.toast(
type: .error, title: t("wallet__lnurl_pay__error_min__title"),
description: t("wallet__lnurl_pay__error_min__description", variables: ["amount": "\(minSendable)"]),
description: t("wallet__lnurl_pay__error_min__description", variables: ["amount": "\(minSendableSats)"]),
accessibilityIdentifier: "LnurlPayAmountTooLowToast"
)
return
Expand Down
14 changes: 10 additions & 4 deletions Bitkit/Views/Wallets/Send/LnurlPayConfirm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct LnurlPayConfirm: View {

VStack(alignment: .leading) {
MoneyStack(
sats: Int(wallet.sendAmountSats ?? app.lnurlPayData!.minSendable),
sats: Int(wallet.sendAmountSats ?? LightningAmountConversion.satsCeil(fromMsats: app.lnurlPayData!.minSendable)),
showSymbol: true,
testIdPrefix: "ReviewAmount"
)
Expand Down Expand Up @@ -186,12 +186,16 @@ struct LnurlPayConfirm: View {
throw NSError(domain: "LNURL", code: -1, userInfo: [NSLocalizedDescriptionKey: "Missing LNURL pay data"])
}

let amount = wallet.sendAmountSats ?? lnurlPayData.minSendable
let amountMsats: UInt64 = if let userSats = wallet.sendAmountSats {
userSats * 1000
} else {
lnurlPayData.minSendable
}

// Fetch the Lightning invoice from LNURL
let bolt11 = try await LnurlHelper.fetchLnurlInvoice(
callbackUrl: lnurlPayData.callback,
amount: amount,
amountMsats: amountMsats,
comment: comment.isEmpty ? nil : comment
)

Expand All @@ -200,9 +204,11 @@ struct LnurlPayConfirm: View {

do {
// Perform the Lightning payment (10s timeout → navigate to pending for hold invoices)
// LNURL server returns invoices with the amount baked in, so pass sats: nil
// to let LDK use the invoice's native millisatoshi precision.
try await wallet.sendWithTimeout(
bolt11: bolt11,
sats: wallet.sendAmountSats,
sats: nil,
onTimeout: {
app.addPendingPaymentHash(paymentHash)
navigationPath.append(.pending(paymentHash: paymentHash))
Expand Down
Loading
Loading