Skip to content

Commit

Permalink
fix: emit chainChanged first (#2661)
Browse files Browse the repository at this point in the history
* fix: emit  first

* fix: remove only from test
  • Loading branch information
iamacook authored Oct 19, 2023
1 parent e3b3c5f commit 2bb0878
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/services/walletconnect/WalletConnectWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ class WalletConnectWallet {
})
}

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

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

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

public async updateSessions(chainId: string, safeAddress: string) {
Expand Down
18 changes: 9 additions & 9 deletions src/services/walletconnect/__tests__/WalletConnectWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,29 +351,29 @@ describe('WalletConnectWallet', () => {
topic: 'topic',
namespaces: {
eip155: {
chains: ['eip155:1'],
chains: ['eip155:1', 'eip155:5'],
accounts: [`eip155:1:${hexZeroPad('0x123', 20)}`],
},
},
} as unknown as SessionTypes.Struct

await (wallet as any).updateSession(session, '1', hexZeroPad('0x456', 20))
await (wallet as any).updateSession(session, '5', hexZeroPad('0x456', 20))

expect(emitSessionEventSpy).toHaveBeenCalledTimes(2)

expect(emitSessionEventSpy).toHaveBeenNthCalledWith(1, {
topic: 'topic',
event: {
name: 'accountsChanged',
data: [hexZeroPad('0x456', 20)],
},
chainId: 'eip155:1',
event: { data: 5, name: 'chainChanged' },
chainId: 'eip155:5',
})

expect(emitSessionEventSpy).toHaveBeenNthCalledWith(2, {
topic: 'topic',
event: { data: 1, name: 'chainChanged' },
chainId: 'eip155:1',
event: {
name: 'accountsChanged',
data: [hexZeroPad('0x456', 20)],
},
chainId: 'eip155:5',
})
})
})
Expand Down

0 comments on commit 2bb0878

Please sign in to comment.