tek-wallet 0.0.295 → 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.
- package/dist/components/ui/DialogContentLayout/index.d.ts +21 -0
- package/dist/components/ui/DialogContentLayout/index.js +1 -1
- package/dist/components/ui/WithdrawFunction/index.js +5 -0
- package/dist/utils/parseTonTransferUrl.d.ts +2 -1
- package/dist/utils/parseTonTransferUrl.js +87 -81
- package/package.json +1 -1
|
@@ -6,3 +6,24 @@ interface DialogContentLayoutProps extends Omit<BoxProps, "content" | "actions">
|
|
|
6
6
|
}
|
|
7
7
|
declare function DialogContentLayout(props: DialogContentLayoutProps): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export default DialogContentLayout;
|
|
9
|
+
/**
|
|
10
|
+
* LẤY ĐỊA CHỈ VÍ TỪ TEXT QR CODE
|
|
11
|
+
* Sử dụng hàm lấy địa chỉ ví của mạng Ton
|
|
12
|
+
* 1.1 Không lấy được địa chỉ ví => Trả về chuỗi input và hiển thị chọn token
|
|
13
|
+
* 1.2 Lấy được địa chỉ ví
|
|
14
|
+
* 1.2.1 Không có thông tin token => chọn token
|
|
15
|
+
* 1.2.2 Có thông tin token => hiện form
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* #Mặc định là mạng TON
|
|
19
|
+
* Quét mã qr:
|
|
20
|
+
*
|
|
21
|
+
* 1. Không lấy được địa chỉ ví => Báo mã không được hỗ trợ
|
|
22
|
+
* 2. Lấy được địa chỉ ví:
|
|
23
|
+
* 2.1 Địa chỉ ví không khớp với mạng Ton => Báo mã không được hỗ trợ
|
|
24
|
+
* 2.2 Địa chỉ ví khớp:
|
|
25
|
+
* 2.2.1 Là của chính bản thân mình => Báo mày không thể send tới chính mày
|
|
26
|
+
* 2.2.2 Là của người khác:
|
|
27
|
+
* 2.2.2.1 Có trong hệ thống Tek Wallet => Đề xuất user transfer (send internal)
|
|
28
|
+
* 2.2.2.2 Không có trong hệ thống => cho qua withdraw (send external)
|
|
29
|
+
*/
|
|
@@ -31,7 +31,7 @@ var Text_1 = __importDefault(require("../Text"));
|
|
|
31
31
|
function DialogContentLayout(props) {
|
|
32
32
|
var content = props.content, actions = props.actions, sx = props.sx, rest = __rest(props, ["content", "actions", "sx"]);
|
|
33
33
|
var theme = (0, material_1.useTheme)();
|
|
34
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: __assign(__assign(__assign(__assign({}, theme.mixins.column), {
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, __assign({ sx: __assign(__assign(__assign(__assign({}, theme.mixins.column), { borderRadius: theme.mixins.theBorderRadius.r12, backgroundColor: theme.palette.background.black, boxShadow: theme.shadows[1] }), theme.mixins.dialogContent), sx) }, rest, { children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
35
35
|
padding: theme.mixins.customPadding.p12,
|
|
36
36
|
}, children: content }), !!actions && (0, jsx_runtime_1.jsx)(material_1.Divider, {}), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { px: theme.mixins.customPadding.p12 }, children: actions })] })));
|
|
37
37
|
}
|
|
@@ -241,7 +241,12 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
241
241
|
console.error("result", result);
|
|
242
242
|
text = (_b = result === null || result === void 0 ? void 0 : result[0]) === null || _b === void 0 ? void 0 : _b.rawValue;
|
|
243
243
|
tonTransferParam = (0, parseTonTransferUrl_1.default)(text);
|
|
244
|
+
console.warn("🚀 ~ handleScanAllQrCode ~ tonTransferParam:", tonTransferParam);
|
|
244
245
|
(_c = backDropRef.current) === null || _c === void 0 ? void 0 : _c.open();
|
|
246
|
+
if (!tonTransferParam) {
|
|
247
|
+
alert("Unsupported QR");
|
|
248
|
+
return [2 /*return*/];
|
|
249
|
+
}
|
|
245
250
|
return [4 /*yield*/, (0, validate_wallet_address_service_1.default)({
|
|
246
251
|
address: tonTransferParam === null || tonTransferParam === void 0 ? void 0 : tonTransferParam.address,
|
|
247
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
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
91
|
-
|
|
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
|
}
|