From ae5bb5d06b97bcec87d3f30e4f952c261710f596 Mon Sep 17 00:00:00 2001 From: gaurav-cb <143218626+gaurav-cb@users.noreply.github.com> Date: Thu, 2 Nov 2023 13:53:51 -0700 Subject: [PATCH] CoinbaseWalletProvider should NOT listen to 'addressChanged' event (#1045) * CoinbaseWalletProvider should listen to new addressesChanged event --- .../provider/CoinbaseWalletProvider.test.ts | 61 ++----------------- .../src/provider/CoinbaseWalletProvider.ts | 4 -- 2 files changed, 5 insertions(+), 60 deletions(-) diff --git a/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.test.ts b/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.test.ts index 30b87852c6..00104a580e 100644 --- a/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.test.ts +++ b/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.test.ts @@ -225,11 +225,11 @@ describe('CoinbaseWalletProvider', () => { expect(result).toBe('Success'); }); - it("updates the providers address on a postMessage's 'addressChanged' event", () => { + it("does NOT update the providers address on a postMessage's 'addressesChanged' event", () => { const provider = setupCoinbaseWalletProvider(); // @ts-expect-error _addresses is private - expect(provider._addresses).not.toEqual(['0x0000000000000000000000000000000000001010']); + expect(provider._addresses).toEqual([]) const url = 'dapp.finance'; Object.defineProperty(window, 'location', { value: { origin: url } }); @@ -238,8 +238,8 @@ describe('CoinbaseWalletProvider', () => { new MessageEvent('message', { data: { data: { - action: 'addressChanged', - address: '0x0000000000000000000000000000000000001010', + action: 'addressesChanged', + addresses: ['0x0000000000000000000000000000000000001010'], }, type: 'walletLinkMessage', }, @@ -249,60 +249,9 @@ describe('CoinbaseWalletProvider', () => { ); // @ts-expect-error _addresses is private - expect(provider._addresses).toEqual(['0x0000000000000000000000000000000000001010']); + expect(provider._addresses).toEqual([]) }); - it("returns empty address on a postMessage's 'addressChanged' event when window is unspecified", () => { - const provider = setupCoinbaseWalletProvider(); - - // @ts-expect-error _addresses is private - expect(provider._addresses).not.toEqual(['0x0000000000000000000000000000000000001010']); - - fireEvent( - window, - new MessageEvent('message', { - data: { - data: { - action: 'addressChanged', - address: '0x0000000000000000000000000000000000001010', - }, - type: 'walletLinkMessage', - }, - origin: 'dapp.finance', - }) - ); - - // @ts-expect-error _addresses is private - expect(provider._addresses).toEqual([]); - }); - - it("returns empty address on a postMessage's 'addressChanged' event when location's origin is mismatched", () => { - const provider = setupCoinbaseWalletProvider(); - - // @ts-expect-error _addresses is private - expect(provider._addresses).not.toEqual(['0x0000000000000000000000000000000000001010']); - - Object.defineProperty(location, 'origin', { - value: { origin: 'not.dapp.finance' }, - }); - fireEvent( - window, - new MessageEvent('message', { - data: { - data: { - action: 'addressChanged', - address: '0x0000000000000000000000000000000000001010', - }, - type: 'walletLinkMessage', - }, - origin: 'dapp.finance', - source: window, - }) - ); - - // @ts-expect-error _addresses is private - expect(provider._addresses).toEqual([]); - }); it('handles error responses with generic requests', async () => { const relay = new MockRelayClass(); diff --git a/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.ts b/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.ts index e99dbeaa0e..e9fd5e36d4 100644 --- a/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.ts +++ b/packages/wallet-sdk/src/provider/CoinbaseWalletProvider.ts @@ -186,10 +186,6 @@ export class CoinbaseWalletProvider extends EventEmitter implements Web3Provider const jsonRpcUrl = event.data.data.jsonRpcUrl ?? this.jsonRpcUrl; this.updateProviderInfo(jsonRpcUrl, Number(_chainId)); } - - if (event.data.data.action === 'addressChanged') { - this._setAddresses([event.data.data.address]); - } }); }