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: emit chainChanged first #2661

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
20 changes: 10 additions & 10 deletions src/services/walletconnect/__tests__/WalletConnectWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,36 +344,36 @@ describe('WalletConnectWallet', () => {
expect(emitSessionEventSpy).toHaveBeenCalledTimes(2)
})

it('should call emitSessionEvent with the correct parameters', async () => {
it.only('should call emitSessionEvent with the correct parameters', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Don't forget the only.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in 09db2d4.

const emitSessionEventSpy = jest.spyOn((wallet as any).web3Wallet as IWeb3Wallet, 'emitSessionEvent')

const session = {
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
Loading