@dynamic-labs/ton 4.62.0 → 4.63.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 +13 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -9
- package/src/connectors/TonConnectConnector/TonConnectConnector.cjs +394 -353
- package/src/connectors/TonConnectConnector/TonConnectConnector.d.ts +77 -92
- package/src/connectors/TonConnectConnector/TonConnectConnector.js +396 -355
- package/src/index.d.ts +0 -1
- package/src/types.d.ts +12 -8
- package/src/utils/fetchTonWalletConnectors/fetchTonWalletConnectors.cjs +23 -53
- package/src/utils/fetchTonWalletConnectors/fetchTonWalletConnectors.d.ts +4 -19
- package/src/utils/fetchTonWalletConnectors/fetchTonWalletConnectors.js +23 -53
- package/src/wallet/TonWallet/TonWallet.cjs +35 -11
- package/src/wallet/TonWallet/TonWallet.d.ts +10 -4
- package/src/wallet/TonWallet/TonWallet.js +35 -11
- package/src/utils/selectTonWallet/index.d.ts +0 -1
- package/src/utils/selectTonWallet/selectTonWallet.d.ts +0 -16
package/src/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export * from './types';
|
|
|
5
5
|
export { TonWallet, isTonWallet, WaasTonWallet } from './wallet';
|
|
6
6
|
export { TonUiTransaction, NANOTON_PER_TON, prepareTransaction, prepareTonTransfer, prepareJettonTransfer, getJettonWalletAddress, getWalletSeqno, executeTransaction, extractDisplayInfoFromRequest, convertSendTransactionRequest, generateTonConnectProofHash, } from './utils';
|
|
7
7
|
export type { PrepareTransactionParams, PrepareTransactionResult, PrepareTonTransferParams, PrepareJettonTransferParams, GetJettonWalletAddressParams, ExecuteTransactionParams, ExecuteTransactionResult, GenerateTonConnectProofHashParams, TransactionRequestDisplayInfo, } from './utils';
|
|
8
|
-
export type { WalletsModalState as TonConnectModalState } from '@tonconnect/ui';
|
|
9
8
|
export { DynamicWaasTonConnector } from './waas/connector/DynamicWaasTonConnector';
|
|
10
9
|
export type { DynamicWaasTonConnectorProps } from './waas/connector/DynamicWaasTonConnector';
|
|
11
10
|
export { DynamicWaasTonConnectors } from './waas/DynamicWaasTonConnectors';
|
package/src/types.d.ts
CHANGED
|
@@ -82,14 +82,16 @@ export type SendTonOptions = {
|
|
|
82
82
|
* Options for sending Jetton (token) transactions
|
|
83
83
|
*/
|
|
84
84
|
export type SendJettonOptions = {
|
|
85
|
-
/** Jetton contract address */
|
|
86
|
-
|
|
87
|
-
/** Recipient address */
|
|
88
|
-
|
|
89
|
-
/** Amount in
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
|
|
85
|
+
/** Jetton master contract address */
|
|
86
|
+
jettonMasterAddress: string;
|
|
87
|
+
/** Recipient wallet address */
|
|
88
|
+
recipientAddress: string;
|
|
89
|
+
/** Amount of jettons in base units */
|
|
90
|
+
jettonAmount: bigint;
|
|
91
|
+
/** Amount of TON to forward with the transfer notification */
|
|
92
|
+
forwardTonAmount: bigint;
|
|
93
|
+
/** Optional comment/memo forwarded with the transfer */
|
|
94
|
+
forwardPayload?: string;
|
|
93
95
|
};
|
|
94
96
|
/**
|
|
95
97
|
* Result of a transaction send operation
|
|
@@ -139,6 +141,8 @@ export type TonConnectConnectorOpts = {
|
|
|
139
141
|
manifestUrl?: string;
|
|
140
142
|
/** Optional override key for the connector */
|
|
141
143
|
overrideKey?: string;
|
|
144
|
+
/** TonConnect wallet app name used with openSingleWalletModal (e.g. 'tonkeeper', 'mytonwallet', 'telegram-wallet') */
|
|
145
|
+
tonConnectAppName?: string;
|
|
142
146
|
};
|
|
143
147
|
/**
|
|
144
148
|
* TON network configuration.
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
var TonConnectConnector = require('../../connectors/TonConnectConnector/TonConnectConnector.cjs');
|
|
7
|
-
var debugLog = require('../debugLog/debugLog.cjs');
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Checks if a wallet configuration supports TON Connect.
|
|
@@ -16,70 +15,41 @@ var debugLog = require('../debugLog/debugLog.cjs');
|
|
|
16
15
|
* @returns true if the wallet supports TON Connect, false otherwise
|
|
17
16
|
*/
|
|
18
17
|
const isValidTonConnectWallet = (wallet) => { var _a; return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'ton')); };
|
|
18
|
+
// Maps wallet-book keys to TonConnect app_name values where they differ.
|
|
19
|
+
// Most wallets use the same key in both, but Telegram Wallet uses
|
|
20
|
+
// 'telegramwallet' in the wallet-book and 'telegram-wallet' in the
|
|
21
|
+
// TonConnect registry.
|
|
22
|
+
const WALLET_BOOK_TO_TC_APP_NAME = {
|
|
23
|
+
telegramwallet: 'telegram-wallet',
|
|
24
|
+
};
|
|
19
25
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* https://github.com/ton-connect/wallets-list
|
|
24
|
-
*
|
|
25
|
-
* The TON Connect SDK automatically fetches this list when getWallets() is called.
|
|
26
|
-
* When a user clicks to connect, the SDK shows a UI with all available wallets
|
|
27
|
-
* from the official list, so individual connectors aren't needed for each wallet.
|
|
28
|
-
*
|
|
29
|
-
* This function:
|
|
30
|
-
* 1. Creates connectors for wallets found in the wallet book (for custom metadata/icons)
|
|
31
|
-
* 2. Falls back to a generic connector that uses TON Connect SDK's built-in wallet selection
|
|
26
|
+
* Creates per-wallet TonConnect connectors. Each wallet-book entry that
|
|
27
|
+
* supports TON gets its own connector class which opens the TonConnect UI
|
|
28
|
+
* single-wallet modal for the matching wallet.
|
|
32
29
|
*
|
|
33
30
|
* @param walletBook - The wallet book schema containing all wallet configurations
|
|
34
31
|
* @param tonNetworks - Optional TON networks configuration
|
|
35
|
-
* @returns Array of wallet
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const tonConnectors = fetchTonWalletConnectors({ walletBook, tonNetworks });
|
|
40
|
-
* // Returns connectors for wallets like Tonkeeper, MyTonWallet, etc.
|
|
41
|
-
* ```
|
|
32
|
+
* @returns Array of per-wallet TonConnectConnector constructors
|
|
42
33
|
*/
|
|
43
34
|
const fetchTonWalletConnectors = ({ walletBook, tonNetworks = [], }) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const { shortName } = wallet;
|
|
52
|
-
const name = shortName || wallet.name;
|
|
53
|
-
return class extends TonConnectConnector.TonConnectConnector {
|
|
35
|
+
const connectors = [];
|
|
36
|
+
for (const [key, wallet] of Object.entries(walletBook.wallets)) {
|
|
37
|
+
if (!isValidTonConnectWallet(wallet)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const tonConnectAppName = WALLET_BOOK_TO_TC_APP_NAME[key] || key;
|
|
41
|
+
connectors.push(class extends TonConnectConnector.TonConnectConnector {
|
|
54
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
43
|
constructor(props) {
|
|
56
|
-
super(Object.assign(Object.assign({}, props), { overrideKey: key,
|
|
44
|
+
super(Object.assign(Object.assign({}, props), { overrideKey: key, tonConnectAppName,
|
|
45
|
+
tonNetworks,
|
|
57
46
|
walletBook }));
|
|
58
|
-
this.name = name;
|
|
47
|
+
this.name = wallet.name;
|
|
59
48
|
this.overrideKey = key;
|
|
60
49
|
}
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
// If wallets found in wallet book, return them
|
|
64
|
-
if (walletBookConnectors.length > 0) {
|
|
65
|
-
debugLog.debugLog('[TON] Returning', walletBookConnectors.length, 'connector(s) from wallet book');
|
|
66
|
-
return walletBookConnectors;
|
|
50
|
+
});
|
|
67
51
|
}
|
|
68
|
-
|
|
69
|
-
// The SDK automatically fetches wallets from the official list at:
|
|
70
|
-
// https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json
|
|
71
|
-
// When connect() is called, it shows a UI with all available wallets
|
|
72
|
-
return [
|
|
73
|
-
class extends TonConnectConnector.TonConnectConnector {
|
|
74
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
-
constructor(props) {
|
|
76
|
-
super(Object.assign(Object.assign({}, props), { tonNetworks,
|
|
77
|
-
walletBook }));
|
|
78
|
-
this.name = 'TON Connect';
|
|
79
|
-
this.overrideKey = 'tonconnect';
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
];
|
|
52
|
+
return connectors;
|
|
83
53
|
};
|
|
84
54
|
|
|
85
55
|
exports.fetchTonWalletConnectors = fetchTonWalletConnectors;
|
|
@@ -12,28 +12,13 @@ import type { GenericNetwork } from '@dynamic-labs/types';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const isValidTonConnectWallet: (wallet: WalletBookSchema['wallets'][string]) => boolean;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* https://github.com/ton-connect/wallets-list
|
|
19
|
-
*
|
|
20
|
-
* The TON Connect SDK automatically fetches this list when getWallets() is called.
|
|
21
|
-
* When a user clicks to connect, the SDK shows a UI with all available wallets
|
|
22
|
-
* from the official list, so individual connectors aren't needed for each wallet.
|
|
23
|
-
*
|
|
24
|
-
* This function:
|
|
25
|
-
* 1. Creates connectors for wallets found in the wallet book (for custom metadata/icons)
|
|
26
|
-
* 2. Falls back to a generic connector that uses TON Connect SDK's built-in wallet selection
|
|
15
|
+
* Creates per-wallet TonConnect connectors. Each wallet-book entry that
|
|
16
|
+
* supports TON gets its own connector class which opens the TonConnect UI
|
|
17
|
+
* single-wallet modal for the matching wallet.
|
|
27
18
|
*
|
|
28
19
|
* @param walletBook - The wallet book schema containing all wallet configurations
|
|
29
20
|
* @param tonNetworks - Optional TON networks configuration
|
|
30
|
-
* @returns Array of wallet
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const tonConnectors = fetchTonWalletConnectors({ walletBook, tonNetworks });
|
|
35
|
-
* // Returns connectors for wallets like Tonkeeper, MyTonWallet, etc.
|
|
36
|
-
* ```
|
|
21
|
+
* @returns Array of per-wallet TonConnectConnector constructors
|
|
37
22
|
*/
|
|
38
23
|
export declare const fetchTonWalletConnectors: ({ walletBook, tonNetworks, }: {
|
|
39
24
|
walletBook: WalletBookSchema;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { TonConnectConnector } from '../../connectors/TonConnectConnector/TonConnectConnector.js';
|
|
3
|
-
import { debugLogMultiline, debugLog } from '../debugLog/debugLog.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Checks if a wallet configuration supports TON Connect.
|
|
@@ -12,70 +11,41 @@ import { debugLogMultiline, debugLog } from '../debugLog/debugLog.js';
|
|
|
12
11
|
* @returns true if the wallet supports TON Connect, false otherwise
|
|
13
12
|
*/
|
|
14
13
|
const isValidTonConnectWallet = (wallet) => { var _a; return Boolean((_a = wallet.injectedConfig) === null || _a === void 0 ? void 0 : _a.find((config) => config.chain === 'ton')); };
|
|
14
|
+
// Maps wallet-book keys to TonConnect app_name values where they differ.
|
|
15
|
+
// Most wallets use the same key in both, but Telegram Wallet uses
|
|
16
|
+
// 'telegramwallet' in the wallet-book and 'telegram-wallet' in the
|
|
17
|
+
// TonConnect registry.
|
|
18
|
+
const WALLET_BOOK_TO_TC_APP_NAME = {
|
|
19
|
+
telegramwallet: 'telegram-wallet',
|
|
20
|
+
};
|
|
15
21
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* https://github.com/ton-connect/wallets-list
|
|
20
|
-
*
|
|
21
|
-
* The TON Connect SDK automatically fetches this list when getWallets() is called.
|
|
22
|
-
* When a user clicks to connect, the SDK shows a UI with all available wallets
|
|
23
|
-
* from the official list, so individual connectors aren't needed for each wallet.
|
|
24
|
-
*
|
|
25
|
-
* This function:
|
|
26
|
-
* 1. Creates connectors for wallets found in the wallet book (for custom metadata/icons)
|
|
27
|
-
* 2. Falls back to a generic connector that uses TON Connect SDK's built-in wallet selection
|
|
22
|
+
* Creates per-wallet TonConnect connectors. Each wallet-book entry that
|
|
23
|
+
* supports TON gets its own connector class which opens the TonConnect UI
|
|
24
|
+
* single-wallet modal for the matching wallet.
|
|
28
25
|
*
|
|
29
26
|
* @param walletBook - The wallet book schema containing all wallet configurations
|
|
30
27
|
* @param tonNetworks - Optional TON networks configuration
|
|
31
|
-
* @returns Array of wallet
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const tonConnectors = fetchTonWalletConnectors({ walletBook, tonNetworks });
|
|
36
|
-
* // Returns connectors for wallets like Tonkeeper, MyTonWallet, etc.
|
|
37
|
-
* ```
|
|
28
|
+
* @returns Array of per-wallet TonConnectConnector constructors
|
|
38
29
|
*/
|
|
39
30
|
const fetchTonWalletConnectors = ({ walletBook, tonNetworks = [], }) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const { shortName } = wallet;
|
|
48
|
-
const name = shortName || wallet.name;
|
|
49
|
-
return class extends TonConnectConnector {
|
|
31
|
+
const connectors = [];
|
|
32
|
+
for (const [key, wallet] of Object.entries(walletBook.wallets)) {
|
|
33
|
+
if (!isValidTonConnectWallet(wallet)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const tonConnectAppName = WALLET_BOOK_TO_TC_APP_NAME[key] || key;
|
|
37
|
+
connectors.push(class extends TonConnectConnector {
|
|
50
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
39
|
constructor(props) {
|
|
52
|
-
super(Object.assign(Object.assign({}, props), { overrideKey: key,
|
|
40
|
+
super(Object.assign(Object.assign({}, props), { overrideKey: key, tonConnectAppName,
|
|
41
|
+
tonNetworks,
|
|
53
42
|
walletBook }));
|
|
54
|
-
this.name = name;
|
|
43
|
+
this.name = wallet.name;
|
|
55
44
|
this.overrideKey = key;
|
|
56
45
|
}
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
// If wallets found in wallet book, return them
|
|
60
|
-
if (walletBookConnectors.length > 0) {
|
|
61
|
-
debugLog('[TON] Returning', walletBookConnectors.length, 'connector(s) from wallet book');
|
|
62
|
-
return walletBookConnectors;
|
|
46
|
+
});
|
|
63
47
|
}
|
|
64
|
-
|
|
65
|
-
// The SDK automatically fetches wallets from the official list at:
|
|
66
|
-
// https://raw.githubusercontent.com/ton-connect/wallets-list/main/wallets.json
|
|
67
|
-
// When connect() is called, it shows a UI with all available wallets
|
|
68
|
-
return [
|
|
69
|
-
class extends TonConnectConnector {
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
-
constructor(props) {
|
|
72
|
-
super(Object.assign(Object.assign({}, props), { tonNetworks,
|
|
73
|
-
walletBook }));
|
|
74
|
-
this.name = 'TON Connect';
|
|
75
|
-
this.overrideKey = 'tonconnect';
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
];
|
|
48
|
+
return connectors;
|
|
79
49
|
};
|
|
80
50
|
|
|
81
51
|
export { fetchTonWalletConnectors, isValidTonConnectWallet };
|
|
@@ -7,7 +7,9 @@ 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
9
|
var sdk = require('@tonconnect/sdk');
|
|
10
|
+
var prepareJettonTransfer = require('../../utils/prepareJettonTransfer/prepareJettonTransfer.cjs');
|
|
10
11
|
|
|
12
|
+
const DEFAULT_FORWARD_TON_AMOUNT = BigInt(1);
|
|
11
13
|
/**
|
|
12
14
|
* TON wallet implementation
|
|
13
15
|
*
|
|
@@ -45,24 +47,32 @@ class TonWallet extends walletConnectorCore.Wallet {
|
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
/**
|
|
48
|
-
* Send balance
|
|
50
|
+
* Send balance - implements the base Wallet interface.
|
|
51
|
+
* Supports both native TON and Jetton (token) transfers.
|
|
49
52
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
53
|
+
* For Jetton transfers, pass the token param with the Jetton master address.
|
|
54
|
+
* For full control over Jetton transfer params, use sendJetton() instead.
|
|
52
55
|
*/
|
|
53
56
|
sendBalance(_a) {
|
|
54
|
-
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, comment, toAddress, }) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ amount, comment, toAddress, token, }) {
|
|
58
|
+
if (token === null || token === void 0 ? void 0 : token.address) {
|
|
59
|
+
return this.sendJettonViaConnector({
|
|
60
|
+
forwardPayload: comment,
|
|
61
|
+
forwardTonAmount: DEFAULT_FORWARD_TON_AMOUNT,
|
|
62
|
+
jettonAmount: BigInt(amount),
|
|
63
|
+
jettonMasterAddress: token.address,
|
|
64
|
+
recipientAddress: toAddress,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
57
67
|
const result = yield this._connector.sendTransaction({
|
|
58
68
|
messages: [
|
|
59
69
|
Object.assign({ address: toAddress, amount: amount }, (comment
|
|
60
70
|
? { payload: this._connector.encodeComment(comment) }
|
|
61
71
|
: {})),
|
|
62
72
|
],
|
|
63
|
-
validUntil: Math.floor(Date.now() / 1000) + 300,
|
|
73
|
+
validUntil: Math.floor(Date.now() / 1000) + 300,
|
|
64
74
|
});
|
|
65
|
-
return
|
|
75
|
+
return result;
|
|
66
76
|
});
|
|
67
77
|
}
|
|
68
78
|
/**
|
|
@@ -73,7 +83,8 @@ class TonWallet extends walletConnectorCore.Wallet {
|
|
|
73
83
|
*/
|
|
74
84
|
sendJetton(options) {
|
|
75
85
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
|
|
86
|
+
const boc = yield this.sendJettonViaConnector(options);
|
|
87
|
+
return { boc, hash: boc };
|
|
77
88
|
});
|
|
78
89
|
}
|
|
79
90
|
/**
|
|
@@ -115,10 +126,9 @@ class TonWallet extends walletConnectorCore.Wallet {
|
|
|
115
126
|
getNetworkDetails() {
|
|
116
127
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
117
128
|
const network = yield this._connector.getNetwork();
|
|
118
|
-
// Network is returned as a string (chain ID)
|
|
119
129
|
const chainId = network
|
|
120
130
|
? parseInt(network, 10)
|
|
121
|
-
: parseInt(sdk.CHAIN.MAINNET, 10);
|
|
131
|
+
: parseInt(sdk.CHAIN.MAINNET, 10);
|
|
122
132
|
let name;
|
|
123
133
|
if (chainId === parseInt(sdk.CHAIN.MAINNET, 10)) {
|
|
124
134
|
name = 'mainnet';
|
|
@@ -135,6 +145,20 @@ class TonWallet extends walletConnectorCore.Wallet {
|
|
|
135
145
|
};
|
|
136
146
|
});
|
|
137
147
|
}
|
|
148
|
+
sendJettonViaConnector(options) {
|
|
149
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
if (!this.address) {
|
|
151
|
+
throw new utils.DynamicError('Wallet address is required');
|
|
152
|
+
}
|
|
153
|
+
const client = this._connector.getTonClient();
|
|
154
|
+
const networkStr = yield this._connector.getNetwork();
|
|
155
|
+
const network = (networkStr || sdk.CHAIN.MAINNET);
|
|
156
|
+
const request = yield prepareJettonTransfer.prepareJettonTransfer(Object.assign({ client, forwardTonAmount: options.forwardTonAmount, jettonAmount: options.jettonAmount, jettonMasterAddress: options.jettonMasterAddress, network, recipientAddress: options.recipientAddress, timeout: 60, walletAddress: this.address }, (options.forwardPayload
|
|
157
|
+
? { forwardPayload: options.forwardPayload }
|
|
158
|
+
: {})));
|
|
159
|
+
return this._connector.sendTransaction(request);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
138
162
|
}
|
|
139
163
|
|
|
140
164
|
exports.TonWallet = TonWallet;
|
|
@@ -22,15 +22,20 @@ export declare class TonWallet extends Wallet<TonConnectConnector> {
|
|
|
22
22
|
*/
|
|
23
23
|
sendTon(to: string, amount: string | number, comment?: string): Promise<TonTransactionResult>;
|
|
24
24
|
/**
|
|
25
|
-
* Send balance
|
|
25
|
+
* Send balance - implements the base Wallet interface.
|
|
26
|
+
* Supports both native TON and Jetton (token) transfers.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* For Jetton transfers, pass the token param with the Jetton master address.
|
|
29
|
+
* For full control over Jetton transfer params, use sendJetton() instead.
|
|
29
30
|
*/
|
|
30
|
-
sendBalance({ amount, comment, toAddress, }: {
|
|
31
|
+
sendBalance({ amount, comment, toAddress, token, }: {
|
|
31
32
|
amount: string;
|
|
32
33
|
comment?: string;
|
|
33
34
|
toAddress: string;
|
|
35
|
+
token?: {
|
|
36
|
+
address: string;
|
|
37
|
+
decimals?: number;
|
|
38
|
+
};
|
|
34
39
|
}): Promise<string | undefined>;
|
|
35
40
|
/**
|
|
36
41
|
* Send Jetton (token) to an address
|
|
@@ -62,4 +67,5 @@ export declare class TonWallet extends Wallet<TonConnectConnector> {
|
|
|
62
67
|
chainId: number;
|
|
63
68
|
name: string;
|
|
64
69
|
}>;
|
|
70
|
+
private sendJettonViaConnector;
|
|
65
71
|
}
|
|
@@ -3,7 +3,9 @@ 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
5
|
import { CHAIN } from '@tonconnect/sdk';
|
|
6
|
+
import { prepareJettonTransfer } from '../../utils/prepareJettonTransfer/prepareJettonTransfer.js';
|
|
6
7
|
|
|
8
|
+
const DEFAULT_FORWARD_TON_AMOUNT = BigInt(1);
|
|
7
9
|
/**
|
|
8
10
|
* TON wallet implementation
|
|
9
11
|
*
|
|
@@ -41,24 +43,32 @@ class TonWallet extends Wallet {
|
|
|
41
43
|
});
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
|
-
* Send balance
|
|
46
|
+
* Send balance - implements the base Wallet interface.
|
|
47
|
+
* Supports both native TON and Jetton (token) transfers.
|
|
45
48
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
49
|
+
* For Jetton transfers, pass the token param with the Jetton master address.
|
|
50
|
+
* For full control over Jetton transfer params, use sendJetton() instead.
|
|
48
51
|
*/
|
|
49
52
|
sendBalance(_a) {
|
|
50
|
-
return __awaiter(this, arguments, void 0, function* ({ amount, comment, toAddress, }) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
return __awaiter(this, arguments, void 0, function* ({ amount, comment, toAddress, token, }) {
|
|
54
|
+
if (token === null || token === void 0 ? void 0 : token.address) {
|
|
55
|
+
return this.sendJettonViaConnector({
|
|
56
|
+
forwardPayload: comment,
|
|
57
|
+
forwardTonAmount: DEFAULT_FORWARD_TON_AMOUNT,
|
|
58
|
+
jettonAmount: BigInt(amount),
|
|
59
|
+
jettonMasterAddress: token.address,
|
|
60
|
+
recipientAddress: toAddress,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
53
63
|
const result = yield this._connector.sendTransaction({
|
|
54
64
|
messages: [
|
|
55
65
|
Object.assign({ address: toAddress, amount: amount }, (comment
|
|
56
66
|
? { payload: this._connector.encodeComment(comment) }
|
|
57
67
|
: {})),
|
|
58
68
|
],
|
|
59
|
-
validUntil: Math.floor(Date.now() / 1000) + 300,
|
|
69
|
+
validUntil: Math.floor(Date.now() / 1000) + 300,
|
|
60
70
|
});
|
|
61
|
-
return
|
|
71
|
+
return result;
|
|
62
72
|
});
|
|
63
73
|
}
|
|
64
74
|
/**
|
|
@@ -69,7 +79,8 @@ class TonWallet extends Wallet {
|
|
|
69
79
|
*/
|
|
70
80
|
sendJetton(options) {
|
|
71
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
|
|
82
|
+
const boc = yield this.sendJettonViaConnector(options);
|
|
83
|
+
return { boc, hash: boc };
|
|
73
84
|
});
|
|
74
85
|
}
|
|
75
86
|
/**
|
|
@@ -111,10 +122,9 @@ class TonWallet extends Wallet {
|
|
|
111
122
|
getNetworkDetails() {
|
|
112
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
124
|
const network = yield this._connector.getNetwork();
|
|
114
|
-
// Network is returned as a string (chain ID)
|
|
115
125
|
const chainId = network
|
|
116
126
|
? parseInt(network, 10)
|
|
117
|
-
: parseInt(CHAIN.MAINNET, 10);
|
|
127
|
+
: parseInt(CHAIN.MAINNET, 10);
|
|
118
128
|
let name;
|
|
119
129
|
if (chainId === parseInt(CHAIN.MAINNET, 10)) {
|
|
120
130
|
name = 'mainnet';
|
|
@@ -131,6 +141,20 @@ class TonWallet extends Wallet {
|
|
|
131
141
|
};
|
|
132
142
|
});
|
|
133
143
|
}
|
|
144
|
+
sendJettonViaConnector(options) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
if (!this.address) {
|
|
147
|
+
throw new DynamicError('Wallet address is required');
|
|
148
|
+
}
|
|
149
|
+
const client = this._connector.getTonClient();
|
|
150
|
+
const networkStr = yield this._connector.getNetwork();
|
|
151
|
+
const network = (networkStr || CHAIN.MAINNET);
|
|
152
|
+
const request = yield prepareJettonTransfer(Object.assign({ client, forwardTonAmount: options.forwardTonAmount, jettonAmount: options.jettonAmount, jettonMasterAddress: options.jettonMasterAddress, network, recipientAddress: options.recipientAddress, timeout: 60, walletAddress: this.address }, (options.forwardPayload
|
|
153
|
+
? { forwardPayload: options.forwardPayload }
|
|
154
|
+
: {})));
|
|
155
|
+
return this._connector.sendTransaction(request);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
134
158
|
}
|
|
135
159
|
|
|
136
160
|
export { TonWallet };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { selectTonWallet, checkWalletFeatures } from './selectTonWallet';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type WalletInfo, type RequiredFeatures } from '@tonconnect/sdk';
|
|
2
|
-
/**
|
|
3
|
-
* Selects the best wallet from available wallets, preferring injected wallets.
|
|
4
|
-
*
|
|
5
|
-
* @param wallets - Array of available TON Connect wallets
|
|
6
|
-
* @returns The selected wallet, or undefined if no wallet is available
|
|
7
|
-
*/
|
|
8
|
-
export declare const selectTonWallet: (wallets: WalletInfo[]) => WalletInfo | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* Checks if a wallet supports the required features and logs a warning if not.
|
|
11
|
-
*
|
|
12
|
-
* @param wallet - The wallet to check
|
|
13
|
-
* @param requiredFeatures - The required features configuration
|
|
14
|
-
* @returns true if the wallet supports all required features, false otherwise
|
|
15
|
-
*/
|
|
16
|
-
export declare const checkWalletFeatures: (wallet: WalletInfo, requiredFeatures: RequiredFeatures) => boolean;
|