fix(frontend): show exact Sats for swap order amounts#2510
Open
21Mill wants to merge 1 commit into
Open
Conversation
a2b0edd to
86f7b87
Compare
86f7b87 to
2aa3bb2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Swap orders (currency code
1000) are denominated in Sats, but the order amount inOrderDetailswas rendered throughamountToString(), which rounds to 4 significant figures (toPrecision(4)).For a real order with
amount = 0.01012540 BTC, the interface showed1,013,000 Sats, while the "Confirm sent" button — which uses the exactorder.amountviatoFixed(8)— showed0.01012540 BTC = 1,012,540 Sats.The two figures disagree. The peer expects exactly
order.amount(1,012,540Sats), so the rounded value in the interface is misleading and could cause the payer to send the wrong amount.Root cause
toPrecision(4)is the right rounding for fiat amounts, but when the swap amount is expressed in Sats (amount * 1e8), it collapses1012540to1.013e6→1,013,000.Fix
btcToSatsString()helper inprettyNumbers.tsthat formats the exact integer Sat amount (with range support), usingMath.round(btc * 1e8)instead of significant-figure rounding.OrderDetailsfor thecurrency === 1000branch, so the displayed Sats always match the exact contract amount (and the "Confirm sent" button).Tests
Adds unit tests for
btcToSatsString, including a regression test:0.01012540 BTC → "1,012,540"(previously1,013,000).Verification
Confirmed against a real order from the backend (
amount: "0.01012540",currency: 1000,payment_method: "On-Chain BTC"): the expected amount is1,012,540Sats, which the fix now renders correctly.Checklist before merging
pip install pre-commit, thenpre-commit install. Pre-commit installs git hooks that automatically check the codebase. If pre-commit fails when you commit your changes, please fix the problems it points out.