From d46c80032967328ea28b375c3e2c729bd393cd91 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Wed, 27 Mar 2024 15:34:22 +0100 Subject: [PATCH] Revert "fix: cannot connect with WC to Opensea (#3437)" This reverts commit 3e49165b037a20f6d28c350ddde68893916862fc. --- .../services/WalletConnectWallet.ts | 18 ++--- .../__tests__/WalletConnectWallet.test.ts | 70 +++---------------- 2 files changed, 15 insertions(+), 73 deletions(-) diff --git a/src/features/walletconnect/services/WalletConnectWallet.ts b/src/features/walletconnect/services/WalletConnectWallet.ts index 437c5cfb36..d497e78642 100644 --- a/src/features/walletconnect/services/WalletConnectWallet.ts +++ b/src/features/walletconnect/services/WalletConnectWallet.ts @@ -81,18 +81,15 @@ class WalletConnectWallet { }) } - private getNamespaces( - proposal: Web3WalletTypes.SessionProposal, - currentChainId: string, - safeAddress: string, - optional = false, - ) { + private getNamespaces(proposal: Web3WalletTypes.SessionProposal, currentChainId: string, safeAddress: string) { + // Most dApps require mainnet, but we aren't always on mainnet + // As workaround, we pretend include all required and optional chains with the Safe chainId const requiredChains = proposal.params.requiredNamespaces[EIP155]?.chains || [] const optionalChains = proposal.params.optionalNamespaces[EIP155]?.chains || [] const supportedChainIds = [currentChainId].concat( requiredChains.map(stripEip155Prefix), - optional ? optionalChains.map(stripEip155Prefix) : [], + optionalChains.map(stripEip155Prefix), ) const eip155ChainIds = supportedChainIds.map(getEip155ChainId) @@ -126,13 +123,6 @@ class WalletConnectWallet { namespaces, }) - const updatedNamespaces = { - ...session.namespaces, - ...this.getNamespaces(proposal, currentChainId, safeAddress, true), - } - - await this.web3Wallet.updateSession({ topic: session.topic, namespaces: updatedNamespaces }) - await this.chainChanged(session.topic, currentChainId) // Workaround: WalletConnect doesn't have a session_add event diff --git a/src/features/walletconnect/services/__tests__/WalletConnectWallet.test.ts b/src/features/walletconnect/services/__tests__/WalletConnectWallet.test.ts index 8a40e4d80d..ce86f0dbbb 100644 --- a/src/features/walletconnect/services/__tests__/WalletConnectWallet.test.ts +++ b/src/features/walletconnect/services/__tests__/WalletConnectWallet.test.ts @@ -105,9 +105,7 @@ describe('WalletConnectWallet', () => { describe('approveSession', () => { it('should approve the session with proposed required/optional chains/methods and required events', async () => { const approveSessionSpy = jest.spyOn((wallet as any).web3Wallet as IWeb3Wallet, 'approveSession') - const updateSessionSpy = jest.spyOn((wallet as any).web3Wallet as IWeb3Wallet, 'updateSession') approveSessionSpy.mockResolvedValue({ - topic: 'abc', namespaces: { eip155: {}, }, @@ -161,23 +159,7 @@ describe('WalletConnectWallet', () => { toBeHex('0x123', 20), ) - const namespaceWithOnlyRequired = { - eip155: { - chains: ['eip155:1'], - methods: [ - 'eth_sendTransaction', - 'personal_sign', - 'eth_accounts', - 'eth_sign', - 'eth_signTypedData', - 'eth_signTypedData_v4', - 'wallet_switchEthereumChain', - ], - events: ['chainChanged', 'accountsChanged'], - accounts: [`eip155:1:${toBeHex('0x123', 20)}`], - }, - } - const namespacesWithOptional = { + const namespaces = { eip155: { chains: [ 'eip155:1', @@ -212,12 +194,7 @@ describe('WalletConnectWallet', () => { expect(approveSessionSpy).toHaveBeenCalledWith({ id: 123, - namespaces: namespaceWithOnlyRequired, - }) - - expect(updateSessionSpy).toHaveBeenCalledWith({ - topic: 'abc', - namespaces: namespacesWithOptional, + namespaces, }) }) @@ -253,51 +230,26 @@ describe('WalletConnectWallet', () => { toBeHex('0x123', 20), ) - let chains = ['eip155:43114', 'eip155:42161', 'eip155:8453', 'eip155:100', 'eip155:137', 'eip155:1101'] - let accounts = [ - `eip155:43114:${toBeHex('0x123', 20)}`, - `eip155:42161:${toBeHex('0x123', 20)}`, - `eip155:8453:${toBeHex('0x123', 20)}`, - `eip155:100:${toBeHex('0x123', 20)}`, - `eip155:137:${toBeHex('0x123', 20)}`, - `eip155:1101:${toBeHex('0x123', 20)}`, - ] const namespaces = { eip155: { - chains: [], + chains: ['eip155:43114', 'eip155:42161', 'eip155:8453', 'eip155:100', 'eip155:137', 'eip155:1101'], methods: ['eth_accounts', 'personal_sign', 'eth_sendTransaction'], events: ['chainChanged', 'accountsChanged'], - accounts: [], + accounts: [ + `eip155:43114:${toBeHex('0x123', 20)}`, + `eip155:42161:${toBeHex('0x123', 20)}`, + `eip155:8453:${toBeHex('0x123', 20)}`, + `eip155:100:${toBeHex('0x123', 20)}`, + `eip155:137:${toBeHex('0x123', 20)}`, + `eip155:1101:${toBeHex('0x123', 20)}`, + ], }, } - await wallet.approveSession( - proposal, - '69420', // not in proposal, therefore not supported - toBeHex('0x123', 20), - ) - expect(approveSessionSpy).toHaveBeenCalledWith({ id: 123, namespaces, }) - - await wallet.approveSession( - proposal, - '42161', // in proposal, therefore supported - toBeHex('0x123', 20), - ) - expect(approveSessionSpy).toHaveBeenCalledWith({ - id: 123, - namespaces: { - ...namespaces, - eip155: { - ...namespaces.eip155, - chains: [chains[1]], - accounts: [accounts[1]], - }, - }, - }) }) it('should call updateSession with the correct parameters', async () => {