@dynamic-labs/ton 4.51.2 → 4.52.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 +9 -0
- package/_virtual/_tslib.cjs +36 -0
- package/_virtual/_tslib.js +32 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +6 -2
- package/src/index.cjs +6 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -0
- package/src/utils/TonUiTransaction/TonUiTransaction.cjs +158 -0
- package/src/utils/TonUiTransaction/TonUiTransaction.d.ts +76 -0
- package/src/utils/TonUiTransaction/TonUiTransaction.js +153 -0
- package/src/utils/TonUiTransaction/index.d.ts +1 -0
- package/src/utils/index.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
|
|
2
|
+
## [4.52.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.51.2...v4.52.0) (2025-12-22)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add dynamic waas ton connector ([#9981](https://github.com/dynamic-labs/dynamic-auth/issues/9981)) ([95f2ecf](https://github.com/dynamic-labs/dynamic-auth/commit/95f2ecf253550ec8badad588a904599321a5846d))
|
|
8
|
+
* add getTransactionHistory to react-native ([#10132](https://github.com/dynamic-labs/dynamic-auth/issues/10132)) ([bed6ce1](https://github.com/dynamic-labs/dynamic-auth/commit/bed6ce13b5e12f80121eebf6421355ae2b87968d))
|
|
9
|
+
* add useGetTransactionHistory hook ([#10131](https://github.com/dynamic-labs/dynamic-auth/issues/10131)) ([431e7e1](https://github.com/dynamic-labs/dynamic-auth/commit/431e7e1a70cd0556c14f55c2827bb419f38a59c9))
|
|
10
|
+
|
|
2
11
|
### [4.51.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.51.1...v4.51.2) (2025-12-19)
|
|
3
12
|
|
|
4
13
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
/******************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
|
|
21
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
32
|
+
var e = new Error(message);
|
|
33
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.__awaiter = __awaiter;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
/******************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
9
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
10
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
11
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
12
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
13
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
14
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
|
|
17
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
28
|
+
var e = new Error(message);
|
|
29
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { __awaiter };
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ton",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.52.0",
|
|
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,6 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
21
|
+
"@dynamic-labs/assert-package-version": "4.52.0",
|
|
22
|
+
"@dynamic-labs/types": "4.52.0",
|
|
23
|
+
"@dynamic-labs/utils": "4.52.0",
|
|
24
|
+
"@dynamic-labs/wallet-connector-core": "4.52.0",
|
|
25
|
+
"@ton/ton": "16.0.0"
|
|
22
26
|
}
|
|
23
27
|
}
|
package/src/index.cjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
4
6
|
var assertPackageVersion = require('@dynamic-labs/assert-package-version');
|
|
5
7
|
var _package = require('../package.cjs');
|
|
8
|
+
var TonUiTransaction = require('./utils/TonUiTransaction/TonUiTransaction.cjs');
|
|
6
9
|
|
|
7
10
|
assertPackageVersion.assertPackageVersion('@dynamic-labs/ton', _package.version);
|
|
11
|
+
|
|
12
|
+
exports.NANOTON_PER_TON = TonUiTransaction.NANOTON_PER_TON;
|
|
13
|
+
exports.TonUiTransaction = TonUiTransaction.TonUiTransaction;
|
package/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './utils';
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { assertPackageVersion } from '@dynamic-labs/assert-package-version';
|
|
3
3
|
import { version } from '../package.js';
|
|
4
|
+
export { NANOTON_PER_TON, TonUiTransaction } from './utils/TonUiTransaction/TonUiTransaction.js';
|
|
4
5
|
|
|
5
6
|
assertPackageVersion('@dynamic-labs/ton', version);
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var _tslib = require('../../../_virtual/_tslib.cjs');
|
|
7
|
+
var ton = require('@ton/ton');
|
|
8
|
+
var utils = require('@dynamic-labs/utils');
|
|
9
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 1 TON = 1,000,000,000 nanoTON (atomic units)
|
|
13
|
+
*/
|
|
14
|
+
const NANOTON_PER_TON = 1000000000;
|
|
15
|
+
/**
|
|
16
|
+
* TonUiTransaction class for managing TON transactions in the UI
|
|
17
|
+
*/
|
|
18
|
+
class TonUiTransaction {
|
|
19
|
+
constructor({ onSubmit, from, client }) {
|
|
20
|
+
this.chain = 'TON';
|
|
21
|
+
this.data = undefined;
|
|
22
|
+
this.fee = { gas: undefined };
|
|
23
|
+
this.from = from;
|
|
24
|
+
this.onSubmit = onSubmit;
|
|
25
|
+
this.client = client;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* TODO: Implement dynamic fee estimation using client.estimateFee()
|
|
29
|
+
*/
|
|
30
|
+
fetchFee() {
|
|
31
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (this.fee.gas !== undefined)
|
|
33
|
+
return;
|
|
34
|
+
// Default conservative estimate: 0.01 TON for simple transfers
|
|
35
|
+
// This covers most native TON transfers
|
|
36
|
+
const DEFAULT_FEE = BigInt(10000000);
|
|
37
|
+
// For jetton transfers, fees are higher due to multiple messages
|
|
38
|
+
const DEFAULT_JETTON_FEE = BigInt(50000000);
|
|
39
|
+
if (this.nonNativeAddress) {
|
|
40
|
+
this.fee.gas = DEFAULT_JETTON_FEE;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.fee.gas = DEFAULT_FEE;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse string input to bigint (for TON)
|
|
49
|
+
*/
|
|
50
|
+
parse(input) {
|
|
51
|
+
const [whole, fraction = '0'] = input.split('.');
|
|
52
|
+
const numericWhole = parseInt(whole, 10);
|
|
53
|
+
if (isNaN(numericWhole))
|
|
54
|
+
return BigInt(0);
|
|
55
|
+
const paddedFraction = fraction.padEnd(9, '0').slice(0, 9);
|
|
56
|
+
return (BigInt(numericWhole) * BigInt(NANOTON_PER_TON) +
|
|
57
|
+
BigInt(parseInt(paddedFraction, 10)));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse string input to bigint (for Jetton tokens)
|
|
61
|
+
*/
|
|
62
|
+
parseNonNativeToken(input, decimals) {
|
|
63
|
+
const [whole, fraction = '0'] = input.split('.');
|
|
64
|
+
const numericWhole = parseInt(whole, 10);
|
|
65
|
+
if (isNaN(numericWhole))
|
|
66
|
+
return BigInt(0);
|
|
67
|
+
const paddedFraction = fraction.padEnd(decimals, '0').slice(0, decimals);
|
|
68
|
+
return (BigInt(numericWhole) * BigInt(Math.pow(10, decimals)) +
|
|
69
|
+
BigInt(parseInt(paddedFraction, 10)));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Format bigint value to string (for TON)
|
|
73
|
+
*/
|
|
74
|
+
format(value, options) {
|
|
75
|
+
var _a;
|
|
76
|
+
const precision = (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 9;
|
|
77
|
+
const divisor = BigInt(NANOTON_PER_TON);
|
|
78
|
+
const whole = value / divisor;
|
|
79
|
+
const remainder = value % divisor;
|
|
80
|
+
const fractional = remainder.toString().padStart(9, '0');
|
|
81
|
+
return utils.formatNumberText(`${whole}.${fractional}`, { precision });
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Format bigint value to string (for Jetton tokens)
|
|
85
|
+
*/
|
|
86
|
+
formatNonNativeToken(value, decimals) {
|
|
87
|
+
const divisor = BigInt(Math.pow(10, decimals));
|
|
88
|
+
const whole = value / divisor;
|
|
89
|
+
const remainder = value % divisor;
|
|
90
|
+
const fractional = remainder.toString().padStart(decimals, '0');
|
|
91
|
+
return utils.formatNumberText(`${whole}.${fractional}`, {
|
|
92
|
+
precision: decimals > 9 ? 9 : decimals,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Submit the transaction
|
|
97
|
+
*/
|
|
98
|
+
submit() {
|
|
99
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
if (!this.to) {
|
|
101
|
+
throw new Error('Destination address is required');
|
|
102
|
+
}
|
|
103
|
+
if (!this.value && !this.nonNativeValue) {
|
|
104
|
+
throw new Error('Transaction value is required');
|
|
105
|
+
}
|
|
106
|
+
return this.onSubmit(this);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the balance for the from address
|
|
111
|
+
*/
|
|
112
|
+
getBalance() {
|
|
113
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
try {
|
|
115
|
+
if (this.nonNativeAddress) {
|
|
116
|
+
walletConnectorCore.logger.debug('Jetton balance fetching not yet implemented');
|
|
117
|
+
return BigInt(0);
|
|
118
|
+
}
|
|
119
|
+
const address = ton.Address.parse(this.from);
|
|
120
|
+
const balance = yield this.client.getBalance(address);
|
|
121
|
+
return balance;
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
walletConnectorCore.logger.error('Error occurred while fetching TON balance. Please try again or contact support.');
|
|
125
|
+
return BigInt(0);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Validate TON address format
|
|
131
|
+
*
|
|
132
|
+
* TON addresses can be in multiple formats:
|
|
133
|
+
* - Raw: 0:<64 hex chars> (workchain:hash)
|
|
134
|
+
* - User-friendly: Base64 encoded, starts with E/U (bounceable) or 0 (non-bounceable)
|
|
135
|
+
*/
|
|
136
|
+
validateAddressFormat(address) {
|
|
137
|
+
if (address === 'dyn_send_transaction.multiple_recipients') {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
// Use @ton/ton's Address.parse which handles all formats
|
|
142
|
+
ton.Address.parse(address);
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
catch (_a) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Check if gas is sponsored
|
|
151
|
+
*/
|
|
152
|
+
isGasSponsored() {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
exports.NANOTON_PER_TON = NANOTON_PER_TON;
|
|
158
|
+
exports.TonUiTransaction = TonUiTransaction;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { TonClient } from '@ton/ton';
|
|
2
|
+
import { IUITransaction, IUITransactionFormatOptions } from '@dynamic-labs/types';
|
|
3
|
+
/**
|
|
4
|
+
* 1 TON = 1,000,000,000 nanoTON (atomic units)
|
|
5
|
+
*/
|
|
6
|
+
export declare const NANOTON_PER_TON = 1000000000;
|
|
7
|
+
type TonUiTransactionProps = {
|
|
8
|
+
/** TON Address of the sender */
|
|
9
|
+
from: string;
|
|
10
|
+
/** The TonClient instance for interacting with the network */
|
|
11
|
+
client: TonClient;
|
|
12
|
+
/** The function to call when the transaction is submitted */
|
|
13
|
+
onSubmit: (transaction: TonUiTransaction) => Promise<string>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* TonUiTransaction class for managing TON transactions in the UI
|
|
17
|
+
*/
|
|
18
|
+
export declare class TonUiTransaction implements IUITransaction {
|
|
19
|
+
to: string | undefined;
|
|
20
|
+
from: string;
|
|
21
|
+
value: bigint | undefined;
|
|
22
|
+
chain: string;
|
|
23
|
+
receipt: string | undefined;
|
|
24
|
+
data: undefined;
|
|
25
|
+
fee: {
|
|
26
|
+
gas: bigint | undefined;
|
|
27
|
+
};
|
|
28
|
+
nonNativeAddress?: string;
|
|
29
|
+
nonNativeDecimal?: number;
|
|
30
|
+
nonNativeValue?: bigint;
|
|
31
|
+
nativePrice?: number;
|
|
32
|
+
private onSubmit;
|
|
33
|
+
private client;
|
|
34
|
+
constructor({ onSubmit, from, client }: TonUiTransactionProps);
|
|
35
|
+
/**
|
|
36
|
+
* TODO: Implement dynamic fee estimation using client.estimateFee()
|
|
37
|
+
*/
|
|
38
|
+
fetchFee(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Parse string input to bigint (for TON)
|
|
41
|
+
*/
|
|
42
|
+
parse(input: string): bigint;
|
|
43
|
+
/**
|
|
44
|
+
* Parse string input to bigint (for Jetton tokens)
|
|
45
|
+
*/
|
|
46
|
+
parseNonNativeToken(input: string, decimals: number): bigint;
|
|
47
|
+
/**
|
|
48
|
+
* Format bigint value to string (for TON)
|
|
49
|
+
*/
|
|
50
|
+
format(value: bigint, options?: IUITransactionFormatOptions): string;
|
|
51
|
+
/**
|
|
52
|
+
* Format bigint value to string (for Jetton tokens)
|
|
53
|
+
*/
|
|
54
|
+
formatNonNativeToken(value: bigint, decimals: number): string;
|
|
55
|
+
/**
|
|
56
|
+
* Submit the transaction
|
|
57
|
+
*/
|
|
58
|
+
submit(): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Get the balance for the from address
|
|
61
|
+
*/
|
|
62
|
+
getBalance(): Promise<bigint>;
|
|
63
|
+
/**
|
|
64
|
+
* Validate TON address format
|
|
65
|
+
*
|
|
66
|
+
* TON addresses can be in multiple formats:
|
|
67
|
+
* - Raw: 0:<64 hex chars> (workchain:hash)
|
|
68
|
+
* - User-friendly: Base64 encoded, starts with E/U (bounceable) or 0 (non-bounceable)
|
|
69
|
+
*/
|
|
70
|
+
validateAddressFormat(address: string): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Check if gas is sponsored
|
|
73
|
+
*/
|
|
74
|
+
isGasSponsored(): boolean;
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../../../_virtual/_tslib.js';
|
|
3
|
+
import { Address } from '@ton/ton';
|
|
4
|
+
import { formatNumberText } from '@dynamic-labs/utils';
|
|
5
|
+
import { logger } from '@dynamic-labs/wallet-connector-core';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 1 TON = 1,000,000,000 nanoTON (atomic units)
|
|
9
|
+
*/
|
|
10
|
+
const NANOTON_PER_TON = 1000000000;
|
|
11
|
+
/**
|
|
12
|
+
* TonUiTransaction class for managing TON transactions in the UI
|
|
13
|
+
*/
|
|
14
|
+
class TonUiTransaction {
|
|
15
|
+
constructor({ onSubmit, from, client }) {
|
|
16
|
+
this.chain = 'TON';
|
|
17
|
+
this.data = undefined;
|
|
18
|
+
this.fee = { gas: undefined };
|
|
19
|
+
this.from = from;
|
|
20
|
+
this.onSubmit = onSubmit;
|
|
21
|
+
this.client = client;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* TODO: Implement dynamic fee estimation using client.estimateFee()
|
|
25
|
+
*/
|
|
26
|
+
fetchFee() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (this.fee.gas !== undefined)
|
|
29
|
+
return;
|
|
30
|
+
// Default conservative estimate: 0.01 TON for simple transfers
|
|
31
|
+
// This covers most native TON transfers
|
|
32
|
+
const DEFAULT_FEE = BigInt(10000000);
|
|
33
|
+
// For jetton transfers, fees are higher due to multiple messages
|
|
34
|
+
const DEFAULT_JETTON_FEE = BigInt(50000000);
|
|
35
|
+
if (this.nonNativeAddress) {
|
|
36
|
+
this.fee.gas = DEFAULT_JETTON_FEE;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.fee.gas = DEFAULT_FEE;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parse string input to bigint (for TON)
|
|
45
|
+
*/
|
|
46
|
+
parse(input) {
|
|
47
|
+
const [whole, fraction = '0'] = input.split('.');
|
|
48
|
+
const numericWhole = parseInt(whole, 10);
|
|
49
|
+
if (isNaN(numericWhole))
|
|
50
|
+
return BigInt(0);
|
|
51
|
+
const paddedFraction = fraction.padEnd(9, '0').slice(0, 9);
|
|
52
|
+
return (BigInt(numericWhole) * BigInt(NANOTON_PER_TON) +
|
|
53
|
+
BigInt(parseInt(paddedFraction, 10)));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Parse string input to bigint (for Jetton tokens)
|
|
57
|
+
*/
|
|
58
|
+
parseNonNativeToken(input, decimals) {
|
|
59
|
+
const [whole, fraction = '0'] = input.split('.');
|
|
60
|
+
const numericWhole = parseInt(whole, 10);
|
|
61
|
+
if (isNaN(numericWhole))
|
|
62
|
+
return BigInt(0);
|
|
63
|
+
const paddedFraction = fraction.padEnd(decimals, '0').slice(0, decimals);
|
|
64
|
+
return (BigInt(numericWhole) * BigInt(Math.pow(10, decimals)) +
|
|
65
|
+
BigInt(parseInt(paddedFraction, 10)));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Format bigint value to string (for TON)
|
|
69
|
+
*/
|
|
70
|
+
format(value, options) {
|
|
71
|
+
var _a;
|
|
72
|
+
const precision = (_a = options === null || options === void 0 ? void 0 : options.precision) !== null && _a !== void 0 ? _a : 9;
|
|
73
|
+
const divisor = BigInt(NANOTON_PER_TON);
|
|
74
|
+
const whole = value / divisor;
|
|
75
|
+
const remainder = value % divisor;
|
|
76
|
+
const fractional = remainder.toString().padStart(9, '0');
|
|
77
|
+
return formatNumberText(`${whole}.${fractional}`, { precision });
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Format bigint value to string (for Jetton tokens)
|
|
81
|
+
*/
|
|
82
|
+
formatNonNativeToken(value, decimals) {
|
|
83
|
+
const divisor = BigInt(Math.pow(10, decimals));
|
|
84
|
+
const whole = value / divisor;
|
|
85
|
+
const remainder = value % divisor;
|
|
86
|
+
const fractional = remainder.toString().padStart(decimals, '0');
|
|
87
|
+
return formatNumberText(`${whole}.${fractional}`, {
|
|
88
|
+
precision: decimals > 9 ? 9 : decimals,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Submit the transaction
|
|
93
|
+
*/
|
|
94
|
+
submit() {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
if (!this.to) {
|
|
97
|
+
throw new Error('Destination address is required');
|
|
98
|
+
}
|
|
99
|
+
if (!this.value && !this.nonNativeValue) {
|
|
100
|
+
throw new Error('Transaction value is required');
|
|
101
|
+
}
|
|
102
|
+
return this.onSubmit(this);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the balance for the from address
|
|
107
|
+
*/
|
|
108
|
+
getBalance() {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
try {
|
|
111
|
+
if (this.nonNativeAddress) {
|
|
112
|
+
logger.debug('Jetton balance fetching not yet implemented');
|
|
113
|
+
return BigInt(0);
|
|
114
|
+
}
|
|
115
|
+
const address = Address.parse(this.from);
|
|
116
|
+
const balance = yield this.client.getBalance(address);
|
|
117
|
+
return balance;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
logger.error('Error occurred while fetching TON balance. Please try again or contact support.');
|
|
121
|
+
return BigInt(0);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validate TON address format
|
|
127
|
+
*
|
|
128
|
+
* TON addresses can be in multiple formats:
|
|
129
|
+
* - Raw: 0:<64 hex chars> (workchain:hash)
|
|
130
|
+
* - User-friendly: Base64 encoded, starts with E/U (bounceable) or 0 (non-bounceable)
|
|
131
|
+
*/
|
|
132
|
+
validateAddressFormat(address) {
|
|
133
|
+
if (address === 'dyn_send_transaction.multiple_recipients') {
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
// Use @ton/ton's Address.parse which handles all formats
|
|
138
|
+
Address.parse(address);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
catch (_a) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Check if gas is sponsored
|
|
147
|
+
*/
|
|
148
|
+
isGasSponsored() {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { NANOTON_PER_TON, TonUiTransaction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TonUiTransaction, NANOTON_PER_TON } from './TonUiTransaction';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TonUiTransaction, NANOTON_PER_TON, } from './TonUiTransaction/TonUiTransaction';
|