@drift-labs/sdk 0.1.34-master.0 → 0.1.34-master.1

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.
@@ -35,6 +35,7 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
35
35
  getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
36
36
  addToAccountLoader(): Promise<void>;
37
37
  fetch(): Promise<void>;
38
+ didSubscriptionSucceed(): boolean;
38
39
  unsubscribe(): Promise<void>;
39
40
  assertIsSubscribed(): void;
40
41
  assertOptionalIsSubscribed(optionalSubscription: ClearingHouseAccountTypes): void;
@@ -42,11 +42,14 @@ class PollingClearingHouseAccountSubscriber {
42
42
  yield this.updateAccountsToPoll();
43
43
  yield this.addToAccountLoader();
44
44
  yield this.fetch();
45
- this.eventEmitter.emit('update');
45
+ const subscriptionSucceeded = this.didSubscriptionSucceed();
46
+ if (subscriptionSucceeded) {
47
+ this.eventEmitter.emit('update');
48
+ }
46
49
  this.isSubscribing = false;
47
- this.isSubscribed = true;
48
- this.subscriptionPromiseResolver(true);
49
- return true;
50
+ this.isSubscribed = subscriptionSucceeded;
51
+ this.subscriptionPromiseResolver(subscriptionSucceeded);
52
+ return subscriptionSucceeded;
50
53
  });
51
54
  }
52
55
  updateAccountsToPoll() {
@@ -177,6 +180,16 @@ class PollingClearingHouseAccountSubscriber {
177
180
  }
178
181
  });
179
182
  }
183
+ didSubscriptionSucceed() {
184
+ let success = true;
185
+ for (const [_, accountToPoll] of this.accountsToPoll) {
186
+ if (!this[accountToPoll.key]) {
187
+ success = false;
188
+ break;
189
+ }
190
+ }
191
+ return success;
192
+ }
180
193
  unsubscribe() {
181
194
  return __awaiter(this, void 0, void 0, function* () {
182
195
  if (!this.isSubscribed) {
@@ -24,6 +24,7 @@ export declare class PollingUserAccountSubscriber implements UserAccountSubscrib
24
24
  addToAccountLoader(userPublicKeys?: UserPublicKeys): Promise<void>;
25
25
  fetchIfUnloaded(): Promise<void>;
26
26
  fetch(): Promise<void>;
27
+ didSubscriptionSucceed(): boolean;
27
28
  unsubscribe(): Promise<void>;
28
29
  assertIsSubscribed(): void;
29
30
  getUserAccount(): UserAccount;
@@ -31,9 +31,12 @@ class PollingUserAccountSubscriber {
31
31
  }
32
32
  yield this.addToAccountLoader();
33
33
  yield this.fetchIfUnloaded();
34
- this.eventEmitter.emit('update');
35
- this.isSubscribed = true;
36
- return true;
34
+ const subscriptionSucceeded = this.didSubscriptionSucceed();
35
+ if (subscriptionSucceeded) {
36
+ this.eventEmitter.emit('update');
37
+ }
38
+ this.isSubscribed = subscriptionSucceeded;
39
+ return subscriptionSucceeded;
37
40
  });
38
41
  }
39
42
  addToAccountLoader(userPublicKeys) {
@@ -122,6 +125,17 @@ class PollingUserAccountSubscriber {
122
125
  }
123
126
  });
124
127
  }
128
+ didSubscriptionSucceed() {
129
+ let success = true;
130
+ for (const [_, accountToPoll] of this.accountsToPoll) {
131
+ // userOrders may not exist
132
+ if (accountToPoll.key !== 'userOrders' && !this[accountToPoll.key]) {
133
+ success = false;
134
+ break;
135
+ }
136
+ }
137
+ return success;
138
+ }
125
139
  unsubscribe() {
126
140
  return __awaiter(this, void 0, void 0, function* () {
127
141
  if (!this.isSubscribed) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.34-master.0",
3
+ "version": "0.1.34-master.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -86,13 +86,17 @@ export class PollingClearingHouseAccountSubscriber
86
86
  await this.updateAccountsToPoll();
87
87
  await this.addToAccountLoader();
88
88
  await this.fetch();
89
- this.eventEmitter.emit('update');
89
+ const subscriptionSucceeded = this.didSubscriptionSucceed();
90
+
91
+ if (subscriptionSucceeded) {
92
+ this.eventEmitter.emit('update');
93
+ }
90
94
 
91
95
  this.isSubscribing = false;
92
- this.isSubscribed = true;
93
- this.subscriptionPromiseResolver(true);
96
+ this.isSubscribed = subscriptionSucceeded;
97
+ this.subscriptionPromiseResolver(subscriptionSucceeded);
94
98
 
95
- return true;
99
+ return subscriptionSucceeded;
96
100
  }
97
101
 
98
102
  async updateAccountsToPoll(): Promise<void> {
@@ -254,6 +258,17 @@ export class PollingClearingHouseAccountSubscriber
254
258
  }
255
259
  }
256
260
 
261
+ didSubscriptionSucceed(): boolean {
262
+ let success = true;
263
+ for (const [_, accountToPoll] of this.accountsToPoll) {
264
+ if (!this[accountToPoll.key]) {
265
+ success = false;
266
+ break;
267
+ }
268
+ }
269
+ return success;
270
+ }
271
+
257
272
  public async unsubscribe(): Promise<void> {
258
273
  if (!this.isSubscribed) {
259
274
  return;
@@ -53,10 +53,15 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
53
53
 
54
54
  await this.addToAccountLoader();
55
55
  await this.fetchIfUnloaded();
56
- this.eventEmitter.emit('update');
57
56
 
58
- this.isSubscribed = true;
59
- return true;
57
+ const subscriptionSucceeded = this.didSubscriptionSucceed();
58
+
59
+ if (subscriptionSucceeded) {
60
+ this.eventEmitter.emit('update');
61
+ }
62
+
63
+ this.isSubscribed = subscriptionSucceeded;
64
+ return subscriptionSucceeded;
60
65
  }
61
66
 
62
67
  async addToAccountLoader(userPublicKeys?: UserPublicKeys): Promise<void> {
@@ -168,6 +173,18 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
168
173
  }
169
174
  }
170
175
 
176
+ didSubscriptionSucceed(): boolean {
177
+ let success = true;
178
+ for (const [_, accountToPoll] of this.accountsToPoll) {
179
+ // userOrders may not exist
180
+ if (accountToPoll.key !== 'userOrders' && !this[accountToPoll.key]) {
181
+ success = false;
182
+ break;
183
+ }
184
+ }
185
+ return success;
186
+ }
187
+
171
188
  async unsubscribe(): Promise<void> {
172
189
  if (!this.isSubscribed) {
173
190
  return;