Skip to content

fix: validate deposits, fix milestone progress, XLM precision, role-based redirect - #332

Merged
chonilius merged 3 commits into
MergeFi:mainfrom
brightcli-stack:fix/69-75-deposit-validation-and-milestone-progress
Aug 25, 2026
Merged

chonilius merged 3 commits into
MergeFi:mainfrom
brightcli-stack:fix/69-75-deposit-validation-and-milestone-progress

Conversation

@brightcli-stack

@brightcli-stack brightcli-stack commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #69
Fixes #75
Fixes #76
Fixes #77

What changed

  • Added parseMoneyInput helper in src/lib/utils.ts that validates monetary input strings against asset-specific precision limits (USDC: 2 decimals, XLM: 7 decimals), rejects empty/zero/negative/non-finite/over-precision values, and returns a normalized canonical decimal string
  • Updated PoolDepositButton to accept an asset prop, validate the amount on every change and at submit time, disable the Deposit button when invalid, and send the normalized value to the API
  • Threaded pool.asset from the milestones page through to PoolDepositButton
  • Guarded the milestone progress pct calculation against budget <= 0 to prevent NaN/Infinity, clamped to 100% for over-funded milestones, and added honest labels ("Not yet funded", "Over-funded") for edge cases
  • Made formatCurrency and StatCard's internal currency formatter branch maximumFractionDigits on asset: XLM gets 7 decimal places, USDC stays at 2
  • Updated CallbackClient to redirect post-login based on user.roles with precedence maintainer > sponsor > contributor, falling back to /dashboard/contributor for empty/missing roles or null user

Why

  • PoolDepositButton had no client-side validation — empty, negative, zero, or non-numeric amounts were sent directly to the backend
  • Milestone progress bar produced NaN% when budget was 0, and showed misleading "0%" when distributed > budget
  • formatCurrency hardcoded 2-decimal precision for all assets, silently discarding XLM's native 7-decimal precision
  • CallbackClient always redirected to /dashboard/contributor regardless of the user's actual roles, forcing maintainers and sponsors to manually navigate to their dashboard

How to test

  • Deposit: enter empty, zero, negative, non-numeric, or over-precision values — button should be disabled with inline error
  • Deposit: enter a valid amount — button enabled, clicking sends the normalized value
  • Milestones: a milestone with budget=0 should show "Not yet funded" with no NaN
  • Milestones: a milestone with distributed > budget should show "Over-funded" with bar at 100%
  • formatCurrency(12.3456789, "XLM") should show more than 2 decimal places
  • formatCurrency(0.0000005, "XLM") should not display as "0 XLM"
  • OAuth: a user with roles: ["maintainer"] should be redirected to /dashboard/maintainer
  • OAuth: a user with empty roles should be redirected to /dashboard/contributor
  • Run npx jest src/lib/utils.test.ts src/app/auth/callback/CallbackClient.test.tsx — all tests pass

- Add parseMoneyInput helper to validate monetary input strings against
  asset-specific precision limits (USDC: 2 decimals, XLM: 7 decimals)
- Validate PoolDepositButton amount on every change and at submit time,
  disable button when invalid, normalize the value before sending to API
- Thread pool.asset through to PoolDepositButton for precision-aware
  validation (fixes MergeFi#69)
- Guard milestone progress pct calculation against budget <= 0 to prevent
  NaN/Infinity, clamp to 100% for over-funded milestones, show honest
  labels for unfunded and over-funded states (fixes MergeFi#75)
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

@brightcli-stack is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

…ased redirect

- Add parseMoneyInput helper to validate deposit amounts against
  asset-specific precision (USDC: 2, XLM: 7 decimals), normalize output,
  and disable the Deposit button when invalid (fixes MergeFi#69)
- Guard milestone progress pct against budget <= 0 to prevent NaN/Infinity,
  clamp to 100% for over-funded milestones, show honest labels (fixes MergeFi#75)
- Make formatCurrency and StatCard branch maximumFractionDigits on asset:
  XLM gets 7 decimal places, USDC stays at 2 (fixes MergeFi#76)
- Redirect CallbackClient post-login based on user.roles with precedence
  maintainer > sponsor > contributor, fallback to /dashboard/contributor
  for empty/missing roles or null user (fixes MergeFi#77)
@brightcli-stack brightcli-stack changed the title fix: validate deposit amounts and fix milestone progress divide-by-zero fix: validate deposits, fix milestone progress, XLM precision, role-based redirect Aug 25, 2026
@drips-wave

drips-wave Bot commented Aug 25, 2026

Copy link
Copy Markdown

@brightcli-stack 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