@dynamic-labs/tron 4.45.2 → 4.45.3

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,20 @@
1
1
 
2
+ ### [4.45.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.2...v4.45.3) (2025-11-18)
3
+
4
+
5
+ ### Features
6
+
7
+ * add trc20 token transfer to dynamic widget ([#9877](https://github.com/dynamic-labs/dynamic-auth/issues/9877)) ([4365102](https://github.com/dynamic-labs/dynamic-auth/commit/436510253436239d64d4f47b7d0532e65401c19d))
8
+ * add trc20 tokens to sendBalance ([#9873](https://github.com/dynamic-labs/dynamic-auth/issues/9873)) ([fec5e67](https://github.com/dynamic-labs/dynamic-auth/commit/fec5e6715f87fd6a3f7b2ca21c94e4f32ec86031))
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * don't allow mobileExperience override to redirect for wallets that don't support it ([#9865](https://github.com/dynamic-labs/dynamic-auth/issues/9865)) ([b34ada5](https://github.com/dynamic-labs/dynamic-auth/commit/b34ada5ac0450667bf33b3cf2ce13e5c16235cfc))
14
+ * **global-wallet:** validate the redirect url ([#9894](https://github.com/dynamic-labs/dynamic-auth/issues/9894)) ([4cf27b5](https://github.com/dynamic-labs/dynamic-auth/commit/4cf27b538da5a9d1da04160faad009880f15f175))
15
+ * temporarily skip Phantom account creation steps due to extension… ([#9893](https://github.com/dynamic-labs/dynamic-auth/issues/9893)) ([87f8a2e](https://github.com/dynamic-labs/dynamic-auth/commit/87f8a2e1185be09c255e7865980f02b13e916db4))
16
+ * wallet book is required console errors ([#9887](https://github.com/dynamic-labs/dynamic-auth/issues/9887)) ([417605d](https://github.com/dynamic-labs/dynamic-auth/commit/417605d605f70ee558dd550b1fb50c996f219b31))
17
+
2
18
  ### [4.45.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.45.1...v4.45.2) (2025-11-17)
3
19
 
4
20
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.45.2";
6
+ var version = "4.45.3";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.45.2";
2
+ var version = "4.45.3";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/tron",
3
- "version": "4.45.2",
3
+ "version": "4.45.3",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,14 +18,14 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/assert-package-version": "4.45.2",
21
+ "@dynamic-labs/assert-package-version": "4.45.3",
22
22
  "@tronweb3/tronwallet-abstract-adapter": "1.1.9",
23
23
  "@tronweb3/tronwallet-adapters": "1.2.14",
24
24
  "tronweb": "6.0.4",
25
- "@dynamic-labs/types": "4.45.2",
26
- "@dynamic-labs/utils": "4.45.2",
27
- "@dynamic-labs/wallet-book": "4.45.2",
28
- "@dynamic-labs/wallet-connector-core": "4.45.2"
25
+ "@dynamic-labs/types": "4.45.3",
26
+ "@dynamic-labs/utils": "4.45.3",
27
+ "@dynamic-labs/wallet-book": "4.45.3",
28
+ "@dynamic-labs/wallet-connector-core": "4.45.3"
29
29
  },
30
30
  "peerDependencies": {}
31
31
  }
@@ -415,8 +415,17 @@ class TronWalletAdapterConnector extends walletConnectorCore.WalletConnectorBase
415
415
  key: 'temp-key',
416
416
  });
417
417
  if (transaction.nonNativeAddress && transaction.nonNativeValue) {
418
- // Handle TRC20 token transfers - not yet implemented
419
- throw new utils.DynamicError('TRC20 token transfers not yet implemented');
418
+ const result = yield wallet.sendTrc20({
419
+ amount: transaction.formatNonNativeToken(transaction.nonNativeValue, transaction.nonNativeDecimal || 18),
420
+ toAddress: transaction.to,
421
+ token: {
422
+ address: transaction.nonNativeAddress,
423
+ },
424
+ });
425
+ if (!result) {
426
+ throw new utils.DynamicError('Failed to send TRC20 token');
427
+ }
428
+ return result;
420
429
  }
421
430
  else if (transaction.value) {
422
431
  // Handle native TRX transfers
@@ -411,8 +411,17 @@ class TronWalletAdapterConnector extends WalletConnectorBase {
411
411
  key: 'temp-key',
412
412
  });
413
413
  if (transaction.nonNativeAddress && transaction.nonNativeValue) {
414
- // Handle TRC20 token transfers - not yet implemented
415
- throw new DynamicError('TRC20 token transfers not yet implemented');
414
+ const result = yield wallet.sendTrc20({
415
+ amount: transaction.formatNonNativeToken(transaction.nonNativeValue, transaction.nonNativeDecimal || 18),
416
+ toAddress: transaction.to,
417
+ token: {
418
+ address: transaction.nonNativeAddress,
419
+ },
420
+ });
421
+ if (!result) {
422
+ throw new DynamicError('Failed to send TRC20 token');
423
+ }
424
+ return result;
416
425
  }
417
426
  else if (transaction.value) {
418
427
  // Handle native TRX transfers
@@ -0,0 +1 @@
1
+ export { isNonNativeTronTransactionType } from './nonNativeTronTransactionType';
@@ -0,0 +1,16 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const isNonNativeTronTransactionType = (contractAddress) => {
7
+ if (!isNaN(Number(contractAddress))) {
8
+ return 'trc10';
9
+ }
10
+ if (contractAddress.startsWith('T')) {
11
+ return 'trc20';
12
+ }
13
+ return undefined;
14
+ };
15
+
16
+ exports.isNonNativeTronTransactionType = isNonNativeTronTransactionType;
@@ -0,0 +1 @@
1
+ export declare const isNonNativeTronTransactionType: (contractAddress: string) => 'trc20' | 'trc10' | undefined;
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ const isNonNativeTronTransactionType = (contractAddress) => {
3
+ if (!isNaN(Number(contractAddress))) {
4
+ return 'trc10';
5
+ }
6
+ if (contractAddress.startsWith('T')) {
7
+ return 'trc20';
8
+ }
9
+ return undefined;
10
+ };
11
+
12
+ export { isNonNativeTronTransactionType };
@@ -6,6 +6,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../../_virtual/_tslib.cjs');
7
7
  var utils = require('@dynamic-labs/utils');
8
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var nonNativeTronTransactionType = require('../../utils/nonNativeTronTransactionType/nonNativeTronTransactionType.cjs');
10
+ var getTronGasEstimation = require('../../utils/getTronGasEstimation/getTronGasEstimation.cjs');
9
11
 
10
12
  class TronWallet extends walletConnectorCore.Wallet {
11
13
  constructor(props) {
@@ -48,11 +50,74 @@ class TronWallet extends walletConnectorCore.Wallet {
48
50
  * Send balance (sends TRX)
49
51
  */
50
52
  sendBalance(_a) {
51
- return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
53
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
54
+ if (token && token.address) {
55
+ const transactionType = nonNativeTronTransactionType.isNonNativeTronTransactionType(token.address);
56
+ if (transactionType === 'trc20') {
57
+ const result = yield this.sendTrc20({
58
+ amount,
59
+ toAddress,
60
+ token,
61
+ });
62
+ return result;
63
+ }
64
+ throw new utils.DynamicError(`Unsupported transaction type: ${transactionType}`);
65
+ }
52
66
  const result = yield this.sendTrx(toAddress, Number(amount));
53
67
  return result.txid;
54
68
  });
55
69
  }
70
+ /**
71
+ * Send TRC20 token to an address
72
+ *
73
+ * @param amount - Amount as a string (in token units, e.g., "1.5" for 1.5 tokens)
74
+ * @param toAddress - Recipient address
75
+ * @param token - Token contract address and decimals
76
+ * @param options - Optional parameters including from address and fee limit
77
+ * @returns Transaction result with txid
78
+ */
79
+ sendTrc20(_a) {
80
+ return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, options, }) {
81
+ var _b;
82
+ const tronWeb = this.getTronWeb();
83
+ if (!(tronWeb === null || tronWeb === void 0 ? void 0 : tronWeb.contract)) {
84
+ throw new utils.DynamicError('TRC20 token operations not supported by this wallet');
85
+ }
86
+ const contract = yield tronWeb.contract().at(token.address);
87
+ const fromAddress = (options === null || options === void 0 ? void 0 : options.from) || this.address;
88
+ //
89
+ const decimals = token.decimals || Number((_b = (yield contract.decimals().call())) === null || _b === void 0 ? void 0 : _b.toString());
90
+ // Convert amount to smallest unit (considering decimals)
91
+ // e.g., if amount is "1.5" and decimals is 18, result should be "1500000000000000000"
92
+ const amountNumber = parseFloat(amount);
93
+ if (isNaN(amountNumber) || amountNumber < 0) {
94
+ throw new utils.DynamicError('Invalid token amount');
95
+ }
96
+ const amountInSmallestUnit = BigInt(Math.floor(amountNumber * Math.pow(10, decimals)));
97
+ // Default 5 TRX max fee limit until we implement the gas estimation
98
+ const feeLimit = (options === null || options === void 0 ? void 0 : options.feeLimit) ||
99
+ (yield getTronGasEstimation.getTronGasEstimation({
100
+ from: fromAddress,
101
+ nonNativeAddress: token.address,
102
+ nonNativeValue: amountInSmallestUnit,
103
+ to: toAddress,
104
+ tronWeb,
105
+ })) ||
106
+ 5000000;
107
+ try {
108
+ const result = yield contract
109
+ .transfer(toAddress, amountInSmallestUnit.toString())
110
+ .send({
111
+ feeLimit: feeLimit || 5000000, // Default 5 TRX max fee limit
112
+ from: fromAddress,
113
+ });
114
+ return result;
115
+ }
116
+ catch (error) {
117
+ throw new utils.DynamicError(`Failed to send TRC20 token: ${error instanceof Error ? error.message : String(error)}`);
118
+ }
119
+ });
120
+ }
56
121
  /**
57
122
  * Send TRX to an address
58
123
  *
@@ -18,9 +18,34 @@ export declare class TronWallet extends Wallet<TronWalletAdapterConnector> {
18
18
  /**
19
19
  * Send balance (sends TRX)
20
20
  */
21
- sendBalance({ amount, toAddress, }: {
21
+ sendBalance({ amount, toAddress, token, }: {
22
22
  amount: string;
23
23
  toAddress: string;
24
+ token?: {
25
+ address: string;
26
+ decimals?: number;
27
+ };
28
+ }): Promise<string | undefined>;
29
+ /**
30
+ * Send TRC20 token to an address
31
+ *
32
+ * @param amount - Amount as a string (in token units, e.g., "1.5" for 1.5 tokens)
33
+ * @param toAddress - Recipient address
34
+ * @param token - Token contract address and decimals
35
+ * @param options - Optional parameters including from address and fee limit
36
+ * @returns Transaction result with txid
37
+ */
38
+ sendTrc20({ amount, toAddress, token, options, }: {
39
+ amount: string;
40
+ toAddress: string;
41
+ token: {
42
+ address: string;
43
+ decimals?: number;
44
+ };
45
+ options?: {
46
+ from?: string;
47
+ feeLimit?: number;
48
+ };
24
49
  }): Promise<string | undefined>;
25
50
  /**
26
51
  * Send TRX to an address
@@ -2,6 +2,8 @@
2
2
  import { __awaiter } from '../../../_virtual/_tslib.js';
3
3
  import { DynamicError } from '@dynamic-labs/utils';
4
4
  import { Wallet } from '@dynamic-labs/wallet-connector-core';
5
+ import { isNonNativeTronTransactionType } from '../../utils/nonNativeTronTransactionType/nonNativeTronTransactionType.js';
6
+ import { getTronGasEstimation } from '../../utils/getTronGasEstimation/getTronGasEstimation.js';
5
7
 
6
8
  class TronWallet extends Wallet {
7
9
  constructor(props) {
@@ -44,11 +46,74 @@ class TronWallet extends Wallet {
44
46
  * Send balance (sends TRX)
45
47
  */
46
48
  sendBalance(_a) {
47
- return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, }) {
49
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, }) {
50
+ if (token && token.address) {
51
+ const transactionType = isNonNativeTronTransactionType(token.address);
52
+ if (transactionType === 'trc20') {
53
+ const result = yield this.sendTrc20({
54
+ amount,
55
+ toAddress,
56
+ token,
57
+ });
58
+ return result;
59
+ }
60
+ throw new DynamicError(`Unsupported transaction type: ${transactionType}`);
61
+ }
48
62
  const result = yield this.sendTrx(toAddress, Number(amount));
49
63
  return result.txid;
50
64
  });
51
65
  }
66
+ /**
67
+ * Send TRC20 token to an address
68
+ *
69
+ * @param amount - Amount as a string (in token units, e.g., "1.5" for 1.5 tokens)
70
+ * @param toAddress - Recipient address
71
+ * @param token - Token contract address and decimals
72
+ * @param options - Optional parameters including from address and fee limit
73
+ * @returns Transaction result with txid
74
+ */
75
+ sendTrc20(_a) {
76
+ return __awaiter(this, arguments, void 0, function* ({ amount, toAddress, token, options, }) {
77
+ var _b;
78
+ const tronWeb = this.getTronWeb();
79
+ if (!(tronWeb === null || tronWeb === void 0 ? void 0 : tronWeb.contract)) {
80
+ throw new DynamicError('TRC20 token operations not supported by this wallet');
81
+ }
82
+ const contract = yield tronWeb.contract().at(token.address);
83
+ const fromAddress = (options === null || options === void 0 ? void 0 : options.from) || this.address;
84
+ //
85
+ const decimals = token.decimals || Number((_b = (yield contract.decimals().call())) === null || _b === void 0 ? void 0 : _b.toString());
86
+ // Convert amount to smallest unit (considering decimals)
87
+ // e.g., if amount is "1.5" and decimals is 18, result should be "1500000000000000000"
88
+ const amountNumber = parseFloat(amount);
89
+ if (isNaN(amountNumber) || amountNumber < 0) {
90
+ throw new DynamicError('Invalid token amount');
91
+ }
92
+ const amountInSmallestUnit = BigInt(Math.floor(amountNumber * Math.pow(10, decimals)));
93
+ // Default 5 TRX max fee limit until we implement the gas estimation
94
+ const feeLimit = (options === null || options === void 0 ? void 0 : options.feeLimit) ||
95
+ (yield getTronGasEstimation({
96
+ from: fromAddress,
97
+ nonNativeAddress: token.address,
98
+ nonNativeValue: amountInSmallestUnit,
99
+ to: toAddress,
100
+ tronWeb,
101
+ })) ||
102
+ 5000000;
103
+ try {
104
+ const result = yield contract
105
+ .transfer(toAddress, amountInSmallestUnit.toString())
106
+ .send({
107
+ feeLimit: feeLimit || 5000000, // Default 5 TRX max fee limit
108
+ from: fromAddress,
109
+ });
110
+ return result;
111
+ }
112
+ catch (error) {
113
+ throw new DynamicError(`Failed to send TRC20 token: ${error instanceof Error ? error.message : String(error)}`);
114
+ }
115
+ });
116
+ }
52
117
  /**
53
118
  * Send TRX to an address
54
119
  *