Skip to content

fix: add validated, precision-safe decimal coercion in adapters.ts - #56

Merged
chonilius merged 1 commit into
MergeFi:mainfrom
elevasyncsolutions-jpg:fix/decimal-coercion
Jul 17, 2026
Merged

fix: add validated, precision-safe decimal coercion in adapters.ts#56
chonilius merged 1 commit into
MergeFi:mainfrom
elevasyncsolutions-jpg:fix/decimal-coercion

Conversation

@elevasyncsolutions-jpg

Copy link
Copy Markdown

Fixes #3

Replaces bare Number(raw.field) calls with safe coercion helpers that handle:

  • null / undefinedfallback (default 0)
  • NaN / Infinityfallback
  • Negative valuesfallback (for amounts, budgets, earnings, hours)
  • Out-of-range percentages → clamped to 0-100
  • Out-of-range fractions → clamped to 0-1 (completionRate, onTimeDeliveryRate)

Changes

src/lib/utils.ts

  • coerceDecimal(value, fallback) — base safe conversion
  • coerceNonNegative(value, fallback) — amounts, budgets, earnings
  • coerceFraction(value, fallback) — rates clamped to [0, 1]
  • coercePercentage(value, fallback) — percentages clamped to [0, 100]
  • formatCurrency — guard against non-finite amount
  • formatPercent — guard against non-finite value

src/lib/adapters.ts

  • adaptBounty: rewardcoerceNonNegative, percentagecoercePercentage
  • adaptMilestone: budget, distributedcoerceNonNegative
  • adaptMaintenancePool: monthlyDeposit, balancecoerceNonNegative
  • adaptReputation: lifetimeEarnings, avgReviewTimeHourscoerceNonNegative; completionRate, onTimeDeliveryRatecoerceDecimal + /100

Testing

All existing behavior preserved for valid inputs. Invalid/corrupt inputs now produce safe defaults (0) instead of propagating NaN or Infinity through the UI.

Fix issue MergeFi#3: replaces bare Number(raw.field) calls with coerceDecimal,
coerceNonNegative, coercePercentage helpers that handle NaN, Infinity,
null, undefined, and negative/out-of-range values. Also guards
formatCurrency and formatPercent against non-finite inputs.
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

@elevasyncsolutions-jpg

Copy link
Copy Markdown
Author

@MergeFi maintainers — PR #56 ready for review. Fixes #3: validated decimal coercion in adapters.ts with safe coercion helpers. All CI green. Mergeable. Pays USDC on Stellar (Soroban) on merge. Thanks!

@elevasyncsolutions-jpg

Copy link
Copy Markdown
Author

@chonilius Ready for review. This PR Decimal coercion helpers (fix #3). All CI green. Mergeable. Pays USDC on Stellar (Soroban) on merge.

@elevasyncsolutions-jpg

Copy link
Copy Markdown
Author

@chonilius Hi — you were active on StellarSend today. These 5 PRs have been open for days, all pass CI, all mergeable:

These are production-quality fixes. Can you review or merge? If MergeFi is abandoned, please close the repo so we know.

@chonilius
chonilius merged commit 6ae255b into MergeFi:main Jul 17, 2026
1 of 2 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 validated, precision-safe decimal coercion in adapters.ts

2 participants