Repository navigation
Conversation
sortPayments compared amounts with String(a.amount).localeCompare(...), so 999 ($9.99) ranked above 10000 ($100.00) and sort=amount&direction=desc returned the wrong largest payments. Compare integer minor units as numbers and add a test that fails on the old comparator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Ticket
No ticket. Ops (Dana) mentioned in passing that finding the largest payments means eyeballing the table. While checking whether the API could already sort by amount, I found that it can, but it returns the wrong rows.
What changed
Sorting payments by amount now orders them by value. Before,
GET /api/payments?sort=amount&direction=descput £99.99, $99.92 and £9.94 at the top, ahead of payments worth hundreds. Asking the API for the largest payments now returns them.How I verified it
Reproduced it before the fix:
curl "http://localhost:3000/api/payments?sort=amount&direction=desc"returned9999 GBP,9992 USD,994 GBPas the first three rows.Added
src/data/queries.test.tsfirst and ran it against the old comparator. 2 of its 3 tests failed (descending and ascending order). The third, which checks that the caller's array isn't reordered, passed.After the fix:
npm testreports 4 test files and 31 tests passing, including the 3 new ones.Same
curlafter the fix. The top five are47980 GBP,47935 GBP,47880 EUR,47826 GBP,47778 USD.npm testpassesNew behavior is covered by a test
Checked it in the browser. The payments table has no sort control yet, so I checked through the API, not the UI.
Acceptance criteria
No ticket, so no formal criteria. The goal was that sorting by amount, descending, returns the largest payments first. Met, and shown by the test and the
curloutput above.Bugs fixed along the way
src/data/queries.ts:81:sortPaymentscompared amounts withString(a.amount).localeCompare(String(b.amount)). Amounts are integer minor units, so comparing them as text ranks"9999"above"47980"because "9" > "4". Its comment said it sorted "by the formatted amount", but no formatting happened. It now compares numerically:(a.amount - b.amount) * factor.localeComparesorts insrc/(disputes, payouts, overview, payment detail). They all compare ISO-8601 UTC timestamps, where text order is chronological order. Nothing else sorts amounts as text.Notes for the reviewer
src/components/BarChart.tsxhas unrelated local edits, which are not in this PR.🤖 Generated with Claude Code