@fivenorth/loop-sdk 0.7.4 → 0.7.6

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -11
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2694,7 +2694,7 @@ class LoopWallet {
2694
2694
 
2695
2695
  // src/index.ts
2696
2696
  class LoopSDK {
2697
- version = "0.7.3";
2697
+ version = "0.7.6";
2698
2698
  appName = "Unknown";
2699
2699
  connection = null;
2700
2700
  session = null;
@@ -2789,22 +2789,24 @@ class LoopSDK {
2789
2789
  throw new Error("SDK not initialized. Call init() first.");
2790
2790
  }
2791
2791
  await this.autoConnect();
2792
- if (this.session?.ticketId) {
2793
- this.showQrCode(this.buildConnectUrl(this.session.ticketId));
2794
- return;
2792
+ if (!this.session) {
2793
+ throw new Error("No valid session found. The network connection maynot available or the backend is not reachable.");
2795
2794
  }
2796
- if (this.session && this.session.isAuthorized()) {
2795
+ if (this.session.isAuthorized()) {
2797
2796
  return;
2798
2797
  }
2799
2798
  try {
2800
- const { ticket_id: ticketId } = await this.connection.getTicket(this.appName, this.session.sessionId, this.version);
2801
- this.session.setTicketId(ticketId);
2802
- const connectUrl = this.buildConnectUrl(this.session.ticketId);
2803
- this.showQrCode(connectUrl);
2804
- this.connection.connectWebSocket(ticketId, this.handleWebSocketMessage.bind(this));
2799
+ if (!this.session.ticketId) {
2800
+ const { ticket_id: ticketId } = await this.connection.getTicket(this.appName, this.session.sessionId, this.version);
2801
+ this.session.setTicketId(ticketId);
2802
+ }
2803
+ if (!this.connection.connectInProgress()) {
2804
+ this.connection.connectWebSocket(this.session.ticketId, this.handleWebSocketMessage.bind(this));
2805
+ }
2806
+ this.showQrCode(this.buildConnectUrl(this.session.ticketId));
2805
2807
  } catch (error) {
2806
2808
  console.error(error);
2807
- return;
2809
+ throw error;
2808
2810
  }
2809
2811
  }
2810
2812
  handleWebSocketMessage(event) {
@@ -2857,6 +2859,12 @@ class LoopSDK {
2857
2859
  this.provider.handleResponse(message);
2858
2860
  }
2859
2861
  }
2862
+ getConnectUrl() {
2863
+ if (!this.session?.ticketId) {
2864
+ throw new Error("No ticket ID found. Please call connect() first.");
2865
+ }
2866
+ return this.buildConnectUrl(this.session.ticketId);
2867
+ }
2860
2868
  buildConnectUrl(ticketId) {
2861
2869
  const url = new URL("/.connect/", this.connection.walletUrl);
2862
2870
  url.searchParams.set("ticketId", ticketId);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fivenorth/loop-sdk",
3
- "version": "0.7.4",
4
- "author": "hello@fivenorth.io",
3
+ "version": "0.7.6",
4
+ "author": "support@fivenorth.io",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "devDependencies": {