Giveth / giveth-dapps-v2

This project is the aggregation of GIVeconomy and Giveth.io DApps in a single repo
https://staging.giveth.io
GNU General Public License v3.0
54 stars 32 forks source link

Fix: estimated matching range #4330

Closed Meriem-BM closed 6 days ago

Meriem-BM commented 6 days ago

Related to https://github.com/Giveth/giveth-dapps-v2/issues/4251#issuecomment-2188417593

Summary by CodeRabbit

vercel[bot] commented 6 days ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
giveth-dapps-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 25, 2024 11:17am
coderabbitai[bot] commented 6 days ago

Walkthrough

The update across multiple files includes the removal and refactoring of various formatting functions to streamline logic. Key enhancements involve replacing old formatting methods with a new getEstimatedMatchingRange function that handles currency, locale, and token symbols. These changes aim to improve the project's handling of financial data presentation.

Changes

Files Change Summary
src/components/project-card/ProjectCard.tsx Removed thousandsSeparator and formatWithCurrency functions. Introduced the getEstimatedMatchingRange function for calculating the estimated matching range.
src/components/views/archivedQFRounds/ArchivedQFRoundsTable.tsx Added formatPrice function to format the allocatedFund value.
src/components/views/donate/EstimatedMatchingToast.tsx Removed formatDonation. Refactored logic using getEstimatedMatchingRange with added parameters for handling currency, locale, and token symbols.
src/components/views/project/projectActionCard/QFSection.tsx Updated getEstimatedMatchingRange with additional parameters and modified its usage inside the EstimatedMatchingSection component.
src/helpers/number.ts Updated formatDonation function to round and format numbers using Math.round(num).toLocaleString(local).
src/helpers/qf.ts Introduced getEstimatedMatchingRange function to calculate and format an estimated matching range based on donation amount, currency, locale, and token symbols.

Sequence Diagram(s)

(Sequence diagrams omitted due to the straightforward nature of the changes.)

Poem

In the code, a change was found,
Where currencies and formats dance around.
No more separators, they're old and gray,
New matching ranges now lead the way.
With each o’ coin and locale set,
Our project's polished, you can bet!

 (\(\ 
 ( -.-) 
 o_(")(")

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 9efa1318a93cc80a07c00ce81d1aaeb67b020c09 and 686af9834e17f6345953698b4894449899a310af.
Files selected for processing (4) * src/components/project-card/ProjectCard.tsx (3 hunks) * src/components/views/donate/EstimatedMatchingToast.tsx (2 hunks) * src/components/views/project/projectActionCard/QFSection.tsx (3 hunks) * src/helpers/qf.ts (2 hunks)
Additional context used
Biome
src/helpers/qf.ts
[error] 44-44: Use the '**' operator instead of 'Math.pow'. (lint/style/useExponentiationOperator) Unsafe fix: Use the '**' operator instead of 'Math.pow'. --- [error] 61-61: Use the '**' operator instead of 'Math.pow'. (lint/style/useExponentiationOperator) Unsafe fix: Use the '**' operator instead of 'Math.pow'. --- [error] 62-65: Use the '**' operator instead of 'Math.pow'. (lint/style/useExponentiationOperator) Unsafe fix: Use the '**' operator instead of 'Math.pow'.
Additional comments not posted (4)
src/helpers/qf.ts (1)
`80-102`: **Review of `getEstimatedMatchingRange` function.** 1. **Logic Correctness**: The function correctly handles different ranges and conditions based on the `amount` parameter. It uses a nested function `formatWithCurrency` for formatting, which is a good practice for encapsulation. 2. **Performance**: No performance issues detected as the operations are straightforward and bounded by the function's input. 3. **Best Practices**: Good use of ternary operators for conditional rendering of strings. However, the function could be simplified by integrating the `formatWithCurrency` directly into the return statements to reduce redundancy. 4. **Readability**: The function is readable, but comments explaining the logic for the specific multipliers (e.g., why `30 / 100` is used) could enhance understanding for future maintainers. 5. **Global Applicability**: The function is specific to this module but is written in a way that could be easily adapted or extended for similar functionalities in other modules. Overall, the function is well-implemented with minor suggestions for improvements.
src/components/views/donate/EstimatedMatchingToast.tsx (1)
`82-87`: **Ensure consistent currency symbol usage in `getEstimatedMatchingRange`.** The conditional logic for determining the currency symbol seems to be based on whether `allocatedFundUSDPreferred` is truthy. This could potentially lead to inconsistencies if the value of `allocatedFundUSDPreferred` is not strictly boolean. Consider ensuring that this property is always boolean or handle different cases more explicitly.
Verification successful --- **Ensure consistent currency symbol usage in `getEstimatedMatchingRange`.** The property `allocatedFundUSDPreferred` is defined as a boolean in `src/apollo/types/types.ts`. However, it is used in various files across the codebase, including `src/components/views/donate/EstimatedMatchingToast.tsx`. Given its definition as a boolean in the type definitions, it should be consistently used as a boolean. - **Location of boolean definition:** - `src/apollo/types/types.ts` - **Usage in relevant files:** - `src/components/views/donate/EstimatedMatchingToast.tsx` - `src/components/views/projects/ActiveQFRoundStats.tsx` - `src/components/views/project/projectActionCard/QFSection.tsx` - `src/components/views/projects/ArchivedQFRoundStats.tsx` - `src/components/views/project/projectDonations/ProjectTotalFundCard.tsx` - `src/components/project-card/ProjectCard.tsx` - `src/apollo/gql/gqlQF.ts` - `src/apollo/gql/gqlProjects.ts` Since the property is defined as a boolean in the type definitions, it is safe to assume that its usage should be consistent with this type.
Scripts executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Ensure `allocatedFundUSDPreferred` is always boolean. # Test: Search for the property's usage. Expect: Only boolean contexts. ast-grep --lang typescript --pattern $'{ allocatedFundUSDPreferred: boolean, }' ``` Length of output: 82 --- --- Script: ```shell #!/bin/bash # Search for all instances of `allocatedFundUSDPreferred` in the codebase to understand its usage context. rg 'allocatedFundUSDPreferred' -tjs -tjsx -ttsx -ttypescript ``` Length of output: 88 --- --- Script: ```shell #!/bin/bash # Search for all instances of `allocatedFundUSDPreferred` in the codebase to understand its usage context. rg 'allocatedFundUSDPreferred' --type js --type ts --type tsx ``` Length of output: 89 --- --- Script: ```shell #!/bin/bash # Search for all instances of `allocatedFundUSDPreferred` in the codebase to understand its usage context. rg 'allocatedFundUSDPreferred' --type js --type ts ``` Length of output: 2902
src/components/views/project/projectActionCard/QFSection.tsx (1)
`86-91`: **Review usage of `getEstimatedMatchingRange` within `QFSection`.** The function is used correctly here to dynamically calculate and display the estimated matching range. The use of ternary operators for conditional currency symbols is consistent with other parts of the application. Ensure that the `allocatedFundUSDPreferred` is always treated as a boolean throughout the application to prevent any type inconsistencies.
src/components/project-card/ProjectCard.tsx (1)
`251-253`: **Check consistent currency symbol handling in `getEstimatedMatchingRange`.** The usage of `getEstimatedMatchingRange` here is consistent with other parts of the application. However, ensure that the `allocatedFundUSDPreferred` property is consistently treated as a boolean across the application to avoid any potential issues with type inconsistency.
--- 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?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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 generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@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 as 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 resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
RamRamez commented 6 days ago

@Meriem-BM told me this logic is only for this QF round, so I think it's ok.