@dynamic-labs/sui 4.9.7 → 4.9.9
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 +19 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -7
- package/src/SuiWalletConnector.cjs +55 -3
- package/src/SuiWalletConnector.d.ts +12 -3
- package/src/SuiWalletConnector.js +55 -3
- package/src/index.cjs +3 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +3 -2
- package/src/types.d.ts +8 -1
- package/src/utils/network/index.d.ts +1 -0
- package/src/utils/network/networkHelpers.cjs +16 -0
- package/src/utils/network/networkHelpers.d.ts +2 -0
- package/src/utils/network/networkHelpers.js +12 -0
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.cjs +49 -11
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.d.ts +4 -1
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.js +49 -11
- package/src/wallets/injected/injected.cjs +4 -3
- package/src/wallets/injected/injected.d.ts +8 -1
- package/src/wallets/injected/injected.js +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.9.9](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.8...v4.9.9) (2025-03-26)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* **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))
|
|
8
|
+
* 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))
|
|
9
|
+
* 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))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* 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))
|
|
13
|
+
|
|
14
|
+
### [4.9.8](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.7...v4.9.8) (2025-03-24)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* unlink wallets when using 7702 account ([#8367](https://github.com/dynamic-labs/dynamic-auth/issues/8367)) ([f5acf05](https://github.com/dynamic-labs/dynamic-auth/commit/f5acf05ef31b8f411f3b0cd0e90e919e71f4ad50))
|
|
20
|
+
|
|
2
21
|
### [4.9.7](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.6...v4.9.7) (2025-03-21)
|
|
3
22
|
|
|
4
23
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/sui",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.9",
|
|
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",
|
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
"@dynamic-labs/sdk-api-core": "0.0.644",
|
|
22
22
|
"@mysten/wallet-standard": "0.13.29",
|
|
23
23
|
"text-encoding": "0.7.0",
|
|
24
|
-
"@dynamic-labs/assert-package-version": "4.9.
|
|
25
|
-
"@dynamic-labs/logger": "4.9.
|
|
26
|
-
"@dynamic-labs/rpc-providers": "4.9.
|
|
27
|
-
"@dynamic-labs/
|
|
28
|
-
"@dynamic-labs/
|
|
29
|
-
"@dynamic-labs/wallet-
|
|
24
|
+
"@dynamic-labs/assert-package-version": "4.9.9",
|
|
25
|
+
"@dynamic-labs/logger": "4.9.9",
|
|
26
|
+
"@dynamic-labs/rpc-providers": "4.9.9",
|
|
27
|
+
"@dynamic-labs/types": "4.9.9",
|
|
28
|
+
"@dynamic-labs/utils": "4.9.9",
|
|
29
|
+
"@dynamic-labs/wallet-book": "4.9.9",
|
|
30
|
+
"@dynamic-labs/wallet-connector-core": "4.9.9"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {}
|
|
32
33
|
}
|
|
@@ -8,6 +8,7 @@ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
|
8
8
|
var utils = require('@dynamic-labs/utils');
|
|
9
9
|
var logger = require('@dynamic-labs/logger');
|
|
10
10
|
var SuiWallet = require('./wallet/SuiWallet.cjs');
|
|
11
|
+
var networkHelpers = require('./utils/network/networkHelpers.cjs');
|
|
11
12
|
|
|
12
13
|
class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
13
14
|
constructor(name, opts) {
|
|
@@ -16,11 +17,13 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
16
17
|
this.ChainWallet = SuiWallet.SuiWallet;
|
|
17
18
|
this.connectedChain = 'SUI';
|
|
18
19
|
this.supportedChains = ['SUI'];
|
|
20
|
+
this.switchNetworkOnlyFromWallet = true;
|
|
19
21
|
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
20
22
|
this.canSetEventListeners = true;
|
|
21
23
|
this.name = name;
|
|
22
24
|
this.wallet = opts.wallet;
|
|
23
25
|
this.chainRpcProviders = opts.chainRpcProviders;
|
|
26
|
+
this.suiNetworks = opts.suiNetworks;
|
|
24
27
|
this.logger = new logger.Logger(this.name);
|
|
25
28
|
}
|
|
26
29
|
/** Helper to return the wallet features */
|
|
@@ -64,15 +67,61 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
64
67
|
return this.account.address;
|
|
65
68
|
});
|
|
66
69
|
}
|
|
70
|
+
/** Returns the network id of the account's active chain */
|
|
67
71
|
getNetwork() {
|
|
68
72
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
var _a;
|
|
70
|
-
if (!
|
|
73
|
+
var _a, _b;
|
|
74
|
+
if (!this.account) {
|
|
75
|
+
yield this.connect();
|
|
76
|
+
}
|
|
77
|
+
if (!((_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.chains) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
71
78
|
return undefined;
|
|
72
79
|
}
|
|
73
|
-
return this.account.chains[0];
|
|
80
|
+
return networkHelpers.getSuiNetworkIdFromName(this.account.chains[0], this.suiNetworks);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
getConnectedAccounts() {
|
|
84
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
var _a;
|
|
86
|
+
return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
|
|
74
87
|
});
|
|
75
88
|
}
|
|
89
|
+
setupEventListeners() {
|
|
90
|
+
var _a;
|
|
91
|
+
if (!this.canSetEventListeners)
|
|
92
|
+
return;
|
|
93
|
+
const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
|
|
94
|
+
if (!eventsFeature) {
|
|
95
|
+
throw new utils.DynamicError('Wallet not connected or does not support standard:events');
|
|
96
|
+
}
|
|
97
|
+
if (this.eventsHandler) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
this.eventsHandler = (event) => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
var _b;
|
|
102
|
+
this.logger.debug('[eventsHandler] Received argument:', event);
|
|
103
|
+
if (!event.accounts || event.accounts.length === 0) {
|
|
104
|
+
this.emit('disconnect');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const [primaryAccount] = event.accounts;
|
|
108
|
+
if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
|
|
109
|
+
this.account = primaryAccount;
|
|
110
|
+
this.emit('accountChange', { accounts: [primaryAccount.address] });
|
|
111
|
+
}
|
|
112
|
+
if (primaryAccount.chains && primaryAccount.chains.length > 0) {
|
|
113
|
+
const [primaryChain] = primaryAccount.chains;
|
|
114
|
+
const suiChainId = networkHelpers.getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
|
|
115
|
+
if (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
|
+
}
|
|
76
125
|
getBalance(address) {
|
|
77
126
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
78
127
|
// Make RPC call to get balance
|
|
@@ -137,6 +186,9 @@ class SuiWalletConnector extends walletConnectorCore.WalletConnectorBase {
|
|
|
137
186
|
throw new utils.DynamicError('Wallet does not support disconnect');
|
|
138
187
|
});
|
|
139
188
|
}
|
|
189
|
+
getEnabledNetworks() {
|
|
190
|
+
return this.suiNetworks;
|
|
191
|
+
}
|
|
140
192
|
}
|
|
141
193
|
|
|
142
194
|
exports.SuiWalletConnector = SuiWalletConnector;
|
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
import { SuiWalletFeatures, WalletAccount, WalletWithFeatures } from '@mysten/wallet-standard';
|
|
2
2
|
import { Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { Logger } from '@dynamic-labs/logger';
|
|
4
|
+
import { GenericNetwork } from '@dynamic-labs/types';
|
|
4
5
|
import { SuiWallet } from './wallet/SuiWallet';
|
|
5
|
-
import { SuiWalletConnectorProps } from './types';
|
|
6
|
+
import { SuiWalletConnectorProps, SuiWalletStandardEventHandler } from './types';
|
|
6
7
|
export declare abstract class SuiWalletConnector extends WalletConnectorBase<typeof SuiWallet> {
|
|
7
8
|
name: string;
|
|
8
9
|
ChainWallet: typeof SuiWallet;
|
|
9
10
|
connectedChain: Chain;
|
|
10
11
|
supportedChains: Chain[];
|
|
12
|
+
switchNetworkOnlyFromWallet: boolean;
|
|
11
13
|
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
12
14
|
canSetEventListeners: boolean;
|
|
15
|
+
eventsHandler: SuiWalletStandardEventHandler | undefined;
|
|
13
16
|
/** Sui wallet instance */
|
|
14
17
|
wallet: WalletWithFeatures<SuiWalletFeatures> | undefined;
|
|
15
18
|
/** Tracks the active wallet account */
|
|
16
19
|
protected account: WalletAccount | undefined;
|
|
20
|
+
/** Enabled SUI networks */
|
|
21
|
+
suiNetworks: GenericNetwork[];
|
|
17
22
|
/** Dynamic logger */
|
|
18
23
|
logger: Logger;
|
|
19
24
|
constructor(name: string, opts: SuiWalletConnectorProps);
|
|
20
25
|
/** Helper to return the wallet features */
|
|
21
|
-
|
|
26
|
+
getFeatures(): SuiWalletFeatures | undefined;
|
|
22
27
|
/** Connect to the wallet using the standard:connect feature */
|
|
23
28
|
connect(): Promise<void>;
|
|
24
29
|
/** Get the wallet address by connecting to the current account */
|
|
25
30
|
getAddress(): Promise<string | undefined>;
|
|
26
|
-
|
|
31
|
+
/** Returns the network id of the account's active chain */
|
|
32
|
+
getNetwork(): Promise<string | undefined>;
|
|
33
|
+
getConnectedAccounts(): Promise<string[]>;
|
|
34
|
+
setupEventListeners(): void;
|
|
27
35
|
getBalance(address: string): Promise<string | undefined>;
|
|
28
36
|
signMessage(messageToSign: string): Promise<string | undefined>;
|
|
29
37
|
getWalletAccount(): Promise<WalletAccount | undefined>;
|
|
30
38
|
getProvider(): Promise<string>;
|
|
31
39
|
endSession(): Promise<void>;
|
|
40
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
32
41
|
}
|
|
33
42
|
export type SuiWalletConnectorType = SuiWalletConnector;
|
|
@@ -4,6 +4,7 @@ import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
|
4
4
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
5
|
import { Logger } from '@dynamic-labs/logger';
|
|
6
6
|
import { SuiWallet } from './wallet/SuiWallet.js';
|
|
7
|
+
import { getSuiNetworkIdFromName } from './utils/network/networkHelpers.js';
|
|
7
8
|
|
|
8
9
|
class SuiWalletConnector extends WalletConnectorBase {
|
|
9
10
|
constructor(name, opts) {
|
|
@@ -12,11 +13,13 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
12
13
|
this.ChainWallet = SuiWallet;
|
|
13
14
|
this.connectedChain = 'SUI';
|
|
14
15
|
this.supportedChains = ['SUI'];
|
|
16
|
+
this.switchNetworkOnlyFromWallet = true;
|
|
15
17
|
/** required for metamask snap integration as MM snaps don't have event listeners */
|
|
16
18
|
this.canSetEventListeners = true;
|
|
17
19
|
this.name = name;
|
|
18
20
|
this.wallet = opts.wallet;
|
|
19
21
|
this.chainRpcProviders = opts.chainRpcProviders;
|
|
22
|
+
this.suiNetworks = opts.suiNetworks;
|
|
20
23
|
this.logger = new Logger(this.name);
|
|
21
24
|
}
|
|
22
25
|
/** Helper to return the wallet features */
|
|
@@ -60,15 +63,61 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
60
63
|
return this.account.address;
|
|
61
64
|
});
|
|
62
65
|
}
|
|
66
|
+
/** Returns the network id of the account's active chain */
|
|
63
67
|
getNetwork() {
|
|
64
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
var _a;
|
|
66
|
-
if (!
|
|
69
|
+
var _a, _b;
|
|
70
|
+
if (!this.account) {
|
|
71
|
+
yield this.connect();
|
|
72
|
+
}
|
|
73
|
+
if (!((_b = (_a = this.account) === null || _a === void 0 ? void 0 : _a.chains) === null || _b === void 0 ? void 0 : _b[0])) {
|
|
67
74
|
return undefined;
|
|
68
75
|
}
|
|
69
|
-
return this.account.chains[0];
|
|
76
|
+
return getSuiNetworkIdFromName(this.account.chains[0], this.suiNetworks);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getConnectedAccounts() {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
var _a;
|
|
82
|
+
return ((_a = this.account) === null || _a === void 0 ? void 0 : _a.address) ? [this.account.address] : [];
|
|
70
83
|
});
|
|
71
84
|
}
|
|
85
|
+
setupEventListeners() {
|
|
86
|
+
var _a;
|
|
87
|
+
if (!this.canSetEventListeners)
|
|
88
|
+
return;
|
|
89
|
+
const eventsFeature = (_a = this.getFeatures()) === null || _a === void 0 ? void 0 : _a['standard:events'];
|
|
90
|
+
if (!eventsFeature) {
|
|
91
|
+
throw new DynamicError('Wallet not connected or does not support standard:events');
|
|
92
|
+
}
|
|
93
|
+
if (this.eventsHandler) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
this.eventsHandler = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
var _b;
|
|
98
|
+
this.logger.debug('[eventsHandler] Received argument:', event);
|
|
99
|
+
if (!event.accounts || event.accounts.length === 0) {
|
|
100
|
+
this.emit('disconnect');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const [primaryAccount] = event.accounts;
|
|
104
|
+
if (primaryAccount.address !== ((_b = this.account) === null || _b === void 0 ? void 0 : _b.address)) {
|
|
105
|
+
this.account = primaryAccount;
|
|
106
|
+
this.emit('accountChange', { accounts: [primaryAccount.address] });
|
|
107
|
+
}
|
|
108
|
+
if (primaryAccount.chains && primaryAccount.chains.length > 0) {
|
|
109
|
+
const [primaryChain] = primaryAccount.chains;
|
|
110
|
+
const suiChainId = getSuiNetworkIdFromName(primaryChain, this.suiNetworks);
|
|
111
|
+
if (suiChainId) {
|
|
112
|
+
this.emit('chainChange', {
|
|
113
|
+
chain: suiChainId,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
this.logger.debug('[setupEventListeners] Setting up sui wallet connector event listeners');
|
|
119
|
+
eventsFeature.on('change', this.eventsHandler);
|
|
120
|
+
}
|
|
72
121
|
getBalance(address) {
|
|
73
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
123
|
// Make RPC call to get balance
|
|
@@ -133,6 +182,9 @@ class SuiWalletConnector extends WalletConnectorBase {
|
|
|
133
182
|
throw new DynamicError('Wallet does not support disconnect');
|
|
134
183
|
});
|
|
135
184
|
}
|
|
185
|
+
getEnabledNetworks() {
|
|
186
|
+
return this.suiNetworks;
|
|
187
|
+
}
|
|
136
188
|
}
|
|
137
189
|
|
|
138
190
|
export { SuiWalletConnector };
|
package/src/index.cjs
CHANGED
|
@@ -10,8 +10,9 @@ var SuiWalletConnector = require('./SuiWalletConnector.cjs');
|
|
|
10
10
|
|
|
11
11
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
12
12
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/sui', _package.version);
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
const SuiWalletConnectors = (props) => [
|
|
15
|
+
...fetchSuiInjectedWalletConnectors.fetchSuiInjectedWalletConnectors(props),
|
|
15
16
|
];
|
|
16
17
|
|
|
17
18
|
exports.SuiWalletConnector = SuiWalletConnector.SuiWalletConnector;
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SuiWalletConnectors: () => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
|
1
|
+
export declare const SuiWalletConnectors: (props: any) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
|
2
2
|
export { SuiWalletConnector } from './SuiWalletConnector';
|
package/src/index.js
CHANGED
|
@@ -6,8 +6,9 @@ export { SuiWalletConnector } from './SuiWalletConnector.js';
|
|
|
6
6
|
|
|
7
7
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
8
|
assertPackageVersion('@dynamic-labs/sui', version);
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
+
const SuiWalletConnectors = (props) => [
|
|
11
|
+
...fetchSuiInjectedWalletConnectors(props),
|
|
11
12
|
];
|
|
12
13
|
|
|
13
14
|
export { SuiWalletConnectors };
|
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';
|
|
@@ -9,4 +9,11 @@ export type SuiWalletConnectorProps = {
|
|
|
9
9
|
walletBook: WalletBookSchema;
|
|
10
10
|
metadata?: WalletMetadata;
|
|
11
11
|
wallet: WalletWithFeatures<SuiWalletFeatures>;
|
|
12
|
+
overrideKey?: string;
|
|
12
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,16 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const getSuiNetworkIdFromName = (name, networks) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const suiNetworkName = name.split(':').pop();
|
|
9
|
+
if (!suiNetworkName) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
const chainId = (_a = networks.find((network) => network.name.toLowerCase().includes(suiNetworkName.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
13
|
+
return chainId ? String(chainId) : undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.getSuiNetworkIdFromName = getSuiNetworkIdFromName;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
const getSuiNetworkIdFromName = (name, networks) => {
|
|
3
|
+
var _a;
|
|
4
|
+
const suiNetworkName = name.split(':').pop();
|
|
5
|
+
if (!suiNetworkName) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
const chainId = (_a = networks.find((network) => network.name.toLowerCase().includes(suiNetworkName.toLowerCase()))) === null || _a === void 0 ? void 0 : _a.chainId;
|
|
9
|
+
return chainId ? String(chainId) : undefined;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { getSuiNetworkIdFromName };
|
|
@@ -4,25 +4,63 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var walletStandard = require('@mysten/wallet-standard');
|
|
7
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
7
9
|
var injected = require('./injected.cjs');
|
|
8
10
|
|
|
9
|
-
const fetchSuiInjectedWalletConnectors = () => {
|
|
11
|
+
const fetchSuiInjectedWalletConnectors = ({ walletBook, }) => {
|
|
12
|
+
var _a;
|
|
10
13
|
const walletStandardWallets = walletStandard.getWallets().get();
|
|
11
14
|
// Wallet standard wallets don't always have injectedConfig from wallet book,
|
|
12
15
|
// so we filter them by checking if they support critical sui features.
|
|
16
|
+
const suiWalletStandardWallets = walletStandardWallets.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; });
|
|
17
|
+
const suiWalletsByKey = Object.fromEntries(suiWalletStandardWallets.map((wallet) => [wallet.name, wallet]));
|
|
18
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
19
|
+
.filter(([, wallet]) => {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sui');
|
|
22
|
+
const isSuiWallet = Boolean(injectedConfig);
|
|
23
|
+
const walletStandardName = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.name;
|
|
24
|
+
// If the wallet is injected via wallet standard, use that over the wallet book entry
|
|
25
|
+
const shouldBeFiltered = walletStandardName && suiWalletsByKey[walletStandardName];
|
|
26
|
+
return isSuiWallet && !shouldBeFiltered;
|
|
27
|
+
})
|
|
28
|
+
.map(([key, wallet]) => {
|
|
29
|
+
// Wallet book wallets are not currently installed on the browser
|
|
30
|
+
const isInstalled = false;
|
|
31
|
+
const metadata = walletConnectorCore.getWalletMetadataFromWalletBook({
|
|
32
|
+
walletBook,
|
|
33
|
+
walletBookWallet: wallet,
|
|
34
|
+
walletKey: key,
|
|
35
|
+
});
|
|
36
|
+
return class extends injected.Injected {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
constructor(props) {
|
|
39
|
+
super(wallet.name, isInstalled, Object.assign({ metadata, overrideKey: key, wallet: wallet, walletBookEntry: wallet }, props));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
// The remaining wallets are wallet standard wallets injected from the browser
|
|
44
|
+
const isInstalled = true;
|
|
45
|
+
// Wallet standard wallets don't always have injectedConfig from wallet book,
|
|
46
|
+
// so we filter them by checking if they support critical sui features.
|
|
13
47
|
const walletStandardConnectors = walletStandardWallets
|
|
14
48
|
.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; })
|
|
15
|
-
.map((wallet) =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
49
|
+
.map((wallet) => {
|
|
50
|
+
const sanitizedName = utils.sanitizeName(wallet.name);
|
|
51
|
+
return class extends injected.Injected {
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
constructor(props) {
|
|
54
|
+
super(wallet.name, isInstalled, Object.assign({ metadata: {
|
|
55
|
+
groupKey: sanitizedName,
|
|
56
|
+
icon: wallet.icon,
|
|
57
|
+
id: wallet.name,
|
|
58
|
+
name: wallet.name,
|
|
59
|
+
}, name: wallet.name, overrideKey: `${sanitizedName}sui`, wallet: wallet }, props));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
24
62
|
});
|
|
25
|
-
return [...walletStandardConnectors];
|
|
63
|
+
return [...walletBookConnectors, ...walletStandardConnectors];
|
|
26
64
|
};
|
|
27
65
|
|
|
28
66
|
exports.fetchSuiInjectedWalletConnectors = fetchSuiInjectedWalletConnectors;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
-
|
|
2
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
3
|
+
export declare const fetchSuiInjectedWalletConnectors: ({ walletBook, }: {
|
|
4
|
+
walletBook?: WalletBookSchema;
|
|
5
|
+
}) => WalletConnectorConstructor[];
|
|
@@ -1,24 +1,62 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { getWallets } from '@mysten/wallet-standard';
|
|
3
|
+
import { getWalletMetadataFromWalletBook } from '@dynamic-labs/wallet-connector-core';
|
|
4
|
+
import { sanitizeName } from '@dynamic-labs/utils';
|
|
3
5
|
import { Injected } from './injected.js';
|
|
4
6
|
|
|
5
|
-
const fetchSuiInjectedWalletConnectors = () => {
|
|
7
|
+
const fetchSuiInjectedWalletConnectors = ({ walletBook, }) => {
|
|
8
|
+
var _a;
|
|
6
9
|
const walletStandardWallets = getWallets().get();
|
|
7
10
|
// Wallet standard wallets don't always have injectedConfig from wallet book,
|
|
8
11
|
// so we filter them by checking if they support critical sui features.
|
|
12
|
+
const suiWalletStandardWallets = walletStandardWallets.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; });
|
|
13
|
+
const suiWalletsByKey = Object.fromEntries(suiWalletStandardWallets.map((wallet) => [wallet.name, wallet]));
|
|
14
|
+
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
15
|
+
.filter(([, wallet]) => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sui');
|
|
18
|
+
const isSuiWallet = Boolean(injectedConfig);
|
|
19
|
+
const walletStandardName = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.name;
|
|
20
|
+
// If the wallet is injected via wallet standard, use that over the wallet book entry
|
|
21
|
+
const shouldBeFiltered = walletStandardName && suiWalletsByKey[walletStandardName];
|
|
22
|
+
return isSuiWallet && !shouldBeFiltered;
|
|
23
|
+
})
|
|
24
|
+
.map(([key, wallet]) => {
|
|
25
|
+
// Wallet book wallets are not currently installed on the browser
|
|
26
|
+
const isInstalled = false;
|
|
27
|
+
const metadata = getWalletMetadataFromWalletBook({
|
|
28
|
+
walletBook,
|
|
29
|
+
walletBookWallet: wallet,
|
|
30
|
+
walletKey: key,
|
|
31
|
+
});
|
|
32
|
+
return class extends Injected {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
constructor(props) {
|
|
35
|
+
super(wallet.name, isInstalled, Object.assign({ metadata, overrideKey: key, wallet: wallet, walletBookEntry: wallet }, props));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
// The remaining wallets are wallet standard wallets injected from the browser
|
|
40
|
+
const isInstalled = true;
|
|
41
|
+
// Wallet standard wallets don't always have injectedConfig from wallet book,
|
|
42
|
+
// so we filter them by checking if they support critical sui features.
|
|
9
43
|
const walletStandardConnectors = walletStandardWallets
|
|
10
44
|
.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; })
|
|
11
|
-
.map((wallet) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
45
|
+
.map((wallet) => {
|
|
46
|
+
const sanitizedName = sanitizeName(wallet.name);
|
|
47
|
+
return class extends Injected {
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
constructor(props) {
|
|
50
|
+
super(wallet.name, isInstalled, Object.assign({ metadata: {
|
|
51
|
+
groupKey: sanitizedName,
|
|
52
|
+
icon: wallet.icon,
|
|
53
|
+
id: wallet.name,
|
|
54
|
+
name: wallet.name,
|
|
55
|
+
}, name: wallet.name, overrideKey: `${sanitizedName}sui`, wallet: wallet }, props));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
20
58
|
});
|
|
21
|
-
return [...walletStandardConnectors];
|
|
59
|
+
return [...walletBookConnectors, ...walletStandardConnectors];
|
|
22
60
|
};
|
|
23
61
|
|
|
24
62
|
export { fetchSuiInjectedWalletConnectors };
|
|
@@ -6,12 +6,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var SuiWalletConnector = require('../../SuiWalletConnector.cjs');
|
|
7
7
|
|
|
8
8
|
class Injected extends SuiWalletConnector.SuiWalletConnector {
|
|
9
|
-
constructor(name, props) {
|
|
9
|
+
constructor(name, isInstalledOnBrowser, props) {
|
|
10
10
|
super(name, props);
|
|
11
|
+
this._isInstalledOnBrowser = isInstalledOnBrowser;
|
|
12
|
+
this.overrideKey = props.overrideKey;
|
|
11
13
|
}
|
|
12
|
-
// Injected wallets are always already installed on browser
|
|
13
14
|
isInstalledOnBrowser() {
|
|
14
|
-
return
|
|
15
|
+
return this._isInstalledOnBrowser;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { SuiWalletConnector } from '../../SuiWalletConnector';
|
|
2
2
|
import { SuiWalletConnectorProps } from '../../types';
|
|
3
3
|
export declare class Injected extends SuiWalletConnector {
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Tracks whether the injected wallet is installed on the browser
|
|
6
|
+
*
|
|
7
|
+
* If the wallet is in wallet book but not found with getWallets().get(),
|
|
8
|
+
* it's not installed on the browser.
|
|
9
|
+
*/
|
|
10
|
+
private _isInstalledOnBrowser;
|
|
11
|
+
constructor(name: string, isInstalledOnBrowser: boolean, props: SuiWalletConnectorProps);
|
|
5
12
|
isInstalledOnBrowser(): boolean;
|
|
6
13
|
}
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { SuiWalletConnector } from '../../SuiWalletConnector.js';
|
|
3
3
|
|
|
4
4
|
class Injected extends SuiWalletConnector {
|
|
5
|
-
constructor(name, props) {
|
|
5
|
+
constructor(name, isInstalledOnBrowser, props) {
|
|
6
6
|
super(name, props);
|
|
7
|
+
this._isInstalledOnBrowser = isInstalledOnBrowser;
|
|
8
|
+
this.overrideKey = props.overrideKey;
|
|
7
9
|
}
|
|
8
|
-
// Injected wallets are always already installed on browser
|
|
9
10
|
isInstalledOnBrowser() {
|
|
10
|
-
return
|
|
11
|
+
return this._isInstalledOnBrowser;
|
|
11
12
|
}
|
|
12
13
|
}
|
|
13
14
|
|