From 4aed155ce63017558024d6f8d99a06a828ec9b5d Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 16:51:34 +0530 Subject: [PATCH] Fix NaN handling in currency conversion input validation The functions didn't validate that credits and amountInCents are finite numbers. If they were NaN or Infinity, Math.ceil(NaN * centsPerCredit) would return NaN. Added Number.isFinite() checks to return 0 for invalid inputs. --- common/src/util/currency.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/util/currency.ts b/common/src/util/currency.ts index b3499c01e5..09fbfcecea 100644 --- a/common/src/util/currency.ts +++ b/common/src/util/currency.ts @@ -8,6 +8,8 @@ export function convertCreditsToUsdCents( credits: number, centsPerCredit: number, ): number { + if (centsPerCredit <= 0) return 0 + if (!Number.isFinite(credits)) return 0 return Math.ceil(credits * centsPerCredit) } @@ -21,5 +23,7 @@ export function convertStripeGrantAmountToCredits( amountInCents: number, centsPerCredit: number, ): number { + if (centsPerCredit <= 0) return 0 + if (!Number.isFinite(amountInCents)) return 0 return Math.floor(amountInCents / centsPerCredit) }