fix: prevent "NaN" market cap in watchlist when Finnhub omits the value#82
fix: prevent "NaN" market cap in watchlist when Finnhub omits the value#82Mubashirrrr wants to merge 1 commit into
Conversation
formatNumber computes `num * 1e6` and renders the result. When a stock's market cap is unavailable, getWatchlistData passes `profile?.marketCapitalization` straight through as undefined, so WatchlistTable renders the literal string "NaN" in the Market Cap column. This is common for ETFs and many non-US symbols where Finnhub's profile2 endpoint does not return marketCapitalization. Guard against undefined/null/non-finite input and return 'N/A', matching the convention already used by the sibling formatMarketCapValue helper. Adds a regression test covering both the normal (millions-scaled) path and the missing/non-finite path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
@Mubashirrrr is attempting to deploy a commit to the ravixalgorithm's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesformatNumber Input Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Bug
The watchlist table renders the literal string
NaNin the Market Cap column for any stock whose market cap is unavailable.formatNumber(lib/utils.ts) computesnum * 1e6and formats the result. ButgetWatchlistData(lib/actions/finnhub.actions.ts) passes the value straight through:Finnhub's
/stock/profile2endpoint omitsmarketCapitalizationfor many symbols (ETFs and a lot of non-US tickers). When it's missing,formatNumber(undefined)evaluatesundefined * 1e6 → NaN, falls through everyvalue >= …branch, and returnsNaN.toString()→"NaN", whichWatchlistTable.tsxrenders directly:Reproduction
The included regression test asserts this and fails before the fix:
Fix
Guard against
undefined/null/ non-finite input and return'N/A'— the same convention already used by the sibling helperformatMarketCapValue. The parameter type is widened tonumber | null | undefinedto reflect what actually reaches the function on the watchlist call path. No other behavior changes; the existing millions-scaling logic is untouched.Regression test
Added a
formatNumberblock to__tests__/utils.test.tscovering:3_000_000 → "3.00T",150_000 → "150.00B",150 → "150.00M")undefined,null,NaN,Infinity→"N/A")npm testis green (81 passed, 4 pre-existing skips). Confirmed the new test fails before the fix and passes after.Summary by CodeRabbit