Skip to content

feat(lib): Add centralised amount formatting helper for consistent token rendering#168

Open
NUMBER72857 wants to merge 1 commit into
Tx-wat:mainfrom
NUMBER72857:feat/105-amount-formatting-helper
Open

feat(lib): Add centralised amount formatting helper for consistent token rendering#168
NUMBER72857 wants to merge 1 commit into
Tx-wat:mainfrom
NUMBER72857:feat/105-amount-formatting-helper

Conversation

@NUMBER72857
Copy link
Copy Markdown

Summary

Centralises all amount rendering in lib/formatAmount.ts so decimal places, locale formatting, and unit labels are consistent site-wide. Replace inline toFixed() / template literal calls in WebhookLog.tsx with these helpers.

Changes

  • lib/formatAmount.ts:
    • formatAmount(raw, asset, stroops?): full label, asset-aware decimals (XLM=7, USDC=2)
    • formatAmountValue(): number only — for table cells where column header names the asset
    • formatAmountCompact(): K/M abbreviations for summary widgets
    • isZeroAmount(): zero-value predicate for conditional styling
  • __tests__/formatAmount.test.ts: 16 tests covering all paths, edge cases, stroops conversion, NaN

Usage in WebhookLog.tsx

import { formatAmount } from '@/lib/formatAmount';
// Replace: {entry.amount} {entry.asset}
// With:    {formatAmount(entry.amount, entry.asset)}

Closes #105

…endering (Tx-wat#105)

- formatAmount(): asset-aware decimal places (XLM=7, USDC=2, unknown=7)
- formatAmountValue(): label-free variant for table cells with asset header
- formatAmountCompact(): K/M abbreviations for dashboard summaries
- isZeroAmount(): zero-value predicate
- stroops flag: divide by 1e7 for raw Stellar ledger values
- 16 unit tests covering all functions, edge cases, and NaN/non-finite input

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

drips-wave Bot commented May 30, 2026

@NUMBER72857 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

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 amount formatting helper

2 participants