tek-wallet 0.0.283 → 0.0.285

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.
@@ -33,6 +33,6 @@ var Text_1 = __importDefault(require("../Text"));
33
33
  function ListItemCustom(_a) {
34
34
  var title = _a.title, description = _a.description, icon = _a.icon, rightIcon = _a.rightIcon, hideDefaultRightIcon = _a.hideDefaultRightIcon, sx = _a.sx, rest = __rest(_a, ["title", "description", "icon", "rightIcon", "hideDefaultRightIcon", "sx"]);
35
35
  var theme = (0, material_1.useTheme)();
36
- return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, __assign({}, rest, { sx: __assign(__assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g12, backgroundColor: "background.white16", borderRadius: theme.mixins.theBorderRadius.r12, padding: 0 }), sx), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 32, src: icon }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g2, alignItems: "start", flex: 1 }), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.listTitle), children: title }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.listDescription), children: description })] }), rightIcon !== null && rightIcon !== void 0 ? rightIcon : (!hideDefaultRightIcon && ((0, jsx_runtime_1.jsx)(Icon_1.default, { width: 10, src: (0, getIcon_1.default)("right_arrow"), sx: { ml: "auto" } })))] })));
36
+ return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, __assign({}, rest, { sx: __assign(__assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g12, padding: 0 }), sx), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 32, src: icon }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g2, alignItems: "start", flex: 1 }), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.listTitle), children: title }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.listDescription), children: description })] }), rightIcon !== null && rightIcon !== void 0 ? rightIcon : (!hideDefaultRightIcon && ((0, jsx_runtime_1.jsx)(Icon_1.default, { width: 10, src: (0, getIcon_1.default)("right_arrow"), sx: { ml: "auto" } })))] })));
37
37
  }
38
38
  exports.default = ListItemCustom;
@@ -30,7 +30,7 @@ var QrCodeReader = (0, react_1.forwardRef)(function (props, ref) {
30
30
  open: open,
31
31
  close: close,
32
32
  }); });
33
- return ((0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { trigger: props.children, ref: drawerRef, onClose: onClose, onOpen: onOpen, children: isOpen && ((0, jsx_runtime_1.jsx)(react_qr_scanner_1.Scanner, { components: {
33
+ return ((0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { trigger: props.children, ref: drawerRef, onClose: onClose, onOpen: onOpen, children: isOpen && ((0, jsx_runtime_1.jsxs)(react_qr_scanner_1.Scanner, { components: {
34
34
  audio: false,
35
35
  finder: false,
36
36
  }, styles: {
@@ -44,51 +44,57 @@ var QrCodeReader = (0, react_1.forwardRef)(function (props, ref) {
44
44
  height: "100%",
45
45
  objectFit: "cover",
46
46
  },
47
- }, onScan: props.onResult, children: (0, jsx_runtime_1.jsxs)("div", { style: {
48
- width: "60%",
49
- aspectRatio: "1",
50
- position: "absolute",
51
- top: "40%",
52
- left: "50%",
53
- transform: "translateX(-50%) translateY(-50%)",
54
- display: "relative",
55
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
56
- position: "absolute",
57
- borderTopLeftRadius: "12px",
58
- top: "0",
59
- left: "0",
60
- width: "18%",
61
- height: "18%",
62
- borderTop: "3px solid white",
63
- borderLeft: "3px solid white",
64
- } }), (0, jsx_runtime_1.jsx)("div", { style: {
65
- position: "absolute",
66
- borderTopRightRadius: "12px",
67
- top: "0",
68
- right: "0",
69
- width: "18%",
70
- height: "18%",
71
- borderTop: "3px solid white",
72
- borderRight: "3px solid white",
73
- } }), (0, jsx_runtime_1.jsx)("div", { style: {
74
- position: "absolute",
75
- borderBottomLeftRadius: "12px",
76
- bottom: "0",
77
- left: "0",
78
- width: "18%",
79
- height: "18%",
80
- borderBottom: "3px solid white",
81
- borderLeft: "3px solid white",
82
- } }), (0, jsx_runtime_1.jsx)("div", { style: {
83
- position: "absolute",
84
- borderBottomRightRadius: "12px",
85
- bottom: "0",
86
- right: "0",
87
- width: "18%",
88
- height: "18%",
89
- borderBottom: "3px solid white",
90
- borderRight: "3px solid white",
91
- } })] }) })) }));
47
+ }, onScan: props.onResult, children: [(0, jsx_runtime_1.jsxs)("div", { style: {
48
+ width: "60%",
49
+ aspectRatio: "1",
50
+ position: "absolute",
51
+ top: "40%",
52
+ left: "50%",
53
+ transform: "translateX(-50%) translateY(-50%)",
54
+ display: "relative",
55
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
56
+ position: "absolute",
57
+ borderTopLeftRadius: "12px",
58
+ top: "0",
59
+ left: "0",
60
+ width: "18%",
61
+ height: "18%",
62
+ borderTop: "3px solid white",
63
+ borderLeft: "3px solid white",
64
+ } }), (0, jsx_runtime_1.jsx)("div", { style: {
65
+ position: "absolute",
66
+ borderTopRightRadius: "12px",
67
+ top: "0",
68
+ right: "0",
69
+ width: "18%",
70
+ height: "18%",
71
+ borderTop: "3px solid white",
72
+ borderRight: "3px solid white",
73
+ } }), (0, jsx_runtime_1.jsx)("div", { style: {
74
+ position: "absolute",
75
+ borderBottomLeftRadius: "12px",
76
+ bottom: "0",
77
+ left: "0",
78
+ width: "18%",
79
+ height: "18%",
80
+ borderBottom: "3px solid white",
81
+ borderLeft: "3px solid white",
82
+ } }), (0, jsx_runtime_1.jsx)("div", { style: {
83
+ position: "absolute",
84
+ borderBottomRightRadius: "12px",
85
+ bottom: "0",
86
+ right: "0",
87
+ width: "18%",
88
+ height: "18%",
89
+ borderBottom: "3px solid white",
90
+ borderRight: "3px solid white",
91
+ } })] }), (0, jsx_runtime_1.jsx)("div", { onClick: close, style: {
92
+ position: "absolute",
93
+ top: "1rem",
94
+ right: "1rem",
95
+ zIndex: 6000,
96
+ cursor: "pointer",
97
+ }, children: "Close" })] })) }));
92
98
  });
93
99
  QrCodeReader.displayName = "QrCodeReader";
94
100
  exports.default = QrCodeReader;
@@ -11,6 +11,42 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  return __assign.apply(this, arguments);
13
13
  };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __generator = (this && this.__generator) || function (thisArg, body) {
24
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
25
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26
+ function verb(n) { return function (v) { return step([n, v]); }; }
27
+ function step(op) {
28
+ if (f) throw new TypeError("Generator is already executing.");
29
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
30
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
31
+ if (y = 0, t) op = [op[0] & 2, t.value];
32
+ switch (op[0]) {
33
+ case 0: case 1: t = op; break;
34
+ case 4: _.label++; return { value: op[1], done: false };
35
+ case 5: _.label++; y = op[1]; op = [0]; continue;
36
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
37
+ default:
38
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
39
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
40
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
41
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
42
+ if (t[2]) _.ops.pop();
43
+ _.trys.pop(); continue;
44
+ }
45
+ op = body.call(thisArg, _);
46
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
47
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
+ }
49
+ };
14
50
  var __importDefault = (this && this.__importDefault) || function (mod) {
15
51
  return (mod && mod.__esModule) ? mod : { "default": mod };
16
52
  };
@@ -38,6 +74,8 @@ var useWithdrawData_1 = __importDefault(require("../../../hooks/useWithdrawData"
38
74
  var ListItemCustom_1 = __importDefault(require("../ListItemCustom"));
39
75
  var Input_1 = __importDefault(require("../Input"));
40
76
  var QrCodeReader_1 = __importDefault(require("../QrCodeReader"));
77
+ var validate_wallet_address_service_1 = __importDefault(require("../../../services/axios/validate-wallet-address-service"));
78
+ var parseTonTransferUrl_1 = __importDefault(require("../../../utils/parseTonTransferUrl"));
41
79
  var SendMethods;
42
80
  (function (SendMethods) {
43
81
  SendMethods["SCAN_QR_CODE"] = "scan qr code";
@@ -177,13 +215,49 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
177
215
  setSelectedNetwork(network);
178
216
  nextStep();
179
217
  };
180
- var handleScanAllQrCode = function (result) {
181
- var _a;
182
- if (result) {
183
- console.error("result", result);
184
- (_a = scannerAllQrCodeRef.current) === null || _a === void 0 ? void 0 : _a.close();
185
- }
186
- };
218
+ // const handleValidateWalletAddress = async (
219
+ // data: ValidateWalletAddressBody
220
+ // ) => {
221
+ // const validateWalletAddress = await validateWalletAddressService({
222
+ // address: data?.address,
223
+ // network: data?.network,
224
+ // });
225
+ // };
226
+ var handleScanAllQrCode = function (result) { return __awaiter(void 0, void 0, void 0, function () {
227
+ var text, tonTransferParam, validateWalletAddress;
228
+ var _a, _b;
229
+ return __generator(this, function (_c) {
230
+ switch (_c.label) {
231
+ case 0:
232
+ if (!result) return [3 /*break*/, 2];
233
+ console.error("result", result);
234
+ text = (_a = result === null || result === void 0 ? void 0 : result[0]) === null || _a === void 0 ? void 0 : _a.rawValue;
235
+ tonTransferParam = (0, parseTonTransferUrl_1.default)(text);
236
+ return [4 /*yield*/, (0, validate_wallet_address_service_1.default)({
237
+ address: tonTransferParam === null || tonTransferParam === void 0 ? void 0 : tonTransferParam.address,
238
+ network: (selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.slug) || "",
239
+ })];
240
+ case 1:
241
+ validateWalletAddress = _c.sent();
242
+ console.warn("validateWalletAddress", validateWalletAddress);
243
+ if (!!(validateWalletAddress === null || validateWalletAddress === void 0 ? void 0 : validateWalletAddress.master_wallet_address)) {
244
+ //internal
245
+ console.warn("internal");
246
+ }
247
+ else if (!!(validateWalletAddress === null || validateWalletAddress === void 0 ? void 0 : validateWalletAddress.valid)) {
248
+ //external
249
+ console.warn("external");
250
+ }
251
+ else {
252
+ //invalid
253
+ console.warn("invalid");
254
+ }
255
+ (_b = scannerAllQrCodeRef.current) === null || _b === void 0 ? void 0 : _b.close();
256
+ _c.label = 2;
257
+ case 2: return [2 /*return*/];
258
+ }
259
+ });
260
+ }); };
187
261
  var handleScanAddressQrCode = function () { };
188
262
  (0, react_1.useEffect)(function () {
189
263
  if (isAuthenticated && !withdrawTokens) {
@@ -0,0 +1,3 @@
1
+ import { ValidateWalletAddressBody, ValidateWalletAddressData } from "./type";
2
+ declare const validateWalletAddressService: (body: ValidateWalletAddressBody) => Promise<ValidateWalletAddressData>;
3
+ export default validateWalletAddressService;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var userClientRequest_1 = __importDefault(require("../clients/userClientRequest"));
43
+ var validateWalletAddressService = function (body) { return __awaiter(void 0, void 0, void 0, function () {
44
+ var response;
45
+ var _a;
46
+ return __generator(this, function (_b) {
47
+ switch (_b.label) {
48
+ case 0: return [4 /*yield*/, userClientRequest_1.default.get("/crypto/validate-address/".concat(body.network, "?address=").concat(body.address))];
49
+ case 1:
50
+ response = _b.sent();
51
+ return [2 /*return*/, (_a = response.data) === null || _a === void 0 ? void 0 : _a.data];
52
+ }
53
+ });
54
+ }); };
55
+ exports.default = validateWalletAddressService;
@@ -0,0 +1,17 @@
1
+ export interface ValidateWalletAddressResponse {
2
+ success: boolean;
3
+ message: string;
4
+ data: ValidateWalletAddressData;
5
+ timestamp: string;
6
+ }
7
+ export interface ValidateWalletAddressData {
8
+ status: number;
9
+ address: string;
10
+ valid: number;
11
+ master_wallet_address: null;
12
+ is_existed: boolean;
13
+ }
14
+ export interface ValidateWalletAddressBody {
15
+ address: string;
16
+ network: string;
17
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export interface TonTransferUrlParams {
2
+ protocol: "ton" | "https";
3
+ address: string;
4
+ amount: string | undefined;
5
+ text: string | undefined;
6
+ bin: string | undefined;
7
+ init: string | undefined;
8
+ jetton: string | undefined;
9
+ isDeepLinkFormat: boolean;
10
+ }
11
+ export default function parseTonTransferUrl(url: string): TonTransferUrlParams;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = parseTonTransferUrl;
4
+ var ton_core_1 = require("ton-core");
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
+ 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;
62
+ }
63
+ // text
64
+ if (params.has("text")) {
65
+ result.text = decodeURIComponent(params.get("text"));
66
+ }
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;
74
+ }
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;
82
+ }
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;
89
+ }
90
+ catch (_e) {
91
+ throw new Error("Invalid jetton address");
92
+ }
93
+ }
94
+ }
95
+ return result;
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.283",
3
+ "version": "0.0.285",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -48,7 +48,9 @@
48
48
  "react-otp-input": "^3.1.1",
49
49
  "react-qr-reader": "^3.0.0-beta-1",
50
50
  "styled-components": "^6.1.17",
51
- "swiper": "^11.2.4"
51
+ "swiper": "^11.2.4",
52
+ "ton-core": "^0.53.0",
53
+ "ton-crypto": "^3.2.0"
52
54
  },
53
55
  "peerDependencies": {
54
56
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",