Conversation
WalkthroughIntroduces Wagmi-based connection handling alongside existing Privy flow in two Pulse hooks. Both hooks now initialize SDKs via either Privy or WalletConnect (via Wagmi) with added provider/account checks, async initialization, and error handling. Test setup adds a wagmi.useConnect mock to simulate a non-connected environment. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Component
participant H as Hook use...Sdk (useEffect)
participant P as Privy
participant W as Wagmi
participant WC as WalletConnect Provider
participant S as SDK (Intent/Modular)
C->>H: Mount / deps change
rect rgba(230,245,255,0.6)
note over H: Async initializeSdk()
alt Privy path
H->>P: isReady && authenticated && walletProvider?
P-->>H: Ethereum provider
H->>S: create wallet client + init SDK
S-->>H: instance set
else Wagmi path
H->>W: isConnected? connectors?
W-->>H: WalletConnect connector
H->>WC: getProvider() + accounts
WC-->>H: provider + account
H->>S: create wallet client + init SDK
S-->>H: instance set
end
end
H-->>C: sdk state updated
opt Error
H->>H: try/catch sets error and resets sdk
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
Deploying x with
|
| Latest commit: |
10ebc1a
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0ba2de0b.x-e62.pages.dev |
| Branch Preview URL: | https://fix-pro-3743-pw-fix-pulse.x-e62.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/apps/pulse/hooks/useModularSdk.ts (1)
48-112: Reset Modular SDK on disconnectWhen neither Privy nor WalletConnect succeeds, the previous
modularSdkinstance stays in state. After a wallet disconnect, callers still see a non-null SDK and keep invoking methods against a closed provider. Mirror the connection teardown by clearingmodularSdk(and any dependent flags if needed) whenever no connector is available so the hook accurately signals “not ready”.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/apps/pulse/hooks/useIntentSdk.ts(3 hunks)src/apps/pulse/hooks/useModularSdk.ts(4 hunks)src/test-utils/setupTests.ts(1 hunks)
⏰ 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). (3)
- GitHub Check: lint
- GitHub Check: unit-tests
- GitHub Check: build
| const initializeSdk = async () => { | ||
| if (!accountAddress) return; | ||
|
|
||
| const options: Options = { | ||
| bundlerApiKey: import.meta.env.VITE_ETHERSPOT_BUNDLER_API_KEY || '', | ||
| modularAccount: accountAddress as Hex, | ||
| }; | ||
|
|
||
| walletProvider | ||
| .getEthereumProvider() | ||
| .then((provider) => { | ||
| try { | ||
| // 1: Check if connected via Privy wallet | ||
| if (ready && authenticated && walletProvider) { | ||
| const provider = await walletProvider.getEthereumProvider(); | ||
| const walletClient = createWalletClient({ | ||
| account: walletProvider.address as Hex, | ||
| transport: custom(provider), | ||
| }); | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| const sdk = new IntentSdk(walletClient as any, options); | ||
| setIntentSdk(sdk); | ||
| setError(null); // Clear any previous errors when SDK initializes | ||
| }) | ||
| .catch((err) => { | ||
| console.error('Failed to initialize Intent SDK:', err); | ||
| setError('Failed to initialize Intent SDK. Please try again.'); | ||
| }); | ||
| } | ||
| }, [accountAddress, ready, authenticated, walletProvider]); | ||
| setError(null); | ||
| return; | ||
| } | ||
|
|
||
| // 2: Check if connected via WalletConnect (only if no Privy wallet) | ||
| const hasWallets = walletProvider !== undefined; | ||
| if (isWagmiConnected && !hasWallets) { | ||
| const walletConnectConnector = connectors.find( | ||
| ({ id }) => id === 'walletConnect' | ||
| ); | ||
|
|
||
| if (walletConnectConnector) { | ||
| const wcProvider: any = await walletConnectConnector.getProvider(); | ||
|
|
||
| // Only proceed if the provider is actually connected | ||
| if ( | ||
| wcProvider && | ||
| wcProvider.connected && | ||
| wcProvider.accounts && | ||
| wcProvider.accounts.length > 0 | ||
| ) { | ||
| // Get the connected account | ||
| const accounts = await wcProvider.request({ | ||
| method: 'eth_accounts', | ||
| }); | ||
| const wcAccount = accounts[0]; | ||
|
|
||
| if (wcAccount) { | ||
| const walletClient = createWalletClient({ | ||
| account: wcAccount as Hex, | ||
| transport: custom(wcProvider), | ||
| }); | ||
| const sdk = new IntentSdk(walletClient as any, options); | ||
| setIntentSdk(sdk); | ||
| setError(null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error('Failed to initialize Intent SDK:', err); | ||
| setError('Failed to initialize Intent SDK. Please try again.'); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Clear stale Intent SDK when no connector is active
If the user disconnects (Privy logout or Wagmi session ends), neither branch executes and intentSdk keeps the previous instance. Downstream hooks will keep issuing requests against a dead provider, producing misleading state. Please reset intentSdk (and related error state) whenever both the Privy and WalletConnect paths fail so the hook reflects the disconnected state.
🤖 Prompt for AI Agents
In src/apps/pulse/hooks/useIntentSdk.ts around lines 26–88, the initialization
function never clears a previously set intentSdk when neither the Privy nor
WalletConnect branches run (e.g., on disconnect), leaving a stale SDK; update
the function so that whenever you early-return because !accountAddress or after
executing both connector checks with no active connection, call
setIntentSdk(null) and clear related error state with setError(null) (and also
ensure the catch block clears intentSdk on fatal failures) so the hook
accurately reflects the disconnected state.
Description
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests