tek-wallet 0.0.296 → 0.0.297

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.
@@ -243,6 +243,10 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
243
243
  tonTransferParam = (0, parseTonTransferUrl_1.default)(text);
244
244
  console.warn("🚀 ~ handleScanAllQrCode ~ tonTransferParam:", tonTransferParam);
245
245
  (_c = backDropRef.current) === null || _c === void 0 ? void 0 : _c.open();
246
+ if (!tonTransferParam) {
247
+ alert("Unsupported QR");
248
+ return [2 /*return*/];
249
+ }
246
250
  return [4 /*yield*/, (0, validate_wallet_address_service_1.default)({
247
251
  address: tonTransferParam === null || tonTransferParam === void 0 ? void 0 : tonTransferParam.address,
248
252
  network: (selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.slug) || "ton",
@@ -8,4 +8,5 @@ export interface TonTransferUrlParams {
8
8
  jetton: string | undefined;
9
9
  isDeepLinkFormat: boolean;
10
10
  }
11
- export default function parseTonTransferUrl(url: string): TonTransferUrlParams;
11
+ export type ParseTonTransferUrlResult = TonTransferUrlParams | undefined;
12
+ export default function parseTonTransferUrl(url: string): ParseTonTransferUrlResult;
@@ -3,94 +3,100 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = parseTonTransferUrl;
4
4
  var ton_core_1 = require("ton-core");
5
5
  function parseTonTransferUrl(url) {
6
- var protocol;
7
- var address;
8
- var queryString = "";
9
- var isDeepLinkFormat = false;
10
- // Xác định loại URL
11
- if (url.startsWith("ton://transfer/")) {
12
- protocol = "ton";
13
- var _a = url.split("?"), path = _a[0], query = _a[1];
14
- address = path.split("/transfer/")[1];
15
- queryString = query || "";
16
- }
17
- else if (url.startsWith("https://app.tonkeeper.com/transfer/")) {
18
- protocol = "https";
19
- var _b = url.split("?"), path = _b[0], query = _b[1];
20
- address = path.split("/transfer/")[1];
21
- queryString = query || "";
22
- }
23
- else if (url.startsWith("ton:")) {
24
- protocol = "ton";
25
- isDeepLinkFormat = true;
26
- var _c = url.slice(4).split("?"), path = _c[0], query = _c[1];
27
- address = path;
28
- queryString = query || "";
29
- }
30
- else {
31
- throw new Error('Invalid TON transfer URL. Must start with "ton://transfer/", "https://app.tonkeeper.com/transfer/", or "ton:"');
32
- }
33
- if (!address) {
34
- throw new Error("Missing TON address in URL");
35
- }
36
- // Xác thực địa chỉ là TON address
37
6
  try {
38
- ton_core_1.Address.parse(address); // Throws nếu không hợp lệ
39
- }
40
- catch (_d) {
41
- throw new Error("Invalid TON address");
42
- }
43
- var result = {
44
- protocol: protocol,
45
- address: address,
46
- amount: undefined,
47
- text: undefined,
48
- bin: undefined,
49
- init: undefined,
50
- jetton: undefined,
51
- isDeepLinkFormat: isDeepLinkFormat,
52
- };
53
- if (queryString) {
54
- var params = new URLSearchParams(queryString);
55
- // amount
56
- var amount = params.get("amount");
57
- if (amount) {
58
- if (!/^\d+(\.\d+)?$/.test(amount)) {
59
- throw new Error("Invalid amount: must be a number");
60
- }
61
- result.amount = amount;
7
+ var protocol = void 0;
8
+ var address = void 0;
9
+ var queryString = "";
10
+ var isDeepLinkFormat = false;
11
+ // Xác định loại URL
12
+ if (url.startsWith("ton://transfer/")) {
13
+ protocol = "ton";
14
+ var _a = url.split("?"), path = _a[0], query = _a[1];
15
+ address = path.split("/transfer/")[1];
16
+ queryString = query || "";
62
17
  }
63
- // text
64
- if (params.has("text")) {
65
- result.text = decodeURIComponent(params.get("text"));
18
+ else if (url.startsWith("https://app.tonkeeper.com/transfer/")) {
19
+ protocol = "https";
20
+ var _b = url.split("?"), path = _b[0], query = _b[1];
21
+ address = path.split("/transfer/")[1];
22
+ queryString = query || "";
66
23
  }
67
- // bin
68
- var bin = params.get("bin");
69
- if (bin) {
70
- if (!/^[A-Za-z0-9-_]+={0,2}$/.test(bin)) {
71
- throw new Error("Invalid bin: must be Base64 URL-safe encoded");
72
- }
73
- result.bin = bin;
24
+ else if (url.startsWith("ton:")) {
25
+ protocol = "ton";
26
+ isDeepLinkFormat = true;
27
+ var _c = url.slice(4).split("?"), path = _c[0], query = _c[1];
28
+ address = path;
29
+ queryString = query || "";
74
30
  }
75
- // init
76
- var init = params.get("init");
77
- if (init) {
78
- if (!/^[A-Za-z0-9-_]+={0,2}$/.test(init)) {
79
- throw new Error("Invalid init: must be Base64 URL-safe encoded");
80
- }
81
- result.init = init;
31
+ else {
32
+ throw new Error('Invalid TON transfer URL. Must start with "ton://transfer/", "https://app.tonkeeper.com/transfer/", or "ton:"');
33
+ }
34
+ if (!address) {
35
+ throw new Error("Missing TON address in URL");
36
+ }
37
+ // Xác thực địa chỉ là TON address
38
+ try {
39
+ ton_core_1.Address.parse(address); // Throws nếu không hợp lệ
40
+ }
41
+ catch (_d) {
42
+ throw new Error("Invalid TON address");
82
43
  }
83
- // jetton
84
- var jetton = params.get("jetton");
85
- if (jetton) {
86
- try {
87
- ton_core_1.Address.parse(jetton); // kiểm tra hợp lệ
88
- result.jetton = jetton;
44
+ var result = {
45
+ protocol: protocol,
46
+ address: address,
47
+ amount: undefined,
48
+ text: undefined,
49
+ bin: undefined,
50
+ init: undefined,
51
+ jetton: undefined,
52
+ isDeepLinkFormat: isDeepLinkFormat,
53
+ };
54
+ if (queryString) {
55
+ var params = new URLSearchParams(queryString);
56
+ // amount
57
+ var amount = params.get("amount");
58
+ if (amount) {
59
+ if (!/^\d+(\.\d+)?$/.test(amount)) {
60
+ throw new Error("Invalid amount: must be a number");
61
+ }
62
+ result.amount = amount;
89
63
  }
90
- catch (_e) {
91
- throw new Error("Invalid jetton address");
64
+ // text
65
+ if (params.has("text")) {
66
+ result.text = decodeURIComponent(params.get("text"));
67
+ }
68
+ // bin
69
+ var bin = params.get("bin");
70
+ if (bin) {
71
+ if (!/^[A-Za-z0-9-_]+={0,2}$/.test(bin)) {
72
+ throw new Error("Invalid bin: must be Base64 URL-safe encoded");
73
+ }
74
+ result.bin = bin;
75
+ }
76
+ // init
77
+ var init = params.get("init");
78
+ if (init) {
79
+ if (!/^[A-Za-z0-9-_]+={0,2}$/.test(init)) {
80
+ throw new Error("Invalid init: must be Base64 URL-safe encoded");
81
+ }
82
+ result.init = init;
83
+ }
84
+ // jetton
85
+ var jetton = params.get("jetton");
86
+ if (jetton) {
87
+ try {
88
+ ton_core_1.Address.parse(jetton); // kiểm tra hợp lệ
89
+ result.jetton = jetton;
90
+ }
91
+ catch (_e) {
92
+ throw new Error("Invalid jetton address");
93
+ }
92
94
  }
93
95
  }
96
+ return result;
97
+ }
98
+ catch (error) {
99
+ console.error("error", error);
100
+ return undefined;
94
101
  }
95
- return result;
96
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.296",
3
+ "version": "0.0.297",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",