-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolved : Rendering big numbers in a better way #931
Conversation
@GradleD is attempting to deploy a commit to the LFG Labs Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce a new utility function, Changes
Possibly related PRs
Suggested labels
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
components/dashboard/PortfolioSummary.tsx (1)
22-25
: Consider centralizing formatting logicThe current implementation spreads formatting logic across multiple locations. Consider:
- Moving formatting utilities to a dedicated module (e.g.,
utils/formatting.ts
)- Creating separate utilities for percentage and currency formatting
- Adding proper TypeScript interfaces for the formatting functions
Example structure:
// utils/formatting.ts export interface FormattingOptions { minimumFractionDigits?: number; maximumFractionDigits?: number; } export const formatCurrency = (amount: number, options?: FormattingOptions): string => { // Implementation } export const formatPercentage = (value: number, options?: FormattingOptions): string => { // Implementation }Also applies to: 34-37, 81-81
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
components/dashboard/PortfolioSummary.tsx
(4 hunks)
🔇 Additional comments (1)
components/dashboard/PortfolioSummary.tsx (1)
81-81
:
Fix tooltip callback implementation
The current implementation has potential issues:
- The
item
variable is undefined (should be usingtooltipItem.raw
) - Redundant concatenation of currency symbol
- return ` ${item.itemValueSymbol}${formatCurrency(item.itemValue)}`;
+ const value = Number(tooltipItem.raw);
+ return tooltipItem.dataset.label === '%'
+ ? ` ${value}%`
+ : ` ${formatCurrency(value)}`;
Likely invalid or redundant comment.
const formattedValue = itemValueSymbol === '%' | ||
? `${itemValue}${itemValueSymbol}` | ||
: `${itemValueSymbol}${formatCurrency(itemValue)}`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix undefined variable reference and standardize string interpolation
There's a critical error in the ChartEntry component where an undefined 'value' variable is being rendered.
const formattedValue = itemValueSymbol === '%'
- ? `${itemValue}${itemValueSymbol}`
- : `${itemValueSymbol}${formatCurrency(itemValue)}`;
+ ? `${itemValue}${itemValueSymbol}`
+ : formatCurrency(itemValue);
- <Typography type={TEXT_TYPE.BODY_MIDDLE}>{value}</Typography>
+ <Typography type={TEXT_TYPE.BODY_MIDDLE}>{formattedValue}</Typography>
Also applies to: 47-47
// Utility function to format currency | ||
const formatCurrency = (amount) => { | ||
return `$${amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Enhance the formatCurrency utility function for better robustness
While the function handles basic currency formatting, it needs improvements for production use:
-const formatCurrency = (amount) => {
+const formatCurrency = (amount: number): string => {
+ if (!Number.isFinite(amount)) {
+ return '$0';
+ }
+ // Handle numbers > 1e16 with scientific notation
+ if (Math.abs(amount) >= 1e16) {
+ return `$${amount.toExponential(2)}`;
+ }
+ // Format with 2 decimal places and thousand separators
+ return `$${amount.toLocaleString('en-US', {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2
+ })}`;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// Utility function to format currency | |
const formatCurrency = (amount) => { | |
return `$${amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}`; | |
}; | |
// Utility function to format currency | |
const formatCurrency = (amount: number): string => { | |
if (!Number.isFinite(amount)) { | |
return '$0'; | |
} | |
// Handle numbers > 1e16 with scientific notation | |
if (Math.abs(amount) >= 1e16) { | |
return `$${amount.toExponential(2)}`; | |
} | |
// Format with 2 decimal places and thousand separators | |
return `$${amount.toLocaleString('en-US', { | |
minimumFractionDigits: 2, | |
maximumFractionDigits: 2 | |
})}`; | |
}; |
Resolves: Rendering big numbers in a better way
Summary by CodeRabbit
New Features
Bug Fixes