fix: add validated, precision-safe decimal coercion in adapters.ts - #56
Merged
chonilius merged 1 commit intoJul 17, 2026
Merged
Conversation
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.
|
Someone is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
Author
|
@chonilius Ready for review. This PR Decimal coercion helpers (fix #3). All CI green. Mergeable. Pays USDC on Stellar (Soroban) on merge. |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3
Replaces bare
Number(raw.field)calls with safe coercion helpers that handle:null/undefined→fallback(default 0)NaN/Infinity→fallbackfallback(for amounts, budgets, earnings, hours)Changes
src/lib/utils.tscoerceDecimal(value, fallback)— base safe conversioncoerceNonNegative(value, fallback)— amounts, budgets, earningscoerceFraction(value, fallback)— rates clamped to [0, 1]coercePercentage(value, fallback)— percentages clamped to [0, 100]formatCurrency— guard against non-finiteamountformatPercent— guard against non-finitevaluesrc/lib/adapters.tsadaptBounty:reward→coerceNonNegative,percentage→coercePercentageadaptMilestone:budget,distributed→coerceNonNegativeadaptMaintenancePool:monthlyDeposit,balance→coerceNonNegativeadaptReputation:lifetimeEarnings,avgReviewTimeHours→coerceNonNegative;completionRate,onTimeDeliveryRate→coerceDecimal+/100Testing
All existing behavior preserved for valid inputs. Invalid/corrupt inputs now produce safe defaults (0) instead of propagating NaN or Infinity through the UI.