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

added recurring donation sum in project card of QF active round #4538

Merged

Conversation

lovelgeorge99
Copy link
Collaborator

@lovelgeorge99 lovelgeorge99 commented Aug 7, 2024

Recurring donations made during the active QF round period are added to the amount raised in this round in the project card
Issue #4287

Summary by CodeRabbit

  • New Features

    • Introduced a GraphQL query to fetch recurring donations by date, enhancing data retrieval capabilities.
    • Updated the ProjectCard component to calculate and display recurring donations, providing a comprehensive overview of project funding.
  • Bug Fixes

    • Improved the rendering logic in the ProjectCard to correctly sum and display recurring donation totals.

Copy link

vercel bot commented Aug 7, 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 Aug 8, 2024 2:21pm

Copy link
Contributor

coderabbitai bot commented Aug 7, 2024

Walkthrough

The recent updates introduce a new GraphQL query to fetch recurring donations by project ID and date range, enhancing data retrieval capabilities. Additionally, the ProjectCard component is modified to calculate and display the total amount from these recurring donations, offering a more comprehensive financial overview for projects.

Changes

File Change Summary
src/apollo/gql/gqlProjects.ts Added FETCH_RECURRING_DONATIONS_BY_DATE query for retrieving recurring donations by date range.
src/components/project-card/ProjectCard.tsx Enhanced ProjectCard to fetch and display total recurring donations using a new IRecurringDonation interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ProjectCard
    participant GraphQL

    User->>ProjectCard: View Project
    ProjectCard->>GraphQL: Request recurring donations by date
    GraphQL-->>ProjectCard: Return donation data
    ProjectCard->>ProjectCard: Sum totalUsdStreamed
    ProjectCard->>User: Display total donations
Loading

Poem

🐇 In the meadow where donations flow,
A new query brings a radiant glow.
Recurring gifts from hearts so grand,
Calculated sums, a helping hand.
Hooray for change, let’s dance and play,
For every rabbit knows, it's a brighter day! 🎉


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

Outside diff range, codebase verification and nitpick comments (1)
src/components/project-card/ProjectCard.tsx (1)

Line range hint 80-131: Add error handling in the async function.

The state variables and the fetchProjectRecurringDonationsByDate function are well-implemented. However, consider adding error handling in the async function.

+ try {
		const { data: projectRecurringDonations } = await client.query({
			query: FETCH_RECURRING_DONATIONS_BY_DATE,
			variables: {
				projectId: parseInt(id),
				startDate,
				endDate,
			},
		});
		const { recurringDonationsByDate } = projectRecurringDonations;
		return recurringDonationsByDate;
+ } catch (error) {
+   console.error("Error fetching recurring donations:", error);
+ }

Comment on lines +132 to +152
useEffect(() => {
const calculateTotalAmountStreamed = async () => {
if (activeStartedRound?.isActive) {
const donations = await fetchProjectRecurringDonationsByDate();
let totalAmountStreamed;
if (donations.totalCount != 0) {
console.log(id, donations.recurringDonations);
totalAmountStreamed = donations.recurringDonations.reduce(
(sum: number, donation: IRecurringDonation) => {
return sum + donation.totalUsdStreamed;
},
0,
);
setRecurringDonationSumInQF(totalAmountStreamed);
}
console.log(id, totalAmountStreamed);
}
};

calculateTotalAmountStreamed();
}, [props]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize useEffect dependencies.

The useEffect hook and the calculateTotalAmountStreamed function are well-implemented. However, consider optimizing the dependencies to avoid unnecessary re-renders.

- }, [props]);
+ }, [project, activeStartedRound]);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
const calculateTotalAmountStreamed = async () => {
if (activeStartedRound?.isActive) {
const donations = await fetchProjectRecurringDonationsByDate();
let totalAmountStreamed;
if (donations.totalCount != 0) {
console.log(id, donations.recurringDonations);
totalAmountStreamed = donations.recurringDonations.reduce(
(sum: number, donation: IRecurringDonation) => {
return sum + donation.totalUsdStreamed;
},
0,
);
setRecurringDonationSumInQF(totalAmountStreamed);
}
console.log(id, totalAmountStreamed);
}
};
calculateTotalAmountStreamed();
}, [props]);
useEffect(() => {
const calculateTotalAmountStreamed = async () => {
if (activeStartedRound?.isActive) {
const donations = await fetchProjectRecurringDonationsByDate();
let totalAmountStreamed;
if (donations.totalCount != 0) {
console.log(id, donations.recurringDonations);
totalAmountStreamed = donations.recurringDonations.reduce(
(sum: number, donation: IRecurringDonation) => {
return sum + donation.totalUsdStreamed;
},
0,
);
setRecurringDonationSumInQF(totalAmountStreamed);
}
console.log(id, totalAmountStreamed);
}
};
calculateTotalAmountStreamed();
}, [project, activeStartedRound]);

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.

@lovelgeorge99 you fetch recurring donation as I can see, but isn't this number related to the total donation in this round?
recurring_2C640706

When I check here total donation for this project numbers do not match.

Thx

@kkatusic kkatusic self-requested a review August 8, 2024 13:17
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.

@lovelgeorge99 give me more explanation, everything is ok, thx @lovelgeorge99

@lovelgeorge99 lovelgeorge99 merged commit 1b62f9a into develop Aug 8, 2024
3 checks passed
@lovelgeorge99 lovelgeorge99 deleted the include-recuring-donation-in-project-card#4287 branch August 8, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: QA
Development

Successfully merging this pull request may close these issues.

2 participants