Skip to content

feat(formatting): centralise XLM and relative-time formatting in shared hooks - #620

Closed
Obiajulu-gif wants to merge 1 commit into
accesslayerorg:mainfrom
Obiajulu-gif:fix/issue-547-formatting-hooks
Closed

feat(formatting): centralise XLM and relative-time formatting in shared hooks#620
Obiajulu-gif wants to merge 1 commit into
accesslayerorg:mainfrom
Obiajulu-gif:fix/issue-547-formatting-hooks

Conversation

@Obiajulu-gif

Copy link
Copy Markdown
Contributor

Summary

New src/hooks/formatting/ module (useFormatXlm.ts, useRelativeTime.ts):

  • useFormatXlm(amount: bigint | number, decimals = 2)Intl.NumberFormat('en-US', {min/maxFractionDigits}). A number is treated as an already-denominated XLM value; a bigint is treated as raw stroops and converted with whole/remainder bigint division against the existing STROOPS_PER_XLM constant (src/constants/stellar.ts, the same factor keyPriceDisplay.utils.ts already uses) to preserve fractional precision — no new conversion logic was written.
  • useRelativeTime(timestamp)Intl.RelativeTimeFormat('en-US', {numeric: 'auto'}), matching the same unit thresholds as the previous hand-rolled logic (minute/hour/day/"now"), with a 60-second setInterval re-render cleaned up on unmount (matching the useDropCountdown.ts convention).

Call sites migrated:

  • TransactionHistory.tsx ("the activity feed") — replaced the hand-rolled relative-time formatting and two (tx.amount * tx.price).toFixed(4) calls. Rows are rendered via .map(), so a TransactionRow child component was extracted to call the hooks legally per row.
  • TrendingCreatorCard.tsx — a genuine inline (creator.priceStroops / 1e7).toFixed(2) stroops→XLM display found via a repo-wide search, now routed through useFormatXlm.

"Trade panel"/"holdings" finding: there's no separate inline-formatted XLM amount to migrate there. TradeDialog.tsx already routes every XLM figure through the existing shared formatDisplayKeyPrice util, and its "Holdings: … keys" is a key count via formatNumber, not an XLM amount — so the only real migrations were TransactionHistory and TrendingCreatorCard.

Closes #547

Pre-existing bug noticed, not fixed (out of scope)

TransactionHistory.tsx labels amounts "ETH" in this Stellar/XLM app. Left untouched per scope — worth its own issue.

Test plan

  • Could not run vitest locally (no node_modules, disk space constraint in my environment) — please run the new useFormatXlm.test.ts/useRelativeTime.test.ts
  • Manually verify the activity feed and trending creator card still show correct amounts/timestamps, and that relative times advance after 60s without a page reload

…ed hooks

Add `hooks/formatting` module with two hooks and migrate inline call sites
(issue accesslayerorg#547):

- `useFormatXlm(amount: bigint | number, decimals = 2)`: locale-aware
  `Intl.NumberFormat('en-US')` output; bigint treated as raw stroops and
  converted via the shared `STROOPS_PER_XLM` factor with bigint division to
  preserve fractional precision.
- `useRelativeTime(timestamp)`: `Intl.RelativeTimeFormat` output using the
  same unit-selection thresholds as the previous hand-rolled logic; re-renders
  every 60s while mounted, interval cleaned up on unmount.

Migrate TransactionHistory (extracted a TransactionRow child so the hooks are
called per-row without violating the rules of hooks) and TrendingCreatorCard's
inline stroops->XLM `toFixed` off the shared hook. Add renderHook tests for
both hooks including fake-timer coverage of the 60s refresh.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@netlify

netlify Bot commented Jul 26, 2026

Copy link
Copy Markdown

Deploy Preview for accesslayer ready!

Name Link
🔨 Latest commit 385de18
🔍 Latest deploy log https://app.netlify.com/projects/accesslayer/deploys/6a665fbf01953800082c7bc9
😎 Deploy Preview https://deploy-preview-620--accesslayer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

Copy link
Copy Markdown

👋 Hey @Obiajulu-gif, thanks for your contribution!

This PR is targeting main directly. We use main for stable releases only — all contributions should be opened against the dev branch instead.

Please close this PR and reopen it with dev as the base branch. If you're unsure how to do that, you can change the base branch using the Edit button at the top of this PR page.

Closing this PR automatically. See you in dev! 🚀

@github-actions github-actions Bot closed this Jul 26, 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.

1 participant