Skip to content

Commit

Permalink
refactor: remove existedSDK redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
q20274982 committed Oct 31, 2023
1 parent 552bf3e commit 868c971
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/blocto-sdk/src/providers/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,9 @@ export default class EthereumProvider
switchableNetwork: SwitchableNetwork;
};

override on(event: string, listener: (arg: any) => void): void {
const existedSDK = (window as any).ethereum;
if (existedSDK && existedSDK.isBlocto) {
existedSDK.on(event, listener);
}

super.on(event, listener);
}

override removeListener(event: string, listener: (arg: any) => void): void {
const existedSDK = (window as any).ethereum;
if (existedSDK && existedSDK.isBlocto) {
existedSDK.off(event, listener);
}

super.off(event, listener);
private get existedSDK() {
return (window as any).ethereum;
}

off = this.removeListener;

constructor({ chainId, rpc, walletServer, appId }: EthereumProviderConfig) {
super();
Expand Down Expand Up @@ -928,4 +912,20 @@ export default class EthereumProvider
throw ethErrors.rpc.invalidParams('Empty networkList');
}
}

override on(event: string, listener: (arg: any) => void): void {
if (this.existedSDK?.isBlocto)
this.existedSDK.on(event, listener);

super.on(event, listener);
}

override removeListener(event: string, listener: (arg: any) => void): void {
if (this.existedSDK?.isBlocto)
this.existedSDK.off(event, listener);

super.off(event, listener);
}

off = this.removeListener;
}

0 comments on commit 868c971

Please sign in to comment.