@konemono/nostr-login 1.10.10 → 1.10.11

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.10.10",
3
+ "version": "1.10.11",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -148,6 +148,7 @@ export class NostrLoginInitializer {
148
148
 
149
149
  this.bannerManager.on('cancelTimeout', () => {
150
150
  this.authNostrService.cancelSignerInit();
151
+ this.processManager.cancelAllPendingCalls();
151
152
  this.bannerManager.onCallEnd();
152
153
  });
153
154
  }
@@ -4,11 +4,20 @@ import { CALL_TIMEOUT } from '../const';
4
4
  class ProcessManager extends EventEmitter {
5
5
  private callCount: number = 0;
6
6
  private callTimer: NodeJS.Timeout | undefined;
7
+ private pendingCalls: Map<number, { reject: (reason?: any) => void }> = new Map();
8
+ private callIdCounter: number = 0;
7
9
 
8
10
  constructor() {
9
11
  super();
10
12
  }
11
13
 
14
+ public cancelAllPendingCalls() {
15
+ for (const [id, { reject }] of this.pendingCalls.entries()) {
16
+ reject(new Error('Cancelled by user'));
17
+ }
18
+ this.pendingCalls.clear();
19
+ }
20
+
12
21
  public onAuthUrl() {
13
22
  if (Boolean(this.callTimer)) {
14
23
  clearTimeout(this.callTimer);
@@ -34,11 +43,22 @@ class ProcessManager extends EventEmitter {
34
43
 
35
44
  this.callCount++;
36
45
 
46
+ const callId = this.callIdCounter++;
37
47
  let error;
38
48
  let result;
39
49
 
40
50
  try {
41
- result = await cb();
51
+ result = await new Promise<T>(async (resolve, reject) => {
52
+ this.pendingCalls.set(callId, { reject });
53
+ try {
54
+ const res = await cb();
55
+ this.pendingCalls.delete(callId);
56
+ resolve(res);
57
+ } catch (e) {
58
+ this.pendingCalls.delete(callId);
59
+ reject(e);
60
+ }
61
+ });
42
62
  } catch (e) {
43
63
  error = e;
44
64
  }