@dynamic-labs/sui-core 4.47.3 → 4.48.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.
- package/CHANGELOG.md +22 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -9
- package/src/SuiWalletConnector.cjs +60 -47
- package/src/SuiWalletConnector.d.ts +6 -2
- package/src/SuiWalletConnector.js +60 -47
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.cjs +27 -2
- package/src/wallets/injected/fetchSuiInjectedWalletConnectors.js +27 -2
- package/src/wallets/slush/Slush.cjs +307 -0
- package/src/wallets/slush/Slush.d.ts +82 -0
- package/src/wallets/slush/Slush.js +303 -0
- package/src/wallets/slush/index.d.ts +1 -0
|
@@ -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.
|
|
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(
|
|
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.
|
|
58
|
-
const primaryChain = (_b = this.
|
|
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
|
-
|
|
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.
|
|
105
|
-
throw new DynamicError(
|
|
112
|
+
if (!this.getPrimaryAccount()) {
|
|
113
|
+
throw new DynamicError(`[${this.name}] [getAddress] No account found`);
|
|
106
114
|
}
|
|
107
|
-
return this.
|
|
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.
|
|
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.
|
|
130
|
+
if (!this.getPrimaryAccount()) {
|
|
123
131
|
yield this.connect({ silent: true });
|
|
124
132
|
}
|
|
125
|
-
const address = (_a = this.
|
|
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(
|
|
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
|
-
|
|
165
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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.
|
|
332
|
-
chain: this.
|
|
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.
|
|
342
|
-
chain: this.
|
|
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
|
-
|
|
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.
|
|
360
|
-
chain: this.
|
|
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.
|
|
370
|
-
chain: this.
|
|
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;
|
package/src/index.cjs
CHANGED
|
@@ -9,6 +9,7 @@ var constants = require('./utils/constants/constants.cjs');
|
|
|
9
9
|
var SuiWalletConnector = require('./SuiWalletConnector.cjs');
|
|
10
10
|
var SuiWallet = require('./wallet/SuiWallet.cjs');
|
|
11
11
|
var isSuiWallet = require('./wallet/isSuiWallet/isSuiWallet.cjs');
|
|
12
|
+
var Slush = require('./wallets/slush/Slush.cjs');
|
|
12
13
|
var SuiUiTransaction = require('./utils/SuiUiTransaction/SuiUiTransaction.cjs');
|
|
13
14
|
var fetchSuiInjectedWalletConnectors = require('./wallets/injected/fetchSuiInjectedWalletConnectors.cjs');
|
|
14
15
|
|
|
@@ -19,5 +20,6 @@ exports.MIST_PER_SUI = constants.MIST_PER_SUI;
|
|
|
19
20
|
exports.SuiWalletConnector = SuiWalletConnector.SuiWalletConnector;
|
|
20
21
|
exports.SuiWallet = SuiWallet.SuiWallet;
|
|
21
22
|
exports.isSuiWallet = isSuiWallet.isSuiWallet;
|
|
23
|
+
exports.Slush = Slush.Slush;
|
|
22
24
|
exports.SuiUiTransaction = SuiUiTransaction.SuiUiTransaction;
|
|
23
25
|
exports.fetchSuiInjectedWalletConnectors = fetchSuiInjectedWalletConnectors.fetchSuiInjectedWalletConnectors;
|
package/src/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './utils/constants';
|
|
|
2
2
|
export { SuiWalletConnector } from './SuiWalletConnector';
|
|
3
3
|
export { SuiWallet } from './wallet/SuiWallet';
|
|
4
4
|
export { isSuiWallet } from './wallet/isSuiWallet';
|
|
5
|
+
export { Slush } from './wallets/slush';
|
|
5
6
|
export type { SuiWalletConnectorProps, SuiSendBalanceProps } from './types';
|
|
6
7
|
export { SuiUiTransaction } from './utils/SuiUiTransaction/SuiUiTransaction';
|
|
7
8
|
export { fetchSuiInjectedWalletConnectors } from './wallets/injected/fetchSuiInjectedWalletConnectors';
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export { MIST_PER_SUI } from './utils/constants/constants.js';
|
|
|
5
5
|
export { SuiWalletConnector } from './SuiWalletConnector.js';
|
|
6
6
|
export { SuiWallet } from './wallet/SuiWallet.js';
|
|
7
7
|
export { isSuiWallet } from './wallet/isSuiWallet/isSuiWallet.js';
|
|
8
|
+
export { Slush } from './wallets/slush/Slush.js';
|
|
8
9
|
export { SuiUiTransaction } from './utils/SuiUiTransaction/SuiUiTransaction.js';
|
|
9
10
|
export { fetchSuiInjectedWalletConnectors } from './wallets/injected/fetchSuiInjectedWalletConnectors.js';
|
|
10
11
|
|
|
@@ -6,22 +6,33 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
6
6
|
var walletStandard = require('@mysten/wallet-standard');
|
|
7
7
|
var utils = require('@dynamic-labs/utils');
|
|
8
8
|
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
var Slush = require('../slush/Slush.cjs');
|
|
9
10
|
var injected = require('./injected.cjs');
|
|
10
11
|
|
|
12
|
+
// Wallets with custom connectors that should not be auto-generated
|
|
13
|
+
const walletsWithCustomConnectors = {
|
|
14
|
+
slush: Slush.Slush,
|
|
15
|
+
};
|
|
16
|
+
const getCustomConnectorForKey = (name) => {
|
|
17
|
+
var _a;
|
|
18
|
+
return (_a = Object.entries(walletsWithCustomConnectors).find(([key]) => name.toLowerCase().includes(key.toLowerCase()))) === null || _a === void 0 ? void 0 : _a[1];
|
|
19
|
+
};
|
|
11
20
|
const fetchSuiInjectedWalletConnectors = ({ walletBook, }) => {
|
|
12
21
|
var _a;
|
|
13
22
|
const walletStandardWallets = walletStandard.getWallets().get();
|
|
14
23
|
const suiWalletStandardWallets = walletStandardWallets.filter((wallet) => walletStandard.isWalletWithRequiredFeatureSet(wallet, ['sui:signPersonalMessage']));
|
|
15
24
|
const suiWalletsByKey = Object.fromEntries(suiWalletStandardWallets.map((wallet) => [wallet.name, wallet]));
|
|
16
25
|
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
17
|
-
.filter(([, wallet]) => {
|
|
26
|
+
.filter(([key, wallet]) => {
|
|
18
27
|
var _a, _b;
|
|
19
28
|
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sui');
|
|
20
29
|
const isSuiWallet = Boolean(injectedConfig);
|
|
21
30
|
const walletStandardName = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.name;
|
|
22
31
|
// If the wallet is injected via wallet standard, use that over the wallet book entry
|
|
23
32
|
const shouldBeFiltered = walletStandardName && suiWalletsByKey[walletStandardName];
|
|
24
|
-
|
|
33
|
+
// Filter out wallets that have custom connectors
|
|
34
|
+
const hasCustomConnector = Boolean(getCustomConnectorForKey(key));
|
|
35
|
+
return isSuiWallet && !shouldBeFiltered && !hasCustomConnector;
|
|
25
36
|
})
|
|
26
37
|
.map(([key, wallet]) => {
|
|
27
38
|
// Currently we only support wallet standard wallets
|
|
@@ -44,7 +55,21 @@ const fetchSuiInjectedWalletConnectors = ({ walletBook, }) => {
|
|
|
44
55
|
.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; })
|
|
45
56
|
.map((wallet) => {
|
|
46
57
|
const sanitizedName = utils.sanitizeName(wallet.name);
|
|
58
|
+
const customConnector = getCustomConnectorForKey(sanitizedName);
|
|
47
59
|
const isInstalled = true;
|
|
60
|
+
if (customConnector) {
|
|
61
|
+
return class extends customConnector {
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
|
+
constructor(props) {
|
|
64
|
+
super(wallet.name, isInstalled, Object.assign({ metadata: {
|
|
65
|
+
groupKey: sanitizedName,
|
|
66
|
+
icon: wallet.icon,
|
|
67
|
+
id: wallet.name,
|
|
68
|
+
name: wallet.name,
|
|
69
|
+
}, name: wallet.name, overrideKey: `${sanitizedName}sui`, wallet: wallet }, props));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
48
73
|
return class extends injected.Injected {
|
|
49
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
50
75
|
constructor(props) {
|
|
@@ -2,22 +2,33 @@
|
|
|
2
2
|
import { getWallets, isWalletWithRequiredFeatureSet } from '@mysten/wallet-standard';
|
|
3
3
|
import { sanitizeName } from '@dynamic-labs/utils';
|
|
4
4
|
import { getWalletMetadataFromWalletBook } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { Slush } from '../slush/Slush.js';
|
|
5
6
|
import { Injected } from './injected.js';
|
|
6
7
|
|
|
8
|
+
// Wallets with custom connectors that should not be auto-generated
|
|
9
|
+
const walletsWithCustomConnectors = {
|
|
10
|
+
slush: Slush,
|
|
11
|
+
};
|
|
12
|
+
const getCustomConnectorForKey = (name) => {
|
|
13
|
+
var _a;
|
|
14
|
+
return (_a = Object.entries(walletsWithCustomConnectors).find(([key]) => name.toLowerCase().includes(key.toLowerCase()))) === null || _a === void 0 ? void 0 : _a[1];
|
|
15
|
+
};
|
|
7
16
|
const fetchSuiInjectedWalletConnectors = ({ walletBook, }) => {
|
|
8
17
|
var _a;
|
|
9
18
|
const walletStandardWallets = getWallets().get();
|
|
10
19
|
const suiWalletStandardWallets = walletStandardWallets.filter((wallet) => isWalletWithRequiredFeatureSet(wallet, ['sui:signPersonalMessage']));
|
|
11
20
|
const suiWalletsByKey = Object.fromEntries(suiWalletStandardWallets.map((wallet) => [wallet.name, wallet]));
|
|
12
21
|
const walletBookConnectors = Object.entries((_a = walletBook === null || walletBook === void 0 ? void 0 : walletBook.wallets) !== null && _a !== void 0 ? _a : {})
|
|
13
|
-
.filter(([, wallet]) => {
|
|
22
|
+
.filter(([key, wallet]) => {
|
|
14
23
|
var _a, _b;
|
|
15
24
|
const injectedConfig = (_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'sui');
|
|
16
25
|
const isSuiWallet = Boolean(injectedConfig);
|
|
17
26
|
const walletStandardName = (_b = injectedConfig === null || injectedConfig === void 0 ? void 0 : injectedConfig.walletStandard) === null || _b === void 0 ? void 0 : _b.name;
|
|
18
27
|
// If the wallet is injected via wallet standard, use that over the wallet book entry
|
|
19
28
|
const shouldBeFiltered = walletStandardName && suiWalletsByKey[walletStandardName];
|
|
20
|
-
|
|
29
|
+
// Filter out wallets that have custom connectors
|
|
30
|
+
const hasCustomConnector = Boolean(getCustomConnectorForKey(key));
|
|
31
|
+
return isSuiWallet && !shouldBeFiltered && !hasCustomConnector;
|
|
21
32
|
})
|
|
22
33
|
.map(([key, wallet]) => {
|
|
23
34
|
// Currently we only support wallet standard wallets
|
|
@@ -40,7 +51,21 @@ const fetchSuiInjectedWalletConnectors = ({ walletBook, }) => {
|
|
|
40
51
|
.filter((wallet) => { var _a; return (_a = wallet.features) === null || _a === void 0 ? void 0 : _a['sui:signPersonalMessage']; })
|
|
41
52
|
.map((wallet) => {
|
|
42
53
|
const sanitizedName = sanitizeName(wallet.name);
|
|
54
|
+
const customConnector = getCustomConnectorForKey(sanitizedName);
|
|
43
55
|
const isInstalled = true;
|
|
56
|
+
if (customConnector) {
|
|
57
|
+
return class extends customConnector {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
constructor(props) {
|
|
60
|
+
super(wallet.name, isInstalled, Object.assign({ metadata: {
|
|
61
|
+
groupKey: sanitizedName,
|
|
62
|
+
icon: wallet.icon,
|
|
63
|
+
id: wallet.name,
|
|
64
|
+
name: wallet.name,
|
|
65
|
+
}, name: wallet.name, overrideKey: `${sanitizedName}sui`, wallet: wallet }, props));
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
44
69
|
return class extends Injected {
|
|
45
70
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
71
|
constructor(props) {
|