@tonconnect/sdk 3.0.8-beta.0 → 3.1.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/lib/cjs/index.cjs CHANGED
@@ -2045,50 +2045,6 @@ const FALLBACK_WALLETS_LIST = [
2045
2045
  }
2046
2046
  ];
2047
2047
 
2048
- function checkSendTransactionSupport(features, options) {
2049
- const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
2050
- const sendTransactionFeature = features.find(feature => feature && typeof feature === 'object' && feature.name === 'SendTransaction');
2051
- if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
2052
- throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
2053
- }
2054
- if (options.requireExtraCurrencies) {
2055
- if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
2056
- throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
2057
- }
2058
- }
2059
- if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
2060
- if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
2061
- throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
2062
- }
2063
- return;
2064
- }
2065
- logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
2066
- }
2067
- function checkRequiredWalletFeatures(features, walletsRequiredFeatures) {
2068
- if (typeof walletsRequiredFeatures === 'function') {
2069
- return walletsRequiredFeatures(features);
2070
- }
2071
- const res = walletsRequiredFeatures.every(requiredFeature => {
2072
- const feature = features.find(f => typeof f === 'object' && f.name === requiredFeature.name);
2073
- if (!feature) {
2074
- return false;
2075
- }
2076
- switch (requiredFeature.name) {
2077
- case 'SendTransaction': {
2078
- const sendTransactionFeature = feature;
2079
- const correctMessagesNumber = requiredFeature.minMessages === undefined ||
2080
- requiredFeature.minMessages <= sendTransactionFeature.maxMessages;
2081
- const correctExtraCurrency = !requiredFeature.extraCurrencyRequired ||
2082
- sendTransactionFeature.extraCurrencySupported;
2083
- return correctMessagesNumber && correctExtraCurrency;
2084
- }
2085
- default:
2086
- return false;
2087
- }
2088
- });
2089
- return res;
2090
- }
2091
-
2092
2048
  class WalletsListManager {
2093
2049
  constructor(options) {
2094
2050
  var _a;
@@ -2097,9 +2053,6 @@ class WalletsListManager {
2097
2053
  this.walletsListSource =
2098
2054
  (_a = options === null || options === void 0 ? void 0 : options.walletsListSource) !== null && _a !== void 0 ? _a : 'https://raw.githubusercontent.com/ton-blockchain/wallets-list/main/wallets-v2.json';
2099
2055
  this.cacheTTLMs = options === null || options === void 0 ? void 0 : options.cacheTTLMs;
2100
- this.checkRequiredFeatures = (options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures)
2101
- ? features => checkRequiredWalletFeatures(features !== null && features !== void 0 ? features : [], options.walletsRequiredFeatures)
2102
- : () => true;
2103
2056
  }
2104
2057
  getWallets() {
2105
2058
  return __awaiter(this, void 0, void 0, function* () {
@@ -2249,6 +2202,51 @@ class WalletsListManager {
2249
2202
  }
2250
2203
  }
2251
2204
 
2205
+ function checkSendTransactionSupport(features, options) {
2206
+ const supportsDeprecatedSendTransactionFeature = features.includes('SendTransaction');
2207
+ const sendTransactionFeature = findFeature(features, 'SendTransaction');
2208
+ if (!supportsDeprecatedSendTransactionFeature && !sendTransactionFeature) {
2209
+ throw new WalletNotSupportFeatureError("Wallet doesn't support SendTransaction feature.");
2210
+ }
2211
+ if (options.requireExtraCurrencies) {
2212
+ if (!sendTransactionFeature || !sendTransactionFeature.extraCurrencySupported) {
2213
+ throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Extra currencies support is required.`);
2214
+ }
2215
+ }
2216
+ if (sendTransactionFeature && sendTransactionFeature.maxMessages !== undefined) {
2217
+ if (sendTransactionFeature.maxMessages < options.requiredMessagesNumber) {
2218
+ throw new WalletNotSupportFeatureError(`Wallet is not able to handle such SendTransaction request. Max support messages number is ${sendTransactionFeature.maxMessages}, but ${options.requiredMessagesNumber} is required.`);
2219
+ }
2220
+ return;
2221
+ }
2222
+ logWarning("Connected wallet didn't provide information about max allowed messages in the SendTransaction request. Request may be rejected by the wallet.");
2223
+ }
2224
+ function checkRequiredWalletFeatures(features, walletsRequiredFeatures) {
2225
+ if (typeof walletsRequiredFeatures !== 'object') {
2226
+ return true;
2227
+ }
2228
+ const { sendTransaction } = walletsRequiredFeatures;
2229
+ if (sendTransaction) {
2230
+ const feature = findFeature(features, 'SendTransaction');
2231
+ if (!feature) {
2232
+ return false;
2233
+ }
2234
+ if (!checkSendTransaction(feature, sendTransaction)) {
2235
+ return false;
2236
+ }
2237
+ }
2238
+ return true;
2239
+ }
2240
+ function findFeature(features, requiredFeatureName) {
2241
+ return features.find(f => f && typeof f === 'object' && f.name === requiredFeatureName);
2242
+ }
2243
+ function checkSendTransaction(feature, requiredFeature) {
2244
+ const correctMessagesNumber = requiredFeature.minMessages === undefined ||
2245
+ requiredFeature.minMessages <= feature.maxMessages;
2246
+ const correctExtraCurrency = !requiredFeature.extraCurrencyRequired || feature.extraCurrencySupported;
2247
+ return !!(correctMessagesNumber && correctExtraCurrency);
2248
+ }
2249
+
2252
2250
  /**
2253
2251
  * Create a request version event.
2254
2252
  */
@@ -2665,7 +2663,7 @@ class TonConnectTracker {
2665
2663
  }
2666
2664
  }
2667
2665
 
2668
- const tonConnectSdkVersion = "3.0.8-beta.0";
2666
+ const tonConnectSdkVersion = "3.1.0";
2669
2667
 
2670
2668
  class TonConnect {
2671
2669
  constructor(options) {
@@ -2681,8 +2679,7 @@ class TonConnect {
2681
2679
  this.walletsRequiredFeatures = options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures;
2682
2680
  this.walletsList = new WalletsListManager({
2683
2681
  walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
2684
- cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs,
2685
- walletsRequiredFeatures: options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures
2682
+ cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs
2686
2683
  });
2687
2684
  this.tracker = new TonConnectTracker({
2688
2685
  eventDispatcher: options === null || options === void 0 ? void 0 : options.eventDispatcher,
@@ -3003,15 +3000,15 @@ class TonConnect {
3003
3000
  }
3004
3001
  }
3005
3002
  onWalletConnected(connectEvent) {
3006
- var _a, _b;
3003
+ var _a;
3007
3004
  const tonAccountItem = connectEvent.items.find(item => item.name === 'ton_addr');
3008
3005
  const tonProofItem = connectEvent.items.find(item => item.name === 'ton_proof');
3009
3006
  if (!tonAccountItem) {
3010
3007
  throw new TonConnectError('ton_addr connection item was not found');
3011
3008
  }
3012
- const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features, (_a = this.walletsRequiredFeatures) !== null && _a !== void 0 ? _a : []);
3009
+ const hasRequiredFeatures = checkRequiredWalletFeatures(connectEvent.device.features, this.walletsRequiredFeatures);
3013
3010
  if (!hasRequiredFeatures) {
3014
- (_b = this.provider) === null || _b === void 0 ? void 0 : _b.disconnect();
3011
+ (_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect();
3015
3012
  this.onWalletConnectError(new WalletMissingRequiredFeaturesError('Wallet does not support required features', { cause: { connectEvent } }));
3016
3013
  return;
3017
3014
  }