Skip to content

Conversation

@piotr-iohk
Copy link
Collaborator

@piotr-iohk piotr-iohk commented Dec 17, 2025

Description

  • LNURL-pay/withdraw endpoints express minSendable / maxSendable (and withdraw bounds) in millisatoshis (msat), while Bitkit’s amount entry and validation are in whole sats.
  • Previously we converted msats→sats using integer division (floor). This is usually fine when values are multiples of 1000, but it can understate the true minimum when the server returns non-round msat values (e.g. 100500 msat), letting the user enter 100 sats even though the server requires at least 101 sats.
  • This PR fixes the conversion by rounding minimum bounds up (ceil) and keeping maximum bounds down (floor), preventing “amount too low” errors after the user already satisfied the UI minimum.
  • Added unit tests that document the rounding rules and guard against regressions.
  • additionally adding Boost toast ids (not related to fix)

Linked Issues/Tasks

Screenshot / Video

Insert relevant screenshot / recording

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an edge case in LNURL amount conversion where millisatoshi values not divisible by 1000 could cause validation errors. The fix introduces proper ceiling/floor rounding when converting from millisatoshis to satoshis, ensuring minimum bounds are met and maximum bounds are not exceeded.

Key Changes

  • Introduced LnurlAmountConversion utility enum with satsCeil and satsFloor methods for proper msat→sats conversion
  • Updated LNURL pay and withdraw handlers to use the new conversion methods instead of integer division
  • Added comprehensive unit tests covering rounding edge cases

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Bitkit/Utilities/LnurlAmountConversion.swift New utility enum providing ceiling and floor conversion methods from millisatoshis to satoshis
BitkitTests/LnurlAmountConversionTests.swift Unit tests verifying correct rounding behavior for both exact and non-divisible msat values
Bitkit/ViewModels/AppViewModel.swift Updated handleLnurlPayInvoice and handleLnurlWithdraw methods to use new conversion utilities instead of integer division

@piotr-iohk piotr-iohk requested review from jvsena42 and pwltr December 17, 2025 11:40
Copy link
Contributor

@pwltr pwltr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utAck

@piotr-iohk piotr-iohk merged commit 73dbd4f into master Dec 17, 2025
11 of 12 checks passed
@piotr-iohk piotr-iohk deleted the fix/lnurl-min-send-ceil branch December 17, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants