@dynamic-labs/tron 4.40.1 → 4.41.0
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 +6 -6
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.cjs +201 -69
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.d.ts +25 -17
- package/src/connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.js +201 -69
- package/src/index.cjs +2 -10
- package/src/index.d.ts +4 -5
- package/src/index.js +2 -10
- package/src/utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.cjs +80 -0
- package/src/utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.d.ts +35 -0
- package/src/utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.js +75 -0
- package/src/utils/fetchTronWalletAdapterConnectors/index.d.ts +1 -0
- package/src/utils/index.d.ts +1 -0
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.cjs +0 -20
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.d.ts +0 -7
- package/src/connectors/BitgetTronConnector/BitgetTronConnector.js +0 -16
- package/src/connectors/BitgetTronConnector/index.d.ts +0 -1
- package/src/connectors/OKXTronConnector/OKXTronConnector.cjs +0 -20
- package/src/connectors/OKXTronConnector/OKXTronConnector.d.ts +0 -7
- package/src/connectors/OKXTronConnector/OKXTronConnector.js +0 -16
- package/src/connectors/OKXTronConnector/index.d.ts +0 -1
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.cjs +0 -20
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.d.ts +0 -7
- package/src/connectors/TokenPocketTronConnector/TokenPocketTronConnector.js +0 -16
- package/src/connectors/TokenPocketTronConnector/index.d.ts +0 -1
- package/src/connectors/TrustTronConnector/TrustTronConnector.cjs +0 -20
- package/src/connectors/TrustTronConnector/TrustTronConnector.d.ts +0 -7
- package/src/connectors/TrustTronConnector/TrustTronConnector.js +0 -16
- package/src/connectors/TrustTronConnector/index.d.ts +0 -1
|
@@ -1,58 +1,123 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { TronLinkAdapter, BitKeepAdapter, OkxWalletAdapter, TokenPocketAdapter, TrustAdapter } from '@tronweb3/tronwallet-adapters';
|
|
3
4
|
import { WalletConnectorBase, logger } from '@dynamic-labs/wallet-connector-core';
|
|
4
5
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
6
|
import { TronWallet } from '../../wallet/TronWallet/TronWallet.js';
|
|
6
7
|
import { TronUiTransaction } from '../../utils/TronUiTransaction/TronUiTransaction.js';
|
|
7
8
|
import { convertChainIdToDecimal } from '../../utils/convertChainIdToDecimal/convertChainIdToDecimal.js';
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Registry mapping wallet keys to their adapter classes
|
|
12
|
+
*/
|
|
13
|
+
const ADAPTER_REGISTRY = {
|
|
14
|
+
bitgettron: BitKeepAdapter,
|
|
15
|
+
okxtron: OkxWalletAdapter,
|
|
16
|
+
tokenpockettron: TokenPocketAdapter,
|
|
17
|
+
tronlinkwallet: TronLinkAdapter,
|
|
18
|
+
trusttron: TrustAdapter,
|
|
19
|
+
};
|
|
9
20
|
class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
21
|
+
/**
|
|
22
|
+
* Create the TronWallet Adapter instance for this connector
|
|
23
|
+
* Uses the adapter registry to create the appropriate adapter
|
|
24
|
+
*/
|
|
25
|
+
createAdapter() {
|
|
26
|
+
const AdapterClass = ADAPTER_REGISTRY[this.overrideKey];
|
|
27
|
+
if (!AdapterClass) {
|
|
28
|
+
logger.warn(`[${this.name}] Unknown adapter for overrideKey: ${this.overrideKey}. Falling back to TronLink.`);
|
|
29
|
+
return new TronLinkAdapter();
|
|
30
|
+
}
|
|
31
|
+
const adapter = new AdapterClass();
|
|
32
|
+
return adapter;
|
|
33
|
+
}
|
|
10
34
|
constructor(opts) {
|
|
11
35
|
super(opts);
|
|
12
36
|
this.ChainWallet = TronWallet;
|
|
13
|
-
this.name = 'Tron';
|
|
14
|
-
this.overrideKey = '
|
|
37
|
+
this.name = 'Tron Wallet';
|
|
38
|
+
this.overrideKey = 'tronwallet';
|
|
15
39
|
this.connectedChain = 'TRON';
|
|
16
40
|
this.supportedChains = ['TRON'];
|
|
17
41
|
this.switchNetworkOnlyFromWallet = true;
|
|
42
|
+
this.adapter = undefined;
|
|
43
|
+
this.balanceCache = new Map();
|
|
44
|
+
this.networkCache = null;
|
|
18
45
|
this.tronNetworks = opts.tronNetworks;
|
|
19
|
-
|
|
20
|
-
this.adapter = this.createAdapter();
|
|
46
|
+
this.overrideKey = opts.overrideKey || 'tronwallet';
|
|
21
47
|
}
|
|
22
48
|
confirmTransactionStatus() {
|
|
23
49
|
throw new Error('Method not implemented.');
|
|
24
50
|
}
|
|
25
51
|
/**
|
|
26
52
|
* Get the TronWallet Adapter instance
|
|
53
|
+
* Adapter is created lazily only when connect() is called to avoid multiple adapters
|
|
54
|
+
* polling simultaneously at startup.
|
|
27
55
|
*/
|
|
28
56
|
getAdapter() {
|
|
57
|
+
if (!this.adapter) {
|
|
58
|
+
throw new Error('Adapter not initialized. Call connect() first.');
|
|
59
|
+
}
|
|
29
60
|
return this.adapter;
|
|
30
61
|
}
|
|
31
62
|
/**
|
|
32
|
-
* Check if the wallet is installed
|
|
63
|
+
* Check if the specific wallet is installed on the browser
|
|
64
|
+
* Each wallet adapter checks for its own specific browser injection
|
|
33
65
|
*/
|
|
34
66
|
isInstalledOnBrowser() {
|
|
35
|
-
|
|
36
|
-
|
|
67
|
+
try {
|
|
68
|
+
// Create the adapter to check if the wallet is installed
|
|
69
|
+
if (!this.adapter) {
|
|
70
|
+
const AdapterClass = ADAPTER_REGISTRY[this.overrideKey];
|
|
71
|
+
if (!AdapterClass) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
this.adapter = new AdapterClass();
|
|
75
|
+
}
|
|
76
|
+
// The adapter's readyState indicates if the wallet is installed:
|
|
77
|
+
// NotFound = wallet not installed
|
|
78
|
+
// Loading/Found = wallet is installed
|
|
79
|
+
return this.adapter.readyState !== 'NotFound';
|
|
80
|
+
}
|
|
81
|
+
catch (_a) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
37
84
|
}
|
|
38
85
|
/**
|
|
39
86
|
* Connect to the wallet
|
|
40
87
|
*/
|
|
41
88
|
connect() {
|
|
42
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
|
|
90
|
+
// Create adapter NOW (first time connect is called)
|
|
91
|
+
if (!this.adapter) {
|
|
92
|
+
this.adapter = this.createAdapter();
|
|
93
|
+
}
|
|
94
|
+
const { adapter } = { adapter: this.adapter };
|
|
95
|
+
// If already connected, return early
|
|
44
96
|
if (adapter.connected) {
|
|
45
97
|
return;
|
|
46
98
|
}
|
|
47
|
-
|
|
48
|
-
throw new DynamicError(`${this.name} wallet not found. Please install the extension.`);
|
|
49
|
-
}
|
|
99
|
+
// Connect to the adapter
|
|
50
100
|
try {
|
|
51
101
|
yield adapter.connect();
|
|
52
102
|
}
|
|
53
103
|
catch (error) {
|
|
54
104
|
throw new DynamicError(`Failed to connect to ${this.name}: ${error}`);
|
|
55
105
|
}
|
|
106
|
+
// Some wallets (Trust, Bitget) populate the address asynchronously after connect()
|
|
107
|
+
// Wait briefly for the address to be populated by the wallet
|
|
108
|
+
const initialAddress = adapter.address;
|
|
109
|
+
const hasNoAddress = !initialAddress ||
|
|
110
|
+
(typeof initialAddress === 'string' && initialAddress.length === 0);
|
|
111
|
+
if (hasNoAddress) {
|
|
112
|
+
// Give the wallet 1000ms to populate the address
|
|
113
|
+
const startTime = Date.now();
|
|
114
|
+
while ((!adapter.address ||
|
|
115
|
+
(typeof adapter.address === 'string' &&
|
|
116
|
+
adapter.address.length === 0)) &&
|
|
117
|
+
Date.now() - startTime < 1000) {
|
|
118
|
+
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
56
121
|
});
|
|
57
122
|
}
|
|
58
123
|
/**
|
|
@@ -60,12 +125,41 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
60
125
|
*/
|
|
61
126
|
getAddress() {
|
|
62
127
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
|
|
64
|
-
|
|
128
|
+
// Create adapter if it doesn't exist yet (defensive against SDK calling getAddress before connect)
|
|
129
|
+
if (!this.adapter) {
|
|
130
|
+
this.adapter = this.createAdapter();
|
|
131
|
+
}
|
|
132
|
+
const { adapter } = { adapter: this.adapter };
|
|
133
|
+
// If adapter exists but isn't connected yet, connect it first
|
|
65
134
|
if (!adapter.connected) {
|
|
66
|
-
|
|
135
|
+
try {
|
|
136
|
+
yield adapter.connect();
|
|
137
|
+
// Some wallets (Trust, Bitget) populate the address asynchronously after connect()
|
|
138
|
+
// Wait briefly for the address to be populated by the wallet
|
|
139
|
+
const initialAddress = adapter.address;
|
|
140
|
+
const hasNoAddress = !initialAddress ||
|
|
141
|
+
(typeof initialAddress === 'string' && initialAddress.length === 0);
|
|
142
|
+
if (hasNoAddress) {
|
|
143
|
+
// Give the wallet 1000ms to populate the address
|
|
144
|
+
const startTime = Date.now();
|
|
145
|
+
while ((!adapter.address ||
|
|
146
|
+
(typeof adapter.address === 'string' &&
|
|
147
|
+
adapter.address.length === 0)) &&
|
|
148
|
+
Date.now() - startTime < 1000) {
|
|
149
|
+
yield new Promise((resolve) => setTimeout(resolve, 50));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throw new DynamicError(`Failed to connect to ${this.name}: ${error}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const { address } = adapter;
|
|
158
|
+
// Handle null, undefined, and empty string
|
|
159
|
+
if (!address || address.length === 0) {
|
|
160
|
+
return undefined;
|
|
67
161
|
}
|
|
68
|
-
return
|
|
162
|
+
return address;
|
|
69
163
|
});
|
|
70
164
|
}
|
|
71
165
|
/**
|
|
@@ -78,15 +172,35 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
78
172
|
});
|
|
79
173
|
}
|
|
80
174
|
/**
|
|
81
|
-
* Get the current network
|
|
175
|
+
* Get the current network with caching to prevent rate limiting
|
|
82
176
|
*/
|
|
83
177
|
getNetwork() {
|
|
84
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
var _a;
|
|
180
|
+
// Don't create adapter if it doesn't exist yet (prevents initialization crashes)
|
|
181
|
+
if (!this.adapter) {
|
|
182
|
+
return '728126428'; // Mainnet fallback
|
|
183
|
+
}
|
|
184
|
+
// Check cache first (10 second cache for network info)
|
|
185
|
+
if (this.networkCache && Date.now() - this.networkCache.timestamp < 10000) {
|
|
186
|
+
return this.networkCache.network;
|
|
187
|
+
}
|
|
85
188
|
try {
|
|
86
189
|
const networkInfo = yield this.adapter.network();
|
|
87
|
-
|
|
190
|
+
const networkStr = convertChainIdToDecimal(networkInfo.chainId);
|
|
191
|
+
// Cache the result
|
|
192
|
+
this.networkCache = {
|
|
193
|
+
network: networkStr,
|
|
194
|
+
timestamp: Date.now(),
|
|
195
|
+
};
|
|
196
|
+
return networkStr;
|
|
88
197
|
}
|
|
89
198
|
catch (error) {
|
|
199
|
+
// Handle rate limiting gracefully
|
|
200
|
+
if (error instanceof Error && error.message.includes('429')) {
|
|
201
|
+
logger.warn(`[${this.name}] Rate limited, returning cached network or mainnet`);
|
|
202
|
+
return ((_a = this.networkCache) === null || _a === void 0 ? void 0 : _a.network) || '728126428'; // Mainnet in decimal format
|
|
203
|
+
}
|
|
90
204
|
// If adapter is not connected, fall back to mainnet
|
|
91
205
|
return '728126428'; // Mainnet in decimal format
|
|
92
206
|
}
|
|
@@ -97,6 +211,10 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
97
211
|
*/
|
|
98
212
|
isTestnet() {
|
|
99
213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
// Don't create adapter if it doesn't exist yet (prevents initialization crashes)
|
|
215
|
+
if (!this.adapter) {
|
|
216
|
+
return false; // Assume mainnet if not connected
|
|
217
|
+
}
|
|
100
218
|
try {
|
|
101
219
|
const networkInfo = yield this.adapter.network();
|
|
102
220
|
// Testnet networkTypes: Shasta, Nile
|
|
@@ -104,6 +222,11 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
104
222
|
networkInfo.networkType === 'Nile');
|
|
105
223
|
}
|
|
106
224
|
catch (error) {
|
|
225
|
+
// Handle rate limiting gracefully - assume mainnet (not testnet)
|
|
226
|
+
if (error instanceof Error && error.message.includes('429')) {
|
|
227
|
+
logger.warn(`[${this.name}] Rate limited, assuming mainnet (not testnet)`);
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
107
230
|
// If adapter is not connected, assume mainnet (not testnet)
|
|
108
231
|
return false;
|
|
109
232
|
}
|
|
@@ -114,7 +237,10 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
114
237
|
*/
|
|
115
238
|
signMessage(messageToSign) {
|
|
116
239
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
|
|
240
|
+
if (!this.adapter) {
|
|
241
|
+
throw new DynamicError('Wallet not connected');
|
|
242
|
+
}
|
|
243
|
+
const { adapter } = { adapter: this.adapter };
|
|
118
244
|
if (!adapter.connected) {
|
|
119
245
|
throw new DynamicError('Wallet not connected');
|
|
120
246
|
}
|
|
@@ -130,36 +256,70 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
130
256
|
}
|
|
131
257
|
/**
|
|
132
258
|
* Get the TronWeb instance from the adapter
|
|
133
|
-
*
|
|
259
|
+
*
|
|
260
|
+
* CRITICAL: Each adapter maintains its own _wallet.tronWeb reference
|
|
261
|
+
* to avoid collision. We access it through the adapter's internal state,
|
|
262
|
+
* NOT through global window objects.
|
|
263
|
+
*
|
|
264
|
+
* This is the key insight from the tronwallet-adapter implementation:
|
|
265
|
+
* - TronLink stores in _wallet (can be window.tronLink or window.tron.tronWeb)
|
|
266
|
+
* - TokenPocket stores in _wallet (from window.tokenpocket.tronWeb)
|
|
267
|
+
* - BitKeep stores in _wallet (from window.bitkeep.tronWeb)
|
|
268
|
+
* - Each adapter handles its own detection and isolation
|
|
134
269
|
*/
|
|
135
270
|
getWalletTronWeb() {
|
|
136
|
-
var _a;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (adapter.tronWeb) {
|
|
140
|
-
return adapter.tronWeb;
|
|
271
|
+
var _a, _b, _c;
|
|
272
|
+
if (!this.adapter) {
|
|
273
|
+
return undefined;
|
|
141
274
|
}
|
|
142
|
-
|
|
275
|
+
const adapter = this.adapter;
|
|
276
|
+
// The adapter's internal wallet contains the wallet-specific TronWeb
|
|
277
|
+
// This is the safe way to access it without collisions
|
|
143
278
|
if ((_a = adapter._wallet) === null || _a === void 0 ? void 0 : _a.tronWeb) {
|
|
144
279
|
return adapter._wallet.tronWeb;
|
|
145
280
|
}
|
|
281
|
+
// Some adapters nest it under _wallet.tron.tronWeb
|
|
282
|
+
if ((_c = (_b = adapter._wallet) === null || _b === void 0 ? void 0 : _b.tron) === null || _c === void 0 ? void 0 : _c.tronWeb) {
|
|
283
|
+
return adapter._wallet.tron.tronWeb;
|
|
284
|
+
}
|
|
146
285
|
return undefined;
|
|
147
286
|
}
|
|
148
287
|
/**
|
|
149
|
-
* Get balance of an address
|
|
288
|
+
* Get balance of an address with caching to prevent rate limiting
|
|
150
289
|
*/
|
|
151
290
|
getBalance(address) {
|
|
152
291
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
292
|
var _a;
|
|
293
|
+
if (!this.adapter) {
|
|
294
|
+
return '0';
|
|
295
|
+
}
|
|
296
|
+
// Check cache first (5 second cache)
|
|
297
|
+
const cached = this.balanceCache.get(address);
|
|
298
|
+
if (cached && Date.now() - cached.timestamp < 5000) {
|
|
299
|
+
return cached.balance;
|
|
300
|
+
}
|
|
301
|
+
// Get TronWeb from the adapter's internal wallet state
|
|
154
302
|
const tronWeb = this.getWalletTronWeb();
|
|
155
303
|
if (!((_a = tronWeb === null || tronWeb === void 0 ? void 0 : tronWeb.trx) === null || _a === void 0 ? void 0 : _a.getBalance)) {
|
|
304
|
+
logger.debug(`[${this.name}] TronWeb not available for balance check`);
|
|
156
305
|
return '0';
|
|
157
306
|
}
|
|
158
307
|
try {
|
|
159
308
|
const balance = yield tronWeb.trx.getBalance(address);
|
|
160
|
-
|
|
309
|
+
const balanceStr = (balance / 1000000).toFixed(6); // SUN → TRX
|
|
310
|
+
// Cache the result
|
|
311
|
+
this.balanceCache.set(address, {
|
|
312
|
+
balance: balanceStr,
|
|
313
|
+
timestamp: Date.now(),
|
|
314
|
+
});
|
|
315
|
+
return balanceStr;
|
|
161
316
|
}
|
|
162
317
|
catch (error) {
|
|
318
|
+
// Handle rate limiting gracefully
|
|
319
|
+
if (error instanceof Error && error.message.includes('429')) {
|
|
320
|
+
logger.warn(`[${this.name}] Rate limited, returning cached balance or 0`);
|
|
321
|
+
return (cached === null || cached === void 0 ? void 0 : cached.balance) || '0';
|
|
322
|
+
}
|
|
163
323
|
logger.error(`[${this.name}] Failed to get balance:`, error);
|
|
164
324
|
return '0';
|
|
165
325
|
}
|
|
@@ -184,15 +344,19 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
184
344
|
*/
|
|
185
345
|
getBlockExplorerUrlsForCurrentNetwork() {
|
|
186
346
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
var _a, _b, _c, _d;
|
|
347
|
+
var _a, _b, _c, _d, _e, _f;
|
|
348
|
+
if (!this.adapter) {
|
|
349
|
+
// If adapter is not connected, return mainnet block explorer URLs
|
|
350
|
+
return ((_b = (_a = this.tronNetworks.find((n) => String(n.chainId) === '728126428')) === null || _a === void 0 ? void 0 : _a.blockExplorerUrls) !== null && _b !== void 0 ? _b : []);
|
|
351
|
+
}
|
|
188
352
|
try {
|
|
189
353
|
const networkInfo = yield this.adapter.network();
|
|
190
354
|
const decimalChainId = convertChainIdToDecimal(networkInfo.chainId);
|
|
191
|
-
return ((
|
|
355
|
+
return ((_d = (_c = this.tronNetworks.find((n) => String(n.chainId) === decimalChainId)) === null || _c === void 0 ? void 0 : _c.blockExplorerUrls) !== null && _d !== void 0 ? _d : []);
|
|
192
356
|
}
|
|
193
357
|
catch (error) {
|
|
194
358
|
// If adapter is not connected, return mainnet block explorer URLs
|
|
195
|
-
return ((
|
|
359
|
+
return ((_f = (_e = this.tronNetworks.find((n) => String(n.chainId) === '728126428')) === null || _e === void 0 ? void 0 : _e.blockExplorerUrls) !== null && _f !== void 0 ? _f : []);
|
|
196
360
|
}
|
|
197
361
|
});
|
|
198
362
|
}
|
|
@@ -201,52 +365,20 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
201
365
|
*/
|
|
202
366
|
endSession() {
|
|
203
367
|
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
-
|
|
205
|
-
if (adapter.connected) {
|
|
368
|
+
var _a;
|
|
369
|
+
if ((_a = this.adapter) === null || _a === void 0 ? void 0 : _a.connected) {
|
|
206
370
|
try {
|
|
207
|
-
yield adapter.disconnect();
|
|
371
|
+
yield this.adapter.disconnect();
|
|
208
372
|
}
|
|
209
373
|
catch (error) {
|
|
210
374
|
logger.debug(`[${this.name}] Error during disconnect:`, error);
|
|
211
375
|
}
|
|
212
376
|
}
|
|
377
|
+
// Clear caches on disconnect
|
|
378
|
+
this.balanceCache.clear();
|
|
379
|
+
this.networkCache = null;
|
|
213
380
|
});
|
|
214
381
|
}
|
|
215
|
-
/**
|
|
216
|
-
* Setup event listeners - called by Dynamic's initEventListener()
|
|
217
|
-
*/
|
|
218
|
-
setupEventListeners() {
|
|
219
|
-
const { adapter } = this;
|
|
220
|
-
// Connect event
|
|
221
|
-
adapter.on('connect', (address) => {
|
|
222
|
-
this.emit('accountChange', {
|
|
223
|
-
accounts: [address],
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
// Disconnect event
|
|
227
|
-
adapter.on('disconnect', () => {
|
|
228
|
-
this.emit('disconnect');
|
|
229
|
-
});
|
|
230
|
-
// Account change event
|
|
231
|
-
adapter.on('accountsChanged', (address) => {
|
|
232
|
-
this.emit('accountChange', {
|
|
233
|
-
accounts: [address],
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
// Chain change event
|
|
237
|
-
adapter.on('chainChanged', (chainData) => {
|
|
238
|
-
const data = chainData;
|
|
239
|
-
this.emit('chainChange', {
|
|
240
|
-
chain: data.chainId,
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Cleanup event listeners
|
|
246
|
-
*/
|
|
247
|
-
teardownEventListeners() {
|
|
248
|
-
this.adapter.removeAllListeners();
|
|
249
|
-
}
|
|
250
382
|
/**
|
|
251
383
|
* Create a UI transaction for the send balance flow
|
|
252
384
|
*
|
|
@@ -256,7 +388,7 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
|
|
|
256
388
|
createUiTransaction(from) {
|
|
257
389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
258
390
|
yield this.validateActiveWallet(from);
|
|
259
|
-
// Get TronWeb from the wallet
|
|
391
|
+
// Get TronWeb from the adapter's internal wallet state
|
|
260
392
|
const tronWeb = this.getWalletTronWeb();
|
|
261
393
|
if (!tronWeb) {
|
|
262
394
|
throw new DynamicError('TronWeb not available');
|
package/src/index.cjs
CHANGED
|
@@ -5,20 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
7
7
|
var _package = require('../package.cjs');
|
|
8
|
-
var
|
|
9
|
-
var OKXTronConnector = require('./connectors/OKXTronConnector/OKXTronConnector.cjs');
|
|
10
|
-
var TokenPocketTronConnector = require('./connectors/TokenPocketTronConnector/TokenPocketTronConnector.cjs');
|
|
11
|
-
var TrustTronConnector = require('./connectors/TrustTronConnector/TrustTronConnector.cjs');
|
|
8
|
+
var fetchTronWalletAdapterConnectors = require('./utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.cjs');
|
|
12
9
|
var TronWallet = require('./wallet/TronWallet/TronWallet.cjs');
|
|
13
10
|
var isTronWallet = require('./wallet/isTronWallet/isTronWallet.cjs');
|
|
14
11
|
|
|
15
12
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/tron', _package.version);
|
|
16
|
-
const TronWalletConnectors = () => [
|
|
17
|
-
BitgetTronConnector.BitgetTronConnector,
|
|
18
|
-
OKXTronConnector.OKXTronConnector,
|
|
19
|
-
TokenPocketTronConnector.TokenPocketTronConnector,
|
|
20
|
-
TrustTronConnector.TrustTronConnector,
|
|
21
|
-
];
|
|
13
|
+
const TronWalletConnectors = (props) => [...fetchTronWalletAdapterConnectors.fetchTronWalletAdapterConnectors(props)];
|
|
22
14
|
|
|
23
15
|
exports.TronWallet = TronWallet.TronWallet;
|
|
24
16
|
exports.isTronWallet = isTronWallet.isTronWallet;
|
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { BitgetTronConnector } from './connectors/BitgetTronConnector';
|
|
2
|
-
import { OKXTronConnector } from './connectors/OKXTronConnector';
|
|
3
|
-
import { TokenPocketTronConnector } from './connectors/TokenPocketTronConnector';
|
|
4
|
-
import { TrustTronConnector } from './connectors/TrustTronConnector';
|
|
5
1
|
export { TronWallet } from './wallet/TronWallet';
|
|
6
2
|
export { isTronWallet } from './wallet/isTronWallet';
|
|
7
|
-
export declare const TronWalletConnectors: (
|
|
3
|
+
export declare const TronWalletConnectors: (props: {
|
|
4
|
+
walletBook: any;
|
|
5
|
+
tronNetworks: any[];
|
|
6
|
+
}) => import("dist/packages/wallet-connector-core/src").WalletConnectorConstructor[];
|
package/src/index.js
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
3
|
import { version } from '../package.js';
|
|
4
|
-
import {
|
|
5
|
-
import { OKXTronConnector } from './connectors/OKXTronConnector/OKXTronConnector.js';
|
|
6
|
-
import { TokenPocketTronConnector } from './connectors/TokenPocketTronConnector/TokenPocketTronConnector.js';
|
|
7
|
-
import { TrustTronConnector } from './connectors/TrustTronConnector/TrustTronConnector.js';
|
|
4
|
+
import { fetchTronWalletAdapterConnectors } from './utils/fetchTronWalletAdapterConnectors/fetchTronWalletAdapterConnectors.js';
|
|
8
5
|
export { TronWallet } from './wallet/TronWallet/TronWallet.js';
|
|
9
6
|
export { isTronWallet } from './wallet/isTronWallet/isTronWallet.js';
|
|
10
7
|
|
|
11
8
|
assertPackageVersion('@dynamic-labs/tron', version);
|
|
12
|
-
const TronWalletConnectors = () => [
|
|
13
|
-
BitgetTronConnector,
|
|
14
|
-
OKXTronConnector,
|
|
15
|
-
TokenPocketTronConnector,
|
|
16
|
-
TrustTronConnector,
|
|
17
|
-
];
|
|
9
|
+
const TronWalletConnectors = (props) => [...fetchTronWalletAdapterConnectors(props)];
|
|
18
10
|
|
|
19
11
|
export { TronWalletConnectors };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var walletBook = require('@dynamic-labs/wallet-book');
|
|
7
|
+
var TronWalletAdapterConnector = require('../../connectors/TronWalletAdapterConnector/TronWalletAdapterConnector.cjs');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a wallet configuration supports TronWallet Adapters.
|
|
11
|
+
*
|
|
12
|
+
* A wallet is considered valid if it has:
|
|
13
|
+
* - An injected config for the 'tron' chain
|
|
14
|
+
* - The tronwallet-adapters feature included in wallet standard features
|
|
15
|
+
* - A valid provider ID
|
|
16
|
+
*
|
|
17
|
+
* @param wallet - The wallet configuration to check
|
|
18
|
+
* @returns true if the wallet supports TronWallet Adapters, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
const isValidTronWalletAdapterWallet = (wallet) => {
|
|
21
|
+
var _a;
|
|
22
|
+
return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
return config.chain === 'tron' &&
|
|
25
|
+
Array.isArray((_a = config.walletStandard) === null || _a === void 0 ? void 0 : _a.features) &&
|
|
26
|
+
config.walletStandard.features.includes('tronwallet-adapters:') &&
|
|
27
|
+
((_b = config.walletStandard) === null || _b === void 0 ? void 0 : _b.providerId);
|
|
28
|
+
}));
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Fetches all Tron wallet connectors that support TronWallet Adapters from the wallet book.
|
|
32
|
+
*
|
|
33
|
+
* This function scans the wallet book for wallets with Tron chain configuration
|
|
34
|
+
* and creates connector classes for each matching wallet.
|
|
35
|
+
*
|
|
36
|
+
* @param walletBook - The wallet book schema containing all wallet configurations
|
|
37
|
+
* @param tronNetworks - The Tron networks configuration
|
|
38
|
+
* @returns Array of wallet connector constructors for TronWallet Adapter enabled wallets
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const tronConnectors = fetchTronWalletAdapterConnectors({ walletBook, tronNetworks });
|
|
43
|
+
* // Returns connectors for wallets like TronLink, TokenPocket, OKX, etc.
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
const fetchTronWalletAdapterConnectors = ({ walletBook: walletBook$1, tronNetworks, }) => {
|
|
47
|
+
var _a;
|
|
48
|
+
return Object.entries((_a = walletBook$1 === null || walletBook$1 === void 0 ? void 0 : walletBook$1.wallets) !== null && _a !== void 0 ? _a : {})
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
50
|
+
.filter(([_, wallet]) => isValidTronWalletAdapterWallet(wallet))
|
|
51
|
+
.map(([key, wallet]) => {
|
|
52
|
+
const { shortName } = wallet;
|
|
53
|
+
const name = shortName || wallet.name;
|
|
54
|
+
return class extends TronWalletAdapterConnector.TronWalletAdapterConnector {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
constructor(props) {
|
|
57
|
+
var _a;
|
|
58
|
+
super(Object.assign(Object.assign({}, props), { metadata: {
|
|
59
|
+
brandColor: undefined,
|
|
60
|
+
deepLinks: undefined,
|
|
61
|
+
downloadLinks: undefined,
|
|
62
|
+
groupKey: undefined,
|
|
63
|
+
icon: ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.brand) === null || _a === void 0 ? void 0 : _a.spriteId)
|
|
64
|
+
? walletBook.renderTemplate('iconicUrl', wallet.brand.spriteId)
|
|
65
|
+
: '',
|
|
66
|
+
id: key,
|
|
67
|
+
name: name,
|
|
68
|
+
rdns: undefined,
|
|
69
|
+
supportedHardwareWallets: undefined,
|
|
70
|
+
walletLimitations: undefined,
|
|
71
|
+
}, overrideKey: key, tronNetworks, walletData: wallet }));
|
|
72
|
+
this.name = name;
|
|
73
|
+
this.overrideKey = key;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.fetchTronWalletAdapterConnectors = fetchTronWalletAdapterConnectors;
|
|
80
|
+
exports.isValidTronWalletAdapterWallet = isValidTronWalletAdapterWallet;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
2
|
+
import { WalletConnectorConstructor } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import type { GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a wallet configuration supports TronWallet Adapters.
|
|
6
|
+
*
|
|
7
|
+
* A wallet is considered valid if it has:
|
|
8
|
+
* - An injected config for the 'tron' chain
|
|
9
|
+
* - The tronwallet-adapters feature included in wallet standard features
|
|
10
|
+
* - A valid provider ID
|
|
11
|
+
*
|
|
12
|
+
* @param wallet - The wallet configuration to check
|
|
13
|
+
* @returns true if the wallet supports TronWallet Adapters, false otherwise
|
|
14
|
+
*/
|
|
15
|
+
export declare const isValidTronWalletAdapterWallet: (wallet: WalletBookSchema['wallets'][string]) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Fetches all Tron wallet connectors that support TronWallet Adapters from the wallet book.
|
|
18
|
+
*
|
|
19
|
+
* This function scans the wallet book for wallets with Tron chain configuration
|
|
20
|
+
* and creates connector classes for each matching wallet.
|
|
21
|
+
*
|
|
22
|
+
* @param walletBook - The wallet book schema containing all wallet configurations
|
|
23
|
+
* @param tronNetworks - The Tron networks configuration
|
|
24
|
+
* @returns Array of wallet connector constructors for TronWallet Adapter enabled wallets
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const tronConnectors = fetchTronWalletAdapterConnectors({ walletBook, tronNetworks });
|
|
29
|
+
* // Returns connectors for wallets like TronLink, TokenPocket, OKX, etc.
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const fetchTronWalletAdapterConnectors: ({ walletBook, tronNetworks, }: {
|
|
33
|
+
walletBook: WalletBookSchema;
|
|
34
|
+
tronNetworks: GenericNetwork[];
|
|
35
|
+
}) => WalletConnectorConstructor[];
|