Skip to content

Commit

Permalink
Merge pull request #2050 from WalletConnect/fix/on-return-type
Browse files Browse the repository at this point in the history
fix: ethereum-provider `on` return type
  • Loading branch information
ganchoradkov authored Feb 28, 2023
2 parents 39e3aa5 + 9092388 commit c67c37c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
14 changes: 9 additions & 5 deletions providers/ethereum-provider/src/EthereumProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export interface EthereumProviderOptions {
}

export class EthereumProvider implements IEthereumProvider {
public events: IEthereumProviderEvents = new EventEmitter();
public events = new EventEmitter();
public namespace = "eip155";
public accounts: string[] = [];
public signer: InstanceType<typeof UniversalProvider>;
Expand Down Expand Up @@ -295,19 +295,23 @@ export class EthereumProvider implements IEthereumProvider {
}

public on: IEthereumProviderEvents["on"] = (event, listener) => {
return this.events.on(event, listener);
this.events.on(event, listener);
return this;
};

public once: IEthereumProviderEvents["once"] = (event, listener) => {
return this.events.once(event, listener);
this.events.once(event, listener);
return this;
};

public removeListener: IEthereumProviderEvents["removeListener"] = (event, listener) => {
return this.events.removeListener(event, listener);
this.events.removeListener(event, listener);
return this;
};

public off: IEthereumProviderEvents["off"] = (event, listener) => {
return this.events.off(event, listener);
this.events.off(event, listener);
return this;
};

get isWalletConnect() {
Expand Down
32 changes: 16 additions & 16 deletions providers/ethereum-provider/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignClientTypes } from "@walletconnect/types";
import EventEmitter from "events";
import { EthereumProvider } from "./EthereumProvider";

export interface ProviderRpcError extends Error {
message: string;
Expand Down Expand Up @@ -53,44 +53,44 @@ export declare namespace IProviderEvents {
display_uri: string;
}
}
export interface IEthereumProviderEvents extends EventEmitter {
export interface IEthereumProviderEvents {
on: <E extends IProviderEvents.Event>(
event: E,
listener: (args: IProviderEvents.EventArguments[E]) => any,
) => any;
listener: (args: IProviderEvents.EventArguments[E]) => void,
) => EthereumProvider;

once: <E extends IProviderEvents.Event>(
event: E,
listener: (args: IProviderEvents.EventArguments[E]) => any,
) => any;
listener: (args: IProviderEvents.EventArguments[E]) => void,
) => EthereumProvider;

off: <E extends IProviderEvents.Event>(
event: E,
listener: (args: IProviderEvents.EventArguments[E]) => any,
) => any;
listener: (args: IProviderEvents.EventArguments[E]) => void,
) => EthereumProvider;

removeListener: <E extends IProviderEvents.Event>(
event: E,
listener: (args: IProviderEvents.EventArguments[E]) => any,
) => any;
listener: (args: IProviderEvents.EventArguments[E]) => void,
) => EthereumProvider;

emit: <E extends IProviderEvents.Event>(
event: E,
payload: IProviderEvents.EventArguments[E],
) => any;
) => boolean;
}

export interface EIP1193Provider {
// connection event
on(event: "connect", listener: (info: ProviderInfo) => void): this;
on(event: "connect", listener: (info: ProviderInfo) => void): EthereumProvider;
// disconnection event
on(event: "disconnect", listener: (error: ProviderRpcError) => void): this;
on(event: "disconnect", listener: (error: ProviderRpcError) => void): EthereumProvider;
// arbitrary messages
on(event: "message", listener: (message: ProviderMessage) => void): this;
on(event: "message", listener: (message: ProviderMessage) => void): EthereumProvider;
// chain changed event
on(event: "chainChanged", listener: (chainId: ProviderChainId) => void): this;
on(event: "chainChanged", listener: (chainId: ProviderChainId) => void): EthereumProvider;
// accounts changed event
on(event: "accountsChanged", listener: (accounts: ProviderAccounts) => void): this;
on(event: "accountsChanged", listener: (accounts: ProviderAccounts) => void): EthereumProvider;
// make an Ethereum RPC method call.
request(args: RequestArguments): Promise<unknown>;
}
Expand Down

0 comments on commit c67c37c

Please sign in to comment.