-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: QR rejection handling #156
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
c580866 to
23dfed3
Compare
When users scan a QR code and reject the connection on MetaMask Mobile, the rejection error was not being propagated to the dApp. This fix ensures that error responses from the wallet are correctly identified and rejected with EIP-1193 compliant error codes (4001 = User Rejected Request). Changes: - Add error handling to initialConnectionMessageHandler for initial connections - Add error handling to handleMessage for ongoing requests - Create EIP-1193 compliant errors with code property - Update playground to display Legacy EVM errors in UI - Add unit tests for MWPTransport error handling Tested with: - Connect Multichain (QR code flow) - Connect Legacy EVM (QR code flow) - Wagmi connector (QR code flow)
- Replace manual error construction with providerErrors.custom() - Simplify initialConnectionMessageHandler with early returns - Reduce nesting depth from 5 levels to 2 levels - Remove code duplication between ID-based and method-based matching - Preserve wallet error codes while defaulting to 4001 (User Rejected)
- Close QR modal automatically when user rejects connection - Add wagmiError state to track Wagmi connection errors - Display Wagmi errors in the error section alongside Multichain and Legacy EVM
- Document QR rejection error propagation fix in connect-multichain - Document modal auto-close on rejection - Document Wagmi error display fix in browser-playground
23dfed3 to
8a253fb
Compare
| code: errorData.code ?? 4001, | ||
| message: errorData.message ?? 'Request rejected by user', |
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.
not sure about these default values.
wow. so were we missing request.reject from errors this whole time? I guess that makes sense because I feel like the DefaultTransport has handling errors differently than the MWPTransport. sigh, good catch
| code: errorData.code ?? 4001, | ||
| message: errorData.message ?? 'Connection rejected', |
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.
not sure about these defaults
Explanation
Problem
When users scan a QR code and reject the connection on MetaMask Mobile, the error was not propagated to the dApp. The connection would just hang instead of showing an error, and the QR modal would remain open.
Solution
Error Handling:
initialConnectionMessageHandler(for initial QR connections)handleMessage(for ongoing requests)@metamask/rpc-errors(providerErrors.custom()) for proper EIP-1193 compliant errors4001(User Rejected Request)Modal Behavior:
unload()on error)Playground Improvements:
Code Quality:
initialConnectionMessageHandlerto use early returns (reduced nesting from 5 to 2 levels)Testing
References
Checklist