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 referrer account id handling issues #355

Merged
merged 2 commits into from
Feb 26, 2025

Conversation

carina-akaia
Copy link
Collaborator

@carina-akaia carina-akaia commented Feb 26, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined referral and session management across wallet, contribution, pot application, and profile areas to ensure consistent referral link behavior.
    • Simplified form interfaces by removing deprecated and redundant parameters.
    • Enhanced tab navigation logic to manage query parameters effectively.
  • Bug Fixes
    • Improved validation checks for transaction references to avoid empty values during processing.

@carina-akaia carina-akaia self-assigned this Feb 26, 2025
@carina-akaia carina-akaia linked an issue Feb 26, 2025 that may be closed by this pull request
Copy link

vercel bot commented Feb 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
potlock-next-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 26, 2025 5:17pm

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

This PR updates how referral parameters are handled and improves type safety and input signatures across several wallet and pot-related modules. Changes include the introduction of a new hook and memoized logic for calculating the referral account ID, renaming query parameters from referrerId to referrerAccountId, and streamlining form hooks by removing unnecessary parameters. Additional refinements ensure that transaction hashes are only accepted if they are non-empty, while session handling in matching pool contributions is refactored to rely on user session data.

Changes

Files Change Summary
src/common/wallet/components.tsx, src/layout/pot/components/.../layout-hero.tsx, src/layout/profile/components/summary.tsx Updated query parameter handling: renamed referrerId to referrerAccountId, introduced useRouteQuery, computed referrerAccountIdUrlParameter, and updated URL constructions.
src/common/wallet/model.ts Updated type definitions by replacing optional string with AccountId for referrerAccountId and adjusted method signature accordingly.
src/entities/pot/hooks/forms.ts, src/features/pot-application/hooks/forms.ts, src/features/matching-pool-contribution/hooks/forms.ts Simplified hook signatures by removing the optional referrerId (and other redundant parameters) in favor of using the potDetail and session-derived values.
src/features/donation/hooks/redirects.ts, src/features/pot-configuration/hooks/middlewares.ts Refined transaction hash validation to ensure the value is a non-empty string before assignment.
src/features/matching-pool-contribution/components/MatchingPoolContributionModal.tsx Refactored session handling by replacing router-based query extraction with the useWalletUserSession hook and fixed minor naming issues.

Sequence Diagram(s)

sequenceDiagram
    participant Q as QueryParams
    participant WP as WalletProvider
    participant UM as useMemo Hook
    participant UE as useEffect Hook
    participant SS as Session Setter

    Q->>WP: Provide referrerAccountId/referrerId
    WP->>UM: Compute referrerAccountIdUrlParameter
    UM-->>WP: Return computed referral parameter
    WP->>UE: Trigger effect with updated dependency
    UE->>SS: Validate and update wallet session with new referrerAccountId
Loading

Possibly related PRs

Poem

I’m a hopping rabbit, quick on my feet,
Digging through code where clean changes meet.
Query parameters now neat and refined,
Session and types beautifully aligned.
With every nibble of logic so bright,
I leap with joy—coding feels just right!
🐇✨

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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.

@carina-akaia carina-akaia marked this pull request as ready for review February 26, 2025 16:54
@carina-akaia carina-akaia removed the request for review from Ebube111 February 26, 2025 16:55
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

🧹 Nitpick comments (2)
src/features/pot-configuration/hooks/middlewares.ts (1)

19-22: Enhanced validation prevents empty transaction hash issues.

Adding the check for transactionHashes.length > 0 is a good defensive programming practice that prevents empty strings from being treated as valid transaction hashes, which could lead to subtle bugs.

For even more robust validation, consider using a helper function for this transaction hash validation pattern since it's also implemented in src/features/donation/hooks/redirects.ts.

src/common/wallet/components.tsx (1)

21-21: Remove console.log statements

Debug console logs should be removed before merging to production.

-  console.log(query);
-  console.log(referrerAccountIdUrlParameter);

Also applies to: 89-89

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbd4009 and 085c0e1.

📒 Files selected for processing (10)
  • src/common/wallet/components.tsx (4 hunks)
  • src/common/wallet/model.ts (2 hunks)
  • src/entities/pot/hooks/forms.ts (1 hunks)
  • src/features/donation/hooks/redirects.ts (1 hunks)
  • src/features/matching-pool-contribution/components/MatchingPoolContributionModal.tsx (6 hunks)
  • src/features/matching-pool-contribution/hooks/forms.ts (3 hunks)
  • src/features/pot-application/hooks/forms.ts (0 hunks)
  • src/features/pot-configuration/hooks/middlewares.ts (1 hunks)
  • src/layout/pot/components/layout-hero.tsx (1 hunks)
  • src/layout/profile/components/summary.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • src/features/pot-application/hooks/forms.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Fleek - broad-haze-5260
🔇 Additional comments (21)
src/layout/pot/components/layout-hero.tsx (1)

71-71: Query parameter name change improves clarity.

The change from referrerId to referrerAccountId makes the parameter name more descriptive of what it actually contains (an account ID). This aligns with the broader renaming effort across the codebase as mentioned in the summary.

src/layout/profile/components/summary.tsx (1)

39-39: Consistent parameter naming improves code maintainability.

The change from referrerId to referrerAccountId maintains consistency with similar changes made in other files, such as src/layout/pot/components/layout-hero.tsx.

src/features/donation/hooks/redirects.ts (1)

23-27: Consistent validation pattern for transaction hashes.

This validation enhancement matches the one in src/features/pot-configuration/hooks/middlewares.ts, ensuring that empty strings aren't treated as valid transaction hashes. This consistency in validation patterns across the codebase is excellent.

src/entities/pot/hooks/forms.ts (1)

12-12: Simplified function signature to remove unused parameter

The referrerId parameter has been removed from useChallengeForm, streamlining the API surface. This is a good simplification since the parameter wasn't being used in the function implementation.

src/common/wallet/model.ts (2)

12-12: Improved type safety by using AccountId type

Changing referrerAccountId from string to AccountId improves type safety and alignment with the domain model. This ensures that only valid account IDs can be assigned to this property.


54-54: Updated method signature for type consistency

The parameter name has been changed from recipientAccountId to accountId, which better reflects its purpose. The type has also been updated to AccountId | undefined for consistency with the property type.

src/common/wallet/components.tsx (4)

24-29: Good backward compatibility approach

Adding comments for backward compatibility with the deprecated referrerId parameter is a good practice. This helps other developers understand why both parameters are being handled.


31-34: Well-implemented memoization of referrer parameter

Using useMemo to consolidate the values of both referrerAccountId and the deprecated referrerId parameters is an efficient approach that ensures backward compatibility.


95-103: Improved validation logic for referrer account ID

The updated logic correctly validates the referrer account ID using isAccountId before setting it, and checks it against both the current referrer account ID and the user's own account ID to avoid unnecessary updates.


104-112: Complete dependency array for useEffect

The dependency array has been correctly updated to include all variables used in the effect, which prevents potential stale closure issues.

src/features/matching-pool-contribution/components/MatchingPoolContributionModal.tsx (5)

17-17: Good refactoring to use session data

Replacing router query access with the useWalletUserSession hook simplifies the code and centralizes the logic for accessing user session data.

Also applies to: 33-33


40-40: Fixed variable name typo

The variable name has been corrected from yoctoMinimumAmout to yoctoMinimumAmount.


61-63: Simplified referrer fee calculation

Using viewer.referrerAccountId directly to determine if a referrer fee should be applied improves code clarity and maintainability.


174-178: Improved conditional rendering for referrer fee display

The conditional rendering now uses viewer.referrerAccountId to determine whether to show the referrer fee information.


194-203: Enhanced button text display

The button text now clearly differentiates between regular contributions and DAO proposal creations based on viewer.isDaoRepresentative. This provides better user guidance.

src/features/matching-pool-contribution/hooks/forms.ts (6)

11-11: Import change looks good.

The new import statement for useWalletUserSession correctly brings in the hook that provides centralized access to user session data.


15-17: Good refactoring to use centralized session management.

Streamlining the function parameters by removing accountId, referrerId, and asDao in favor of the viewer object from useWalletUserSession improves code maintainability and follows the single source of truth principle.


30-30: Consistent naming for referrer ID.

Replacing referrerId with viewer.referrerAccountId aligns with the PR's objective to standardize referrer parameter naming across the application.


64-65: Proper DAO representation check.

Using viewer.isDaoRepresentative and viewer.daoAccountId from the centralized session improves consistency and maintainability compared to passing these values as separate parameters.


76-81: Contract call implementation is correctly maintained.

The implementation of the non-DAO path maintains the same functionality while using the centralized parameters from the viewer object.


90-96: Correctly updated dependencies array.

The dependencies array has been properly updated to include all the relevant properties from the viewer object, ensuring the callback function reacts appropriately to changes in these values.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 085c0e1 and cfcce52.

📒 Files selected for processing (3)
  • src/common/api/indexer/hooks.ts (1 hunks)
  • src/common/wallet/components.tsx (3 hunks)
  • src/layout/pot/hooks/tab-navigation.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/common/wallet/components.tsx
🔇 Additional comments (5)
src/layout/pot/hooks/tab-navigation.ts (5)

1-2: Consider creating a separate ticket for the TODO comment

This TODO comment about storage optimizations appears to be unrelated to the current PR's focus on referrer handling. Consider creating a dedicated ticket to track this work separately.


181-185: Good improvement in tab detection logic

The changes to split the current path at "?" and compare only the base path ensures that query parameters don't affect which tab is considered active. This is a solid improvement that helps properly handle URLs with varying query parameters.


189-203: Well-implemented query parameter preservation

Excellent implementation for preserving query parameters during tab navigation. The code now extracts query parameters from the current URL and appends them to the target tab's href, ensuring referrer information and other query parameters are maintained when switching tabs.


206-206: Correct dependency array update

Good addition of currentPath to the dependency array, as it's now used within the callback function. This prevents potential stale closure issues.


212-214: Consistent path comparison for default tab navigation

The updated logic properly uses the same base path comparison technique for the default tab navigation, ensuring consistency with the other path handling changes in this file.

@carina-akaia carina-akaia merged commit d7f90cf into main Feb 26, 2025
3 of 6 checks passed
@carina-akaia carina-akaia deleted the 168-bug-referrerid-on-alphapotlockorg branch February 26, 2025 17:24
Ebube111 added a commit that referenced this pull request Feb 27, 2025
* Implement generalized solution for cross-field validation (#352)

* Fix referrer account id handling issues (#355)

* Campaign Fixes (#354)

* fixed issue with start date

* es lint fix

* change field to number field

* es lint fix

---------

Co-authored-by: Carina Akaia <cvo.akaia@gmail.com>

---------

Co-authored-by: Carina.Akaia.org <cvo.akaia@gmail.com>
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.

[BUG] ReferrerId on alpha.potlock.org
1 participant