@dynamic-labs/sui-core 4.48.0 → 4.48.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/CHANGELOG.md CHANGED
@@ -1,4 +1,18 @@
1
1
 
2
+ ### [4.48.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.48.1...v4.48.2) (2025-12-03)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * only prompt ready wallet once to connect ([#10013](https://github.com/dynamic-labs/dynamic-auth/issues/10013)) ([fd3e306](https://github.com/dynamic-labs/dynamic-auth/commit/fd3e306f175969efee6d82ce539f77e55c329f38))
8
+
9
+ ### [4.48.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.48.0...v4.48.1) (2025-12-02)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * support for linking multiple slush wallets ([#9957](https://github.com/dynamic-labs/dynamic-auth/issues/9957)) ([b1433a4](https://github.com/dynamic-labs/dynamic-auth/commit/b1433a49d1b31abe4806bcc66fc5b03750c953d4))
15
+
2
16
  ## [4.48.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.47.3...v4.48.0) (2025-12-01)
3
17
 
4
18
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.48.0";
6
+ var version = "4.48.2";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.48.0";
2
+ var version = "4.48.2";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sui-core",
3
- "version": "4.48.0",
3
+ "version": "4.48.2",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,17 +18,17 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/sdk-api-core": "0.0.824",
21
+ "@dynamic-labs/sdk-api-core": "0.0.831",
22
22
  "@mysten/wallet-standard": "0.13.29",
23
23
  "@mysten/sui": "1.24.0",
24
24
  "text-encoding": "0.7.0",
25
- "@dynamic-labs/assert-package-version": "4.48.0",
26
- "@dynamic-labs/logger": "4.48.0",
27
- "@dynamic-labs/rpc-providers": "4.48.0",
28
- "@dynamic-labs/types": "4.48.0",
29
- "@dynamic-labs/utils": "4.48.0",
30
- "@dynamic-labs/wallet-book": "4.48.0",
31
- "@dynamic-labs/wallet-connector-core": "4.48.0"
25
+ "@dynamic-labs/assert-package-version": "4.48.2",
26
+ "@dynamic-labs/logger": "4.48.2",
27
+ "@dynamic-labs/rpc-providers": "4.48.2",
28
+ "@dynamic-labs/types": "4.48.2",
29
+ "@dynamic-labs/utils": "4.48.2",
30
+ "@dynamic-labs/wallet-book": "4.48.2",
31
+ "@dynamic-labs/wallet-connector-core": "4.48.2"
32
32
  },
33
33
  "peerDependencies": {}
34
34
  }
@@ -13,6 +13,13 @@ var SuiUiTransaction = require('./utils/SuiUiTransaction/SuiUiTransaction.cjs');
13
13
  var SuiWallet = require('./wallet/SuiWallet.cjs');
14
14
 
15
15
  class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
16
+ /** Returns the active wallet account, may be overridden */
17
+ getPrimaryAccount() {
18
+ return this.account;
19
+ }
20
+ setPrimaryAccount(account) {
21
+ this.account = account;
22
+ }
16
23
  constructor(name, opts) {
17
24
  super(opts);
18
25
  this.name = 'Sui';
@@ -41,7 +48,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
41
48
  connect() {
42
49
  return _tslib.__awaiter(this, arguments, void 0, function* ({ silent } = {}) {
43
50
  var _a, _b;
44
- if (this.account || this.isConnecting) {
51
+ if (this.getPrimaryAccount() || this.isConnecting) {
45
52
  // Account is already connected or we're already connecting
46
53
  return;
47
54
  }
@@ -54,12 +61,12 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
54
61
  }
55
62
  // Start connecting
56
63
  this.isConnecting = true;
57
- this.logger.debug('[connect] Creating new connection');
64
+ this.logger.debug(`[${this.name}] [connect] Creating new connection`);
58
65
  try {
59
66
  const response = yield connectFeature.connect(silent ? { silent } : undefined);
60
- this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
61
- this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
62
- const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
67
+ this.logger.debug(`[${this.name}] [connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
68
+ this.setPrimaryAccount(response === null || response === void 0 ? void 0 : response.accounts[0]);
69
+ const primaryChain = (_b = this.getPrimaryAccount()) === null || _b === void 0 ? void 0 : _b.chains[0];
63
70
  if (primaryChain) {
64
71
  this.activeNetworkId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
65
72
  }
@@ -100,21 +107,22 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
100
107
  /** Get the wallet address by connecting to the current account */
101
108
  getAddress() {
102
109
  return _tslib.__awaiter(this, void 0, void 0, function* () {
103
- this.logger.debug('[getAddress] called, attempting to obtain the account address');
110
+ var _a;
111
+ this.logger.debug(`[${this.name}] [getAddress] called, attempting to obtain the account address`);
104
112
  if (this.handleInAppBrowserGetAddress()) {
105
113
  return;
106
114
  }
107
115
  yield this.connect();
108
- if (!this.account) {
109
- throw new utils.DynamicError('No account found');
116
+ if (!this.getPrimaryAccount()) {
117
+ throw new utils.DynamicError(`[${this.name}] [getAddress] No account found`);
110
118
  }
111
- return this.account.address;
119
+ return (_a = this.getPrimaryAccount()) === null || _a === void 0 ? void 0 : _a.address;
112
120
  });
113
121
  }
114
122
  /** Returns the network id of the account's active chain */
115
123
  getNetwork() {
116
124
  return _tslib.__awaiter(this, void 0, void 0, function* () {
117
- if (!this.account) {
125
+ if (!this.getPrimaryAccount()) {
118
126
  yield this.connect();
119
127
  }
120
128
  return this.activeNetworkId;
@@ -123,10 +131,10 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
123
131
  getConnectedAccounts() {
124
132
  return _tslib.__awaiter(this, void 0, void 0, function* () {
125
133
  var _a;
126
- if (!this.account) {
134
+ if (!this.getPrimaryAccount()) {
127
135
  yield this.connect({ silent: true });
128
136
  }
129
- const address = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address;
137
+ const address = (_a = this.getPrimaryAccount()) === null || _a === void 0 ? void 0 : _a.address;
130
138
  if (address) {
131
139
  return [address];
132
140
  }
@@ -153,29 +161,33 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
153
161
  }
154
162
  return (_e = networkHelpers.getSuiNetworkIdFromName(suiChain, this.suiNetworks)) !== null && _e !== void 0 ? _e : '-1';
155
163
  }
164
+ handleAccountChange(event) {
165
+ var _a;
166
+ // If the event sets accounts but it's empty, we need to disconnect.
167
+ if (event.accounts.length === 0 && this.getPrimaryAccount()) {
168
+ this.setPrimaryAccount(undefined);
169
+ this.emit('disconnect');
170
+ return;
171
+ }
172
+ const [primaryAccount] = event.accounts;
173
+ if (primaryAccount.address !== ((_a = this.getPrimaryAccount()) === null || _a === void 0 ? void 0 : _a.address)) {
174
+ this.setPrimaryAccount(primaryAccount);
175
+ this.emit('accountChange', { accounts: [primaryAccount.address] });
176
+ }
177
+ }
156
178
  setupEventListeners() {
157
179
  var _a;
158
180
  if (!this.canSetEventListeners || this.eventsHandler)
159
181
  return;
160
182
  const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
161
183
  if (!eventsFeature) {
162
- this.logger.debug('[setupEventListeners] Wallet not connected or does not support standard:events');
184
+ this.logger.debug(`[${this.name}] [setupEventListeners] Wallet not connected or does not support standard:events`);
163
185
  return;
164
186
  }
165
187
  this.eventsHandler = (event) => _tslib.__awaiter(this, void 0, void 0, function* () {
166
- var _b;
167
188
  if (event.accounts) {
168
- // If the event sets accounts but it's empty, we need to disconnect.
169
- if (event.accounts.length === 0 && this.account) {
170
- this.account = undefined;
171
- this.emit('disconnect');
172
- return;
173
- }
174
- const [primaryAccount] = event.accounts;
175
- if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
176
- this.account = primaryAccount;
177
- this.emit('accountChange', { accounts: [primaryAccount.address] });
178
- }
189
+ this.handleAccountChange(event);
190
+ return;
179
191
  }
180
192
  // Some events will leave out accounts but set the chains object, so we process those
181
193
  // with the helper.
@@ -185,7 +197,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
185
197
  this.emit('chainChange', { chain: suiChainId });
186
198
  }
187
199
  });
188
- this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
200
+ this.logger.debug(`[${this.name}] [setupEventListeners] Setting up sui wallet connector event listeners`);
189
201
  this.eventsUnsubscribeHandler = eventsFeature.on('change', this.eventsHandler);
190
202
  }
191
203
  /**
@@ -197,7 +209,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
197
209
  return _tslib.__awaiter(this, void 0, void 0, function* () {
198
210
  const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
199
211
  if (!clientNetworkId) {
200
- this.logger.error('[getSuiClient] Failed to get network id');
212
+ this.logger.error(`[${this.name}] [getSuiClient] Failed to get network id`);
201
213
  return undefined;
202
214
  }
203
215
  // Default to an existing client if available
@@ -207,7 +219,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
207
219
  const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
208
220
  const url = network ? networkHelpers.getPreferredRpcUrl(network) : undefined;
209
221
  if (!url) {
210
- this.logger.error('[getSuiClient] Failed to get network url');
222
+ this.logger.error(`[${this.name}] [getSuiClient] Failed to get network url`);
211
223
  return undefined;
212
224
  }
213
225
  this.suiClients[clientNetworkId] = new client.SuiClient({
@@ -220,7 +232,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
220
232
  return _tslib.__awaiter(this, void 0, void 0, function* () {
221
233
  const client = yield this.getSuiClient();
222
234
  if (!client) {
223
- this.logger.error('[getBalance] Failed to get Sui client');
235
+ this.logger.error(`[${this.name}] [getBalance] Failed to get Sui client`);
224
236
  return undefined;
225
237
  }
226
238
  const balanceResult = yield client.getBalance({
@@ -229,7 +241,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
229
241
  // Balance comes back as MIST, 1 SUI = 1e9 MIST
230
242
  const balance = Number(balanceResult === null || balanceResult === void 0 ? void 0 : balanceResult.totalBalance) / 1e9;
231
243
  if (Number.isNaN(balance)) {
232
- this.logger.error(`[getBalance] Failed to get balance for address: ${address}`);
244
+ this.logger.error(`[${this.name}] [getBalance] Failed to get balance for address: ${address}`);
233
245
  return undefined;
234
246
  }
235
247
  return balance.toFixed(6);
@@ -238,19 +250,18 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
238
250
  signMessage(messageToSign) {
239
251
  return _tslib.__awaiter(this, void 0, void 0, function* () {
240
252
  var _a;
241
- this.logger.debug('[signMessage] called, attempting to sign a message');
253
+ this.logger.debug(`[${this.name}] [signMessage] called, attempting to sign a message`);
242
254
  const signFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage'];
243
255
  if (!signFeature) {
244
256
  throw new utils.DynamicError('Wallet does not support sui:signPersonalMessage');
245
257
  }
246
- yield this.connect();
247
- if (!this.account) {
258
+ if (!this.getPrimaryAccount()) {
248
259
  throw new utils.DynamicError('[signMessage] No account found');
249
260
  }
250
261
  let output;
251
262
  try {
252
263
  output = yield signFeature.signPersonalMessage({
253
- account: this.account,
264
+ account: this.getPrimaryAccount(),
254
265
  message: new TextEncoder().encode(messageToSign),
255
266
  });
256
267
  }
@@ -261,13 +272,13 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
261
272
  if (!output || !output.signature) {
262
273
  throw new utils.DynamicError('[signMessage] Failed to sign message');
263
274
  }
264
- this.logger.debug(`[signMessage] Signed message: ${output.signature}`);
275
+ this.logger.debug(`[${this.name}] [signMessage] Signed message: ${output.signature}`);
265
276
  return output.signature;
266
277
  });
267
278
  }
268
279
  getWalletAccount() {
269
280
  return _tslib.__awaiter(this, void 0, void 0, function* () {
270
- return this.account;
281
+ return this.getPrimaryAccount();
271
282
  });
272
283
  }
273
284
  /** Function used to create transactions in the SDK interface */
@@ -305,7 +316,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
305
316
  return _tslib.__awaiter(this, void 0, void 0, function* () {
306
317
  var _a;
307
318
  this.teardownEventListeners();
308
- this.account = undefined;
319
+ this.setPrimaryAccount(undefined);
309
320
  if (!this.isInstalledOnBrowser())
310
321
  return;
311
322
  const disconnectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:disconnect'];
@@ -325,15 +336,16 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
325
336
  }
326
337
  signAndExecuteTransactionFeature(_a) {
327
338
  return _tslib.__awaiter(this, arguments, void 0, function* ({ transaction, legacyOptions, }) {
328
- if (!this.account) {
339
+ var _b, _c;
340
+ if (!this.getPrimaryAccount()) {
329
341
  throw new utils.DynamicError('No account found');
330
342
  }
331
343
  const features = this.getFeatures();
332
344
  const signAndExecuteTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signAndExecuteTransaction'];
333
345
  if (signAndExecuteTransactionFeature) {
334
346
  return signAndExecuteTransactionFeature.signAndExecuteTransaction({
335
- account: this.account,
336
- chain: this.account.chains[0],
347
+ account: this.getPrimaryAccount(),
348
+ chain: (_b = this.getPrimaryAccount()) === null || _b === void 0 ? void 0 : _b.chains[0],
337
349
  transaction,
338
350
  });
339
351
  }
@@ -342,8 +354,8 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
342
354
  throw new utils.DynamicError('Wallet does not support sui:signAndExecuteTransaction or sui:signAndExecuteTransactionBlock');
343
355
  }
344
356
  const result = yield signAndExecuteTransactionBlockFeature.signAndExecuteTransactionBlock({
345
- account: this.account,
346
- chain: this.account.chains[0],
357
+ account: this.getPrimaryAccount(),
358
+ chain: (_c = this.getPrimaryAccount()) === null || _c === void 0 ? void 0 : _c.chains[0],
347
359
  options: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.options,
348
360
  requestType: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.requestType,
349
361
  transactionBlock: transaction,
@@ -353,15 +365,16 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
353
365
  }
354
366
  signTransactionFeature(_a) {
355
367
  return _tslib.__awaiter(this, arguments, void 0, function* ({ transaction, }) {
356
- if (!this.account) {
368
+ var _b, _c;
369
+ if (!this.getPrimaryAccount()) {
357
370
  throw new utils.DynamicError('No account found');
358
371
  }
359
372
  const features = this.getFeatures();
360
373
  const signTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signTransaction'];
361
374
  if (signTransactionFeature) {
362
375
  return signTransactionFeature === null || signTransactionFeature === void 0 ? void 0 : signTransactionFeature.signTransaction({
363
- account: this.account,
364
- chain: this.account.chains[0],
376
+ account: this.getPrimaryAccount(),
377
+ chain: (_b = this.getPrimaryAccount()) === null || _b === void 0 ? void 0 : _b.chains[0],
365
378
  transaction,
366
379
  });
367
380
  }
@@ -370,8 +383,8 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
370
383
  throw new utils.DynamicError('Wallet does not support sui:signTransaction or sui:signTransactionBlock');
371
384
  }
372
385
  const result = yield signTransactionBlockFeature.signTransactionBlock({
373
- account: this.account,
374
- chain: this.account.chains[0],
386
+ account: this.getPrimaryAccount(),
387
+ chain: (_c = this.getPrimaryAccount()) === null || _c === void 0 ? void 0 : _c.chains[0],
375
388
  transactionBlock: transaction,
376
389
  });
377
390
  return result;
@@ -4,7 +4,7 @@ import { Transaction } from '@mysten/sui/transactions';
4
4
  import { Logger } from '@dynamic-labs/logger';
5
5
  import { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
6
6
  import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
7
- import { SuiWalletConnectorProps, SuiWalletStandardEventHandler } from './types';
7
+ import { SuiChangeEvent, SuiWalletConnectorProps, SuiWalletStandardEventHandler } from './types';
8
8
  import { SuiWallet } from './wallet/SuiWallet';
9
9
  export declare abstract class SuiWalletConnector extends WalletConnectorBase<typeof SuiWallet> {
10
10
  name: string;
@@ -20,6 +20,9 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
20
20
  eventsUnsubscribeHandler: (() => void) | undefined;
21
21
  /** Tracks the active wallet account */
22
22
  protected account: WalletAccount | undefined;
23
+ /** Returns the active wallet account, may be overridden */
24
+ getPrimaryAccount(): WalletAccount | undefined;
25
+ setPrimaryAccount(account: WalletAccount | undefined): void;
23
26
  /**
24
27
  * Tracks the active network id
25
28
  *
@@ -61,7 +64,8 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
61
64
  * @param event - The [SuiChangeEvent] to get the chain id from
62
65
  * @returns The dynamic chain id or '-1' if the chain id is not found
63
66
  */
64
- private getChainFromEvent;
67
+ protected getChainFromEvent(event: SuiChangeEvent): string;
68
+ handleAccountChange(event: SuiChangeEvent): void;
65
69
  setupEventListeners(): void;
66
70
  /**
67
71
  * Helper to get the Sui client for the current network
@@ -9,6 +9,13 @@ import { SuiUiTransaction } from './utils/SuiUiTransaction/SuiUiTransaction.js';
9
9
  import { SuiWallet } from './wallet/SuiWallet.js';
10
10
 
11
11
  class SuiWalletConnector extends WalletConnectorBase {
12
+ /** Returns the active wallet account, may be overridden */
13
+ getPrimaryAccount() {
14
+ return this.account;
15
+ }
16
+ setPrimaryAccount(account) {
17
+ this.account = account;
18
+ }
12
19
  constructor(name, opts) {
13
20
  super(opts);
14
21
  this.name = 'Sui';
@@ -37,7 +44,7 @@ class SuiWalletConnector extends WalletConnectorBase {
37
44
  connect() {
38
45
  return __awaiter(this, arguments, void 0, function* ({ silent } = {}) {
39
46
  var _a, _b;
40
- if (this.account || this.isConnecting) {
47
+ if (this.getPrimaryAccount() || this.isConnecting) {
41
48
  // Account is already connected or we're already connecting
42
49
  return;
43
50
  }
@@ -50,12 +57,12 @@ class SuiWalletConnector extends WalletConnectorBase {
50
57
  }
51
58
  // Start connecting
52
59
  this.isConnecting = true;
53
- this.logger.debug('[connect] Creating new connection');
60
+ this.logger.debug(`[${this.name}] [connect] Creating new connection`);
54
61
  try {
55
62
  const response = yield connectFeature.connect(silent ? { silent } : undefined);
56
- this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
57
- this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
58
- const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
63
+ this.logger.debug(`[${this.name}] [connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
64
+ this.setPrimaryAccount(response === null || response === void 0 ? void 0 : response.accounts[0]);
65
+ const primaryChain = (_b = this.getPrimaryAccount()) === null || _b === void 0 ? void 0 : _b.chains[0];
59
66
  if (primaryChain) {
60
67
  this.activeNetworkId = getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
61
68
  }
@@ -96,21 +103,22 @@ class SuiWalletConnector extends WalletConnectorBase {
96
103
  /** Get the wallet address by connecting to the current account */
97
104
  getAddress() {
98
105
  return __awaiter(this, void 0, void 0, function* () {
99
- this.logger.debug('[getAddress] called, attempting to obtain the account address');
106
+ var _a;
107
+ this.logger.debug(`[${this.name}] [getAddress] called, attempting to obtain the account address`);
100
108
  if (this.handleInAppBrowserGetAddress()) {
101
109
  return;
102
110
  }
103
111
  yield this.connect();
104
- if (!this.account) {
105
- throw new DynamicError('No account found');
112
+ if (!this.getPrimaryAccount()) {
113
+ throw new DynamicError(`[${this.name}] [getAddress] No account found`);
106
114
  }
107
- return this.account.address;
115
+ return (_a = this.getPrimaryAccount()) === null || _a === void 0 ? void 0 : _a.address;
108
116
  });
109
117
  }
110
118
  /** Returns the network id of the account's active chain */
111
119
  getNetwork() {
112
120
  return __awaiter(this, void 0, void 0, function* () {
113
- if (!this.account) {
121
+ if (!this.getPrimaryAccount()) {
114
122
  yield this.connect();
115
123
  }
116
124
  return this.activeNetworkId;
@@ -119,10 +127,10 @@ class SuiWalletConnector extends WalletConnectorBase {
119
127
  getConnectedAccounts() {
120
128
  return __awaiter(this, void 0, void 0, function* () {
121
129
  var _a;
122
- if (!this.account) {
130
+ if (!this.getPrimaryAccount()) {
123
131
  yield this.connect({ silent: true });
124
132
  }
125
- const address = (_a = this.account) === null || _a === void 0 ? void 0 : _a.address;
133
+ const address = (_a = this.getPrimaryAccount()) === null || _a === void 0 ? void 0 : _a.address;
126
134
  if (address) {
127
135
  return [address];
128
136
  }
@@ -149,29 +157,33 @@ class SuiWalletConnector extends WalletConnectorBase {
149
157
  }
150
158
  return (_e = getSuiNetworkIdFromName(suiChain, this.suiNetworks)) !== null && _e !== void 0 ? _e : '-1';
151
159
  }
160
+ handleAccountChange(event) {
161
+ var _a;
162
+ // If the event sets accounts but it's empty, we need to disconnect.
163
+ if (event.accounts.length === 0 && this.getPrimaryAccount()) {
164
+ this.setPrimaryAccount(undefined);
165
+ this.emit('disconnect');
166
+ return;
167
+ }
168
+ const [primaryAccount] = event.accounts;
169
+ if (primaryAccount.address !== ((_a = this.getPrimaryAccount()) === null || _a === void 0 ? void 0 : _a.address)) {
170
+ this.setPrimaryAccount(primaryAccount);
171
+ this.emit('accountChange', { accounts: [primaryAccount.address] });
172
+ }
173
+ }
152
174
  setupEventListeners() {
153
175
  var _a;
154
176
  if (!this.canSetEventListeners || this.eventsHandler)
155
177
  return;
156
178
  const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
157
179
  if (!eventsFeature) {
158
- this.logger.debug('[setupEventListeners] Wallet not connected or does not support standard:events');
180
+ this.logger.debug(`[${this.name}] [setupEventListeners] Wallet not connected or does not support standard:events`);
159
181
  return;
160
182
  }
161
183
  this.eventsHandler = (event) => __awaiter(this, void 0, void 0, function* () {
162
- var _b;
163
184
  if (event.accounts) {
164
- // If the event sets accounts but it's empty, we need to disconnect.
165
- if (event.accounts.length === 0 && this.account) {
166
- this.account = undefined;
167
- this.emit('disconnect');
168
- return;
169
- }
170
- const [primaryAccount] = event.accounts;
171
- if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
172
- this.account = primaryAccount;
173
- this.emit('accountChange', { accounts: [primaryAccount.address] });
174
- }
185
+ this.handleAccountChange(event);
186
+ return;
175
187
  }
176
188
  // Some events will leave out accounts but set the chains object, so we process those
177
189
  // with the helper.
@@ -181,7 +193,7 @@ class SuiWalletConnector extends WalletConnectorBase {
181
193
  this.emit('chainChange', { chain: suiChainId });
182
194
  }
183
195
  });
184
- this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
196
+ this.logger.debug(`[${this.name}] [setupEventListeners] Setting up sui wallet connector event listeners`);
185
197
  this.eventsUnsubscribeHandler = eventsFeature.on('change', this.eventsHandler);
186
198
  }
187
199
  /**
@@ -193,7 +205,7 @@ class SuiWalletConnector extends WalletConnectorBase {
193
205
  return __awaiter(this, void 0, void 0, function* () {
194
206
  const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
195
207
  if (!clientNetworkId) {
196
- this.logger.error('[getSuiClient] Failed to get network id');
208
+ this.logger.error(`[${this.name}] [getSuiClient] Failed to get network id`);
197
209
  return undefined;
198
210
  }
199
211
  // Default to an existing client if available
@@ -203,7 +215,7 @@ class SuiWalletConnector extends WalletConnectorBase {
203
215
  const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
204
216
  const url = network ? getPreferredRpcUrl(network) : undefined;
205
217
  if (!url) {
206
- this.logger.error('[getSuiClient] Failed to get network url');
218
+ this.logger.error(`[${this.name}] [getSuiClient] Failed to get network url`);
207
219
  return undefined;
208
220
  }
209
221
  this.suiClients[clientNetworkId] = new SuiClient({
@@ -216,7 +228,7 @@ class SuiWalletConnector extends WalletConnectorBase {
216
228
  return __awaiter(this, void 0, void 0, function* () {
217
229
  const client = yield this.getSuiClient();
218
230
  if (!client) {
219
- this.logger.error('[getBalance] Failed to get Sui client');
231
+ this.logger.error(`[${this.name}] [getBalance] Failed to get Sui client`);
220
232
  return undefined;
221
233
  }
222
234
  const balanceResult = yield client.getBalance({
@@ -225,7 +237,7 @@ class SuiWalletConnector extends WalletConnectorBase {
225
237
  // Balance comes back as MIST, 1 SUI = 1e9 MIST
226
238
  const balance = Number(balanceResult === null || balanceResult === void 0 ? void 0 : balanceResult.totalBalance) / 1e9;
227
239
  if (Number.isNaN(balance)) {
228
- this.logger.error(`[getBalance] Failed to get balance for address: ${address}`);
240
+ this.logger.error(`[${this.name}] [getBalance] Failed to get balance for address: ${address}`);
229
241
  return undefined;
230
242
  }
231
243
  return balance.toFixed(6);
@@ -234,19 +246,18 @@ class SuiWalletConnector extends WalletConnectorBase {
234
246
  signMessage(messageToSign) {
235
247
  return __awaiter(this, void 0, void 0, function* () {
236
248
  var _a;
237
- this.logger.debug('[signMessage] called, attempting to sign a message');
249
+ this.logger.debug(`[${this.name}] [signMessage] called, attempting to sign a message`);
238
250
  const signFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage'];
239
251
  if (!signFeature) {
240
252
  throw new DynamicError('Wallet does not support sui:signPersonalMessage');
241
253
  }
242
- yield this.connect();
243
- if (!this.account) {
254
+ if (!this.getPrimaryAccount()) {
244
255
  throw new DynamicError('[signMessage] No account found');
245
256
  }
246
257
  let output;
247
258
  try {
248
259
  output = yield signFeature.signPersonalMessage({
249
- account: this.account,
260
+ account: this.getPrimaryAccount(),
250
261
  message: new TextEncoder().encode(messageToSign),
251
262
  });
252
263
  }
@@ -257,13 +268,13 @@ class SuiWalletConnector extends WalletConnectorBase {
257
268
  if (!output || !output.signature) {
258
269
  throw new DynamicError('[signMessage] Failed to sign message');
259
270
  }
260
- this.logger.debug(`[signMessage] Signed message: ${output.signature}`);
271
+ this.logger.debug(`[${this.name}] [signMessage] Signed message: ${output.signature}`);
261
272
  return output.signature;
262
273
  });
263
274
  }
264
275
  getWalletAccount() {
265
276
  return __awaiter(this, void 0, void 0, function* () {
266
- return this.account;
277
+ return this.getPrimaryAccount();
267
278
  });
268
279
  }
269
280
  /** Function used to create transactions in the SDK interface */
@@ -301,7 +312,7 @@ class SuiWalletConnector extends WalletConnectorBase {
301
312
  return __awaiter(this, void 0, void 0, function* () {
302
313
  var _a;
303
314
  this.teardownEventListeners();
304
- this.account = undefined;
315
+ this.setPrimaryAccount(undefined);
305
316
  if (!this.isInstalledOnBrowser())
306
317
  return;
307
318
  const disconnectFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:disconnect'];
@@ -321,15 +332,16 @@ class SuiWalletConnector extends WalletConnectorBase {
321
332
  }
322
333
  signAndExecuteTransactionFeature(_a) {
323
334
  return __awaiter(this, arguments, void 0, function* ({ transaction, legacyOptions, }) {
324
- if (!this.account) {
335
+ var _b, _c;
336
+ if (!this.getPrimaryAccount()) {
325
337
  throw new DynamicError('No account found');
326
338
  }
327
339
  const features = this.getFeatures();
328
340
  const signAndExecuteTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signAndExecuteTransaction'];
329
341
  if (signAndExecuteTransactionFeature) {
330
342
  return signAndExecuteTransactionFeature.signAndExecuteTransaction({
331
- account: this.account,
332
- chain: this.account.chains[0],
343
+ account: this.getPrimaryAccount(),
344
+ chain: (_b = this.getPrimaryAccount()) === null || _b === void 0 ? void 0 : _b.chains[0],
333
345
  transaction,
334
346
  });
335
347
  }
@@ -338,8 +350,8 @@ class SuiWalletConnector extends WalletConnectorBase {
338
350
  throw new DynamicError('Wallet does not support sui:signAndExecuteTransaction or sui:signAndExecuteTransactionBlock');
339
351
  }
340
352
  const result = yield signAndExecuteTransactionBlockFeature.signAndExecuteTransactionBlock({
341
- account: this.account,
342
- chain: this.account.chains[0],
353
+ account: this.getPrimaryAccount(),
354
+ chain: (_c = this.getPrimaryAccount()) === null || _c === void 0 ? void 0 : _c.chains[0],
343
355
  options: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.options,
344
356
  requestType: legacyOptions === null || legacyOptions === void 0 ? void 0 : legacyOptions.requestType,
345
357
  transactionBlock: transaction,
@@ -349,15 +361,16 @@ class SuiWalletConnector extends WalletConnectorBase {
349
361
  }
350
362
  signTransactionFeature(_a) {
351
363
  return __awaiter(this, arguments, void 0, function* ({ transaction, }) {
352
- if (!this.account) {
364
+ var _b, _c;
365
+ if (!this.getPrimaryAccount()) {
353
366
  throw new DynamicError('No account found');
354
367
  }
355
368
  const features = this.getFeatures();
356
369
  const signTransactionFeature = features === null || features === void 0 ? void 0 : features['sui:signTransaction'];
357
370
  if (signTransactionFeature) {
358
371
  return signTransactionFeature === null || signTransactionFeature === void 0 ? void 0 : signTransactionFeature.signTransaction({
359
- account: this.account,
360
- chain: this.account.chains[0],
372
+ account: this.getPrimaryAccount(),
373
+ chain: (_b = this.getPrimaryAccount()) === null || _b === void 0 ? void 0 : _b.chains[0],
361
374
  transaction,
362
375
  });
363
376
  }
@@ -366,8 +379,8 @@ class SuiWalletConnector extends WalletConnectorBase {
366
379
  throw new DynamicError('Wallet does not support sui:signTransaction or sui:signTransactionBlock');
367
380
  }
368
381
  const result = yield signTransactionBlockFeature.signTransactionBlock({
369
- account: this.account,
370
- chain: this.account.chains[0],
382
+ account: this.getPrimaryAccount(),
383
+ chain: (_c = this.getPrimaryAccount()) === null || _c === void 0 ? void 0 : _c.chains[0],
371
384
  transactionBlock: transaction,
372
385
  });
373
386
  return result;