[BUG]: Invoices with the same date are sorted out of order (ids compared as strings)

Open Beginner friendly
#330 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@anshulchikhale30-p is already working on this.

Since Nov 7, 2026.

  • #347 by @anshulchikhale30-p — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
frontend

Research direction

Start in frontend/src/utils/invoiceFilterSortHelpers.js at the comparator’s tie-breaker and trace how the default date sort uses it. Add the numeric-id ordering described in the issue, then cover the 9-to-10 boundary in frontend/tests/utils/invoiceFilterSortHelpers.test.js. Done when tied invoices sort by numeric id and the focused unit test passes.

Written by the indexing model from the issue text.

Description

bug
Bug Description

When two invoices tie on the sort key, filterAndSortInvoices breaks the tie with String(a.id).localeCompare(String(b.id)). Invoice ids are BigInts, so they are compared as text and "10" sorts before "9".

This affects the default table view (sort by date, descending):

  • All invoices created in one batch share the same issueDate (CreateInvoicesBatch.jsx uses a single issueDate for every row).
  • On-chain-only stubs have issueDate: null, so they all tie at 0.

File: frontend/src/utils/invoiceFilterSortHelpers.js (tie-breaker at the end of the sort comparator)

Expected behavior

Invoices that tie on the sort key should be ordered by their numeric id.

Proposed fix

Compare ids numerically in the tie-breaker:

cmp = String(a.id ?? "").localeCompare(String(b.id ?? ""), undefined, { numeric: true });

and add a unit test in frontend/tests/utils/invoiceFilterSortHelpers.test.js covering ids that cross a digit boundary (9 → 10).

Steps to Reproduce
const d = "2026-10-20T00:00:00";
const invoices = [8n, 9n, 10n, 11n].map((id) => ({ id, issueDate: d, amountDue: "1" }));

filterAndSortInvoices(invoices).map((i) => String(i.id));
// Actual:   ["9", "8", "11", "10"]
// Expected: ["11", "10", "9", "8"]

Or in the UI: create a batch of 10+ invoices and open the Sent/Received table. The order breaks where ids go from one digit to two digits.

I would like to work on this issue.

Logs and Screenshots

No response

Environment Details

No response

Impact

Critical - Application is unusable

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
Dominant language
JavaScript
Stars
13
Forks
62
Avg merge
2d 14h
Merged PRs (30d)
18

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StabilityNexus/Chainvoice

All issues in StabilityNexus/Chainvoice

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.