Closed Meriem-BM closed 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 |
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.
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 diagrams omitted due to the straightforward nature of the changes.)
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_(")(")
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'.
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: 2902src/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.
@Meriem-BM told me this logic is only for this QF round, so I think it's ok.
Related to https://github.com/Giveth/giveth-dapps-v2/issues/4251#issuecomment-2188417593
Summary by CodeRabbit
New Features
Improvements