@drift-labs/sdk 2.42.0-beta.1 → 2.42.0-beta.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.42.0-beta.1
1
+ 2.42.0-beta.2
@@ -103,7 +103,7 @@ export declare class DriftClient {
103
103
  * @param includeDelegates
104
104
  */
105
105
  updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number, includeDelegates?: boolean, authoritySubaccountMap?: Map<string, number[]>): Promise<boolean>;
106
- switchActiveUser(subAccountId: number, authority?: PublicKey): void;
106
+ switchActiveUser(subAccountId: number, authority?: PublicKey): Promise<void>;
107
107
  addUser(subAccountId: number, authority?: PublicKey, userAccount?: UserAccount): Promise<boolean>;
108
108
  /**
109
109
  * Adds and subscribes to users based on params set by the constructor or by updateWallet.
@@ -339,10 +339,24 @@ class DriftClient {
339
339
  }
340
340
  return success;
341
341
  }
342
- switchActiveUser(subAccountId, authority) {
342
+ async switchActiveUser(subAccountId, authority) {
343
+ var _a;
344
+ const authorityChanged = !((_a = this.authority) === null || _a === void 0 ? void 0 : _a.equals(authority));
343
345
  this.activeSubAccountId = subAccountId;
344
346
  this.authority = authority !== null && authority !== void 0 ? authority : this.authority;
345
347
  this.userStatsAccountPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(this.program.programId, this.authority);
348
+ /* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
349
+ if (authorityChanged) {
350
+ if (this.userStats && this.userStats.isSubscribed) {
351
+ await this.userStats.unsubscribe();
352
+ }
353
+ this.userStats = new userStats_1.UserStats({
354
+ driftClient: this,
355
+ userStatsAccountPublicKey: this.userStatsAccountPublicKey,
356
+ accountSubscription: this.userAccountSubscriptionConfig,
357
+ });
358
+ this.userStats.subscribe();
359
+ }
346
360
  }
347
361
  async addUser(subAccountId, authority, userAccount) {
348
362
  authority = authority !== null && authority !== void 0 ? authority : this.authority;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.42.0-beta.1",
3
+ "version": "2.42.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -588,13 +588,30 @@ export class DriftClient {
588
588
  return success;
589
589
  }
590
590
 
591
- public switchActiveUser(subAccountId: number, authority?: PublicKey) {
591
+ public async switchActiveUser(subAccountId: number, authority?: PublicKey) {
592
+ const authorityChanged = !this.authority?.equals(authority);
593
+
592
594
  this.activeSubAccountId = subAccountId;
593
595
  this.authority = authority ?? this.authority;
594
596
  this.userStatsAccountPublicKey = getUserStatsAccountPublicKey(
595
597
  this.program.programId,
596
598
  this.authority
597
599
  );
600
+
601
+ /* If changing the user authority ie switching from delegate to non-delegate account, need to re-subscribe to the user stats account */
602
+ if (authorityChanged) {
603
+ if (this.userStats && this.userStats.isSubscribed) {
604
+ await this.userStats.unsubscribe();
605
+ }
606
+
607
+ this.userStats = new UserStats({
608
+ driftClient: this,
609
+ userStatsAccountPublicKey: this.userStatsAccountPublicKey,
610
+ accountSubscription: this.userAccountSubscriptionConfig,
611
+ });
612
+
613
+ this.userStats.subscribe();
614
+ }
598
615
  }
599
616
 
600
617
  public async addUser(