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

Merge master into staging #1807

Closed
wants to merge 15 commits into from
Closed

Merge master into staging #1807

wants to merge 15 commits into from

Conversation

Meriem-BM
Copy link
Collaborator

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

Summary by CodeRabbit

  • New Features

    • Introduced new migrations to enhance project record management and enforce unique project address constraints for Stellar.
    • Added functionality for integrating sponsor donations into the givback mechanism.
    • Introduced a new GraphQL query for retrieving allocated givbacks with caching capabilities.
    • Expanded token tab options to include new blockchain types and networks.
    • Added a new optional parameter for improved token information retrieval.
    • Enhanced wallet address validation with additional parameters for improved context.
  • Bug Fixes

    • Updated error messages and validation logic to improve user feedback during wallet address validation.
  • Refactor

    • Improved the structure and readability of transaction checking and wallet address validation functions.
  • Tests

    • Added new test cases to enhance coverage for transaction validations related to draft donations.
    • Introduced a new test suite for allocated givbacks functionality.

CarlosQ96 and others added 3 commits August 28, 2024 09:53
* fix: remove memo for project verification managing funds

* fix: remove memo for project verification managing funds

* fix: getDraftDonationById bug (toWalletMemo can be null)

* fix: add memo for stellar project address uniqueness

* fix: add memo for manage address validation

* fix: add duplicate address error message for stellar

* fix: linter error

* add index for project stellar address

* eslint error

* fix: case when owner donate to his own peoject (Stellar chain)

* fix: add calculateGivbackFactor to Stellar cron job

* feat: register secondary donation

* running migration to set project banners appropriately for endaoment … (#1778)

* running migration to set project banners appropriately for endaoment projects

* chore: correcting tab spaces for syntax

* fix: linter errors

* Modify add banner to endaoment projects migration (#1791)

related to #1600

* Fix lint errors

* Fix running tests

* Fix projectResolver test cases

* Fix donationResolver test cases

* skip should renew the expiration date of the draft donation test case

---------

Co-authored-by: Hrithik Sampson <[email protected]>
Co-authored-by: mohammadranjbarz <[email protected]>

* fix: remove adding secondary donation logic

---------

Co-authored-by: Meriem-BM <[email protected]>
Co-authored-by: HrithikSampson <[email protected]>
Co-authored-by: Hrithik Sampson <[email protected]>
Copy link
Contributor

coderabbitai bot commented Sep 10, 2024

Walkthrough

This pull request introduces multiple database migrations and code modifications aimed at enhancing project and donation management functionalities. Key changes include a migration for updating project records with banner images, enforcing unique constraints on project addresses for Stellar, and refining donation-related logic to accommodate new parameters. Additionally, modifications to GraphQL schemas and validation logic improve flexibility and clarity in handling wallet addresses and donation processes.

Changes

Files Change Summary
migration/.../add_banner_endaoment_projects.ts Introduced a migration to update project records with banner images based on project categories and nteeCode.
migration/.../UniqueProjectAdressWithMomoForStellar.ts Created a unique index on project_address for the combination of address and memo fields for Stellar chain type.
migration/.../add_sponser_donations_to_givback_round_70.ts Added functionality to integrate sponsor donations into a specific givback round, including donor checks and donation record updates.
src/entities/draftDonation.ts Modified toWalletMemo property to be nullable in the GraphQL schema, enhancing flexibility.
src/repositories/donationRepository.ts Added optional parameters to createDonation function, allowing for more contextual information during donation creation, and introduced a new function for eligible donations.
src/repositories/projectAddressRepository.ts Introduced an optional memo parameter to findRelatedAddressByWalletAddress function for nuanced querying.
src/repositories/draftDonationRepository.ts Added a new function to retrieve a DraftDonation by matchedDonationId, enhancing data retrieval capabilities.
src/resolvers/donationResolver.ts Introduced a new GraphQL query allocatedGivbacks for calculating and caching allocated GIV back allocations.
src/resolvers/projectResolver.ts Enhanced validateProjectWalletAddress method to include a memo parameter for improved validation logic.
src/utils/tokenUtils.ts Added an optional coingeckoId parameter to findTokenByNetworkAndSymbol function for enhanced token information handling.
src/server/adminJs/tabs/tokenTab.ts Expanded network options for the Solana blockchain and introduced a chainType property for better categorization of tokens.
src/server/adminJs/tabs/qfRoundTab.ts Added "STELLAR MAINNET" entry to the availableNetworkValues array, expanding network options.

Possibly related PRs

Poem

🐰 In the meadow, changes bloom,
With banners bright, dispelling gloom.
Projects dance, donations flow,
Unique addresses, watch them grow.
A hop, a skip, new paths we pave,
For every gift, our hearts are brave! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cd4de51 and d0eefa4.

Files selected for processing (1)
  • src/server/adminJs/tabs/qfRoundTab.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/server/adminJs/tabs/qfRoundTab.ts

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

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

Line range hint 217-264: Fix test isolation issue so that all tests can run reliably together.

The test cases should return all tokens for giveth projects and should return all tokens for trace projects have been skipped because they fail when run together with other tests due to database state changes.

This indicates an issue with test isolation where tests are impacting the state/data used by other tests. Each test should create its own isolated data and not rely on or impact the data from other tests.

To fix this:

  1. Ensure each test creates its own project, tokens and any other required data.
  2. Clean up the data created by the test in the afterEach hook.
  3. Don't rely on data created outside the test or by other tests.
  4. Use database transactions so that changes from one test don't impact other tests.

After fixing the test isolation, remove the it.skip and ensure the tests pass reliably.

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 (1)
src/repositories/donationRepository.ts (1)

Line range hint 89-147: LGTM!

The addition of the new optional parameters (givbackFactor, projectRank, bottomRankInRound, and powerRound) to the createDonation function enhances its capability to handle more complex donation scenarios. The givbackFactor parameter allows for specifying a custom Givback factor for each donation, enabling more flexible Givback calculations. The projectRank, bottomRankInRound, and powerRound parameters provide additional context about the project's ranking and the associated PowerRound, which can be useful for further analysis and processing. The function update is well-implemented, with the new parameters being destructured from the data object and included in the Donation.create method call.

To improve the code documentation and maintainability, consider adding JSDoc comments to describe the purpose and usage of the new parameters. This will provide clarity for future developers working with the createDonation function.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 165d6b1 and b8a47ba.

Files selected for processing (8)
  • src/repositories/donationRepository.test.ts (3 hunks)
  • src/repositories/donationRepository.ts (5 hunks)
  • src/resolvers/donationResolver.test.ts (4 hunks)
  • src/resolvers/donationResolver.ts (3 hunks)
  • src/resolvers/projectResolver.ts (2 hunks)
  • src/utils/tokenUtils.ts (2 hunks)
  • test/graphqlQueries.ts (1 hunks)
  • test/testUtils.ts (2 hunks)
Additional comments not posted (12)
src/utils/tokenUtils.ts (1)

Line range hint 4-35: LGTM!

The addition of the optional coingeckoId parameter and property in the findTokenByNetworkAndSymbol function provides more flexibility in handling token information. The change is implemented correctly and does not introduce any breaking changes or potential issues.

src/repositories/donationRepository.ts (1)

485-523: LGTM!

The getSumOfGivbackEligibleDonationsForSpecificRound function is well-implemented and introduces a useful capability to calculate the total USD value of Givback-eligible donations for a specific PowerRound. The function handles the case when no powerRound parameter is provided by retrieving the latest PowerRound from the database. It executes a raw SQL query using the AppDataSource to efficiently calculate the sum of donation values that meet the specified criteria, including donation status, project verification, and the specified powerRound. The query also excludes donations made from project recipient addresses to avoid counting self-donations. Error handling is in place to catch any exceptions, log them, and return a default value of 0 to prevent disruption. Overall, the function is a valuable addition to the codebase.

src/resolvers/donationResolver.ts (4)

80-93: LGTM!

The AllocatedGivbacks class definition follows the GraphQL type-graphql library conventions. The field names are descriptive and the types are appropriate.


95-96: LGTM!

The allocatedGivbacksCache variable declaration is appropriate for caching the AllocatedGivbacks object. Initializing it to null indicates the cache is empty.


451-493: LGTM!

The allocatedGivbacks query in the DonationResolver class is well-structured and follows the GraphQL resolver conventions. The caching mechanism is implemented correctly to avoid unnecessary computations. The calculation logic for allocated GIV tokens is accurate and the cache expiration time of one hour seems reasonable.


Line range hint 54-76: LGTM!

The new import statements for getSumOfGivbackEligibleDonationsForSpecificRound, getTokenPrice, and findTokenByNetworkAndSymbol are correctly added. They follow the proper syntax and naming conventions.

test/graphqlQueries.ts (1)

2252-2265: LGTM!

The addition of the allocatedGivbacksQuery looks good. It provides a useful way for clients to retrieve data related to allocated givbacks. The $refreshCache parameter adds flexibility to control data freshness.

src/repositories/donationRepository.test.ts (1)

1466-1824: LGTM!

The test cases for getSumOfGivbackEligibleDonationsForSpecificRound are comprehensive and well-structured. They cover various important scenarios and use appropriate assertions to verify the expected behavior. The test cases also handle test data setup and cleanup properly.

test/testUtils.ts (1)

276-284: Improved chainType determination based on networkId.

The changes to the saveProjectDirectlyToDb function enhance its ability to correctly identify the blockchain type (chainType) associated with the given networkId. By checking if the networkId is part of the SolanaNetworkIds array, the function can now accurately set the chainType to either ChainType.SOLANA or ChainType.EVM. This improves the function's flexibility and eliminates the previous hardcoded assignment of ChainType.EVM.

src/resolvers/projectResolver.ts (1)

1789-1795: LGTM!

The addition of chainType and memo parameters to the walletAddressIsValid query method enhances its flexibility by allowing validation based on the blockchain type and supporting an optional memoization feature. The explicit typing of chainType as ChainType enum improves type safety. Making the memo parameter nullable provides flexibility in specifying the memo.

These changes align with the AI-generated summary and improve the functionality of the wallet address validation.

src/resolvers/donationResolver.test.ts (2)

4972-5164: LGTM!

The test suite allocatedGivbacksQueryTestCases is well-structured and enhances the test coverage for the allocatedGivbacksQuery functionality. The test cases effectively validate the calculation of allocated givbacks based on different donation scenarios and the behavior when the refreshCache variable is passed.


Line range hint 5166-5202: LGTM!

The test suite getDonationByIdTestCases effectively validates the getDonationById query. It covers the basic functionality of retrieving a donation by its ID and handles the scenario when the donation is not found. The test cases ensure the correctness of the query's behavior.

@@ -1255,7 +1255,7 @@ export class ProjectResolver {
);
}

await validateProjectWalletAddress(address, projectId, chainType);
await validateProjectWalletAddress(address, projectId, chainType, memo);
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

Function signature change verified, but test cases may need updating

The validateProjectWalletAddress function signature has been successfully updated to include the new memo parameter. The function definition and usage in src/resolvers/projectResolver.ts correctly incorporate this change.

However, the test cases in src/utils/validators/projectValidator.test.ts do not include the memo parameter in their function calls. These test cases should be reviewed and potentially updated to ensure they cover the new parameter:

  • Lines 101, 112, 121, 127, 130, 136, 142, 151, and 158 in src/utils/validators/projectValidator.test.ts

Please review these test cases and update them as necessary to maintain comprehensive test coverage for the validateProjectWalletAddress function.

Analysis chain

Verify the function signature change in the codebase.

The validateProjectWalletAddress function is now being invoked with an additional memo parameter. Ensure that the function definition has been updated to accept this new parameter and that all other invocations of this function have been updated to pass the memo argument.

Run the following script to verify the function usage:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all invocations of `validateProjectWalletAddress` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'validateProjectWalletAddress'

Length of output: 91


Script:

#!/bin/bash
# Description: Search for validateProjectWalletAddress function usage in TypeScript files

# Find TypeScript files and search for validateProjectWalletAddress
fd -e ts -e tsx | xargs grep -n -C 3 "validateProjectWalletAddress"

Length of output: 8994

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 and nitpick comments (1)
src/server/adminJs/tabs/qfRoundTab.ts (1)

Line range hint 202-228: Consider refactoring network configuration for better maintainability.

The availableNetworkValues array is used for multiple properties and might grow further as more networks are added. To improve maintainability and reduce duplication, consider the following refactoring suggestion:

  1. Extract the availableNetworkValues array to a separate configuration file, e.g., networkConfig.ts.
  2. Import and use this configuration in the current file and any other relevant parts of the application.

Example implementation:

// networkConfig.ts
import { NETWORK_IDS } from '../../../provider';

export const availableNetworkValues = [
  { value: NETWORK_IDS.MAIN_NET, label: 'MAINNET' },
  // ... other network entries ...
  { value: NETWORK_IDS.STELLAR_MAINNET, label: 'STELLAR MAINNET'},
  // ... remaining network entries ...
];

// qfRoundTab.ts
import { availableNetworkValues } from './networkConfig';

// Use availableNetworkValues in your configuration

This refactoring will centralize network configuration, making it easier to maintain and update across the application.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 312a395 and cd4de51.

Files selected for processing (1)
  • src/server/adminJs/tabs/qfRoundTab.ts (1 hunks)
Additional comments not posted (1)
src/server/adminJs/tabs/qfRoundTab.ts (1)

214-214: LGTM! Verify related components for Stellar Mainnet support.

The addition of Stellar Mainnet to the availableNetworkValues array is implemented correctly and consistently with other network entries. This expands the options for allocatedTokenChainId and eligibleNetworks in QF round configurations.

To ensure full support for Stellar Mainnet throughout the application, please verify:

  1. Wallet connection support for Stellar
  2. Transaction processing for Stellar network
  3. Any network-specific logic in other parts of the application

Run the following script to check for Stellar-related implementations:

This script will help identify areas that may need updates to fully support Stellar Mainnet operations.

@Meriem-BM Meriem-BM closed this Sep 26, 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.

6 participants