@dynamic-labs/sui 4.9.8 → 4.9.10

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,23 @@
1
1
 
2
+ ### [4.9.10](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.9...v4.9.10) (2025-03-26)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * auto select primary wallet when embedded wallets are disabled ([#8374](https://github.com/dynamic-labs/dynamic-auth/issues/8374)) ([780f3f1](https://github.com/dynamic-labs/dynamic-auth/commit/780f3f16ebd06dd8bc41fa85e8b4393c906989e2))
8
+
9
+ ### [4.9.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.8...v4.9.9) (2025-03-26)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **global-wallet-client:** properly clean up the popup state when popup is closed ([#8379](https://github.com/dynamic-labs/dynamic-auth/issues/8379)) ([782963f](https://github.com/dynamic-labs/dynamic-auth/commit/782963f87fcb2658b921ff6cc6f22c63be9714fb))
15
+ * hanging promises when a starknet wallet is connected but locked ([#8376](https://github.com/dynamic-labs/dynamic-auth/issues/8376)) ([a753939](https://github.com/dynamic-labs/dynamic-auth/commit/a7539395d4653be49f000ae51d15347a176b5b6c))
16
+ * token balance list should respect sort from backend ([#8383](https://github.com/dynamic-labs/dynamic-auth/issues/8383)) ([1c3bef4](https://github.com/dynamic-labs/dynamic-auth/commit/1c3bef47dbfd319e2444368a4a503b0839b5ad4b))
17
+
18
+
19
+ * add message auth code to global wallet ([#8354](https://github.com/dynamic-labs/dynamic-auth/issues/8354)) ([c847bf8](https://github.com/dynamic-labs/dynamic-auth/commit/c847bf8d66db54534348622255997f30f4309542))
20
+
2
21
  ### [4.9.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.7...v4.9.8) (2025-03-24)
3
22
 
4
23
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.9.8";
6
+ var version = "4.9.10";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.9.8";
2
+ var version = "4.9.10";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sui",
3
- "version": "4.9.8",
3
+ "version": "4.9.10",
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",
@@ -20,13 +20,15 @@
20
20
  "dependencies": {
21
21
  "@dynamic-labs/sdk-api-core": "0.0.644",
22
22
  "@mysten/wallet-standard": "0.13.29",
23
+ "@mysten/sui": "1.24.0",
23
24
  "text-encoding": "0.7.0",
24
- "@dynamic-labs/assert-package-version": "4.9.8",
25
- "@dynamic-labs/logger": "4.9.8",
26
- "@dynamic-labs/rpc-providers": "4.9.8",
27
- "@dynamic-labs/utils": "4.9.8",
28
- "@dynamic-labs/wallet-book": "4.9.8",
29
- "@dynamic-labs/wallet-connector-core": "4.9.8"
25
+ "@dynamic-labs/assert-package-version": "4.9.10",
26
+ "@dynamic-labs/logger": "4.9.10",
27
+ "@dynamic-labs/rpc-providers": "4.9.10",
28
+ "@dynamic-labs/types": "4.9.10",
29
+ "@dynamic-labs/utils": "4.9.10",
30
+ "@dynamic-labs/wallet-book": "4.9.10",
31
+ "@dynamic-labs/wallet-connector-core": "4.9.10"
30
32
  },
31
33
  "peerDependencies": {}
32
34
  }
@@ -4,10 +4,12 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../_virtual/_tslib.cjs');
7
+ var client = require('@mysten/sui/client');
7
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
8
9
  var utils = require('@dynamic-labs/utils');
9
10
  var logger = require('@dynamic-labs/logger');
10
11
  var SuiWallet = require('./wallet/SuiWallet.cjs');
12
+ var networkHelpers = require('./utils/network/networkHelpers.cjs');
11
13
 
12
14
  class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
13
15
  constructor(name, opts) {
@@ -19,9 +21,12 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
19
21
  this.switchNetworkOnlyFromWallet = true;
20
22
  /** required for metamask snap integration as MM snaps don't have event listeners */
21
23
  this.canSetEventListeners = true;
24
+ /** Sui clients */
25
+ this.suiClients = {};
22
26
  this.name = name;
23
27
  this.wallet = opts.wallet;
24
28
  this.chainRpcProviders = opts.chainRpcProviders;
29
+ this.suiNetworks = opts.suiNetworks;
25
30
  this.logger = new logger.Logger(this.name);
26
31
  }
27
32
  /** Helper to return the wallet features */
@@ -32,7 +37,7 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
32
37
  /** Connect to the wallet using the standard:connect feature */
33
38
  connect() {
34
39
  return _tslib.__awaiter(this, void 0, void 0, function* () {
35
- var _a;
40
+ var _a, _b;
36
41
  if (this.account) {
37
42
  // Account is already connected
38
43
  return;
@@ -46,6 +51,10 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
46
51
  const response = yield connectFeature.connect();
47
52
  this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
48
53
  this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
54
+ const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
55
+ if (primaryChain) {
56
+ this.activeNetworkId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
57
+ }
49
58
  }
50
59
  catch (error) {
51
60
  this.logger.error(error);
@@ -65,13 +74,13 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
65
74
  return this.account.address;
66
75
  });
67
76
  }
77
+ /** Returns the network id of the account's active chain */
68
78
  getNetwork() {
69
79
  return _tslib.__awaiter(this, void 0, void 0, function* () {
70
- var _a;
71
- if (!((_a = this.account) === null || _a === void 0 ? void 0 : _a.chains[0])) {
72
- return undefined;
80
+ if (!this.account) {
81
+ yield this.connect();
73
82
  }
74
- return this.account.chains[0];
83
+ return this.activeNetworkId;
75
84
  });
76
85
  }
77
86
  getConnectedAccounts() {
@@ -80,10 +89,88 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
80
89
  return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
81
90
  });
82
91
  }
92
+ setupEventListeners() {
93
+ var _a;
94
+ if (!this.canSetEventListeners)
95
+ return;
96
+ const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
97
+ if (!eventsFeature) {
98
+ throw new utils.DynamicError('Wallet not connected or does not support standard:events');
99
+ }
100
+ if (this.eventsHandler) {
101
+ return;
102
+ }
103
+ this.eventsHandler = (event) => _tslib.__awaiter(this, void 0, void 0, function* () {
104
+ var _b;
105
+ this.logger.debug('[eventsHandler] Received argument:', event);
106
+ if (!event.accounts || event.accounts.length === 0) {
107
+ this.emit('disconnect');
108
+ return;
109
+ }
110
+ const [primaryAccount] = event.accounts;
111
+ if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
112
+ this.account = primaryAccount;
113
+ this.emit('accountChange', { accounts: [primaryAccount.address] });
114
+ }
115
+ if (primaryAccount.chains && primaryAccount.chains.length > 0) {
116
+ const [primaryChain] = primaryAccount.chains;
117
+ const suiChainId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
118
+ if (suiChainId && suiChainId !== this.activeNetworkId) {
119
+ this.activeNetworkId = suiChainId;
120
+ this.emit('chainChange', {
121
+ chain: suiChainId,
122
+ });
123
+ }
124
+ }
125
+ });
126
+ this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
127
+ eventsFeature.on('change', this.eventsHandler);
128
+ }
129
+ /**
130
+ * Helper to get the Sui client for the current network
131
+ *
132
+ * The client will prefer the private customer rpc url if available.
133
+ */
134
+ getSuiClient(networkId) {
135
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
136
+ const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
137
+ if (!clientNetworkId) {
138
+ this.logger.error('[getSuiClient] Failed to get network id');
139
+ return undefined;
140
+ }
141
+ // Default to an existing client if available
142
+ if (this.suiClients[clientNetworkId]) {
143
+ return this.suiClients[clientNetworkId];
144
+ }
145
+ const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
146
+ const url = network ? networkHelpers.getPreferredRpcUrl(network) : undefined;
147
+ if (!url) {
148
+ this.logger.error('[getSuiClient] Failed to get network url');
149
+ return undefined;
150
+ }
151
+ this.suiClients[clientNetworkId] = new client.SuiClient({
152
+ url: url,
153
+ });
154
+ return this.suiClients[clientNetworkId];
155
+ });
156
+ }
83
157
  getBalance(address) {
84
158
  return _tslib.__awaiter(this, void 0, void 0, function* () {
85
- // Make RPC call to get balance
86
- return address;
159
+ const client = yield this.getSuiClient();
160
+ if (!client) {
161
+ this.logger.error('[getBalance] Failed to get Sui client');
162
+ return undefined;
163
+ }
164
+ const balanceResult = yield client.getBalance({
165
+ owner: address,
166
+ });
167
+ // Balance comes back as MIST, 1 SUI = 1e9 MIST
168
+ const balance = Number(balanceResult === null || balanceResult === void 0 ? void 0 : balanceResult.totalBalance) / 1e9;
169
+ if (Number.isNaN(balance)) {
170
+ this.logger.error(`[getBalance] Failed to get balance for address: ${address}`);
171
+ return undefined;
172
+ }
173
+ return balance.toFixed(6);
87
174
  });
88
175
  }
89
176
  signMessage(messageToSign) {
@@ -144,6 +231,9 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
144
231
  throw new utils.DynamicError('Wallet does not support disconnect');
145
232
  });
146
233
  }
234
+ getEnabledNetworks() {
235
+ return this.suiNetworks;
236
+ }
147
237
  }
148
238
 
149
239
  exports.SuiWalletConnector = SuiWalletConnector;
@@ -1,8 +1,10 @@
1
1
  import { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
2
+ import { SuiClient } from '@mysten/sui/client';
2
3
  import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
3
4
  import { Logger } from '@dynamic-labs/logger';
5
+ import { GenericNetwork } from '@dynamic-labs/types';
4
6
  import { SuiWallet } from './wallet/SuiWallet';
5
- import { SuiWalletConnectorProps } from './types';
7
+ import { SuiWalletConnectorProps, SuiWalletStandardEventHandler } from './types';
6
8
  export declare abstract class SuiWalletConnector extends WalletConnectorBase<typeof SuiWallet> {
7
9
  name: string;
8
10
  ChainWallet: typeof SuiWallet;
@@ -11,10 +13,22 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
11
13
  switchNetworkOnlyFromWallet: boolean;
12
14
  /** required for metamask snap integration as MM snaps don't have event listeners */
13
15
  canSetEventListeners: boolean;
16
+ eventsHandler: SuiWalletStandardEventHandler | undefined;
14
17
  /** Sui wallet instance */
15
18
  wallet: WalletWithFeatures<SuiWalletFeatures> | undefined;
16
19
  /** Tracks the active wallet account */
17
20
  protected account: WalletAccount | undefined;
21
+ /**
22
+ * Tracks the active network id
23
+ *
24
+ * This is needed because the account's network order doesn't update after a
25
+ * network change event.
26
+ */
27
+ protected activeNetworkId: string | undefined;
28
+ /** Sui clients */
29
+ suiClients: Record<string, SuiClient>;
30
+ /** Enabled SUI networks */
31
+ suiNetworks: GenericNetwork[];
18
32
  /** Dynamic logger */
19
33
  logger: Logger;
20
34
  constructor(name: string, opts: SuiWalletConnectorProps);
@@ -24,12 +38,21 @@ export declare abstract class SuiWalletConnector extends WalletConnectorBase<typ
24
38
  connect(): Promise<void>;
25
39
  /** Get the wallet address by connecting to the current account */
26
40
  getAddress(): Promise<string | undefined>;
27
- getNetwork(): Promise<`${string}:${string}` | undefined>;
41
+ /** Returns the network id of the account's active chain */
42
+ getNetwork(): Promise<string | undefined>;
28
43
  getConnectedAccounts(): Promise<string[]>;
44
+ setupEventListeners(): void;
45
+ /**
46
+ * Helper to get the Sui client for the current network
47
+ *
48
+ * The client will prefer the private customer rpc url if available.
49
+ */
50
+ getSuiClient(networkId?: string): Promise<SuiClient | undefined>;
29
51
  getBalance(address: string): Promise<string | undefined>;
30
52
  signMessage(messageToSign: string): Promise<string | undefined>;
31
53
  getWalletAccount(): Promise<WalletAccount | undefined>;
32
54
  getProvider(): Promise<string>;
33
55
  endSession(): Promise<void>;
56
+ getEnabledNetworks(): GenericNetwork[];
34
57
  }
35
58
  export type SuiWalletConnectorType = SuiWalletConnector;
@@ -1,9 +1,11 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../_virtual/_tslib.js';
3
+ import { SuiClient } from '@mysten/sui/client';
3
4
  import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
4
5
  import { DynamicError } from '@dynamic-labs/utils';
5
6
  import { Logger } from '@dynamic-labs/logger';
6
7
  import { SuiWallet } from './wallet/SuiWallet.js';
8
+ import { getSuiNetworkIdFromName, getPreferredRpcUrl } from './utils/network/networkHelpers.js';
7
9
 
8
10
  class SuiWalletConnector extends WalletConnectorBase {
9
11
  constructor(name, opts) {
@@ -15,9 +17,12 @@ class SuiWalletConnector extends WalletConnectorBase {
15
17
  this.switchNetworkOnlyFromWallet = true;
16
18
  /** required for metamask snap integration as MM snaps don't have event listeners */
17
19
  this.canSetEventListeners = true;
20
+ /** Sui clients */
21
+ this.suiClients = {};
18
22
  this.name = name;
19
23
  this.wallet = opts.wallet;
20
24
  this.chainRpcProviders = opts.chainRpcProviders;
25
+ this.suiNetworks = opts.suiNetworks;
21
26
  this.logger = new Logger(this.name);
22
27
  }
23
28
  /** Helper to return the wallet features */
@@ -28,7 +33,7 @@ class SuiWalletConnector extends WalletConnectorBase {
28
33
  /** Connect to the wallet using the standard:connect feature */
29
34
  connect() {
30
35
  return __awaiter(this, void 0, void 0, function* () {
31
- var _a;
36
+ var _a, _b;
32
37
  if (this.account) {
33
38
  // Account is already connected
34
39
  return;
@@ -42,6 +47,10 @@ class SuiWalletConnector extends WalletConnectorBase {
42
47
  const response = yield connectFeature.connect();
43
48
  this.logger.debug(`[connect] Connection returned accounts: ${response === null || response === void 0 ? void 0 : response.accounts.length}`);
44
49
  this.account = response === null || response === void 0 ? void 0 : response.accounts[0];
50
+ const primaryChain = (_b = this.account) === null || _b === void 0 ? void 0 : _b.chains[0];
51
+ if (primaryChain) {
52
+ this.activeNetworkId = getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
53
+ }
45
54
  }
46
55
  catch (error) {
47
56
  this.logger.error(error);
@@ -61,13 +70,13 @@ class SuiWalletConnector extends WalletConnectorBase {
61
70
  return this.account.address;
62
71
  });
63
72
  }
73
+ /** Returns the network id of the account's active chain */
64
74
  getNetwork() {
65
75
  return __awaiter(this, void 0, void 0, function* () {
66
- var _a;
67
- if (!((_a = this.account) === null || _a === void 0 ? void 0 : _a.chains[0])) {
68
- return undefined;
76
+ if (!this.account) {
77
+ yield this.connect();
69
78
  }
70
- return this.account.chains[0];
79
+ return this.activeNetworkId;
71
80
  });
72
81
  }
73
82
  getConnectedAccounts() {
@@ -76,10 +85,88 @@ class SuiWalletConnector extends WalletConnectorBase {
76
85
  return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
77
86
  });
78
87
  }
88
+ setupEventListeners() {
89
+ var _a;
90
+ if (!this.canSetEventListeners)
91
+ return;
92
+ const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
93
+ if (!eventsFeature) {
94
+ throw new DynamicError('Wallet not connected or does not support standard:events');
95
+ }
96
+ if (this.eventsHandler) {
97
+ return;
98
+ }
99
+ this.eventsHandler = (event) => __awaiter(this, void 0, void 0, function* () {
100
+ var _b;
101
+ this.logger.debug('[eventsHandler] Received argument:', event);
102
+ if (!event.accounts || event.accounts.length === 0) {
103
+ this.emit('disconnect');
104
+ return;
105
+ }
106
+ const [primaryAccount] = event.accounts;
107
+ if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
108
+ this.account = primaryAccount;
109
+ this.emit('accountChange', { accounts: [primaryAccount.address] });
110
+ }
111
+ if (primaryAccount.chains && primaryAccount.chains.length > 0) {
112
+ const [primaryChain] = primaryAccount.chains;
113
+ const suiChainId = getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
114
+ if (suiChainId && suiChainId !== this.activeNetworkId) {
115
+ this.activeNetworkId = suiChainId;
116
+ this.emit('chainChange', {
117
+ chain: suiChainId,
118
+ });
119
+ }
120
+ }
121
+ });
122
+ this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
123
+ eventsFeature.on('change', this.eventsHandler);
124
+ }
125
+ /**
126
+ * Helper to get the Sui client for the current network
127
+ *
128
+ * The client will prefer the private customer rpc url if available.
129
+ */
130
+ getSuiClient(networkId) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const clientNetworkId = networkId !== null && networkId !== void 0 ? networkId : (yield this.getNetwork());
133
+ if (!clientNetworkId) {
134
+ this.logger.error('[getSuiClient] Failed to get network id');
135
+ return undefined;
136
+ }
137
+ // Default to an existing client if available
138
+ if (this.suiClients[clientNetworkId]) {
139
+ return this.suiClients[clientNetworkId];
140
+ }
141
+ const network = this.getEnabledNetworks().find((network) => network.networkId === clientNetworkId);
142
+ const url = network ? getPreferredRpcUrl(network) : undefined;
143
+ if (!url) {
144
+ this.logger.error('[getSuiClient] Failed to get network url');
145
+ return undefined;
146
+ }
147
+ this.suiClients[clientNetworkId] = new SuiClient({
148
+ url: url,
149
+ });
150
+ return this.suiClients[clientNetworkId];
151
+ });
152
+ }
79
153
  getBalance(address) {
80
154
  return __awaiter(this, void 0, void 0, function* () {
81
- // Make RPC call to get balance
82
- return address;
155
+ const client = yield this.getSuiClient();
156
+ if (!client) {
157
+ this.logger.error('[getBalance] Failed to get Sui client');
158
+ return undefined;
159
+ }
160
+ const balanceResult = yield client.getBalance({
161
+ owner: address,
162
+ });
163
+ // Balance comes back as MIST, 1 SUI = 1e9 MIST
164
+ const balance = Number(balanceResult === null || balanceResult === void 0 ? void 0 : balanceResult.totalBalance) / 1e9;
165
+ if (Number.isNaN(balance)) {
166
+ this.logger.error(`[getBalance] Failed to get balance for address: ${address}`);
167
+ return undefined;
168
+ }
169
+ return balance.toFixed(6);
83
170
  });
84
171
  }
85
172
  signMessage(messageToSign) {
@@ -140,6 +227,9 @@ class SuiWalletConnector extends WalletConnectorBase {
140
227
  throw new DynamicError('Wallet does not support disconnect');
141
228
  });
142
229
  }
230
+ getEnabledNetworks() {
231
+ return this.suiNetworks;
232
+ }
143
233
  }
144
234
 
145
235
  export { SuiWalletConnector };
package/src/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { WalletWithFeatures, SuiWalletFeatures } from '@mysten/wallet-standard';
1
+ import { WalletWithFeatures, SuiWalletFeatures, IdentifierRecord, IdentifierArray, WalletAccount } from '@mysten/wallet-standard';
2
2
  import { IChainRpcProviders } from '@dynamic-labs/rpc-providers';
3
3
  import { NetworkConfiguration } from '@dynamic-labs/sdk-api-core';
4
4
  import { WalletBookSchema } from '@dynamic-labs/wallet-book';
@@ -11,3 +11,9 @@ export type SuiWalletConnectorProps = {
11
11
  wallet: WalletWithFeatures<SuiWalletFeatures>;
12
12
  overrideKey?: string;
13
13
  };
14
+ export type SuiChangeEvent = {
15
+ accounts: WalletAccount[];
16
+ chains: IdentifierArray;
17
+ features: IdentifierRecord<unknown>;
18
+ };
19
+ export type SuiWalletStandardEventHandler = (event: SuiChangeEvent) => Promise<void>;
@@ -0,0 +1 @@
1
+ export * from './networkHelpers';
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ /**
7
+ * Get the Sui network id from the network name
8
+ *
9
+ * The Wallet Standard API returns Sui networks in the format `sui:mainnet`,
10
+ * so we need to map that to our network id.
11
+ *
12
+ * @param name - The network name
13
+ * @param networks - The list of networks
14
+ * @returns The Sui network id
15
+ */
16
+ const getSuiNetworkIdFromName = (name, networks) => {
17
+ var _a;
18
+ const suiNetworkName = name.split(':').pop();
19
+ if (!suiNetworkName) {
20
+ return undefined;
21
+ }
22
+ const chainId = (_a = networks.find((network) => network.name.toLowerCase().includes(suiNetworkName.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.chainId;
23
+ return chainId ? String(chainId) : undefined;
24
+ };
25
+ /**
26
+ * Get the preferred RPC URL for a given network
27
+ *
28
+ * @param network - The network
29
+ * @returns The preferred RPC URL
30
+ */
31
+ const getPreferredRpcUrl = (network) => { var _a, _b, _c; return (_b = (_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = network.rpcUrls) === null || _c === void 0 ? void 0 : _c[0]; };
32
+
33
+ exports.getPreferredRpcUrl = getPreferredRpcUrl;
34
+ exports.getSuiNetworkIdFromName = getSuiNetworkIdFromName;
@@ -0,0 +1,19 @@
1
+ import { GenericNetwork } from '@dynamic-labs/types';
2
+ /**
3
+ * Get the Sui network id from the network name
4
+ *
5
+ * The Wallet Standard API returns Sui networks in the format `sui:mainnet`,
6
+ * so we need to map that to our network id.
7
+ *
8
+ * @param name - The network name
9
+ * @param networks - The list of networks
10
+ * @returns The Sui network id
11
+ */
12
+ export declare const getSuiNetworkIdFromName: (name: string, networks: GenericNetwork[]) => string | undefined;
13
+ /**
14
+ * Get the preferred RPC URL for a given network
15
+ *
16
+ * @param network - The network
17
+ * @returns The preferred RPC URL
18
+ */
19
+ export declare const getPreferredRpcUrl: (network: GenericNetwork) => string;
@@ -0,0 +1,29 @@
1
+ 'use client'
2
+ /**
3
+ * Get the Sui network id from the network name
4
+ *
5
+ * The Wallet Standard API returns Sui networks in the format `sui:mainnet`,
6
+ * so we need to map that to our network id.
7
+ *
8
+ * @param name - The network name
9
+ * @param networks - The list of networks
10
+ * @returns The Sui network id
11
+ */
12
+ const getSuiNetworkIdFromName = (name, networks) => {
13
+ var _a;
14
+ const suiNetworkName = name.split(':').pop();
15
+ if (!suiNetworkName) {
16
+ return undefined;
17
+ }
18
+ const chainId = (_a = networks.find((network) => network.name.toLowerCase().includes(suiNetworkName.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.chainId;
19
+ return chainId ? String(chainId) : undefined;
20
+ };
21
+ /**
22
+ * Get the preferred RPC URL for a given network
23
+ *
24
+ * @param network - The network
25
+ * @returns The preferred RPC URL
26
+ */
27
+ const getPreferredRpcUrl = (network) => { var _a, _b, _c; return (_b = (_a = network.privateCustomerRpcUrls) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : (_c = network.rpcUrls) === null || _c === void 0 ? void 0 : _c[0]; };
28
+
29
+ export { getPreferredRpcUrl, getSuiNetworkIdFromName };