Skip to content

fix(frontend): order same-timestamp send/receive pairs (receive above send)#13243

Open
sbpublic wants to merge 3 commits into
mainfrom
fix/frontend/activity-send-receive-order
Open

fix(frontend): order same-timestamp send/receive pairs (receive above send)#13243
sbpublic wants to merge 3 commits into
mainfrom
fix/frontend/activity-send-receive-order

Conversation

@sbpublic

@sbpublic sbpublic commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Motivation

In the activity list, the two legs of a single operation — a swap's send + receive, or a self-transfer — share the same block timestamp. sortTransactions compared only the (second-normalized) timestamp and returned 0 on ties, so these pairs fell back to Array.sort insertion order (driven by token/provider load order). The result looked arbitrary: sometimes the send appeared above the receive, sometimes below.

Changes

  • sortTransactions: when timestamps are equal, break the tie deterministically by type — the received leg sorts above the sent one. This is the single comparator the whole activity list uses, so every same-second send/receive pair (swaps, self-transfers, …) now orders consistently.
  • sortTransactions: return 0 when both timestamps are nullish (previously 1 — and 1 again when swapped, an antisymmetry-contract violation that left such pairs in engine-dependent order). The single-nullish case still sorts nullish last. (From Copilot review.)

Tests

  • Added sortTransactions tests: the received leg sorts above the sent one for a same-timestamp pair (regardless of input order), and the comparator returns 0 for two nullish-timestamp transactions in both argument orders.
  • transactions.utils.spec.ts passes in full (78).
  • Manual verification on test_fe_3.

Independent of #13242 — based directly on main and mergeable on its own. This is a standalone determinism fix for same-timestamp send/receive ordering (it also covers self-transfers). The full visible swap-pair effect additionally needs #13242's dedup fix (which keeps both legs); the two can land in any order.


Model: Claude Opus 4.8 (claude-opus-4-8)

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Ensures the global Activity list orders same-timestamp transaction pairs (swap/self-transfer send+receive legs) deterministically by adding a tie-breaker to the shared sortTransactions comparator and validating it with a unit test.

Changes:

  • Add a same-second tie-breaker in sortTransactions that ranks receive above send.
  • Introduce a helper to rank transaction types for tie-breaking.
  • Add a unit test asserting receive-before-send ordering regardless of input order.

Reviewed changes

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

File Description
src/frontend/src/lib/utils/transactions.utils.ts Adds type-based tie-breaker for same-timestamp sorting in sortTransactions.
src/frontend/src/tests/lib/utils/transactions.utils.spec.ts Adds regression test for receive-above-send ordering on timestamp ties.

Comment thread src/frontend/src/lib/utils/transactions.utils.ts Outdated
Comment thread src/frontend/src/tests/lib/utils/transactions.utils.spec.ts
sbpublic added a commit that referenced this pull request Jun 28, 2026
Address Copilot review on #13243: sortTransactions returned 1 for the
both-nullish case (and again with the arguments swapped), violating the
comparator's antisymmetry contract and leaving such pairs in engine-
dependent order. Return 0 when both timestamps are nullish; the single-
nullish case still sorts nullish last.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sbpublic added a commit that referenced this pull request Jun 28, 2026
…ions

Address Copilot review on #13243: assert sortTransactions returns 0 when
both timestamps are nullish (in both argument orders), locking the
comparator-contract fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
sbpublic and others added 3 commits June 28, 2026 20:52
…ve first

sortTransactions compared only the (second-normalized) timestamp and
returned 0 on ties, so the two legs of one operation — a swap's send and
receive, or a self-transfer — fell back to Array.sort insertion order,
which depends on token/provider load order and looked arbitrary.

Add a deterministic tie-breaker: when timestamps are equal, rank the
received leg above the sent one. It applies to every same-second
send/receive pair, so swaps and self-transfers now read consistently.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address Copilot review on #13243: sortTransactions returned 1 for the
both-nullish case (and again with the arguments swapped), violating the
comparator's antisymmetry contract and leaving such pairs in engine-
dependent order. Return 0 when both timestamps are nullish; the single-
nullish case still sorts nullish last.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ions

Address Copilot review on #13243: assert sortTransactions returns 0 when
both timestamps are nullish (in both argument orders), locking the
comparator-contract fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sbpublic sbpublic force-pushed the fix/frontend/activity-send-receive-order branch from 07139c2 to cf86823 Compare June 28, 2026 18:53
@sbpublic sbpublic changed the base branch from fix/frontend/activity-native-swap-leg to main June 28, 2026 18:53
@sbpublic sbpublic marked this pull request as ready for review June 28, 2026 18:56
@sbpublic sbpublic requested a review from a team as a code owner June 28, 2026 18:56
@zeropath-ai

zeropath-ai Bot commented Jun 28, 2026

Copy link
Copy Markdown

No security or compliance issues detected. Reviewed everything up to cf86823.

Security Overview
Detected Code Changes
Change Type Relevant files
Enhancement ► src/frontend/src/lib/utils/transactions.utils.ts
    Improve transaction sorting logic to handle timestamp ties deterministically by ranking received transactions above sent transactions.
    Introduce sameTimestampTypeRank helper function for ranking transaction types.
Enhancement ► src/frontend/src/tests/lib/utils/transactions.utils.spec.ts
    Add tests to verify the deterministic sorting of transactions with tied timestamps, specifically ensuring received legs appear before sent legs.
    Add a test case for scenarios where both timestamps are nullish.

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.

2 participants