Skip to content

fix(app): reject non-finite usd in amountForUsd - #28

Merged
kevincodex1 merged 1 commit into
Twigpine:mainfrom
Ayush7614:fix/amount-for-usd-finite-guard
Sep 11, 2026
Merged

kevincodex1 merged 1 commit into
Twigpine:mainfrom
Ayush7614:fix/amount-for-usd-finite-guard

Conversation

@Ayush7614

@Ayush7614 Ayush7614 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

amountForUsd(Infinity, 1, 18) returned the literal string "Infinity", which viem parseUnits rejects downstream in suggestFirstBuy.

Before: `if (!(usd > 0) || !(quoteUsd > 0) || !Number.isFinite(quoteUsd))` — Infinity passes `usd > 0`, divides to Infinity, toFixed(2) is "Infinity", trimZeros is a no-op, places=0 passes, returns "Infinity".

After: also require `Number.isFinite(usd)`, matching the quoteUsd guard. Adds regression coverage for Infinity/NaN on both inputs.

Verified locally on upstream/main base:

  • npm run lint: pass
  • npx tsc --noEmit -p .: pass
  • full unit suite: 323 pass, 0 fail
  • npm run build: pass

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of invalid purchase amount inputs.
    • Non-finite values such as Infinity and NaN are now safely rejected instead of causing invalid amount conversion errors.

…er becomes "Infinity"

amountForUsd(Infinity, 1, 18) returned the literal string "Infinity",
which viem parseUnits rejects downstream in suggestFirstBuy. Guard the
usd input with Number.isFinite like quoteUsd already was, and cover
Infinity/NaN for both inputs.
@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b5cf5311-5ee0-4538-9c2a-f17c5b1d71de

📥 Commits

Reviewing files that changed from the base of the PR and between d067240 and 74f6368.

📒 Files selected for processing (2)
  • app/src/lib/launchpad/first-buy.test.ts
  • app/src/lib/launchpad/first-buy.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

amountForUsd now rejects non-finite USD inputs. Tests cover Infinity and NaN for both USD and quote values.

Changes

Amount validation

Layer / File(s) Summary
Reject non-finite amount inputs
app/src/lib/launchpad/first-buy.ts, app/src/lib/launchpad/first-buy.test.ts
amountForUsd returns null for non-finite USD or quote values. Tests cover Infinity and NaN inputs.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Suggested reviewers: kevincodex1

Merge Risk: ⚪ Minimal · up to 74f63

Non-finite amount inputs are now rejected before formatting, preventing invalid purchase suggestions. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting non-finite usd inputs in amountForUsd.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kevincodex1
kevincodex1 merged commit f779944 into Twigpine:main Sep 11, 2026
3 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.

2 participants