@hashgraphonline/hashinal-wc 1.0.72 → 1.0.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1810,6 +1810,9 @@ var Result = /* @__PURE__ */ ((Result2) => {
1810
1810
  return Result2;
1811
1811
  })(Result || {});
1812
1812
  class HashinalsWalletConnectSDK {
1813
+ get dAppConnector() {
1814
+ return HashinalsWalletConnectSDK.dAppConnectorInstance;
1815
+ }
1813
1816
  constructor(logger, network) {
1814
1817
  this.logger = logger || new DefaultLogger();
1815
1818
  this.network = network || LedgerId.MAINNET;
@@ -1847,22 +1850,26 @@ class HashinalsWalletConnectSDK {
1847
1850
  async init(projectId, metadata, network) {
1848
1851
  const chosenNetwork = network || this.network;
1849
1852
  const isMainnet = chosenNetwork.toString() === "mainnet";
1850
- this.dAppConnector = new DAppConnector(
1853
+ if (HashinalsWalletConnectSDK.dAppConnectorInstance) {
1854
+ return HashinalsWalletConnectSDK.dAppConnectorInstance;
1855
+ }
1856
+ HashinalsWalletConnectSDK.dAppConnectorInstance = new DAppConnector(
1851
1857
  metadata,
1852
1858
  chosenNetwork,
1853
1859
  projectId,
1854
1860
  Object.values(HederaJsonRpcMethod),
1855
1861
  [HederaSessionEvent.ChainChanged, HederaSessionEvent.AccountsChanged],
1856
- [isMainnet ? HederaChainId.Mainnet : HederaChainId.Testnet]
1862
+ [isMainnet ? HederaChainId.Mainnet : HederaChainId.Testnet],
1863
+ "debug"
1857
1864
  );
1858
- await this.dAppConnector.init({ logger: "error" });
1859
- this.dAppConnector.onSessionIframeCreated = (session) => {
1865
+ await HashinalsWalletConnectSDK.dAppConnectorInstance.init({ logger: "error" });
1866
+ HashinalsWalletConnectSDK.dAppConnectorInstance.onSessionIframeCreated = (session) => {
1860
1867
  this.handleNewSession(session);
1861
1868
  };
1862
1869
  this.logger.info(
1863
1870
  `Hedera Wallet Connect SDK initialized on ${chosenNetwork}`
1864
1871
  );
1865
- return this.dAppConnector;
1872
+ return HashinalsWalletConnectSDK.dAppConnectorInstance;
1866
1873
  }
1867
1874
  async connect() {
1868
1875
  this.ensureInitialized();
@@ -1871,10 +1878,29 @@ class HashinalsWalletConnectSDK {
1871
1878
  return session;
1872
1879
  }
1873
1880
  async disconnect() {
1881
+ var _a, _b;
1882
+ try {
1883
+ this.ensureInitialized();
1884
+ const accountInfo = this.getAccountInfo();
1885
+ const accountId = accountInfo == null ? void 0 : accountInfo.accountId;
1886
+ const network = accountInfo == null ? void 0 : accountInfo.network;
1887
+ const signer = (_a = this == null ? void 0 : this.dAppConnector) == null ? void 0 : _a.signers.find(
1888
+ (signer_) => signer_.getAccountId().toString() === accountId
1889
+ );
1890
+ await ((_b = this.dAppConnector) == null ? void 0 : _b.disconnect(signer == null ? void 0 : signer.topic));
1891
+ this.logger.info(`Disconnected from ${accountId} on ${network}`);
1892
+ return true;
1893
+ } catch (e) {
1894
+ this.logger.error("Failed to disconnect", e);
1895
+ return false;
1896
+ }
1897
+ }
1898
+ async disconnectAll() {
1899
+ var _a;
1874
1900
  try {
1875
1901
  this.ensureInitialized();
1876
- await this.dAppConnector.disconnectAll();
1877
- this.logger.info("Disconnected from all wallets");
1902
+ await ((_a = this.dAppConnector) == null ? void 0 : _a.disconnectAll());
1903
+ this.logger.info(`Disconnected from all wallets`);
1878
1904
  return true;
1879
1905
  } catch (e) {
1880
1906
  this.logger.error("Failed to disconnect", e);