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

feat: register secondary stellar donation by cron job #1797

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

Meriem-BM
Copy link
Collaborator

@Meriem-BM Meriem-BM commented Sep 4, 2024

Related to Giveth/giveth-dapps-v2#4667

Summary by CodeRabbit

  • New Features
    • Introduced a new function to handle the registration of secondary donations based on transaction criteria.
    • Implemented a timeout mechanism to enhance processing of secondary donations.
  • Improvements
    • Refactored existing functions for better readability and modern syntax.
    • Streamlined transaction checking logic for improved efficiency.

Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

The changes involve refactoring the getPendingDraftDonations function to an arrow function and adding a new asynchronous function, registerSecondaryDonation, to manage secondary donations based on Stellar network transactions. The checkTransactions function has been optimized for time retrieval and transaction presence checks. A new timeout mechanism is introduced to delay the processing of secondary donations.

Changes

File Path Change Summary
src/services/cronJobs/checkQRTransactionJob.ts Refactored getPendingDraftDonations to an arrow function; added registerSecondaryDonation function; optimized checkTransactions for time retrieval and transaction checks; introduced a timeout for secondary donation processing.

Sequence Diagram(s)

sequenceDiagram
    participant A as User
    participant B as Donation Service
    participant C as Stellar Network

    A->>B: Initiate Donation
    B->>C: Check Transaction
    C-->>B: Return Transactions
    B->>B: Process Transactions
    alt Matching Transaction Found
        B->>B: Wait 10 seconds
        B->>B: Register Secondary Donation
    end
Loading

🐰 "In the meadow, changes bloom,
A new function to dispel the gloom.
With donations hopping here and there,
We celebrate with joy and flair!
Oh, what fun in code we weave,
A brighter path for all to achieve!" 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 133f76f and 6498495.

Files selected for processing (1)
  • src/services/cronJobs/checkQRTransactionJob.ts (6 hunks)
Additional comments not posted (1)
src/services/cronJobs/checkQRTransactionJob.ts (1)

28-33: LGTM!

The code changes are approved.


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 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 resolve resolve all the CodeRabbit review comments.
  • @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.

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/services/cronJobs/checkQRTransactionJob.ts (1)

Line range hint 152-329: Consider refactoring the function into smaller, more focused functions and using a configuration value for the delay.

The checkTransactions function is quite large and complex, which could impact readability and maintainability. It is also performing multiple tasks, such as retrieving transactions, validating transactions, and creating donations, which violates the Single Responsibility Principle.

Consider breaking down the function into smaller, more focused functions to improve readability and maintainability. For example:

  • Extract the logic for retrieving transactions into a separate function.
  • Extract the logic for validating transactions into a separate function.
  • Extract the logic for creating donations into a separate function.

Additionally, the usage of setTimeout with a hardcoded delay of 10 seconds is a code smell. It would be better to use a configuration value for the delay.

Apply this diff to use a configuration value for the delay:

+const SECONDARY_DONATION_DELAY = config.get('SECONDARY_DONATION_DELAY') || 10000;
+
// Register secondary donation after the configured delay
setTimeout(async () => {
  await registerSecondaryDonation(
    donation,
    transaction.source_account,
    transaction.transaction_hash,
    transaction.created_at,
    project,
    token,
    tokenPrice,
    donor,
    qfRound,
  );
-}, 10000);
+}, SECONDARY_DONATION_DELAY);

@Meriem-BM Meriem-BM merged commit b510db1 into staging Sep 4, 2024
5 checks passed
@Meriem-BM Meriem-BM deleted the feat/stellar_integration branch September 4, 2024 08:54
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