Skip to content

Reject malformed unswept balance amounts - #39

Open
samsamtrum wants to merge 1 commit into
PayRam:mainfrom
samsamtrum:fix-unswept-balance-amount-parsing
Open

Reject malformed unswept balance amounts#39
samsamtrum wants to merge 1 commit into
PayRam:mainfrom
samsamtrum:fix-unswept-balance-amount-parsing

Conversation

@samsamtrum

Copy link
Copy Markdown

The unswept balances tool used parseFloat, so malformed API amounts like 1abc could be treated as positive balances.

This adds strict decimal amount parsing and reuses it for both filtering and display formatting.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@samsamtrum is attempting to deploy a commit to the PayRam Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4a06256-f963-4286-a484-46bd74b77ecc

📥 Commits

Reviewing files that changed from the base of the PR and between e19a4e5 and 2062a22.

📒 Files selected for processing (2)
  • src/tools/data/getUnsweptBalances.ts
  • tests/getUnsweptBalances.test.ts

Summary by CodeRabbit

  • Bug Fixes

    • Strengthened validation and filtering of balance amount data to exclude entries with malformed, invalid, or non-positive values. This ensures only properly formatted financial amounts are processed and displayed in balance results.
  • Tests

    • Added test suite to comprehensively verify amount validation behavior, including handling of various input formats and edge cases.

Walkthrough

Adds an exported parsePositiveDecimalAmount helper that regex-validates and returns a positive finite number or null. It replaces parseFloat(e.amount) || 0 in formatEntry and parseFloat(e.amount) > 0 in the balance filter condition. A new Vitest suite verifies acceptance and rejection behavior.

Changes

Positive decimal parsing in getUnsweptBalances

Layer / File(s) Summary
parsePositiveDecimalAmount implementation, wiring, and tests
src/tools/data/getUnsweptBalances.ts, tests/getUnsweptBalances.test.ts
Defines parsePositiveDecimalAmount (trim + regex validation + positive finite guard returning number | null), updates formatEntry to call it with a 0 fallback, changes the filter condition from parseFloat(e.amount) > 0 to parsePositiveDecimalAmount(e.amount) !== null, and adds a Vitest suite asserting acceptance of valid positive decimals (including whitespace) and rejection of malformed strings, Infinity, zero, and negatives.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 A decimal string hops in through the gate,
The rabbit inspects it — is the number straight?
Negative? Zero? Malformed? Off you go!
Only the positives get to stay and glow.
null for the bad ones, a number for the right —
The unswept balances are tidy tonight! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: implementing strict decimal parsing to reject malformed balance amounts, which is the core objective of the PR.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem (parseFloat accepting malformed amounts like '1abc'), the solution (strict decimal parsing), and its application (filtering and formatting).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant