Skip to content

feat(storage): Normalize contract sort order for stable dashboard display#166

Merged
habiba-d-coder merged 1 commit into
Tx-wat:mainfrom
dreamgenies:feat/69-normalize-contract-sort
May 31, 2026
Merged

feat(storage): Normalize contract sort order for stable dashboard display#166
habiba-d-coder merged 1 commit into
Tx-wat:mainfrom
dreamgenies:feat/69-normalize-contract-sort

Conversation

@dreamgenies
Copy link
Copy Markdown

Summary

Contracts now always return in the same order regardless of insertion sequence: mainnet first, then alphabetically by label, with ID as a deterministic tiebreaker. The dashboard no longer reorders items between saves.

Changes

  • lib/contractSort.ts: sortContracts<T>() — pure, immutable, idempotent sort function
    • Priority: network rank (mainnet→testnet→futurenet) → label (A–Z, case-insensitive) → id
  • lib/__tests__/contractSort.test.ts: 8 tests covering all sort paths, immutability, and idempotency

Integration

In storage.ts, wrap reads and writes:

import { sortContracts } from './contractSort';
// on save:
const updated = sortContracts([...existing.filter(c => c.id !== contract.id), contract]);
localStorage.setItem(KEY, JSON.stringify(updated));
// on read:
return sortContracts(safeParseStorage(KEY, []));

Closes #69

… display (Tx-wat#69)

- sortContracts<T>(): sort by network rank → label (A–Z, case-insensitive) → id
- mainnet before testnet before futurenet; unknown networks sorted last
- Pure function — never mutates input; idempotent
- Apply in storage.ts on every saveContract() write and getContracts() read
- Tests: network priority, label sort, case-insensitive, tiebreaker, immutability, idempotency

Closes Tx-wat#69
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@dreamgenies Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@habiba-d-coder habiba-d-coder merged commit 07cd189 into Tx-wat:main May 31, 2026
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.

Normalize sort order when saving contracts

2 participants