diff --git a/.changeset/violet-maps-remember.md b/.changeset/violet-maps-remember.md new file mode 100644 index 0000000..7a624e9 --- /dev/null +++ b/.changeset/violet-maps-remember.md @@ -0,0 +1,5 @@ +--- +"@babylonlabs-io/bbn-wallet-connect": patch +--- + +add ee to wallet connector diff --git a/package-lock.json b/package-lock.json index 2b7a04c..cf78c52 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,15 @@ { "name": "@babylonlabs-io/bbn-wallet-connect", - "version": "0.0.2", + "version": "0.0.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@babylonlabs-io/bbn-wallet-connect", - "version": "0.0.2", + "version": "0.0.3", "dependencies": { "@babylonlabs-io/bbn-core-ui": "^0.0.11", + "nanoevents": "^9.1.0", "react-icons": "^5.3.0" }, "devDependencies": { @@ -6230,6 +6231,14 @@ "thenify-all": "^1.0.0" } }, + "node_modules/nanoevents": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/nanoevents/-/nanoevents-9.1.0.tgz", + "integrity": "sha512-Jd0fILWG44a9luj8v5kED4WI+zfkkgwKyRQKItTtlPfEsh7Lznfi1kr8/iZ+XAIss4Qq5GqRB0qtWbaz9ceO/A==", + "engines": { + "node": "^18.0.0 || >=20.0.0" + } + }, "node_modules/nanoid": { "version": "3.3.7", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", diff --git a/package.json b/package.json index cead3cb..43871ac 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@babylonlabs-io/bbn-core-ui": "^0.0.11", + "nanoevents": "^9.1.0", "react-icons": "^5.3.0" }, "files": [ diff --git a/src/core/WalletConnector.ts b/src/core/WalletConnector.ts index bc3b4d8..e987f02 100644 --- a/src/core/WalletConnector.ts +++ b/src/core/WalletConnector.ts @@ -1,8 +1,14 @@ +import { createNanoEvents } from "nanoevents"; import { Wallet } from "@/core/Wallet"; import type { IProvider, IChain } from "@/core/types"; +export interface ConnectorEvents

{ + connect: (wallet: Wallet

) => void; +} + export class WalletConnector implements IChain { private _connectedWallet: Wallet

| null = null; + private _ee = createNanoEvents>(); constructor( public readonly id: N, @@ -23,6 +29,7 @@ export class WalletConnector implements I } this._connectedWallet = await wallet.connect(); + this._ee.emit("connect", this._connectedWallet); return this.connectedWallet; } @@ -34,4 +41,8 @@ export class WalletConnector implements I clone() { return new WalletConnector(this.id, this.name, this.icon, this.wallets); } + + on>(name: K, handler: ConnectorEvents

[K]) { + return this._ee.on(name, handler); + } }