Skip to content

Commit

Permalink
CoinbaseWalletProvider should NOT listen to 'addressChanged' event (#…
Browse files Browse the repository at this point in the history
…1045)

* CoinbaseWalletProvider should listen to new addressesChanged event
  • Loading branch information
gaurav-cb authored Nov 2, 2023
1 parent d4c15fd commit ae5bb5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 60 deletions.
61 changes: 5 additions & 56 deletions packages/wallet-sdk/src/provider/CoinbaseWalletProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand All @@ -238,8 +238,8 @@ describe('CoinbaseWalletProvider', () => {
new MessageEvent('message', {
data: {
data: {
action: 'addressChanged',
address: '0x0000000000000000000000000000000000001010',
action: 'addressesChanged',
addresses: ['0x0000000000000000000000000000000000001010'],
},
type: 'walletLinkMessage',
},
Expand All @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions packages/wallet-sdk/src/provider/CoinbaseWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
});
}

Expand Down

0 comments on commit ae5bb5d

Please sign in to comment.