Skip to content

fix: fix parse unit error when value is 1e format #115

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

Merged
merged 1 commit into from
Apr 2, 2025

Conversation

thelostone-mc
Copy link
Contributor

@thelostone-mc thelostone-mc commented Apr 2, 2025

🤖 Linear

Closes PAR-XXX

Description

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

Summary by CodeRabbit

  • New Features
    • Introduced a utility to consistently format numerical values without grouping, providing clearer, unambiguous number representations.
  • Bug Fixes
    • Improved the precision of numerical data in pricing and funds processing to ensure more reliable calculations and display.

These changes enhance the consistency and accuracy of financial data presentation across the platform.

@thelostone-mc thelostone-mc requested a review from 0xKurt April 2, 2025 12:26
Copy link

coderabbitai bot commented Apr 2, 2025

📝 Walkthrough

Walkthrough

The changes modify how numerical values are formatted before being processed. In one module, the Coingecko provider now rounds timestamps down to the nearest whole number using Math.floor before dividing by 1000, ensuring that the API request URL contains integer values. In another module, a new function toNumericString has been introduced to convert numbers into a string format without grouping characters. This function is then integrated into several handlers to replace the previous method of directly converting numbers to strings. The handlers—across pool metadata updates, direct transfer strategies, and funding scenarios—now utilize toNumericString to process the matchingFundsAvailable value before it is passed to the parseUnits function. Overall, the control flow remains unchanged, with the primary modifications focusing on how numerical values are formatted for further processing.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98655ec and d5b823b.

📒 Files selected for processing (5)
  • packages/pricing/src/providers/coingecko.provider.ts (1 hunks)
  • packages/processors/src/helpers/utils.ts (1 hunks)
  • packages/processors/src/processors/allo/handlers/poolMetadataUpdated.handler.ts (2 hunks)
  • packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.ts (2 hunks)
  • packages/processors/src/processors/strategy/easyRetroFunding/easyRetroFunding.handler.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.ts`:

**/*.ts:

  • packages/processors/src/helpers/utils.ts
  • packages/pricing/src/providers/coingecko.provider.ts
  • packages/processors/src/processors/strategy/easyRetroFunding/easyRetroFunding.handler.ts
  • packages/processors/src/processors/allo/handlers/poolMetadataUpdated.handler.ts
  • packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.ts
`**/providers/**/*.ts`: Review provider files for the following: - Providers should supply narrowly scoped data/resources. - Ensure classes interacting with metadata sources (e...

**/providers/**/*.ts: Review provider files for the following:

  • Providers should supply narrowly scoped data/resources.
  • Ensure classes interacting with metadata sources (e.g., GitHub, JSON
    files, IPFS) implement the IMetadataProvider interface and follow
    naming conventions (e.g., GithubProvider, JsonFileProvider).
  • Be concise and avoid overly nitpicky feedback outside of these best practices.
  • packages/pricing/src/providers/coingecko.provider.ts
🧬 Code Definitions (3)
packages/processors/src/processors/strategy/easyRetroFunding/easyRetroFunding.handler.ts (1)
packages/processors/src/helpers/utils.ts (1)
  • toNumericString (30-34)
packages/processors/src/processors/allo/handlers/poolMetadataUpdated.handler.ts (1)
packages/processors/src/helpers/utils.ts (1)
  • toNumericString (30-34)
packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.ts (1)
packages/processors/src/helpers/utils.ts (1)
  • toNumericString (30-34)
⏰ Context from checks skipped due to timeout of 300000ms (1)
  • GitHub Check: e2e-tests / E2E Tests
🔇 Additional comments (8)
packages/processors/src/helpers/utils.ts (1)

25-34: Well-implemented utility function for handling scientific notation!

The new toNumericString function properly addresses the issue with parsing unit errors when values are in scientific notation (e.g., 1e6). By using toLocaleString("fullwide", { useGrouping: false }), you ensure that numbers are represented in their full form without scientific notation or grouping separators, which is crucial for functions like parseUnits that expect properly formatted numeric strings.

packages/pricing/src/providers/coingecko.provider.ts (1)

126-126: Good fix for ensuring integer timestamp values in API requests.

Using Math.floor on the timestamp division ensures that you're always passing integer values to the Coingecko API, preventing potential issues with decimal places in URL parameters. This is a solid improvement for API request stability.

packages/processors/src/processors/strategy/easyRetroFunding/easyRetroFunding.handler.ts (2)

14-18: Good import update for the new utility function.

Properly importing the toNumericString function that will be used later in the code.


112-112: Correctly applies the scientific notation fix.

Using toNumericString here ensures that the matchingFundsAvailable value is properly formatted without scientific notation before being passed to parseUnits, which addresses the issue mentioned in the PR title.

packages/processors/src/processors/allo/handlers/poolMetadataUpdated.handler.ts (2)

8-8: Good import update for the new utility function.

Properly importing the toNumericString function that will be used later in the code.


51-56: Correctly applies the scientific notation fix.

The implementation now uses toNumericString to ensure that the matchingFundsAvailable value from the quadratic funding config is properly formatted without scientific notation before being passed to parseUnits. This change successfully addresses the issue described in the PR title.

packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.ts (2)

15-19: Good addition of the toNumericString helper function import.

This import addition is part of the fix for the parsing unit error when dealing with values in scientific notation (1e format).


135-135:

❓ Verification inconclusive

Great fix for the scientific notation parsing issue.

The change from matchingFundsAvailable.toString() to toNumericString(matchingFundsAvailable) properly addresses the issue with parsing values in scientific notation. When JavaScript converts very large or very small numbers to strings using .toString(), it can use scientific notation (e.g., "1e+12"), which can cause parsing errors when passed to parseUnits. The toNumericString function ensures numbers are converted to full numeric string representation without scientific notation.


🏁 Script executed:

#!/bin/bash
# Check if there are other instances in the codebase that might need the same fix
# Look for places where parseUnits is called with a number.toString() pattern

echo "Searching for potential instances of the same issue..."
rg -t ts 'parseUnits\(.*\.toString\(\)' --no-heading

Length of output: 173


Approval: Scientific Notation Parsing Fix Verified
The update replacing .toString() with toNumericString() before passing values to parseUnits correctly prevents scientific notation issues. Our initial search for other instances of a similar pattern did not yield additional occurrences, suggesting the change is isolated and effective. However, since the automated grep did not return detailed output, please verify manually to ensure no edge cases were missed.

  • Location: packages/processors/src/processors/strategy/donationVotingMerkleDistributionDirectTransfer/dvmdDirectTransfer.handler.ts (line 135)
  • Diff Snippet:
            const matchAmount = parseUnits(toNumericString(matchingFundsAvailable), token.decimals);
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

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.

@thelostone-mc thelostone-mc merged commit 1f4de53 into dev Apr 2, 2025
8 checks passed
@thelostone-mc thelostone-mc deleted the bug/parseUnits branch April 2, 2025 13:49
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