tek-wallet 0.0.527 → 0.0.529

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.
@@ -188,7 +188,7 @@ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
188
188
  case 0:
189
189
  setIsValidatingAddress(true);
190
190
  return [4 /*yield*/, (0, validate_wallet_address_service_1.default)({
191
- address: toAddress + "k",
191
+ address: toAddress,
192
192
  network: network === null || network === void 0 ? void 0 : network.slug,
193
193
  })];
194
194
  case 1:
@@ -0,0 +1,24 @@
1
+ import { ConfirmLayoutProps } from "../ConfirmLayout";
2
+ import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
3
+ import { SendInternalBody, SendInternalResponse } from "../../../services/axios/send-internal-service/type";
4
+ interface SendInternalDataType extends Omit<SendInternalBody, "passcode"> {
5
+ }
6
+ interface SendInternalTokenProps extends Omit<ConfirmLayoutProps, "action"> {
7
+ sendInternalData: SendInternalDataType;
8
+ onSuccess?: (data: SendInternalResponse) => any;
9
+ initFeeData?: FeesDataType;
10
+ onStart?: () => void;
11
+ }
12
+ export interface SendInternalTokenRef {
13
+ open: () => void;
14
+ close: () => void;
15
+ }
16
+ export declare enum SendInternalTokenError {
17
+ TOKEN_NOT_FOUND = "Token not found",
18
+ NOT_ENOUGH_BALANCE = "Not enough balance",
19
+ MAX_AMOUNT = "Max amount",
20
+ MIN_AMOUNT = "Min amount",
21
+ FAILED = "Failed"
22
+ }
23
+ declare const SendInternalToken: import("react").ForwardRefExoticComponent<Omit<SendInternalTokenProps, "ref"> & import("react").RefAttributes<SendInternalTokenRef>>;
24
+ export default SendInternalToken;
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ "use client";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
48
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
49
+ return new (P || (P = Promise))(function (resolve, reject) {
50
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
51
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
52
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
53
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
54
+ });
55
+ };
56
+ var __generator = (this && this.__generator) || function (thisArg, body) {
57
+ 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);
58
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
59
+ function verb(n) { return function (v) { return step([n, v]); }; }
60
+ function step(op) {
61
+ if (f) throw new TypeError("Generator is already executing.");
62
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
63
+ 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;
64
+ if (y = 0, t) op = [op[0] & 2, t.value];
65
+ switch (op[0]) {
66
+ case 0: case 1: t = op; break;
67
+ case 4: _.label++; return { value: op[1], done: false };
68
+ case 5: _.label++; y = op[1]; op = [0]; continue;
69
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
70
+ default:
71
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
72
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
73
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
74
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
75
+ if (t[2]) _.ops.pop();
76
+ _.trys.pop(); continue;
77
+ }
78
+ op = body.call(thisArg, _);
79
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
80
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
81
+ }
82
+ };
83
+ var __importDefault = (this && this.__importDefault) || function (mod) {
84
+ return (mod && mod.__esModule) ? mod : { "default": mod };
85
+ };
86
+ Object.defineProperty(exports, "__esModule", { value: true });
87
+ exports.SendInternalTokenError = void 0;
88
+ var jsx_runtime_1 = require("react/jsx-runtime");
89
+ var material_1 = require("@mui/material");
90
+ var Button_1 = __importStar(require("../../ui/Button"));
91
+ var ConfirmLayout_1 = __importDefault(require("../ConfirmLayout"));
92
+ var LineValue_1 = __importDefault(require("../LineValue"));
93
+ var Formatter_1 = __importDefault(require("../Formatter"));
94
+ var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
95
+ var react_1 = require("react");
96
+ var Text_1 = __importDefault(require("../Text"));
97
+ var RequireConnect_1 = __importDefault(require("../RequireConnect"));
98
+ var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
99
+ var useWithdrawData_1 = __importDefault(require("../../../hooks/useWithdrawData"));
100
+ var Fees_1 = __importDefault(require("../Fees"));
101
+ var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
102
+ var type_1 = require("../../../services/axios/get-activities-service/type");
103
+ var send_internal_service_1 = __importDefault(require("../../../services/axios/send-internal-service"));
104
+ var SendInternalTokenError;
105
+ (function (SendInternalTokenError) {
106
+ SendInternalTokenError["TOKEN_NOT_FOUND"] = "Token not found";
107
+ SendInternalTokenError["NOT_ENOUGH_BALANCE"] = "Not enough balance";
108
+ SendInternalTokenError["MAX_AMOUNT"] = "Max amount";
109
+ SendInternalTokenError["MIN_AMOUNT"] = "Min amount";
110
+ SendInternalTokenError["FAILED"] = "Failed";
111
+ })(SendInternalTokenError || (exports.SendInternalTokenError = SendInternalTokenError = {}));
112
+ var transactionSlug = type_1.TransactionSlug.TransferInternal;
113
+ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
114
+ var _a;
115
+ var theme = (0, material_1.useTheme)();
116
+ var withdrawTokens = (0, useWithdrawData_1.default)().withdrawTokens;
117
+ var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
118
+ var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
119
+ var _b = (0, react_1.useState)(undefined), token = _b[0], setToken = _b[1];
120
+ var _c = (0, react_1.useState)(undefined), error = _c[0], setError = _c[1];
121
+ var _d = (0, react_1.useState)(undefined), errorAmount = _d[0], setErrorAmount = _d[1];
122
+ var _e = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _e[0], setButtonStatus = _e[1];
123
+ var _f = (0, react_1.useState)(props.initFeeData), estimateFee = _f[0], setEstimateFee = _f[1];
124
+ var _g = (0, react_1.useState)(false), isLoadingEstimateFee = _g[0], setIsLoadingEstimateFee = _g[1];
125
+ var amount = props.sendInternalData.amount;
126
+ var toAddress = props.sendInternalData.to_address;
127
+ var tokenSlug = props.sendInternalData.currency_slug;
128
+ var getEstimateFee = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
129
+ var response;
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ if (!tokenSlug || !!errorAmount)
134
+ return [2 /*return*/];
135
+ setIsLoadingEstimateFee(true);
136
+ return [4 /*yield*/, (0, get_est_fee_service_1.default)({
137
+ amount: "".concat(amount),
138
+ transaction_type: transactionSlug,
139
+ currency: tokenSlug || "",
140
+ })];
141
+ case 1:
142
+ response = _a.sent();
143
+ setIsLoadingEstimateFee(false);
144
+ setEstimateFee(response === null || response === void 0 ? void 0 : response.data);
145
+ return [2 /*return*/];
146
+ }
147
+ });
148
+ }); }, [amount, tokenSlug, errorAmount]);
149
+ var validateAmount = (0, react_1.useCallback)(function (sendInternalData) {
150
+ var token = withdrawTokens === null || withdrawTokens === void 0 ? void 0 : withdrawTokens.find(function (token) { return token.slug === sendInternalData.currency_slug; });
151
+ setToken(token);
152
+ if (!token) {
153
+ setError(SendInternalTokenError.TOKEN_NOT_FOUND);
154
+ return;
155
+ }
156
+ if (+sendInternalData.amount > token.max_value) {
157
+ setError(SendInternalTokenError.MAX_AMOUNT);
158
+ setErrorAmount(token.max_value);
159
+ return;
160
+ }
161
+ if (+sendInternalData.amount < token.min_value) {
162
+ setError(SendInternalTokenError.MIN_AMOUNT);
163
+ setErrorAmount(token.min_value);
164
+ return;
165
+ }
166
+ if (+sendInternalData.amount > +token.balance) {
167
+ setError(SendInternalTokenError.NOT_ENOUGH_BALANCE);
168
+ setErrorAmount(token.balance);
169
+ return;
170
+ }
171
+ setError(undefined);
172
+ setErrorAmount(undefined);
173
+ }, [withdrawTokens]);
174
+ var handleSendInternalToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
175
+ var response, err_1;
176
+ var _a, _b;
177
+ return __generator(this, function (_c) {
178
+ switch (_c.label) {
179
+ case 0:
180
+ _c.trys.push([0, 2, , 3]);
181
+ setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
182
+ return [4 /*yield*/, (0, send_internal_service_1.default)(__assign(__assign({}, props.sendInternalData), { passcode: passcode }))];
183
+ case 1:
184
+ response = _c.sent();
185
+ if (response.success) {
186
+ (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
187
+ setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
188
+ (_b = props.onSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
189
+ }
190
+ else {
191
+ throw new Error("Send external failed");
192
+ }
193
+ return [3 /*break*/, 3];
194
+ case 2:
195
+ err_1 = _c.sent();
196
+ console.error(err_1);
197
+ setButtonStatus(Button_1.BUTTON_STATUS.ERROR);
198
+ setTimeout(function () {
199
+ setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
200
+ }, 1200);
201
+ return [3 /*break*/, 3];
202
+ case 3: return [2 /*return*/];
203
+ }
204
+ });
205
+ }); };
206
+ var handleOpen = function () {
207
+ var _a;
208
+ if (!isAuthenticated)
209
+ throw new Error("Please connect your wallet");
210
+ (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
211
+ };
212
+ var handleClose = function () {
213
+ var _a;
214
+ if (!isAuthenticated)
215
+ throw new Error("Please connect your wallet");
216
+ (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
217
+ };
218
+ (0, react_1.useImperativeHandle)(ref, function () { return ({
219
+ open: handleOpen,
220
+ close: handleClose,
221
+ }); });
222
+ var estimateReceive = (0, react_1.useMemo)(function () {
223
+ if (!estimateFee || !amount)
224
+ return undefined;
225
+ return +amount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeInCurrency);
226
+ }, [estimateFee, amount]);
227
+ (0, react_1.useEffect)(function () {
228
+ getEstimateFee();
229
+ }, [getEstimateFee]);
230
+ (0, react_1.useEffect)(function () {
231
+ validateAmount(props.sendInternalData);
232
+ }, [validateAmount, props.sendInternalData]);
233
+ return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsx)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Recipient address", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
234
+ wordBreak: "break-all",
235
+ }, children: toAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
236
+ fontWeight: theme.typography.fontWeight600,
237
+ fontSize: theme.typography.fontSize16,
238
+ }, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.gaps.g6 }), children: [error, " ", !!errorAmount && (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: errorAmount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSendInternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee ? Button_1.BUTTON_STATUS.DISABLED : buttonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }) }) }));
239
+ });
240
+ SendInternalToken.displayName = "SendInternalToken";
241
+ exports.default = SendInternalToken;
@@ -1,7 +1,7 @@
1
1
  import { ConfirmLayoutProps } from "../ConfirmLayout";
2
- import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
3
2
  import { SendInternalBody, SendInternalResponse } from "../../../services/axios/send-internal-service/type";
4
- interface SendInternalDataType extends Omit<SendInternalBody, "passcode"> {
3
+ import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
4
+ interface SendInternalDataType extends Omit<SendInternalBody, "network" | "passcode"> {
5
5
  }
6
6
  interface SendInternalTokenProps extends Omit<ConfirmLayoutProps, "action"> {
7
7
  sendInternalData: SendInternalDataType;
@@ -97,10 +97,13 @@ var Text_1 = __importDefault(require("../Text"));
97
97
  var RequireConnect_1 = __importDefault(require("../RequireConnect"));
98
98
  var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
99
99
  var useWithdrawData_1 = __importDefault(require("../../../hooks/useWithdrawData"));
100
+ var send_internal_service_1 = __importDefault(require("../../../services/axios/send-internal-service"));
100
101
  var Fees_1 = __importDefault(require("../Fees"));
101
102
  var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
102
103
  var type_1 = require("../../../services/axios/get-activities-service/type");
103
- var send_internal_service_1 = __importDefault(require("../../../services/axios/send-internal-service"));
104
+ var Activities_1 = __importDefault(require("../Activities"));
105
+ var validate_wallet_address_service_1 = __importDefault(require("../../../services/axios/validate-wallet-address-service"));
106
+ var type_2 = require("../../../services/axios/validate-wallet-address-service/type");
104
107
  var SendInternalTokenError;
105
108
  (function (SendInternalTokenError) {
106
109
  SendInternalTokenError["TOKEN_NOT_FOUND"] = "Token not found";
@@ -109,19 +112,21 @@ var SendInternalTokenError;
109
112
  SendInternalTokenError["MIN_AMOUNT"] = "Min amount";
110
113
  SendInternalTokenError["FAILED"] = "Failed";
111
114
  })(SendInternalTokenError || (exports.SendInternalTokenError = SendInternalTokenError = {}));
112
- var transactionSlug = type_1.TransactionSlug.TransferInternal;
115
+ var transactionSlug = type_1.TransactionSlug.Withdrawn;
113
116
  var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
114
117
  var _a;
115
118
  var theme = (0, material_1.useTheme)();
116
119
  var withdrawTokens = (0, useWithdrawData_1.default)().withdrawTokens;
117
120
  var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
118
121
  var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
119
- var _b = (0, react_1.useState)(undefined), token = _b[0], setToken = _b[1];
120
- var _c = (0, react_1.useState)(undefined), error = _c[0], setError = _c[1];
121
- var _d = (0, react_1.useState)(undefined), errorAmount = _d[0], setErrorAmount = _d[1];
122
- var _e = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _e[0], setButtonStatus = _e[1];
123
- var _f = (0, react_1.useState)(props.initFeeData), estimateFee = _f[0], setEstimateFee = _f[1];
124
- var _g = (0, react_1.useState)(false), isLoadingEstimateFee = _g[0], setIsLoadingEstimateFee = _g[1];
122
+ var _b = (0, react_1.useState)(undefined), error = _b[0], setError = _b[1];
123
+ var _c = (0, react_1.useState)(undefined), errorAmount = _c[0], setErrorAmount = _c[1];
124
+ var _d = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _d[0], setButtonStatus = _d[1];
125
+ var _e = (0, react_1.useState)(undefined), errorAddress = _e[0], setErrorAddress = _e[1];
126
+ var _f = (0, react_1.useState)(false), isValidatingAddress = _f[0], setIsValidatingAddress = _f[1];
127
+ var _g = (0, react_1.useState)(props.initFeeData), estimateFee = _g[0], setEstimateFee = _g[1];
128
+ var _h = (0, react_1.useState)(false), isLoadingEstimateFee = _h[0], setIsLoadingEstimateFee = _h[1];
129
+ var activitiesRef = (0, react_1.useRef)(null);
125
130
  var amount = props.sendInternalData.amount;
126
131
  var toAddress = props.sendInternalData.to_address;
127
132
  var tokenSlug = props.sendInternalData.currency_slug;
@@ -130,7 +135,7 @@ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
130
135
  return __generator(this, function (_a) {
131
136
  switch (_a.label) {
132
137
  case 0:
133
- if (!tokenSlug || !!errorAmount)
138
+ if (!tokenSlug)
134
139
  return [2 /*return*/];
135
140
  setIsLoadingEstimateFee(true);
136
141
  return [4 /*yield*/, (0, get_est_fee_service_1.default)({
@@ -142,35 +147,70 @@ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
142
147
  response = _a.sent();
143
148
  setIsLoadingEstimateFee(false);
144
149
  setEstimateFee(response === null || response === void 0 ? void 0 : response.data);
145
- return [2 /*return*/];
150
+ return [2 /*return*/, true];
146
151
  }
147
152
  });
148
- }); }, [amount, tokenSlug, errorAmount]);
149
- var validateAmount = (0, react_1.useCallback)(function (sendInternalData) {
150
- var token = withdrawTokens === null || withdrawTokens === void 0 ? void 0 : withdrawTokens.find(function (token) { return token.slug === sendInternalData.currency_slug; });
151
- setToken(token);
153
+ }); }, [amount, tokenSlug]);
154
+ var token = (0, react_1.useMemo)(function () {
155
+ return withdrawTokens === null || withdrawTokens === void 0 ? void 0 : withdrawTokens.find(function (token) { return token.slug === tokenSlug; });
156
+ }, [tokenSlug, withdrawTokens]);
157
+ var validateAmount = (0, react_1.useCallback)(function () {
152
158
  if (!token) {
153
159
  setError(SendInternalTokenError.TOKEN_NOT_FOUND);
154
- return;
160
+ return false;
155
161
  }
156
- if (+sendInternalData.amount > token.max_value) {
162
+ if (+amount > token.max_value) {
157
163
  setError(SendInternalTokenError.MAX_AMOUNT);
158
164
  setErrorAmount(token.max_value);
159
- return;
165
+ return false;
160
166
  }
161
- if (+sendInternalData.amount < token.min_value) {
167
+ if (+amount < token.min_value) {
162
168
  setError(SendInternalTokenError.MIN_AMOUNT);
163
169
  setErrorAmount(token.min_value);
164
- return;
170
+ return false;
165
171
  }
166
- if (+sendInternalData.amount > +token.balance) {
172
+ if (+amount > +token.balance) {
167
173
  setError(SendInternalTokenError.NOT_ENOUGH_BALANCE);
168
174
  setErrorAmount(token.balance);
169
- return;
175
+ return false;
170
176
  }
171
177
  setError(undefined);
172
178
  setErrorAmount(undefined);
173
- }, [withdrawTokens]);
179
+ return true;
180
+ }, [amount, token]);
181
+ var validateAddress = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
182
+ var message;
183
+ return __generator(this, function (_a) {
184
+ switch (_a.label) {
185
+ case 0:
186
+ setIsValidatingAddress(true);
187
+ return [4 /*yield*/, (0, validate_wallet_address_service_1.default)({
188
+ address: toAddress,
189
+ network: "ton",
190
+ })];
191
+ case 1:
192
+ message = (_a.sent()).message;
193
+ setIsValidatingAddress(false);
194
+ if (message !== type_2.ValidateWalletAddressResultMessage.INTERNAL_WALLET) {
195
+ setErrorAddress("Invalid wallet address");
196
+ return [2 /*return*/, false];
197
+ }
198
+ setErrorAddress(undefined);
199
+ return [2 /*return*/, true];
200
+ }
201
+ });
202
+ }); }, [toAddress]);
203
+ var validateAll = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
204
+ var isAmountValid;
205
+ return __generator(this, function (_a) {
206
+ isAmountValid = validateAmount();
207
+ if (!isAmountValid)
208
+ return [2 /*return*/, false];
209
+ validateAddress();
210
+ getEstimateFee();
211
+ return [2 /*return*/];
212
+ });
213
+ }); }, [validateAmount, validateAddress, getEstimateFee]);
174
214
  var handleSendInternalToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
175
215
  var response, err_1;
176
216
  var _a, _b;
@@ -186,9 +226,13 @@ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
186
226
  (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
187
227
  setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
188
228
  (_b = props.onSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
229
+ setTimeout(function () {
230
+ var _a;
231
+ (_a = activitiesRef.current) === null || _a === void 0 ? void 0 : _a.openTab(0);
232
+ }, 200);
189
233
  }
190
234
  else {
191
- throw new Error("Send external failed");
235
+ throw new Error("Send internal failed");
192
236
  }
193
237
  return [3 /*break*/, 3];
194
238
  case 2:
@@ -208,6 +252,7 @@ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
208
252
  if (!isAuthenticated)
209
253
  throw new Error("Please connect your wallet");
210
254
  (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
255
+ validateAll();
211
256
  };
212
257
  var handleClose = function () {
213
258
  var _a;
@@ -224,18 +269,14 @@ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
224
269
  return undefined;
225
270
  return +amount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeInCurrency);
226
271
  }, [estimateFee, amount]);
227
- (0, react_1.useEffect)(function () {
228
- getEstimateFee();
229
- }, [getEstimateFee]);
230
- (0, react_1.useEffect)(function () {
231
- validateAmount(props.sendInternalData);
232
- }, [validateAmount, props.sendInternalData]);
233
- return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsx)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Recipient address", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
234
- wordBreak: "break-all",
235
- }, children: toAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
236
- fontWeight: theme.typography.fontWeight600,
237
- fontSize: theme.typography.fontSize16,
238
- }, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.gaps.g6 }), children: [error, " ", !!errorAmount && (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: errorAmount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSendInternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee ? Button_1.BUTTON_STATUS.DISABLED : buttonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }) }) }));
272
+ return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsxs)(ConfirmLayout_1.default, { onOpen: validateAll, ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Recipient address", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
273
+ wordBreak: "break-all",
274
+ }, children: toAddress }), valueDescription: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.validationError), children: errorAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
275
+ fontWeight: theme.typography.fontWeight600,
276
+ fontSize: theme.typography.fontSize16,
277
+ }, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.customMargin.m6 }), children: [error, " ", !!errorAmount && (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: errorAmount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSendInternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee || isValidatingAddress || errorAddress
278
+ ? Button_1.BUTTON_STATUS.DISABLED
279
+ : buttonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }), (0, jsx_runtime_1.jsx)(Activities_1.default, { ref: activitiesRef })] }) }));
239
280
  });
240
281
  SendInternalToken.displayName = "SendInternalToken";
241
282
  exports.default = SendInternalToken;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.527",
3
+ "version": "0.0.529",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",