Skip to content

Conversation

@premiumjibles
Copy link
Contributor

@premiumjibles premiumjibles commented Dec 8, 2025

Summary by CodeRabbit

  • Refactor
    • Automatic network switching now runs automatically when the app renders to keep the active network aligned with connected wallets.
    • Network-switching logic internalized and simplified, reducing repeated attempts and minimizing prompts.
    • Wallet disconnection behavior streamlined so disconnects are immediate and no longer trigger post-disconnect network switches.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
shapeshift-agentic Ready Ready Preview Comment Dec 8, 2025 6:23am

@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

📝 Walkthrough

Walkthrough

Adds a parameterless, app-level useAutoNetworkSwitch() hook that derives connection and network state internally and may trigger modal.switchNetwork(...); removes manual post-disconnect network-switch logic from PortfolioDrawer and simplifies disconnect handlers to only call namespace-specific disconnect.

Changes

Cohort / File(s) Summary
App hook usage
apps/agentic-chat/src/app/app.tsx
Calls useAutoNetworkSwitch() inside AppContent to enable global automatic network-switch side-effects on render.
Disconnect logic simplification
apps/agentic-chat/src/components/Portfolio/PortfolioDrawer.tsx
Removed imports of network constants and modal; handleDisconnectEvm and handleDisconnectSolana now only invoke the namespace-specific disconnect and no longer perform post-disconnect network switching or previous-connection tracking.
Auto network switch hook refactor
apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts
Converted the hook to a parameterless exported function that derives state via useAppKitNetwork, useAppKitAccount, and useAppKitState; replaced previous per-namespace guards and attempt tracking with a getTargetNetwork flow and a single conditional call to modal?.switchNetwork(targetNetwork) when resolved.

Sequence Diagram(s)

sequenceDiagram
  participant App as AppContent
  participant Hook as useAutoNetworkSwitch
  participant State as AppKit State (accounts/networks)
  participant Modal as AppKit Modal (switchNetwork)

  App ->> Hook: invoke useAutoNetworkSwitch()
  Hook ->> State: read currentNamespace, evmConnected, solanaConnected, networks
  alt target network resolved
    Hook ->> Modal: modal?.switchNetwork(targetNetwork)
    Modal -->> Hook: switch result (success/failure)
  else no target
    Hook -->> App: no action
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect effect dependency array and derived-state reads in useAutoNetworkSwitch for potential render loops or missed edge cases.
  • Verify timing/race conditions between PortfolioDrawer disconnects and the centralized auto-switch (ensure no conflicting switches).
  • Confirm app-level invocation location in app.tsx is safe for initial render and does not affect SSR semantics.

Possibly related PRs

Poem

🐰
I hopped through code with whiskers bright,
One silent hook now checks the night.
Networks nudged with gentle cheer,
Disconnects are crisp and clear.
A tiny hop, a tidy flight — 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: improve our automatic network switching logic' directly describes the main change: refactoring the automatic network switching feature with simplified logic and better hook management.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch better-network-switch

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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 (1)
apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (1)

10-14: Consider edge case: empty or malformed caipNetworkId.

If caipNetworkId is an empty string or malformed, currentNamespace could be an empty string or unexpected value. While unlikely in normal operation, adding a guard or fallback could improve robustness.

Example defensive check:

-  const currentNamespace = caipNetwork?.caipNetworkId?.split(':')[0]
+  const currentNamespace = caipNetwork?.caipNetworkId?.split(':')[0] || undefined
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9995d2f and cd6a952.

📒 Files selected for processing (3)
  • apps/agentic-chat/src/app/app.tsx (2 hunks)
  • apps/agentic-chat/src/components/Portfolio/PortfolioDrawer.tsx (2 hunks)
  • apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/agentic-chat/src/app/app.tsx (1)
apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (1)
  • useAutoNetworkSwitch (5-42)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: main
🔇 Additional comments (6)
apps/agentic-chat/src/app/app.tsx (1)

7-7: LGTM! Clean integration of automatic network switching.

The hook is appropriately placed at the app level in AppContent, ensuring automatic network switching behavior is active throughout the application lifecycle.

Also applies to: 48-48

apps/agentic-chat/src/components/Portfolio/PortfolioDrawer.tsx (3)

1-1: LGTM! Cleaned up unused imports.

The removal of mainnet, solana, and modal imports aligns with delegating network switching to the useAutoNetworkSwitch hook.


70-73: LGTM! Consistent with EVM disconnect approach.

The Solana disconnect handler follows the same pattern as the EVM handler, appropriately delegating network switching to the automatic hook.


65-68: The simplified disconnect logic with useAutoNetworkSwitch is well-designed.

The hook correctly includes evmConnected and solanaConnected in its dependency array, ensuring it reliably reacts to account state changes after async disconnect completes. The hasAttemptedSwitchRef prevents race conditions and duplicate switch attempts, with error handling that resets the flag if a switch fails. When disconnect({ namespace: 'eip155' }) completes and updates the account state, the hook's effect automatically re-runs and switches to Solana if needed.

apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (2)

2-2: LGTM! Self-contained hook design improves encapsulation.

The refactored hook derives all necessary state internally from AppKit hooks, eliminating the need for external parameters and making it easier to use throughout the application.

Also applies to: 5-8


38-41: LGTM! Reset mechanism prevents stuck state.

The separate effect that resets the attempt flag when the network changes ensures the hook can respond to future network changes appropriately, preventing the flag from permanently blocking legitimate switches.

Copy link

@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

♻️ Duplicate comments (1)
apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (1)

6-15: Redundant 'evm' namespace check remains unaddressed.

Line 15 still checks for both 'eip155' and 'evm' namespaces. As noted in a previous review, AppKit v1.8.2 only returns 'eip155' for EVM chains (CAIP-2 format). The 'evm' check will never match.

-  const isEvmNamespace = currentNamespace === 'eip155' || currentNamespace === 'evm'
+  const isEvmNamespace = currentNamespace === 'eip155'
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9da7495 and 5f0ffdc.

📒 Files selected for processing (3)
  • apps/agentic-chat/src/app/app.tsx (2 hunks)
  • apps/agentic-chat/src/components/Portfolio/PortfolioDrawer.tsx (2 hunks)
  • apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/agentic-chat/src/app/app.tsx
  • apps/agentic-chat/src/components/Portfolio/PortfolioDrawer.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: main
🔇 Additional comments (1)
apps/agentic-chat/src/hooks/useAutoNetworkSwitch.ts (1)

1-4: LGTM on imports.

Clean imports with proper type annotation for AppKitNetwork.

@premiumjibles premiumjibles merged commit 271a227 into main Dec 8, 2025
4 checks passed
@premiumjibles premiumjibles deleted the better-network-switch branch December 8, 2025 06:28
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