From 957fc845fa6d4db2c0fd226e9e591293477dc328 Mon Sep 17 00:00:00 2001 From: David Totraev Date: Sat, 23 Nov 2024 18:54:47 +0500 Subject: [PATCH] feat: add unsubscribe method to BTCProvider --- .changeset/tame-dragons-arrive.md | 5 +++++ src/core/wallets/btc/BTCProvider.ts | 2 ++ src/core/wallets/btc/okx/provider.ts | 10 ++++++++++ 3 files changed, 17 insertions(+) create mode 100644 .changeset/tame-dragons-arrive.md diff --git a/.changeset/tame-dragons-arrive.md b/.changeset/tame-dragons-arrive.md new file mode 100644 index 0000000..7ad7981 --- /dev/null +++ b/.changeset/tame-dragons-arrive.md @@ -0,0 +1,5 @@ +--- +"@babylonlabs-io/bbn-wallet-connect": patch +--- + +add unsubscribe method to BTCProvider diff --git a/src/core/wallets/btc/BTCProvider.ts b/src/core/wallets/btc/BTCProvider.ts index 22d0fc0..2ac2078 100644 --- a/src/core/wallets/btc/BTCProvider.ts +++ b/src/core/wallets/btc/BTCProvider.ts @@ -68,6 +68,8 @@ export abstract class BTCProvider implements IProvider { */ abstract on(eventName: string, callBack: () => void): void; + abstract off(eventName: string, callBack: () => void): void; + /** * Gets the balance for the connected wallet address. * By default, this method will return the mempool balance if not implemented by the child class. diff --git a/src/core/wallets/btc/okx/provider.ts b/src/core/wallets/btc/okx/provider.ts index 7b42456..2dfa942 100644 --- a/src/core/wallets/btc/okx/provider.ts +++ b/src/core/wallets/btc/okx/provider.ts @@ -133,6 +133,16 @@ export class OKXProvider extends BTCProvider { } }; + off = (eventName: string, callBack: () => void) => { + if (!this.walletInfo) { + throw new Error("OKX Wallet not connected"); + } + // subscribe to account change event + if (eventName === "accountChanged") { + return this.provider.off(eventName, callBack); + } + }; + // Mempool calls getBalance = async (): Promise => { return await this.mempool.getAddressBalance(await this.getAddress());