Skip to content

Commit

Permalink
Merge pull request #27 from babylonlabs-io/add-ee
Browse files Browse the repository at this point in the history
feat: add ee to wallet connector
  • Loading branch information
totraev authored Nov 23, 2024
2 parents 77f7dbe + 061cf1a commit 64bcb01
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-maps-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@babylonlabs-io/bbn-wallet-connect": patch
---

add ee to wallet connector
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"@babylonlabs-io/bbn-core-ui": "^0.0.11",
"nanoevents": "^9.1.0",
"react-icons": "^5.3.0"
},
"files": [
Expand Down
11 changes: 11 additions & 0 deletions src/core/WalletConnector.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { createNanoEvents } from "nanoevents";
import { Wallet } from "@/core/Wallet";
import type { IProvider, IChain } from "@/core/types";

export interface ConnectorEvents<P extends IProvider> {
connect: (wallet: Wallet<P>) => void;
}

export class WalletConnector<N extends string, P extends IProvider> implements IChain {
private _connectedWallet: Wallet<P> | null = null;
private _ee = createNanoEvents<ConnectorEvents<P>>();

constructor(
public readonly id: N,
Expand All @@ -23,6 +29,7 @@ export class WalletConnector<N extends string, P extends IProvider> implements I
}

this._connectedWallet = await wallet.connect();
this._ee.emit("connect", this._connectedWallet);

return this.connectedWallet;
}
Expand All @@ -34,4 +41,8 @@ export class WalletConnector<N extends string, P extends IProvider> implements I
clone() {
return new WalletConnector(this.id, this.name, this.icon, this.wallets);
}

on<K extends keyof ConnectorEvents<P>>(name: K, handler: ConnectorEvents<P>[K]) {
return this._ee.on(name, handler);
}
}

0 comments on commit 64bcb01

Please sign in to comment.