Skip to content

fix: add shared STX formatting utilities and eliminate code duplication (#95)#199

Merged
Mosas2000 merged 2 commits intomainfrom
fix/stx-formatting-utility
Feb 26, 2026
Merged

fix: add shared STX formatting utilities and eliminate code duplication (#95)#199
Mosas2000 merged 2 commits intomainfrom
fix/stx-formatting-utility

Conversation

@Mosas2000
Copy link
Copy Markdown
Owner

Changes

New Utilities (lib/utils.js)

  • formatAddress(addr, startChars, endChars) — Consistent address truncation across all components
  • formatNumber(n, options) — Locale-aware number formatting

Refactored Components

  • TipHistory — Replace (value / 1000000).toFixed(2) with formatSTX(value, 2); use formatAddress()
  • Leaderboard — Replace inline address slice with formatAddress()
  • RecentTips — Replace inline address slice with formatAddress()
  • NotificationBell — Replace inline address slice with formatAddress()

Tests

  • 8 new tests for formatAddress (standard, custom params, short input, null/empty)
  • 4 new tests for formatNumber (locale, decimals, zero, string input)

20 utils tests passing, build clean

Closes #95

- Add formatAddress(addr, startChars, endChars) for consistent truncation
- Add formatNumber(n, options) for locale-aware number formatting
- Add 8 new tests for formatAddress and formatNumber functions
…red utils

- TipHistory: use formatSTX() instead of raw (value / 1000000).toFixed(2)
- TipHistory: use formatAddress() instead of inline slice
- Leaderboard: use formatAddress() instead of inline slice
- RecentTips: use formatAddress() instead of inline slice
- NotificationBell: use formatAddress() instead of inline slice
@Mosas2000 Mosas2000 merged commit 96cbf6b into main Feb 26, 2026
2 of 4 checks passed
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.

Add STX amount formatting utility to prevent code duplication

1 participant