Skip to content

Conversation

@adrianvrj
Copy link

@adrianvrj adrianvrj commented Aug 3, 2025

Summary

This PR fixes GitHub verification by implementing an identity refresh system that automatically
updates user identities after successful verification transactions.

Changes

  • Added Identity Refresh Context System: Created a new context provider
    (IdentityRefreshProvider) and hook (useIdentityRefresh) to manage identity refresh callbacks
    across components
  • Enhanced Available Identities Component: Modified availableIdentities.tsx to register refresh
    callbacks and handle identity updates when verification transactions complete
  • Updated Notification Manager: Enhanced useNotificationManager.ts to trigger identity refreshes
    when verification transactions (GitHub, Twitter, Discord, POP) are successful
  • App-wide Provider Integration: Wrapped the entire application with IdentityRefreshProvider in
    _app.tsx to enable the refresh system

Technical Details

The fix works by:

  1. Creating a centralized refresh callback system that components can register with
  2. Automatically triggering identity refreshes when verification transactions complete
    successfully
  3. Using a 1-second delay after transaction success to ensure backend processing is complete
  4. Supporting all verification types: GitHub, Twitter, Discord, and POP verifications

Files Modified

  • components/identities/availableIdentities.tsx - Added refresh callback registration
  • hooks/useNotificationManager.ts - Added verification transaction detection and refresh
    triggering
  • pages/_app.tsx - Added IdentityRefreshProvider wrapper

Files Added

  • components/providers/IdentityRefreshProvider.tsx - Context provider for refresh system

  • hooks/useIdentityRefresh.ts - Hook for accessing refresh functionality

  • Closes Github verification bug #1127

Summary by CodeRabbit

  • New Features

    • Introduced an identity refresh system, allowing identity data to be updated automatically after successful verification actions.
    • Added a new provider to manage identity refresh callbacks across the app.
    • Integrated identity refresh logic with transaction notifications for real-time updates.
  • Chores

    • Updated app structure to include the new identity refresh provider for consistent access throughout the application.

@vercel
Copy link

vercel bot commented Aug 3, 2025

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

Name Status Preview Comments Updated (UTC)
app-starknet-id ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 3, 2025 10:46pm

@vercel
Copy link

vercel bot commented Aug 3, 2025

@adrianvrj is attempting to deploy a commit to the LFG Labs Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

Walkthrough

This change introduces a new identity refresh mechanism using React context and hooks. It adds an IdentityRefreshProvider and a useIdentityRefresh hook, integrates them into the component tree, and updates relevant components and hooks to use this context for refreshing identity data, especially after certain verification transactions.

Changes

Cohort / File(s) Change Summary
Identity Refresh Provider Integration
pages/_app.tsx
Wraps application with new IdentityRefreshProvider to provide identity refresh context to the component tree.
Identity Refresh Context & Hook
hooks/useIdentityRefresh.ts
Adds IdentityRefreshContext, IdentityRefreshContextType interface, and useIdentityRefresh hook for managing refresh.
Identity Refresh Provider Component
components/providers/IdentityRefreshProvider.tsx
Introduces IdentityRefreshProvider component managing callbacks for refreshing identities by token ID via React context.
Available Identities Integration
components/identities/availableIdentities.tsx
Updates to use useIdentityRefresh for registering/unregistering refresh callbacks per token ID alongside polling logic.
Notification Manager Integration
hooks/useNotificationManager.ts
Enhances to trigger identity refresh on successful verification transactions using refreshIdentity from the new context.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant IdentityRefreshProvider
    participant AvailableIdentities
    participant useNotificationManager

    User->>App: Initiates verification (e.g., GitHub)
    App->>useNotificationManager: Handles transaction notification
    useNotificationManager->>IdentityRefreshProvider: Calls refreshIdentity(tokenId) after success
    IdentityRefreshProvider->>AvailableIdentities: Triggers registered refresh callback for tokenId
    AvailableIdentities->>AvailableIdentities: Updates identity data (refreshData)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Assessment against linked issues

Objective Addressed Explanation
Fix infinite verification loop and ensure GitHub account verification status is accurately reflected (#1127)
Provide a mechanism to refresh or update identity status after verification actions (#1127)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

❌ Change request

Suggested reviewers

  • Marchand-Nicolas

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests 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.

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5999c8b and 5fc8ddd.

📒 Files selected for processing (5)
  • components/identities/availableIdentities.tsx (2 hunks)
  • components/providers/IdentityRefreshProvider.tsx (1 hunks)
  • hooks/useIdentityRefresh.ts (1 hunks)
  • hooks/useNotificationManager.ts (4 hunks)
  • pages/_app.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the `registerv3` component (`components/domains/registerv3.tsx`), the `setdomain` prop is kept de...
Learnt from: Viktohblake
PR: lfglabs-dev/app.starknet.id#995
File: components/domains/registerV3.tsx:19-21
Timestamp: 2025-01-26T19:18:53.841Z
Learning: In the `RegisterV3` component (`components/domains/registerV3.tsx`), the `setDomain` prop is kept despite being unused because removing it would require changes to dependent files. This prop is marked with a comment indicating it's not used since the domain search bar was removed.

Applied to files:

  • components/identities/availableIdentities.tsx
🧬 Code Graph Analysis (4)
pages/_app.tsx (1)
components/providers/IdentityRefreshProvider.tsx (1)
  • IdentityRefreshProvider (8-37)
components/providers/IdentityRefreshProvider.tsx (1)
hooks/useIdentityRefresh.ts (1)
  • IdentityRefreshContext (9-9)
components/identities/availableIdentities.tsx (1)
hooks/useIdentityRefresh.ts (1)
  • useIdentityRefresh (11-17)
hooks/useNotificationManager.ts (1)
hooks/useIdentityRefresh.ts (1)
  • useIdentityRefresh (11-17)
🪛 Biome (2.1.2)
components/identities/availableIdentities.tsx

[error] 41-41: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

hooks/useNotificationManager.ts

[error] 25-25: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

🪛 ESLint
hooks/useNotificationManager.ts

[error] 27-29: Empty block statement.

(no-empty)

🔇 Additional comments (7)
hooks/useIdentityRefresh.ts (1)

1-17: Well-structured React context implementation.

The hook follows standard React context patterns with proper error handling. The interface clearly defines the contract and the error message provides helpful guidance for developers.

pages/_app.tsx (2)

20-20: Good integration of the provider import.

The import is properly placed and follows the existing import structure.


56-72: Proper provider hierarchy and placement.

The IdentityRefreshProvider is correctly positioned within the component tree, ensuring the identity refresh context is available throughout the application while maintaining logical provider nesting.

components/providers/IdentityRefreshProvider.tsx (1)

1-37: Excellent provider implementation.

The use of useRef for the callbacks Map is appropriate since callback changes shouldn't trigger re-renders. All methods are properly memoized with useCallback for stable references, and the implementation efficiently manages the callback registry.

components/identities/availableIdentities.tsx (1)

164-175: Update effect dependencies and cleanup logic.

The registration and cleanup logic is well-structured, but ensure the effect dependencies are updated after fixing the conditional hook usage.

hooks/useNotificationManager.ts (2)

71-84: Good verification transaction handling logic.

The logic to trigger identity refreshes after successful verification transactions is well-implemented:

  • Correctly identifies verification transaction types
  • Properly extracts token ID from notification subtext using regex
  • Uses appropriate delay to ensure backend processing completes

94-94: Update effect dependencies after fixing hook usage.

Remember to update the effect dependencies after fixing the conditional hook usage above.

Comment on lines +38 to +46
let registerRefreshCallback: ((tokenId: string, callback: () => void) => void) | null = null;
let unregisterRefreshCallback: ((tokenId: string) => void) | null = null;
try {
const context = useIdentityRefresh();
registerRefreshCallback = context.registerRefreshCallback;
unregisterRefreshCallback = context.unregisterRefreshCallback;
} catch {
console.error("Unable to refresh user identity.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Fix conditional hook usage violation.

The useIdentityRefresh hook is being called conditionally inside a try-catch block, which violates React's Rules of Hooks. This can cause unpredictable behavior and state corruption.

Apply this diff to fix the hooks violation:

-  let registerRefreshCallback: ((tokenId: string, callback: () => void) => void) | null = null;
-  let unregisterRefreshCallback: ((tokenId: string) => void) | null = null;
-  try {
-    const context = useIdentityRefresh();
-    registerRefreshCallback = context.registerRefreshCallback;
-    unregisterRefreshCallback = context.unregisterRefreshCallback;
-  } catch {
-    console.error("Unable to refresh user identity.");
-  }
+  const { registerRefreshCallback, unregisterRefreshCallback } = useIdentityRefresh();

If you need to handle the case where the provider might not be available, consider using a default context value or ensuring the provider is always present in the component tree.

📝 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
let registerRefreshCallback: ((tokenId: string, callback: () => void) => void) | null = null;
let unregisterRefreshCallback: ((tokenId: string) => void) | null = null;
try {
const context = useIdentityRefresh();
registerRefreshCallback = context.registerRefreshCallback;
unregisterRefreshCallback = context.unregisterRefreshCallback;
} catch {
console.error("Unable to refresh user identity.");
}
const { registerRefreshCallback, unregisterRefreshCallback } = useIdentityRefresh();
🧰 Tools
🪛 Biome (2.1.2)

[error] 41-41: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

🤖 Prompt for AI Agents
In components/identities/availableIdentities.tsx around lines 38 to 46, the
useIdentityRefresh hook is called inside a try-catch block, causing a
conditional hook usage violation. To fix this, move the useIdentityRefresh call
outside of any conditional or try-catch blocks so it is always called
unconditionally at the top level of the component. Then handle the case where
the context might be undefined by providing a default context value or checking
the context after the hook call, rather than catching errors from the hook call
itself.

Comment on lines +23 to +29
let refreshIdentity: ((tokenId: string) => void) | null = null;
try {
const context = useIdentityRefresh();
refreshIdentity = context.refreshIdentity;
} catch {

}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Fix conditional hook usage and empty catch block.

Two issues here:

  1. The useIdentityRefresh hook is called conditionally, violating React's Rules of Hooks
  2. Empty catch block provides no error handling

Apply this diff to fix both issues:

-  let refreshIdentity: ((tokenId: string) => void) | null = null;
-  try {
-    const context = useIdentityRefresh();
-    refreshIdentity = context.refreshIdentity;
-  } catch {
-    
-  }
+  const { refreshIdentity } = useIdentityRefresh();

If the provider might not be available, consider using a default context value or ensuring the provider is always present.

📝 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
let refreshIdentity: ((tokenId: string) => void) | null = null;
try {
const context = useIdentityRefresh();
refreshIdentity = context.refreshIdentity;
} catch {
}
const { refreshIdentity } = useIdentityRefresh();
🧰 Tools
🪛 Biome (2.1.2)

[error] 25-25: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

🪛 ESLint

[error] 27-29: Empty block statement.

(no-empty)

🤖 Prompt for AI Agents
In hooks/useNotificationManager.ts around lines 23 to 29, the useIdentityRefresh
hook is called inside a try-catch block, causing conditional hook usage which
violates React's Rules of Hooks, and the catch block is empty providing no error
handling. To fix this, remove the try-catch and call useIdentityRefresh
unconditionally. Handle the case where the provider might not be available by
using a default context value in the provider or by ensuring the provider is
always present, so the hook never throws. This eliminates conditional hook calls
and removes the need for an empty catch block.

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.

Github verification bug

1 participant