Skip to content

Added new RTK mutation for profile#305

Merged
IAmKio merged 1 commit intostagingfrom
improvement/PRO-3311-eoa-address-reporting
May 15, 2025
Merged

Added new RTK mutation for profile#305
IAmKio merged 1 commit intostagingfrom
improvement/PRO-3311-eoa-address-reporting

Conversation

@IAmKio
Copy link
Collaborator

@IAmKio IAmKio commented May 13, 2025

Description

  • Allows the PillarX home feed app to report to the API which account has what owner address

How Has This Been Tested?

  • Locally

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Summary by CodeRabbit

  • New Features
    • Automatically records and updates wallet address mappings when users connect their wallets, enhancing integration with external wallet providers.
  • Chores
    • Improved internal API integration for profile recording.

@IAmKio IAmKio requested a review from RanaBug May 13, 2025 22:09
@IAmKio IAmKio self-assigned this May 13, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 13, 2025

Walkthrough

A new Redux Toolkit Query API slice for profile recording was implemented, featuring a mutation endpoint to send wallet mapping data to an ingest endpoint. This mutation is now triggered in the main app component whenever wallet information changes, utilizing wallet data from a third-party authentication hook.

Changes

File(s) Change Summary
src/apps/pillarx-app/api/homeFeed.ts Added profileApi with a recordProfile mutation; exports new React hook useRecordProfileMutation.
src/apps/pillarx-app/index.tsx Integrated useWallets from @privy-io/react-auth; calls recordProfile mutation in a new useEffect block.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant PrivyAuth
    participant profileApi
    participant PillarXAPI

    App->>PrivyAuth: useWallets() returns privyWallets
    App->>profileApi: useRecordProfileMutation()
    App->>profileApi: recordProfile({ owner, account })
    profileApi->>PillarXAPI: POST /ingest { owner, account }
    PillarXAPI-->>profileApi: Response
Loading

Poem

In the warren of code, a new path appears,
Where wallets and profiles now lend us their ears.
A record is sent, swift as a hare,
Mapping addresses with diligent care.
The PillarX meadow grows smarter today—
With every mutation, we hop on our way!
🐇✨

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@cloudflare-workers-and-pages
Copy link

Deploying x with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0d0409f
Status: ✅  Deploy successful!
Preview URL: https://5ae3edc4.x-e62.pages.dev
Branch Preview URL: https://improvement-pro-3311-eoa-add.x-e62.pages.dev

View logs

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

🧹 Nitpick comments (2)
src/apps/pillarx-app/api/homeFeed.ts (1)

70-87: Consider adding TypeScript interfaces for the payload and response

The recordProfile mutation doesn't specify TypeScript interfaces for its payload or response. While this might be acceptable for "fire and forget" requests, adding type definitions would improve type safety and documentation.

Consider adding type definitions like this:

export interface RecordProfilePayload {
  owner: string;
  account: string;
}

export interface RecordProfileResponse {
  success: boolean;
  // Add any other fields returned by the API
}

export const profileApi = createApi({
  reducerPath: 'profileApi',
  baseQuery: profileBaseQuery,
  endpoints: (builder) => ({
-   recordProfile: builder.mutation({
+   recordProfile: builder.mutation<RecordProfileResponse, RecordProfilePayload>({
      query: (payload = {}) => {
        return {
          url: 'ingest',
          method: 'POST',
          body: payload,
        };
      },
    }),
  }),
});
src/apps/pillarx-app/index.tsx (1)

105-109: Simplify comments for better readability

The comments on lines 105-109 are somewhat redundant and restate what the code is already doing. Consider simplifying the comments to provide higher-level context rather than restating the code logic.

- // Did we have a truthy wallet address and truthy privyWallets?
  if (walletAddress && privyWallets) {
-   // If we have a privyWallets array, we want to record the profile
    if (privyWallets.length > 0) {
-     // We want to record the profile with the first wallet in the array
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e94a16 and 0d0409f.

📒 Files selected for processing (2)
  • src/apps/pillarx-app/api/homeFeed.ts (2 hunks)
  • src/apps/pillarx-app/index.tsx (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit-tests
  • GitHub Check: lint
  • GitHub Check: build
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (8)
src/apps/pillarx-app/api/homeFeed.ts (3)

48-57: Good implementation of the profile base query

The implementation follows the same pattern as the existing staggeredBaseQuery, which maintains consistency in the codebase. The retry logic with 5 max retries is appropriate for API resilience.


94-94: LGTM!

Correctly adds the profileApi middleware to the store.


98-98: LGTM!

Properly exports the hook for use in other components.

src/apps/pillarx-app/index.tsx (5)

4-4: LGTM!

Correctly imports the useWallets hook from Privy's authentication library.


16-20: LGTM!

Properly imports the new useRecordProfileMutation hook along with existing hooks.


51-51: LGTM!

Correctly destructures the wallets array from the Privy authentication hook.


64-70: LGTM!

Good documentation explaining the purpose of the mutation hook.


110-113:

Details

❓ Verification inconclusive

Verify API payload structure

Ensure that the API endpoint expects the payload in this exact format, with owner being the smart wallet address and account being the EOA address. It might be helpful to add a comment explaining what these fields represent.


🏁 Script executed:

#!/bin/bash
# Let's search for any other uses of this API to confirm the expected payload structure
rg -A 3 "recordProfile" --glob "*.{ts,tsx}"

Length of output: 1323


🏁 Script executed:

#!/bin/bash
rg -n -A10 "recordProfile: builder.mutation" src/apps/pillarx-app/api/homeFeed.ts

Length of output: 318


Verify recordProfile payload shape

We’ve confirmed that the recordProfile RTK Query mutation simply POSTs the passed payload to "/ingest" and there are no other usages to compare against. Please:

  • Confirm that the backend ingest endpoint expects exactly { owner: string, account: string }, where
    owner is the Pillar Smart Wallet address
    account is the user’s EOA address
  • Add an inline comment at the call site clarifying each field’s meaning, for example:
// Notify backend of EOA→Smart Wallet mapping:
// owner: Smart Wallet address; account: EOA address
recordProfile({
  owner: privyWallets[0]?.address,
  account: walletAddress,
});

Comment on lines +102 to +116
useEffect(() => {
// This is a "fire and forget" call to the profile API

// Did we have a truthy wallet address and truthy privyWallets?
if (walletAddress && privyWallets) {
// If we have a privyWallets array, we want to record the profile
if (privyWallets.length > 0) {
// We want to record the profile with the first wallet in the array
recordProfile({
owner: privyWallets[0]?.address,
account: walletAddress,
});
}
}
}, [walletAddress, privyWallets, recordProfile]);
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 additional null/undefined check for wallet address

While the code checks if privyWallets exists and has items, it doesn't explicitly verify that privyWallets[0]?.address is defined before using it in the API call. This could potentially lead to issues if a wallet object exists but doesn't have a valid address property.

Also, consider adding some error handling for the API call:

useEffect(() => {
  // This is a "fire and forget" call to the profile API

  // Did we have a truthy wallet address and truthy privyWallets?
  if (walletAddress && privyWallets) {
    // If we have a privyWallets array, we want to record the profile
    if (privyWallets.length > 0) {
+     const ownerAddress = privyWallets[0]?.address;
+     if (!ownerAddress) {
+       console.warn('Owner address is undefined, skipping profile recording');
+       return;
+     }
      // We want to record the profile with the first wallet in the array
-     recordProfile({
-       owner: privyWallets[0]?.address,
-       account: walletAddress,
-     });
+     recordProfile({
+       owner: ownerAddress,
+       account: walletAddress,
+     }).catch(error => {
+       console.error('Failed to record profile:', error);
+     });
    }
  }
}, [walletAddress, privyWallets, recordProfile]);
📝 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
useEffect(() => {
// This is a "fire and forget" call to the profile API
// Did we have a truthy wallet address and truthy privyWallets?
if (walletAddress && privyWallets) {
// If we have a privyWallets array, we want to record the profile
if (privyWallets.length > 0) {
// We want to record the profile with the first wallet in the array
recordProfile({
owner: privyWallets[0]?.address,
account: walletAddress,
});
}
}
}, [walletAddress, privyWallets, recordProfile]);
useEffect(() => {
// This is a "fire and forget" call to the profile API
// Did we have a truthy wallet address and truthy privyWallets?
if (walletAddress && privyWallets) {
// If we have a privyWallets array, we want to record the profile
if (privyWallets.length > 0) {
const ownerAddress = privyWallets[0]?.address;
if (!ownerAddress) {
console.warn('Owner address is undefined, skipping profile recording');
return;
}
// We want to record the profile with the first wallet in the array
recordProfile({
owner: ownerAddress,
account: walletAddress,
}).catch(error => {
console.error('Failed to record profile:', error);
});
}
}
}, [walletAddress, privyWallets, recordProfile]);

@IAmKio IAmKio merged commit ad49691 into staging May 15, 2025
7 of 8 checks passed
@IAmKio IAmKio deleted the improvement/PRO-3311-eoa-address-reporting branch May 15, 2025 13:55
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