Skip to content
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

fix: change estimated matching to a range #4305

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

Meriem-BM
Copy link
Collaborator

@Meriem-BM Meriem-BM commented Jun 21, 2024

Related to #4251

Change Estimated matching to a range from 30% to 100% of the actual value

Summary by CodeRabbit

  • New Features

    • Introduced messages prompting users to donate to more projects to receive higher matching funds in various languages (Catalan, English, Spanish).
  • Enhancements

    • Updated the EstimatedMatchingToast component to display an estimated matching range.
    • Refined the QFSection component with new functions for currency formatting and matching range calculation, and added a DonationMatch component.
  • Internationalization

    • Enhanced translation files (Catalan, English, Spanish) to emphasize increased matching for additional donations.

Copy link

vercel bot commented Jun 21, 2024

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 21, 2024 10:11am

Copy link
Contributor

coderabbitai bot commented Jun 21, 2024

Walkthrough

The updates focus on enhancing the messaging around funding allocation in donation processes by emphasizing increased benefits from donating to multiple projects. Additionally, new functionalities were added to manage currency formatting and matching range calculations in the EstimatedMatchingToast and QFSection components.

Changes

File Path Change Summary
lang/ca.json, lang/en.json, lang/es.json, lang/t_ca.json, lang/t_es.json Updated the message content related to funding allocation and matching funds in multiple languages.
src/.../donate/EstimatedMatchingToast.tsx Added getEstimatedMatchingRange function to calculate and format estimated matching ranges.
src/.../project/projectActionCard/QFSection.tsx Introduced formatWithCurrency, getEstimatedMatchingRange functions, and DonationMatch component to handle currency formatting and display donation matching information.

Poem

🐰
In the field where donations grow,
Matching funds now steal the show,
Donate more, give projects cheer,
Bigger matches will appear!
Currency formats bright and new,
For every generous deed you do! 🌱💸


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f89e805 and be8f3b6.

Files selected for processing (2)
  • src/components/views/donate/EstimatedMatchingToast.tsx (1 hunks)
  • src/components/views/project/projectActionCard/QFSection.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/components/views/donate/EstimatedMatchingToast.tsx
  • src/components/views/project/projectActionCard/QFSection.tsx

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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
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>.
    • 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 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: 4

src/components/views/donate/EstimatedMatchingToast.tsx Outdated Show resolved Hide resolved
Comment on lines +92 to +100
const getEstimatedMatchingRange = (esMatching: number) => {
if (esMatching >= 1) {
return `${formatWithCurrency((esMatching * 30) / 100, allocatedFundUSDPreferred ? '$' : '', locale)} - ${formatWithCurrency(esMatching, allocatedFundUSDPreferred ? '$' : '', locale)}`;
}
return formatWithCurrency(
esMatching,
allocatedFundUSDPreferred ? '$' : '',
locale,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The implementation of the getEstimatedMatchingRange function has been located. The function currently does not include explicit error handling for edge cases, such as negative values for esMatching.

  • File: src/components/views/project/projectActionCard/QFSection.tsx
  • Lines: 91-100

Recommendation: Add error handling to manage edge cases like negative esMatching values.

const getEstimatedMatchingRange = (esMatching: number) => {
    if (esMatching < 0) {
        throw new Error("esMatching cannot be negative");
    }
    if (esMatching >= 1) {
        return `${formatWithCurrency((esMatching * 30) / 100, allocatedFundUSDPreferred ? '$' : '', locale)} - ${formatWithCurrency(esMatching, allocatedFundUSDPreferred ? '$' : '', locale)}`;
    }
    return formatWithCurrency(
        esMatching,
        allocatedFundUSDPreferred ? '$' : '',
        locale,
    );
};
  • Category:
Analysis chain

Ensure robust error handling in getEstimatedMatchingRange function.

The function getEstimatedMatchingRange calculates a range for estimated matching. It's crucial to ensure that the function handles possible edge cases or unusual inputs robustly, such as negative values for esMatching.


The initial check using ast-grep did not return any results, which means we need to gather more information. First, let's examine the implementation of the getEstimatedMatchingRange function for any built-in error handling.


Let's refine our search to ensure we capture the function definition accurately. We'll look for all function definitions in the QFSection.tsx file and specifically for the getEstimatedMatchingRange function.


Let's expand our search to include arrow functions and traditional function definitions within QFSection.tsx.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify handling of edge cases in `getEstimatedMatchingRange`.

# Test: Search for any additional calls to `getEstimatedMatchingRange`. Expect: Proper handling of edge cases.
ast-grep --lang typescript --pattern $'getEstimatedMatchingRange($_)'

Length of output: 70



Script:

#!/bin/bash
# Locate the implementation of the getEstimatedMatchingRange function to check for error handling.
ast-grep --lang typescript --pattern $'const getEstimatedMatchingRange = ($_)' --json

Length of output: 89



Script:

#!/bin/bash
# Search for all function definitions in the QFSection.tsx file.
fd 'QFSection.tsx' -x ast-grep --lang typescript --pattern 'function $_($$$_) { $$$ }' --json

Length of output: 96



Script:

#!/bin/bash
# Search for arrow functions and traditional function definitions in the QFSection.tsx file.
fd 'QFSection.tsx' -x ast-grep --lang typescript --pattern 'const $_ = ($$$_) => { $$$ }' --json

Length of output: 2072

Comment on lines +127 to +148
const DonationMatch = ({ amount }: { amount: number }) => (
<FlexSameSize $justifyContent='space-between'>
<Subline>
{allocatedFundUSDPreferred && '$'}
{amount} {!allocatedFundUSDPreferred && allocatedTokenSymbol}
</Subline>
<IconArrowRight16 color={brandColors.cyan[500]} />
<EndAlignedSubline>
{getEstimatedMatchingRange(
calculateEstimatedMatchingWithDonationAmount(
amount,
projectDonationsSqrtRootSum,
allProjectsSum,
allocatedFundUSDPreferred
? allocatedFundUSD
: matchingPool,
activeStartedRound?.maximumReward,
),
)}
</EndAlignedSubline>
</FlexSameSize>
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The DonationMatch component effectively uses the getEstimatedMatchingRange and calculateEstimatedMatchingWithDonationAmount functions. However, the current implementation does not explicitly handle edge cases such as negative donation amounts or unusual currency formats.

  • The getEstimatedMatchingRange function formats values greater than or equal to 1 with a currency but does not handle negative values.
  • The calculateEstimatedMatchingWithDonationAmount function returns 0 if any of the critical parameters are missing but does not explicitly handle negative donation amounts.

To ensure robustness, consider adding explicit checks for negative values and unusual currency formats within these functions.

  • Add validation for negative donation amounts in calculateEstimatedMatchingWithDonationAmount.
  • Ensure getEstimatedMatchingRange handles edge cases such as negative values and unusual currency formats.
Analysis chain

Review the DonationMatch component for consistency and error handling.

The DonationMatch component effectively uses the new getEstimatedMatchingRange function. Ensure that the calculations within this component handle all edge cases, such as negative donation amounts or unusual currency formats.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify handling of edge cases in `DonationMatch`.

# Test: Search for any additional calls to `DonationMatch`. Expect: Proper handling of edge cases.
ast-grep --lang typescript --pattern $'DonationMatch($_)'

Length of output: 58



Script:

#!/bin/bash
# Description: Search for the usage of `DonationMatch` in the codebase to verify edge cases handling.

# Find all files containing `DonationMatch` to locate its usage.
rg 'DonationMatch' --type tsx --type ts

Length of output: 67



Script:

#!/bin/bash
# Description: Search for the usage of `DonationMatch` in the codebase to verify edge cases handling.

# Find all files containing `DonationMatch` to locate its usage.
rg 'DonationMatch' --type ts --type tsx

Length of output: 67



Script:

#!/bin/bash
# Description: Search for the usage of `DonationMatch` in the codebase to verify edge cases handling.

# Find all files containing `DonationMatch` to locate its usage.
rg 'DonationMatch' --type ts

Length of output: 444



Script:

#!/bin/bash
# Description: Review the implementations of `getEstimatedMatchingRange` and `calculateEstimatedMatchingWithDonationAmount` for edge case handling.

# Find the implementation of `getEstimatedMatchingRange`.
rg 'function getEstimatedMatchingRange' --type ts

# Find the implementation of `calculateEstimatedMatchingWithDonationAmount`.
rg 'function calculateEstimatedMatchingWithDonationAmount' --type ts

Length of output: 122



Script:

#!/bin/bash
# Description: Review the implementations of `getEstimatedMatchingRange` and `calculateEstimatedMatchingWithDonationAmount` for edge case handling.

# Find the implementation of `getEstimatedMatchingRange`.
ast-grep --lang typescript --pattern 'function getEstimatedMatchingRange($_) { $$$ }'

# Find the implementation of `calculateEstimatedMatchingWithDonationAmount`.
ast-grep --lang typescript --pattern 'function calculateEstimatedMatchingWithDonationAmount($_) { $$$ }'

Length of output: 194



Script:

#!/bin/bash
# Description: Verify if `getEstimatedMatchingRange` and `calculateEstimatedMatchingWithDonationAmount` are defined or imported in the codebase.

# Search for `getEstimatedMatchingRange` function definition or import.
rg 'getEstimatedMatchingRange' --type ts

# Search for `calculateEstimatedMatchingWithDonationAmount` function definition or import.
rg 'calculateEstimatedMatchingWithDonationAmount' --type ts

Length of output: 1169



Script:

#!/bin/bash
# Description: Extract the definition of `getEstimatedMatchingRange` from `QFSection.tsx`.

# Extract the definition of `getEstimatedMatchingRange`.
sed -n '/const getEstimatedMatchingRange =/,/};/p' src/components/views/project/projectActionCard/QFSection.tsx

Length of output: 496



Script:

#!/bin/bash
# Description: Extract the definition of `calculateEstimatedMatchingWithDonationAmount` from `qf.ts`.

# Extract the definition of `calculateEstimatedMatchingWithDonationAmount`.
sed -n '/export const calculateEstimatedMatchingWithDonationAmount =/,/^};/p' src/helpers/qf.ts

Length of output: 1087

Copy link
Collaborator

@kkatusic kkatusic left a comment

Choose a reason for hiding this comment

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

LGTM ;)

@Meriem-BM Meriem-BM merged commit da9b410 into develop Jun 21, 2024
3 checks passed
@Meriem-BM Meriem-BM deleted the change_estimated_matching_to_range branch June 21, 2024 10:55
@coderabbitai coderabbitai bot mentioned this pull request Sep 17, 2024
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