Skip to content

all balances with 2 decimals#316

Merged
RanaBug merged 1 commit intostagingfrom
feat/PRO-3182/portfolio-tile-refactor
May 23, 2025
Merged

all balances with 2 decimals#316
RanaBug merged 1 commit intostagingfrom
feat/PRO-3182/portfolio-tile-refactor

Conversation

@RanaBug
Copy link
Collaborator

@RanaBug RanaBug commented May 23, 2025

Description

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • Style
    • Updated balance and value displays to consistently show numbers with two decimal places.
  • Tests
    • Simplified tests by removing references to a custom number formatting utility.

@RanaBug RanaBug requested a review from IAmKio May 23, 2025 14:57
@RanaBug RanaBug self-assigned this May 23, 2025
@github-actions github-actions bot temporarily deployed to Preview (feat/PRO-3182/portfolio-tile-refactor) May 23, 2025 14:57 Inactive
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 23, 2025

Walkthrough

This update removes the limitDigitsNumber utility from components responsible for displaying balances. Instead, numeric values are now formatted directly with JavaScript’s toFixed(2) method at the rendering stage. Corresponding test files are updated to eliminate references and mocks related to the removed utility.

Changes

File(s) Change Summary
src/apps/pillarx-app/components/PrimeTokensBalance/PrimeTokensBalance.tsx Removed limitDigitsNumber import; replaced balance formatting with .toFixed(2) in rendering; simplified calculation.
src/apps/pillarx-app/components/PrimeTokensBalance/test/PrimeTokensBalance.test.tsx Removed all references, imports, and mocks for limitDigitsNumber in tests; no logic or assertion changes.
src/apps/pillarx-app/components/WalletPortfolioGraph/BalancePnlGraph.tsx Removed limitDigitsNumber import; now uses .toFixed(2) for value formatting in UI rendering.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PrimeTokensBalance
    participant BalancePnlGraph

    User->>PrimeTokensBalance: View balance
    PrimeTokensBalance->>PrimeTokensBalance: Calculate balance (raw sum)
    PrimeTokensBalance->>PrimeTokensBalance: Format with toFixed(2)
    PrimeTokensBalance-->>User: Display formatted balance

    User->>BalancePnlGraph: View portfolio graph
    BalancePnlGraph->>BalancePnlGraph: Get hover/latest values
    BalancePnlGraph->>BalancePnlGraph: Format with toFixed(2)
    BalancePnlGraph-->>User: Display formatted values
Loading

Possibly related PRs

  • balance to be fixes to two decimals #314: Both PRs remove the import and usage of the limitDigitsNumber utility and replace it with direct formatting of numeric values using JavaScript's toFixed(2) method for displaying balances with two decimal places, indicating a shared approach to simplifying number formatting in different components.

Suggested reviewers

  • IAmKio

Poem

A hop and a skip, the digits are trimmed,
No more utility, the code is now primmed.
With .toFixed(2), the numbers align,
Balances sparkle, precisely in line.
The rabbit approves, with a twitch of the nose—
Clean code and clear numbers, that's how it goes! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-23T14_58_40_634Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92797f8 and e2d10be.

⛔ Files ignored due to path filters (1)
  • src/apps/pillarx-app/components/MediaGridCollection/tests/__snapshots__/DisplayCollectionImage.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (3)
  • src/apps/pillarx-app/components/PrimeTokensBalance/PrimeTokensBalance.tsx (2 hunks)
  • src/apps/pillarx-app/components/PrimeTokensBalance/test/PrimeTokensBalance.test.tsx (0 hunks)
  • src/apps/pillarx-app/components/WalletPortfolioGraph/BalancePnlGraph.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • src/apps/pillarx-app/components/PrimeTokensBalance/test/PrimeTokensBalance.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit-tests
  • GitHub Check: lint
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (8)
src/apps/pillarx-app/components/PrimeTokensBalance/PrimeTokensBalance.tsx (6)

46-46: LGTM: Simplified balance calculation.

Returning the raw totalBalance directly instead of applying the limitDigitsNumber utility simplifies the code and moves the formatting responsibility to the display layer where it belongs.


67-67: LGTM: Consistent currency formatting with proper safeguards.

Using toFixed(2) is the appropriate choice for currency display. The conditional check ensures the method is only called on valid positive numbers, with a fallback to '0.00' for edge cases.


46-46: LGTM: Proper separation of concerns.

Moving the number formatting from data processing to display time is a good architectural decision. The raw totalBalance value is now preserved for calculations, with formatting applied only when rendering.


67-67: LGTM: Consistent 2-decimal formatting implemented.

The use of toFixed(2) correctly implements the PR objective of displaying all balances with exactly 2 decimal places. The conditional logic properly guards against calling toFixed(2) on undefined values.


46-46: LGTM! Clean separation of calculation and formatting logic.

Returning the raw totalBalance value allows the calculation logic to remain pure while delegating formatting responsibility to the display layer.


67-67: LGTM! Proper number formatting with safe conditional checks.

The use of toFixed(2) ensures consistent 2-decimal formatting for currency display. The conditional logic properly handles undefined/null values before calling toFixed(2).

src/apps/pillarx-app/components/WalletPortfolioGraph/BalancePnlGraph.tsx (2)

483-484: LGTM: Consistent formatting for hover and latest values.

The implementation correctly uses toFixed(2) for both hoverValue and latestValue with proper conditional checks. The fallback logic ensures a consistent currency format ('$0.00') when values are undefined, maintaining a good user experience.


483-484: LGTM! Consistent currency formatting with proper null safety.

Both hoverValue.toFixed(2) and latestValue.toFixed(2) are safely guarded by conditional checks. The formatting ensures consistent 2-decimal display for all currency values, maintaining uniformity with the fallback '$0.00'.

Comment on lines +483 to +484
? `$${hoverValue.toFixed(2)}`
: `${latestValue ? `$${latestValue.toFixed(2)}` : '$0.00'}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

LGTM: Consistent formatting applied to all balance displays.

The toFixed(2) formatting is properly applied to both hover and latest values, ensuring consistent 2-decimal display across all balance presentations. The conditional logic appropriately protects against undefined values.

Please verify that limitDigitsNumber has been completely removed from the codebase:


🏁 Script executed:

#!/bin/bash
# Description: Verify that limitDigitsNumber utility is no longer used anywhere in the codebase
# Expected: No remaining references to limitDigitsNumber

echo "Searching for any remaining references to limitDigitsNumber..."
rg -i "limitdigitsnumber" --type ts --type tsx --type js --type jsx

echo -e "\nSearching for the utility file itself..."
fd -e ts -e tsx -e js -e jsx | xargs grep -l "limitDigitsNumber.*function\|function.*limitDigitsNumber\|const.*limitDigitsNumber\|export.*limitDigitsNumber" 2>/dev/null || echo "No utility file found"

Length of output: 699


Please remove all remaining limitDigitsNumber references

We still have references to the old utility in the codebase. Update these locations to use .toFixed(2) (or your new formatting helper) and delete the unused utility:

  • src/utils/number.tsx (defines limitDigitsNumber)
  • src/apps/pillarx-app/components/TokenMarketDataRow/tests/RightColumnTokenMarketDataRow.test.tsx
  • src/apps/pillarx-app/components/TokensWithMarketDataTile/test/TokensWithMarketDataTile.test.tsx

Once you’ve refactored those tests and removed the file, re-run the test suite to confirm everything still passes.

🤖 Prompt for AI Agents
In src/apps/pillarx-app/components/WalletPortfolioGraph/BalancePnlGraph.tsx
around lines 483 to 484, the code correctly uses toFixed(2) for formatting
numbers, but there are still remaining references to the old limitDigitsNumber
utility elsewhere in the codebase. Locate and replace all instances of
limitDigitsNumber in src/utils/number.tsx,
src/apps/pillarx-app/components/TokenMarketDataRow/tests/RightColumnTokenMarketDataRow.test.tsx,
and
src/apps/pillarx-app/components/TokensWithMarketDataTile/test/TokensWithMarketDataTile.test.tsx
with toFixed(2) or the new formatting helper. After refactoring these files,
delete the limitDigitsNumber utility file and run the test suite to ensure no
regressions.

@cloudflare-workers-and-pages
Copy link

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: e2d10be
Status: ✅  Deploy successful!
Preview URL: https://a2e0fc8d.x-e62.pages.dev
Branch Preview URL: https://feat-pro-3182-portfolio-tile.x-e62.pages.dev

View logs

@RanaBug RanaBug merged commit 36c6ea6 into staging May 23, 2025
7 of 8 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