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: add instant trx check endpoint #1767

Merged
merged 6 commits into from
Aug 19, 2024
Merged

Conversation

Meriem-BM
Copy link
Collaborator

@Meriem-BM Meriem-BM commented Aug 18, 2024

Related to Giveth/giveth-dapps-v2#4573

Summary by CodeRabbit

  • New Features

    • Introduced enhanced checks and status updates for draft donations, including expiration handling.
    • Added a new method to retrieve draft donations with updated status and transaction validation.
    • Added support for processing Stellar blockchain transactions.
  • Improvements

    • Increased frequency of transaction checks from every three minutes to every minute.
    • Expanded transaction validation to include additional parameters and improved error handling.
  • Bug Fixes

    • Implemented checks for required fields in transaction processing, preventing early exits due to missing data.

Copy link
Contributor

coderabbitai bot commented Aug 18, 2024

Warning

Rate limit exceeded

@Meriem-BM has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 31 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 74b0b02 and a720bb0.

Walkthrough

The recent changes significantly enhance the functionality of draft donation handling and transaction validation. The DraftDonationResolver now includes robust checks for draft expiration and improved transaction checks, while the checkTransactions function has been refactored for increased frequency and better validation. These updates ensure that donations are managed effectively and that transaction statuses are accurately reflected.

Changes

Files Change Summary
src/resolvers/draftDonationResolver.ts Improved DraftDonationResolver with null checks, expiration handling, and a new method for status updates.
src/services/chains/index.ts, src/services/chains/stellar/transactionService.ts Added Stellar blockchain support to transaction functions, expanding capabilities for transaction validity checks.
src/services/cronJobs/checkQRTransactionJob.ts Refactored checkTransactions for enhanced donation checks, increased frequency to every minute, and improved validation logic.

Possibly related issues

  • Stellar | Donation service changes #1691: The changes address the need for tracking pending transactions and adding validity timers for donations, aligning with the issue's objectives related to Stellar transactions.

Poem

In fields of code, a rabbit sings,
Of donations, drafts, and checking things.
With status updates and checks anew,
Our project hops along, all bright and true!
So let us dance, both brave and spry,
For better code, we leap and fly! 🐇✨


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

Outside diff range, codebase verification and nitpick comments (1)
src/resolvers/draftDonationResolver.ts (1)

382-388: Fix missing parentheses in getTime method call.

The getTime method should be invoked with parentheses to properly compare the timestamps. Update the line to new Date(draftDonation.expiresAt).getTime() < new Date().getTime().

  • src/resolvers/draftDonationResolver.ts: Line 384
Analysis chain

Verify time comparison logic for expiration check.

Ensure that the time comparison logic correctly identifies expired donations and updates their status.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the time comparison logic for donation expiration.

# Test: Search for all instances of `expiresAt` usage to ensure consistency.
rg --type ts 'expiresAt'

Length of output: 1565

Copy link
Collaborator

@mohammadranjbarz mohammadranjbarz left a comment

Choose a reason for hiding this comment

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

Thanks @Meriem-BM just rename the resolver name please, and would appreciate writing a few test cases. feel free to merge it once you do them

src/resolvers/draftDonationResolver.ts Outdated Show resolved Hide resolved
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

Comment on lines +15 to +49
const getStellarTransactionInfo = async (
txHash: string,
): Promise<NetworkTransactionInfo | null> => {
const NATIVE_STELLAR_ASSET_CODE = 'XLM';
// Fetch transaction info from stellar network

const response = await axios.get(
`${STELLAR_HORIZON_API_URL}/transactions/${txHash}/payments`,
);

const transaction = response.data._embedded.records[0];

if (!transaction) return null;

// when a transaction is made to a newly created account, Stellar mark it as type 'create_account'
if (transaction.type === 'create_account') {
return {
hash: transaction.transaction_hash,
amount: Number(transaction.starting_balance),
from: transaction.source_account,
to: transaction.account,
currency: NATIVE_STELLAR_ASSET_CODE,
timestamp: transaction.created_at,
};
} else if (transaction.type === 'payment') {
if (transaction.asset_type !== 'native') return null;
return {
hash: transaction.transaction_hash,
amount: Number(transaction.amount),
from: transaction.from,
to: transaction.to,
currency: NATIVE_STELLAR_ASSET_CODE,
timestamp: transaction.created_at,
};
} else return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for network calls.

Consider adding try-catch blocks to handle potential errors from the axios.get call. This will help manage network issues or unexpected responses gracefully.

try {
  const response = await axios.get(
    `${STELLAR_HORIZON_API_URL}/transactions/${txHash}/payments`,
  );
  const transaction = response.data._embedded.records[0];
  if (!transaction) return null;
  // existing logic
} catch (error) {
  // handle error, e.g., log it or throw a custom error
  console.error('Error fetching transaction:', error);
  return null;
}

@Meriem-BM Meriem-BM merged commit 2d263fd into staging Aug 19, 2024
5 checks passed
@Meriem-BM Meriem-BM deleted the feat/stellar_integration branch August 19, 2024 04:12
@Meriem-BM Meriem-BM restored the feat/stellar_integration branch August 21, 2024 09:31
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