fix: ensure 'incorrect wallet' modal can actually close#1483
fix: ensure 'incorrect wallet' modal can actually close#1483timothyylim wants to merge 3 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📊 Test Coverage Report
|
There was a problem hiding this comment.
Pull Request Overview
This PR aims to fix the inability to close the "incorrect wallet" modal by introducing a dismissal mechanism and resetting it when connected wallets change.
- Track user dismissal via a new state flag to prevent the modal from re-opening immediately.
- Reset the dismissal flag when the set of connected wallet addresses changes.
- Adjust the modal close handler to mark dismissals on close.
| const handleCloseWrongWalletModal = useCallback( | ||
| (open: boolean) => { | ||
| disconnect(undefined, { | ||
| onSuccess: () => setIsWrongWalletModalOpen(open), | ||
| onSuccess: () => { | ||
| setIsWrongWalletModalOpen(open); | ||
|
|
||
| // When closing, explicitly mark that the user has dismissed the warning | ||
| if (!open) { | ||
| setUserDismissedWrongWallet(true); | ||
| } | ||
| }, | ||
| }); | ||
| }, | ||
| [setIsWrongWalletModalOpen, disconnect], | ||
| [disconnect], |
There was a problem hiding this comment.
disconnect is invoked unconditionally, which will also run when open is true (e.g., if used as a Dialog onOpenChange handler). This can unintentionally disconnect when the modal opens. Guard so disconnect only runs on close, and set the open state immediately when open is true.
| disconnect(undefined, { | ||
| onSuccess: () => setIsWrongWalletModalOpen(open), | ||
| onSuccess: () => { | ||
| setIsWrongWalletModalOpen(open); | ||
|
|
||
| // When closing, explicitly mark that the user has dismissed the warning | ||
| if (!open) { | ||
| setUserDismissedWrongWallet(true); | ||
| } | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Closing the modal and setting the dismissal flag are gated behind onSuccess; if disconnect fails, the modal cannot close and the dismissal flag never sets. Use onSettled (or also handle onError) to perform state updates regardless of disconnect outcome, or optimistically set the state before calling disconnect.
Fixes APP-653