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

Add recipient address to streams when nonexistent #1890

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

CarlosQ96
Copy link
Collaborator

@CarlosQ96 CarlosQ96 commented Dec 9, 2024

Related to: https://github.com/orgs/Giveth/projects/9/views/3?pane=issue&itemId=88761136&issue=Giveth%7Cimpact-graph%7C1878

Summary by CodeRabbit

  • New Features
    • Introduced an optional recipientAddress argument in the addAnchorContractAddress mutation method.
  • Bug Fixes
    • Updated logic to handle scenarios where the recipientAddress is not provided, ensuring appropriate error messaging.

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The changes involve modifications to the AnchorContractAddressResolver class in the src/resolvers/anchorContractAddressResolver.ts file. A new optional parameter, recipientAddress, has been added to the addAnchorContractAddress method. The method's logic has been updated to handle scenarios where the recipient address is either provided or absent, with specific validation and error handling incorporated for each case.

Changes

File Path Change Summary
src/resolvers/anchorContractAddressResolver.ts Updated addAnchorContractAddress method to include an optional recipientAddress parameter and modified logic for handling its presence or absence.

Poem

In the code where rabbits play,
A new path leads the way,
With addresses now in tow,
We hop along, watch us go!
A recipient here, or none at all,
Error checks keep us standing tall! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 and nitpick comments (2)
src/resolvers/anchorContractAddressResolver.ts (2)

64-64: Remove unnecessary non-null assertion.

The non-null assertion (!) is redundant since recipientAddress is already known to be defined within this if block.

-      address: recipientAddress!,
+      address: recipientAddress,

77-82: Enhance error message specificity.

The error message could be more helpful by including the network ID in the message to help users understand which network is missing the recipient address.

         throw new Error(
           i18n.__(
-            translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK,
+            translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_NETWORK,
+            { networkId }
           ),
         );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 795e035 and 4e3b0e8.

📒 Files selected for processing (1)
  • src/resolvers/anchorContractAddressResolver.ts (3 hunks)
🔇 Additional comments (3)
src/resolvers/anchorContractAddressResolver.ts (3)

17-19: LGTM! Imports are well-organized and relevant.

The new imports appropriately support the added recipient address functionality.


30-30: LGTM! Parameter addition follows GraphQL best practices.

The optional recipientAddress parameter is properly typed and decorated.


60-82: Verify error message key and mutation usage.

Let's ensure the error message key exists and check how this mutation is used in the codebase.

✅ Verification successful

Error message key exists and implementation looks correct

The verification shows that:

  • The error message key PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK is properly defined in src/utils/errorMessages.ts
  • The error message is appropriately used in both the resolver and its test file
  • The mutation appears to be self-contained within the resolver and its test file, suggesting it's a new feature or an internal implementation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the error message key exists
rg "PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK" -A 1 -B 1

# Check for mutation usage in the codebase
rg "addAnchorContractAddress.*recipientAddress.*" -g "*.{ts,tsx,graphql}"

Length of output: 1238


Script:

#!/bin/bash
# Let's check for GraphQL mutations and their usage
rg "mutation.*addAnchorContractAddress" -g "*.{graphql,ts,tsx}" -A 5

# Check for any tests related to this mutation
rg "addAnchorContractAddress.*test" -g "*.test.{ts,tsx}"

# Check for frontend components or pages using this mutation
rg "useAddAnchorContractAddress|ADD_ANCHOR_CONTRACT_ADDRESS" -g "*.{ts,tsx}"

Length of output: 301

Comment on lines +60 to +76
if (recipientAddress) {
const recipientAddressInput = {
project,
user: creatorUser,
address: recipientAddress!,
chainType: ChainType.EVM,
networkId: networkId,
isRecipient: true,
};

await validateProjectRelatedAddresses(
[recipientAddressInput],
projectId,
);

await addBulkNewProjectAddress([recipientAddressInput]);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add address format validation before processing.

The recipient address should be validated for proper format before attempting to create and validate the input object.

   if (recipientAddress) {
+    if (!ethers.utils.isAddress(recipientAddress)) {
+      throw new Error(
+        i18n.__(translationErrorMessagesKeys.INVALID_ADDRESS_FORMAT)
+      );
+    }
+
     const recipientAddressInput = {
       project,
       user: creatorUser,
📝 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
if (recipientAddress) {
const recipientAddressInput = {
project,
user: creatorUser,
address: recipientAddress!,
chainType: ChainType.EVM,
networkId: networkId,
isRecipient: true,
};
await validateProjectRelatedAddresses(
[recipientAddressInput],
projectId,
);
await addBulkNewProjectAddress([recipientAddressInput]);
} else {
if (recipientAddress) {
if (!ethers.utils.isAddress(recipientAddress)) {
throw new Error(
i18n.__(translationErrorMessagesKeys.INVALID_ADDRESS_FORMAT)
);
}
const recipientAddressInput = {
project,
user: creatorUser,
address: recipientAddress!,
chainType: ChainType.EVM,
networkId: networkId,
isRecipient: true,
};
await validateProjectRelatedAddresses(
[recipientAddressInput],
projectId,
);
await addBulkNewProjectAddress([recipientAddressInput]);
} else {

@CarlosQ96 CarlosQ96 merged commit 2051be0 into staging Dec 9, 2024
5 checks passed
@CarlosQ96 CarlosQ96 deleted the hotfix_create_recipient_address_for_stream branch December 9, 2024 15:38
CarlosQ96 added a commit that referenced this pull request Dec 10, 2024
* add includeUnlisted to FilterProjectQueryInputParams

* return proper projects

* add recipient address to streams when nonexistent (#1890)

---------

Co-authored-by: Cherik <[email protected]>
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