Skip to content

formatCurrency and StatCard hardcode 2-decimal precision for every asset, discarding XLM's native 7-decimal precision #76

Closed

Description

@chonilius

Overview

Every currency display in the app funnels through one of two formatters, and both hardcode a 2-decimal precision ceiling regardless of which asset is being shown, even though both functions explicitly accept an asset: "USDC" | "XLM" parameter:

src/lib/utils.ts:

export function formatCurrency(amount: number, asset: "USDC" | "XLM" = "USDC") {
  if (!Number.isFinite(amount)) return `0 ${asset}`;
  const abs = Math.abs(amount);
  return `${abs.toLocaleString("en-US", { maximumFractionDigits: 2 })} ${asset}`;
}

src/components/ui/StatCard.tsx's internal formatter:

case "currency": {
  const formatted = value.toLocaleString("en-US", { maximumFractionDigits: 2 });
  const display = `${formatted} ${asset}`;
  const exact = `${value.toLocaleString("en-US", { maximumFractionDigits: 6 })} ${asset}`;
  return { display, exact };
}

Both accept asset, both use it only to pick the trailing unit label, and neither branches on it for precision. XLM is a native Stellar asset with 7 decimal places of on-chain precision (1 XLM = 10,000,000 stroops) — this is the same 7-decimal precision the rest of this codebase clearly already knows about and treats as significant elsewhere (src/lib/wallet.ts signs real Soroban transactions with stroop-level amounts; the whole point of #17, "Eliminate floating-point drift in aggregated financial figures," is that this app cares about sub-cent/sub-stroop precision in its money math). Bounty.asset, Milestone.asset, and MaintenancePool.asset are all typed "USDC" | "XLM", and the adapters (adaptBounty, adaptMilestone, adaptMaintenancePool) pass whatever asset the backend sends straight through with no assumption that it'll always be USDC — XLM is a first-class, exercised code path, not a hypothetical.

With maximumFractionDigits: 2 applied unconditionally, an XLM amount like 12.3456789 XLM displays as "12.35 XLM" — silently rounding away 5 decimal places of real, on-chain value — and, more alarmingly, a small XLM amount like 0.0000005 XLM (a genuinely nonzero balance at native precision) rounds to "0 XLM", indistinguishable from an actual zero. This directly undermines StatCard's own stated design goal ("financial figures are NOT abbreviated... Instead the value text scales down gracefully... and the full unabbreviated figure is always available via the title attribute") — the exact tooltip string also only goes to maximumFractionDigits: 6 (one digit short of XLM's full 7-decimal precision) and, more importantly, formatCurrency (used everywhere outside StatCard, e.g. BountyCard, IssueDetailPage, ActivityList, MilestonesPage) has no "exact" fallback at all — whatever maximumFractionDigits: 2 throws away for an XLM amount is gone from the UI entirely, with no tooltip, no secondary display, nothing.

Requirements

  • Make formatCurrency branch its maximumFractionDigits on the asset parameter: an XLM-appropriate precision (up to 7 decimal places; consider whether trailing zeros should be trimmed for readability, e.g. via toLocaleString's minimumFractionDigits/maximumFractionDigits combination or a custom trim) versus USDC's existing 2.
  • Apply the same asset-aware precision fix to StatCard's internal formatValue, for both the display and exact strings — the exact string in particular should reflect XLM's true 7-decimal precision, not top out at 6.
  • Decide and document the display policy for very small XLM amounts (e.g. sub-0.0000001 XLM) — should they ever round to a literal "0 XLM," or should there be a floor below which the display switches to a "<0.0000001 XLM" style representation to avoid ever showing a genuinely nonzero balance as zero? This directly interacts with StatCard's zero-state logic (isNumericZero = typeof value === "number" && value === 0), which is a strict equality check on the raw number, not the display string — worth confirming this doesn't need to change, but call it out explicitly since it's adjacent, easily-confused territory.
  • Audit every call site of formatCurrency for any place that assumes 2-decimal-max output specifically (e.g. any manual string-length/width calculations) that might break once XLM amounts can render longer.

Acceptance Criteria

  • formatCurrency(12.3456789, "XLM") (or equivalent) displays meaningfully more precision than formatCurrency(12.3456789, "USDC") — the two are no longer identical modulo the trailing unit label.
  • A small nonzero XLM amount (e.g. 0.0000005) does not display as "0 XLM".
  • StatCard's exact tooltip string for an XLM value reflects up to 7 decimal places, not 6.
  • USDC formatting is unchanged (2 decimal places, no regression).
  • A test in StatCard.test.tsx (extending its existing "large financial value" / "pre-formatted string" suites) and a new test for formatCurrency in src/lib/utils.test.ts (there is currently no test file for utils.ts at all) cover both assets at multiple precision levels, including a small-XLM-amount non-zero case.

Additional Notes

Precise references:

  • src/lib/utils.ts:34-38 — formatCurrency, the hardcoded maximumFractionDigits: 2.
  • src/components/ui/StatCard.tsx:74-88 (the "currency" branch of formatValue) and :58-59 (the doc comment: asset?: "USDC" | "XLM" — "Currency asset label appended when format="currency". Defaults to "USDC"." — note the doc comment itself only describes asset as controlling the trailing label, confirming this was a deliberate (if incomplete) design, not an oversight in the type signature alone).
  • src/types/index.ts:23-40 (Bounty.asset), :42-51 (Milestone.asset), :74-80 (MaintenancePool.asset) — all "USDC" | "XLM", confirming XLM is a modeled, first-class asset throughout the domain types, not just an incidental union member.
  • src/lib/adapters.ts:42-53,108-114 — RawBounty.asset/RawMaintenancePool.asset, both passed through from the backend with no asset-specific branching, confirming XLM bounties/pools are a real, exercised path today.

Relationship to other issues: distinct from #17 ("Eliminate floating-point drift in aggregated financial figures"), which is about summation/accumulation error from using JS floats for money math across many operations. This issue is about display quantization — the formatter deliberately throwing away real precision it was given, for one specific asset, regardless of whether the underlying number itself is exact. Fixing #17 doesn't fix this, and fixing this doesn't fix #17; they compound if both are present (a value that's already drifted from float summation, then further rounded away by 2-decimal display, for an asset that needed 7).

Test/reproduction plan: unit-test formatCurrency(0.0000005, "XLM") and confirm it is not "0 XLM"; unit-test formatCurrency(12.3456789, "XLM") and confirm more than 2 fractional digits are present; unit-test formatCurrency(12.3456789, "USDC") and confirm it's still exactly "12.35 USDC" (no regression); repeat the currency-precision assertions for StatCard's display/exact pair via StatCard.test.tsx, checking the title attribute specifically for the 7-decimal XLM case.

Activity

  1. added
    bug
    very hard
    architecture
    Maybe Rewarded
    GrantFox OSS
    Official Campaign | FWC26
    on Aug 16, 2026
  2. added
    Third Campaign
    on Aug 16, 2026
  3. nighshift-labs commented on Aug 17, 2026

    @nighshift-labs

    I reproduced the issue at public tip 5eec1ce: the current formatter returns 12.35 XLM for 12.3456789 and 0 XLM for 0.0000005, while USDC remains correctly two-decimal. I prepared a bounded precision-policy/test slice here: research/2026-08-17-mergefi-xlm-display-precision-prospect.md and deliverables/mergefi-xlm-display-precision-micro-delivery.md.

    Would maintainers prefer the below-one-stroop display policy to be <0.0000001 XLM, and can you confirm the campaign reward/acceptance path before anyone implements?

  4. added
    Stellar Wave
    on Aug 25, 2026
  5. biqqest commented on Aug 25, 2026

    @biqqest

    @biqqest has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi Maintainer, I'd love to work on this issue please. I deliver high impact solutions, ensuring seamless workflow and client satisfaction

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @biqqest to this issue.

  6. brightcli-stack commented on Aug 25, 2026

    @brightcli-stack
    Contributor

    @brightcli-stack has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    hello can i work on this issue please

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @brightcli-stack to this issue.

  7. codewithzubair07 commented on Aug 25, 2026

    @codewithzubair07

    @codewithzubair07 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I’m interested in contributing to this issue and believe I can deliver a clean, well-tested solution that aligns with the project’s standards.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @codewithzubair07 to this issue.

  8. OmniZlatoon commented on Aug 25, 2026

    @OmniZlatoon

    @OmniZlatoon has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Good day sir, Ready to deliver the task A.S.A.P. Gone through the issue and to be honest, i can work the task with the right tools at hand. please assign me maintainer . My eta is 5 hours

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @OmniZlatoon to this issue.

  9. Songu3020 commented on Aug 25, 2026

    @Songu3020

    @Songu3020 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi! I’m a full-stack developer with a strong blockchain background. I’d love to handle this issue and can deliver a clean, reliable solution. Kindly assign it to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Songu3020 to this issue.

  10. drips-wave commented on Aug 25, 2026

    @drips-wave

    Congratulations, @brightcli-stack! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @brightcli-stack: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  11. added a commit that references this issue on Aug 25, 2026
    b6cb677
  12. drips-wave commented on Aug 25, 2026

    @drips-wave

    This issue has been completed by @brightcli-stack as part of the Stellar Wave Program's 8th Wave 🥳

    😎 @brightcli-stack: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  13. removed
    Stellar Wave
    on Oct 15, 2026
  14. added
    Stellar Wave
    on Oct 15, 2026
  15. removed
    Stellar Wave
    on Oct 15, 2026
  16. added
    Stellar Wave
    on Oct 15, 2026
  17. removed
    Stellar Wave
    on Oct 15, 2026
  18. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26Stellar WaveThird Campaignarchitecturebugvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions