-
Notifications
You must be signed in to change notification settings - Fork 0
WalletConnect support (WIP) #123
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements comprehensive WalletConnect support for the Formo Analytics SDK to address mobile wallet connection detection issues. The main focus is resolving problems where WalletConnect providers weren't emitting connect events and improving mobile wallet recognition.
- Enhanced provider detection using multiple WalletConnect indicators beyond just the
isWalletConnect
flag - Added support for 10 popular mobile wallets with proper identification and event handling
- Implemented WalletConnect-specific event listeners for session updates, connect/disconnect events
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
src/FormoAnalytics.ts | Core implementation with enhanced WalletConnect detection, mobile wallet support, and WalletConnect-specific event handling |
examples/walletconnect-debug.js | Debug utilities for testing and monitoring WalletConnect connections in browser console |
WALLETCONNECT_INTEGRATION.md | Comprehensive documentation covering usage, troubleshooting, and API reference |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
const sessionUpdateListener = (error: any, payload: any) => { | ||
if (error) { | ||
logger.error("WalletConnect session update error:", error); | ||
return; | ||
} | ||
|
||
logger.info("WalletConnect session update:", payload); | ||
|
||
// Handle session connection | ||
if (payload?.params?.[0]?.accounts?.length > 0) { | ||
const accounts = payload.params[0].accounts; | ||
const chainId = payload.params[0].chainId; | ||
|
||
// Simulate accountsChanged event for WalletConnect | ||
this.onAccountsChanged(provider, accounts).catch(error => { | ||
logger.error("Failed to handle WalletConnect session update:", error); | ||
}); | ||
} | ||
}; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The extracted variables accounts
and chainId
on lines 1098-1099 are not used consistently. The chainId
variable is extracted but never used in the subsequent onAccountsChanged
call, which could be confusing to future maintainers.
Copilot uses AI. Check for mistakes.
if (session.accounts?.length > 0) { | ||
// Simulate connect event | ||
this.onConnected(provider, { | ||
chainId: `0x${session.chainId?.toString(16) || '1'}` |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential issue with chainId conversion. If session.chainId
is already a hex string, calling toString(16)
will result in an invalid chainId format. Should check if chainId is already in hex format before conversion.
chainId: `0x${session.chainId?.toString(16) || '1'}` | |
chainId: typeof session.chainId === "string" && session.chainId.startsWith("0x") | |
? session.chainId | |
: `0x${Number(session.chainId ?? 1).toString(16)}` |
Copilot uses AI. Check for mistakes.
} | ||
|
||
// Additional event listeners for different WalletConnect implementations | ||
const additionalEvents = ['session_request', 'call_request', 'wc_sessionUpdate']; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded event names array should be defined as a constant at the class or module level to improve maintainability and avoid potential typos when these events need to be referenced elsewhere.
Copilot uses AI. Check for mistakes.
console.log('All Providers:', providers.map(p => ({ | ||
name: p.info.name, | ||
rdns: p.info.rdns, | ||
isWalletConnect: window.formoAnalytics.isWalletConnectProvider?.(p.provider) || 'unknown' |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isWalletConnectProvider
method is private in the FormoAnalytics class but is being accessed externally. This will result in undefined behavior since private methods are not accessible outside the class.
isWalletConnect: window.formoAnalytics.isWalletConnectProvider?.(p.provider) || 'unknown' | |
isWalletConnect: window.formoAnalytics.isWalletConnectProviderPublic?.(p.provider) || 'unknown' |
Copilot uses AI. Check for mistakes.
console.log('Provider State:', state); | ||
|
||
// List all providers | ||
const providers = window.formoAnalytics.providers; |
Copilot
AI
Sep 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The providers
property appears to be accessing a private field _providers
from the FormoAnalytics class. This should use the public method getProviders()
instead to access provider information.
const providers = window.formoAnalytics.providers; | |
const providers = window.formoAnalytics.getProviders(); |
Copilot uses AI. Check for mistakes.
}; | ||
|
||
provider.on(eventName, listener); | ||
this.addProviderListener(provider, `wc_${eventName}`, listener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: WalletConnect Event Listener Cleanup Fails
WalletConnect-specific event listeners, added to provider.connector
, aren't correctly removed. The cleanup logic targets the main provider
with different event names, causing memory leaks. Separately, the chainId
conversion in onConnected
can generate an invalid 0x0x
format if session.chainId
is already a hex string.
Enhanced Provider Detection:
WalletProviderFlags
interface with mobile wallet flagsisWalletConnectProvider()
method that checks multiple WalletConnect indicatorsdetectWalletConnectProvider()
to identify specific mobile walletsMobile Wallet Support:
Improved Event Handling:
registerWalletConnectSpecificListeners()
methodsession_update
,connect
,disconnect
Debug Utilities:
/examples/walletconnect-debug.js
with browser console debugging toolscheckWalletConnectConnections()
method for manual connection testinggetProviderState()
to include WalletConnect provider countComprehensive Documentation:
WALLETCONNECT_INTEGRATION.md
with full usage guide🔧 Key Improvements:
The main issue you were experiencing - WalletConnect providers not emitting connect events - should now be resolved because:
isWalletConnect
flagsession_update
, etc.)🧪 How to Test:
Enable Debug Mode:
Use Debug Utilities:
examples/walletconnect-debug.js
in your test appTest Mobile Wallets:
🎯 Expected Results:
When you connect a mobile wallet via WalletConnect, you should now see:
The enhanced detection should resolve the issues you mentioned with:
Try testing with your example app at https://formo-analytics-example.vercel.app/ and let me know if you're still experiencing any issues!