Skip to content

Commit 761cd35

Browse files
authored
refactor!: Remove "data" event from SafeEventEmitterProvider (#6328)
## Explanation The `SafeEventEmitterProvider` `'data'` event relies on the `JsonRpcEngine` `'notification'` event, which per #6327 we are trying to get rid of. After failing to find an instance outside of tests where we actually use the `'data'` event, we assess that it can be removed. ## References * Ref: #6327 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [x] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes (really just checking that CI passes in this case) - MetaMask/metamask-extension#35498 - MetaMask/metamask-mobile#18907
1 parent 48d3987 commit 761cd35

File tree

3 files changed

+2
-32
lines changed

3 files changed

+2
-32
lines changed

packages/eth-json-rpc-provider/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- **BREAKING:** Remove `'data'` event ([#6328](https://github.com/MetaMask/core/pull/6328))
13+
- This event was forwarding the `'notification'` event from the underlying `JsonRpcEngine`. It was rarely used in practice, and is now removed.
1214
- Bump `@metamask/utils` from `^11.2.0` to `^11.4.2` ([#6054](https://github.com/MetaMask/core/pull/6054))
1315

1416
## [4.1.8]

packages/eth-json-rpc-provider/src/safe-event-emitter-provider.test.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,6 @@ function createMockEngine(method: string, response: Json) {
3535
}
3636

3737
describe('SafeEventEmitterProvider', () => {
38-
describe('constructor', () => {
39-
it('listens for notifications from provider, emitting them as "data"', async () => {
40-
const engine = new JsonRpcEngine();
41-
const provider = new SafeEventEmitterProvider({ engine });
42-
const notificationListener = jest.fn();
43-
provider.on('data', notificationListener);
44-
45-
// `json-rpc-engine` v6 does not support JSON-RPC notifications directly,
46-
// so this is the best way to emulate this behavior.
47-
// We should replace this with `await engine.handle(notification)` when we update to v7
48-
// TODO: v7 is now integrated; fix this
49-
engine.emit('notification', 'test');
50-
51-
expect(notificationListener).toHaveBeenCalledWith(null, 'test');
52-
});
53-
54-
it('does not throw if engine does not support events', () => {
55-
// TODO: Replace `any` with type
56-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
57-
const engine = new JsonRpcEngine() as any;
58-
delete engine.on;
59-
60-
expect(() => new SafeEventEmitterProvider({ engine })).not.toThrow();
61-
});
62-
});
63-
6438
it('returns the correct block number with @metamask/eth-query', async () => {
6539
const provider = new SafeEventEmitterProvider({
6640
engine: createMockEngine('eth_blockNumber', 42),

packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ export class SafeEventEmitterProvider extends SafeEventEmitter {
6464
constructor({ engine }: { engine: JsonRpcEngine }) {
6565
super();
6666
this.#engine = engine;
67-
68-
if (engine.on) {
69-
engine.on('notification', (message: string) => {
70-
this.emit('data', null, message);
71-
});
72-
}
7367
}
7468

7569
/**

0 commit comments

Comments
 (0)