Skip to content
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

fix: session management when switching chains #2640

Merged
merged 5 commits into from
Oct 17, 2023
Merged

Conversation

iamacook
Copy link
Member

What it solves

Resolves unsupported sessions remaining connected

How this PR fixes it

  1. When switching chain, DApps that don't support the chain being opened are disconnected.
  2. If navigating out of a "Safe route", e.g. the welcome page, all sessions are disconnected.

How to test it

  1. Open a mainnet Safe and connect to AAVE and mint.fun. Observe mint.fun disconnecting when switching to a Polygon Safe.
  2. Navigate to the welcome page and observe AAVE disconnecting, as well as the WC button disabled.

Screenshots

connection

Checklist

  • I've tested the branch on mobile 📱
  • I've documented how it affects the analytics (if at all) 📊
  • I've written a unit/e2e test for it (if applicable) 🧑‍💻

@iamacook iamacook requested a review from katspaugh October 16, 2023 15:44
@iamacook iamacook self-assigned this Oct 16, 2023
@github-actions
Copy link

github-actions bot commented Oct 16, 2023

Branch preview

⏳ Deploying a preview site...

@github-actions
Copy link

github-actions bot commented Oct 16, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

useEffect(() => {
if (!walletConnect || isSafeConnected) return

walletConnect.disconnectAllSessions().catch(setError)
Copy link
Member

@katspaugh katspaugh Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a Safe is just being loaded? WC sessions live across page reloads unless disconnected.
Or the user went to the Welcome page temporarily.

I wouldn't disconnect anything per se, I would just stop accepting requests for a given Safe if you're in another Safe/outside of any Safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We reference the safe search param for this reason.

},
},
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistically, I don't see this function as a util. I would keep it as a private method in the WalletConnectWallet class.

@iamacook iamacook requested a review from katspaugh October 17, 2023 09:24
@iamacook iamacook merged commit c199533 into nect Oct 17, 2023
3 of 7 checks passed
@iamacook iamacook deleted the wc-session-management branch October 17, 2023 13:18
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants