Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ Ensure accessibility modifiers and labels are added to custom components.

### Changelog

- ALWAYS add an entry under `## [Unreleased]` in `CHANGELOG.md` for `feat:` and `fix:` PRs; skip for `chore:`, `ci:`, `refactor:`, `test:`, `docs:` unless the change is user-facing
- ALWAYS add exactly ONE entry per PR under `## [Unreleased]` in `CHANGELOG.md` for `feat:` and `fix:` PRs; skip for `chore:`, `ci:`, `refactor:`, `test:`, `docs:` unless the change is user-facing
- NEVER add multiple changelog lines for the same PR — summarize all changes in a single concise entry
- USE standard Keep a Changelog categories: `### Added`, `### Changed`, `### Deprecated`, `### Removed`, `### Fixed`, `### Security`
- ALWAYS append `#PR_NUMBER` at the end of each changelog entry when the PR number is known
- ALWAYS place new entries at the top of their category section (newest first)
Expand Down
22 changes: 11 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 @@ -100,6 +103,7 @@
Utilities/Crypto.swift,
Utilities/Errors.swift,
Utilities/Keychain.swift,
Utilities/LightningAmountConversion.swift,
Utilities/Logger.swift,
Utilities/StateLocker.swift,
);
Expand All @@ -123,6 +127,7 @@
Utilities/Crypto.swift,
Utilities/Errors.swift,
Utilities/Keychain.swift,
Utilities/LightningAmountConversion.swift,
Utilities/Logger.swift,
Utilities/StateLocker.swift,
);
Expand All @@ -149,6 +154,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 +167,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 +199,7 @@
961058EC2C35798C00E1F1D8 /* Frameworks */ = {
isa = PBXGroup;
children = (
3D76260E4C9C4A53B1E4A001 /* CoreBluetooth.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -917,14 +925,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 +937,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 +987,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.

49 changes: 49 additions & 0 deletions Bitkit/Extensions/LnurlPayData+Amount.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import BitkitCore

extension LnurlPayData {
var minSendableSat: UInt64 {
LightningAmountConversion.satsCeil(fromMsats: minSendable)
}

var maxSendableSat: UInt64 {
LightningAmountConversion.satsFloor(fromMsats: maxSendable)
}

/// True when the LNURL-pay endpoint specifies a single exact amount.
///
/// Also covers the sub-sat edge case where `minSendable` and `maxSendable`
/// differ in their sub-sat fraction but map to the same (or inverted) sat
/// range after rounding, e.g. `min=222222, max=222538` → `minSat=223, maxSat=222`.
var isFixedAmount: Bool {
minSendable == maxSendable || (minSendable > 0 && minSendableSat > maxSendableSat)
}

/// Returns the amount in millisatoshis for the LNURL-pay callback.
///
/// For fixed-amount requests the original msat value is returned verbatim,
/// avoiding precision loss from the msat→sat→msat round-trip.
/// For variable-amount requests the user-selected sat amount is converted to msats.
func callbackAmountMsats(userSats: UInt64? = nil) -> UInt64 {
if isFixedAmount {
return minSendable
}
return (userSats ?? minSendableSat) * Env.msatsPerSat
}
}

extension LnurlWithdrawData {
var minWithdrawableSat: UInt64 {
LightningAmountConversion.satsCeil(fromMsats: minWithdrawable ?? 0)
}

var maxWithdrawableSat: UInt64 {
LightningAmountConversion.satsFloor(fromMsats: maxWithdrawable)
}

/// True when the LNURL-withdraw endpoint specifies a single exact amount,
/// including the sub-sat edge case where rounding causes `min > max` in whole sats.
var isFixedAmount: Bool {
let min = minWithdrawable ?? 0
return min == maxWithdrawable || (min > 0 && minWithdrawableSat > maxWithdrawableSat)
}
}
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 @@ import LDKNode
extension PaymentDetails {
var amountSats: UInt64? {
if let amountMsat {
return amountMsat / 1000
return LightningAmountConversion.satsCeil(fromMsats: amountMsat)
}

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
15 changes: 7 additions & 8 deletions Bitkit/Utilities/PaymentNavigationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct PaymentNavigationHelper {
return false
}

// We need a lightning invoice to use quickpay
guard app.scannedLightningInvoice != nil else {
// We need a lightning invoice or LNURL pay data to use quickpay
guard app.scannedLightningInvoice != nil || app.lnurlPayData != nil else {
return false
}

Expand All @@ -32,8 +32,7 @@ struct PaymentNavigationHelper {

// Check LNURL pay
if let lnurlPayData = app.lnurlPayData {
// For LNURL pay, check if it's a fixed amount and within quickpay threshold
return lnurlPayData.minSendable == lnurlPayData.maxSendable && lnurlPayData.minSendable <= quickpayAmountSats
return lnurlPayData.isFixedAmount && lnurlPayData.minSendableSat <= quickpayAmountSats
}

// Check regular lightning invoice
Expand All @@ -50,7 +49,7 @@ struct PaymentNavigationHelper {
// Handle LNURL withdraw
if let lnurlWithdrawData = app.lnurlWithdrawData {
Logger.info("LNURL withdraw data: \(lnurlWithdrawData)")
if lnurlWithdrawData.minWithdrawable == lnurlWithdrawData.maxWithdrawable {
if lnurlWithdrawData.isFixedAmount {
sheetViewModel.showSheet(.lnurlWithdraw, data: LnurlWithdrawConfig(view: .confirm))
} else {
sheetViewModel.showSheet(.lnurlWithdraw, data: LnurlWithdrawConfig(view: .amount))
Expand All @@ -64,7 +63,7 @@ struct PaymentNavigationHelper {
if let lnurlPayData = app.lnurlPayData {
if shouldUseQuickpay {
sheetViewModel.showSheet(.send, data: SendConfig(view: .quickpay))
} else if lnurlPayData.minSendable == lnurlPayData.maxSendable {
} else if lnurlPayData.isFixedAmount {
sheetViewModel.showSheet(.send, data: SendConfig(view: .lnurlPayConfirm))
} else {
sheetViewModel.showSheet(.send, data: SendConfig(view: .lnurlPayAmount))
Expand Down Expand Up @@ -104,7 +103,7 @@ struct PaymentNavigationHelper {
settings: SettingsViewModel
) -> SendRoute? {
if let lnurlWithdrawData = app.lnurlWithdrawData {
if lnurlWithdrawData.minWithdrawable == lnurlWithdrawData.maxWithdrawable {
if lnurlWithdrawData.isFixedAmount {
return .lnurlWithdrawConfirm
} else {
return .lnurlWithdrawAmount
Expand All @@ -117,7 +116,7 @@ struct PaymentNavigationHelper {
if let lnurlPayData = app.lnurlPayData {
if shouldUseQuickpay {
return .quickpay
} else if lnurlPayData.minSendable == lnurlPayData.maxSendable {
} else if lnurlPayData.isFixedAmount {
return .lnurlPayConfirm
} else {
return .lnurlPayAmount
Expand Down
31 changes: 7 additions & 24 deletions Bitkit/ViewModels/AppViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,13 @@ 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 lightningBalance = lightningService.balances?.totalLightningBalanceSats ?? 0
if lightningBalance < normalizedData.minSendable {
if lightningBalance < max(1, data.minSendableSat) {
toast(
type: .warning,
title: t("other__lnurl_pay_error"),
Expand All @@ -502,21 +496,16 @@ extension AppViewModel {
}

selectedWalletToPayFrom = .lightning
lnurlPayData = normalizedData
lnurlPayData = data
}

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
}

let minMsats = data.minWithdrawable ?? Env.msatsPerSat
let maxMsats = data.maxWithdrawable

// Check if minWithdrawable > maxWithdrawable
if minMsats > maxMsats {
if (data.minWithdrawable ?? 0) > data.maxWithdrawable {
toast(
type: .warning,
title: t("other__lnurl_withdr_error"),
Expand All @@ -525,15 +514,8 @@ 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 {
if lightningBalance < max(1, data.minWithdrawableSat) {
toast(
type: .warning,
title: t("other__lnurl_withdr_error"),
Expand All @@ -542,7 +524,7 @@ extension AppViewModel {
return
}

lnurlWithdrawData = normalizedData
lnurlWithdrawData = data
}

private func handleLnurlChannel(_ data: LnurlChannelData) {
Expand Down Expand Up @@ -739,7 +721,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
6 changes: 3 additions & 3 deletions Bitkit/Views/Wallets/LnurlWithdraw/LnurlWithdrawAmount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ struct LnurlWithdrawAmount: View {
@StateObject private var amountViewModel = AmountInputViewModel()

var minAmount: Int {
Int(app.lnurlWithdrawData!.minWithdrawable ?? 1)
Int(max(1, app.lnurlWithdrawData!.minWithdrawableSat))
}

var maxAmount: Int {
Int(app.lnurlWithdrawData!.maxWithdrawable)
Int(app.lnurlWithdrawData!.maxWithdrawableSat)
}

var amount: UInt64 {
amountViewModel.amountSats
}

var isValid: Bool {
amount <= maxAmount
amount >= minAmount && amount <= max(minAmount, maxAmount)
}

var body: some View {
Expand Down
Loading
Loading