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: multipl session disconnects throwing #2655

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/services/walletconnect/WalletConnectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,16 @@ class WalletConnectWallet {
const newEip155ChainId = getEip155ChainId(chainId)
const newEip155Account = `${newEip155ChainId}:${safeAddress}`

const hasNewChainId = !currentEip155ChainIds.includes(newEip155ChainId)
const hasNewAccount = !currentEip155Accounts.includes(newEip155Account)
const isUnsupportedChain = !currentEip155ChainIds.includes(newEip155ChainId)
const isNewSessionSafe = !currentEip155Accounts.includes(newEip155Account)

// Switching to unsupported chain
if (hasNewChainId) {
if (isUnsupportedChain) {
return this.disconnectSession(session)
}

// Add new account to the session namespace
if (hasNewAccount) {
// Add new Safe to the session namespace
if (isNewSessionSafe) {
Comment on lines +144 to +153
Copy link
Member Author

Choose a reason for hiding this comment

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

These renames somehow didn't merge correctly before.

const namespaces: SessionTypes.Namespaces = {
[EIP155]: {
...session.namespaces[EIP155],
Expand All @@ -165,15 +165,19 @@ class WalletConnectWallet {
})
}

// Switch to the new account
// Switch to the new Safe
await this.accountsChanged(session.topic, chainId, safeAddress)

// Switch to the new chain
await this.chainChanged(session.topic, chainId)
}

public async updateSessions(chainId: string, safeAddress: string) {
await Promise.all(this.getActiveSessions().map((session) => this.updateSession(session, chainId, safeAddress)))
// If updating sessions disconnects multiple due to an unsupported chain,
// we need to wait for the previous session to disconnect before the next
for await (const session of this.getActiveSessions()) {
await this.updateSession(session, chainId, safeAddress)
}
}

public async rejectSession(proposal: Web3WalletTypes.SessionProposal) {
Expand Down
Loading