-
Notifications
You must be signed in to change notification settings - Fork 20
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
ID-913 ZkEvm provider events [NO-CHANGELOG] #580
Conversation
Skipping changelog updated check. Detected |
}; | ||
|
||
export enum ProviderEventNames { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export enum ProviderEventNames { | |
export enum ProviderEvent { |
@@ -31,7 +33,7 @@ type LoggedInZkEvmProvider = { | |||
user: UserZkEvm; | |||
}; | |||
|
|||
export class ZkEvmProvider implements Provider { | |||
export class ZkEvmProvider extends TypedEventEmitter<ProviderEvents> implements Provider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reasons why we're picking inheritance over composition here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EIP-1193 spec states that events must implement on
& removeListener
, and:
To satisfy these requirements, Provider implementers should consider simply extending the Node.js EventEmitter class and bundling it for the target environment.
Alternatively we could manually create these functions on the provider & delegate the handling to the TypedEventEmitter
eventName: TEventName, | ||
handler: (...eventArg: TEvents[TEventName]) => void, | ||
) { | ||
this.emitter.on(eventName, handler as any); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Types look off in this class, can we avoid any
casting here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class comes from here, and the reason is:
In strict mode, an error is raised because TEvents[TEventName] != any[]. This is because (...args: TEvents[TEventName]) => void is narrower than the default typings on the EventEmitter type of (...args: any[]) => void and since function parameters are contravariant, this results in a type error. Because we constrain types when events are raised via the emit function, we can safely suppress this error with an as any type
testEvent2: [{ id: number }], | ||
}; | ||
|
||
describe('TypedEventEmitter', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Summary
This PR adds support for events to the ZkEvm Provider. Only
accountsChanged
is currently being emitted as per this decision log.Additionally, there are a few misc. changes:
EthMethodWithAuthParams
, assendTransaction
can specify its own paramsZkEvmProvider.ts
registerZkEvmUser
tologinZkEvmUser
, as it's responsible for logging in the user, not registering themcreateCounterfactualAddress
toregisterZkEvmUser