Skip to content

Commit

Permalink
fix: multipl session disconnects throwing (#2655)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook authored Oct 19, 2023
1 parent 6e45ac2 commit ec255f4
Showing 1 changed file with 11 additions and 7 deletions.
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) {
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

0 comments on commit ec255f4

Please sign in to comment.