tek-wallet 0.0.464 → 0.0.466

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.
@@ -86,7 +86,7 @@ function ActivityItem(props) {
86
86
  return ((0, jsx_runtime_1.jsxs)(material_1.ListItemButton, __assign({ sx: __assign(__assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g8, backgroundColor: theme.palette.background.white16, borderRadius: theme.mixins.customRadius.r16, p: theme.mixins.customPadding.p12, flexGrow: "unset", boxShadow: theme.shadows[1] }), sx) }, rest, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
87
87
  width: "fit-content",
88
88
  height: "fit-content",
89
- }, children: (0, jsx_runtime_1.jsx)(Icon_1.default, { src: type === null || type === void 0 ? void 0 : type.icon, width: 24 }) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { width: "fit-content" }), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: theme.mixins.activityTitle, children: type === null || type === void 0 ? void 0 : type.name }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: theme.mixins.activityDescription, children: descriptionElement }), status !== type_1.TransactionStatus.Success && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g4 }), children: [status === type_1.TransactionStatus.Processing && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { color: "secondary", size: 16 }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
89
+ }, children: (0, jsx_runtime_1.jsx)(Icon_1.default, { src: type === null || type === void 0 ? void 0 : type.link, width: 24 }) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { width: "fit-content" }), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: theme.mixins.activityTitle, children: type === null || type === void 0 ? void 0 : type.name }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: theme.mixins.activityDescription, children: descriptionElement }), status !== type_1.TransactionStatus.Success && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g4 }), children: [status === type_1.TransactionStatus.Processing && (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { color: "secondary", size: 16 }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
90
90
  fontSize: theme.typography.fontSize12,
91
91
  textTransform: "capitalize",
92
92
  color: getStatusColor(),
@@ -0,0 +1,25 @@
1
+ import { ConfirmLayoutProps } from "../ConfirmLayout";
2
+ import { SendExternalBody, SendExternalResponse } from "../../../services/axios/send-external-service/type";
3
+ import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
4
+ import { NetworkData } from "../../../services/axios/type";
5
+ interface SendExternalDataType extends Omit<SendExternalBody, "network"> {
6
+ network: NetworkData;
7
+ }
8
+ interface SendExternalTokenProps extends Omit<ConfirmLayoutProps, "action"> {
9
+ sendExternalData: SendExternalDataType;
10
+ onSuccess?: (data: SendExternalResponse) => any;
11
+ initFeeData?: FeesDataType;
12
+ }
13
+ export interface SendExternalTokenRef {
14
+ open: () => void;
15
+ close: () => void;
16
+ }
17
+ export declare enum SendExternalTokenError {
18
+ TOKEN_NOT_FOUND = "Token not found",
19
+ NOT_ENOUGH_BALANCE = "Not enough balance",
20
+ MAX_AMOUNT = "Max amount",
21
+ MIN_AMOUNT = "Min amount",
22
+ FAILED = "Failed"
23
+ }
24
+ declare const SendExternalToken: import("react").ForwardRefExoticComponent<Omit<SendExternalTokenProps, "ref"> & import("react").RefAttributes<SendExternalTokenRef>>;
25
+ export default SendExternalToken;
@@ -1,182 +1,247 @@
1
1
  "use strict";
2
- // "use client";
3
- // import { Box, useTheme } from "@mui/material";
4
- // import Button, { BUTTON_STATUS } from "../../ui/Button";
5
- // import { DrawerComponentRef } from "../DrawerComponent";
6
- // import ConfirmLayout, { ConfirmLayoutProps } from "../ConfirmLayout";
7
- // import { ActionConfirm } from "../ConfirmLayout/type";
8
- // import LineValue from "../LineValue";
9
- // import Formatter from "../Formatter";
10
- // import ConfirmByPasscode from "../ConfirmByPasscode";
11
- // import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
12
- // import Text from "../Text";
13
- // import { LockCurrency } from "../../../services/axios/get-lock-tokens-list-service/type";
14
- // import RequireConnect from "../RequireConnect";
15
- // import useWalletData from "../../../hooks/useWalletData";
16
- // import { SendExternalBody, SendExternalResponse } from "../../../services/axios/send-external-service/type";
17
- // import useWithdrawData from "../../../hooks/useWithdrawData";
18
- // import sendExternalService from "../../../services/axios/send-external-service";
19
- // import Icon from "../Icon";
20
- // import Fees from "../Fees";
21
- // import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
22
- // interface SendExternalTokenProps extends Omit<ConfirmLayoutProps, "action"> {
23
- // sendExternalData: SendExternalBody;
24
- // onSuccess?: (data: SendExternalResponse) => any;
25
- // }
26
- // export interface SendExternalTokenRef {
27
- // open: () => void;
28
- // close: () => void;
29
- // }
30
- // export enum SendExternalTokenError {
31
- // TOKEN_NOT_FOUND = "Token not found",
32
- // NOT_ENOUGH_BALANCE = "Not enough balance",
33
- // MAX_AMOUNT = "Max amount",
34
- // MIN_AMOUNT = "Min amount",
35
- // FAILED = "Failed",
36
- // }
37
- // const SendExternalToken = forwardRef<SendExternalTokenRef, SendExternalTokenProps>((props, ref) => {
38
- // const theme = useTheme();
39
- // const { withdrawTokens } = useWithdrawData();
40
- // const { isAuthenticated } = useWalletData();
41
- // const confirmLayoutDrawerRef = useRef<DrawerComponentRef>(null);
42
- // const [token, setToken] = useState<LockCurrency | undefined>(undefined);
43
- // const [error, setError] = useState<SendExternalTokenError | undefined>(undefined);
44
- // const [errorAmount, setErrorAmount] = useState<string | number | undefined>(undefined);
45
- // const [buttonStatus, setButtonStatus] = useState<BUTTON_STATUS>(BUTTON_STATUS.ENABLED);
46
- // const [estimateFee, setEstimateFee] = useState<FeesDataType>();
47
- // const amount = props.sendExternalData.amount;
48
- // const network = props.sendExternalData.network;
49
- // const memo = props.sendExternalData.memo;
50
- // const toAddress = props.sendExternalData.to_address;
51
- // const validateAmount = useCallback(
52
- // (sendExternalData: SendExternalBody) => {
53
- // const token = withdrawTokens?.find((token) => token.slug === sendExternalData.currency_slug);
54
- // console.warn("🚀 ~ validateAmount ~ lockData:", sendExternalData, withdrawTokens, token);
55
- // setToken(token);
56
- // if (!token) {
57
- // setError(SendExternalTokenError.TOKEN_NOT_FOUND);
58
- // return;
59
- // }
60
- // if (+sendExternalData.amount > token.max_value) {
61
- // setError(SendExternalTokenError.MAX_AMOUNT);
62
- // setErrorAmount(token.max_value);
63
- // return;
64
- // }
65
- // if (+sendExternalData.amount < token.min_value) {
66
- // setError(SendExternalTokenError.MIN_AMOUNT);
67
- // setErrorAmount(token.min_value);
68
- // return;
69
- // }
70
- // if (+sendExternalData.amount > +token.balance) {
71
- // setError(SendExternalTokenError.NOT_ENOUGH_BALANCE);
72
- // setErrorAmount(token.balance);
73
- // return;
74
- // }
75
- // setError(undefined);
76
- // setErrorAmount(undefined);
77
- // },
78
- // [withdrawTokens]
79
- // );
80
- // const handleSendExternalToken = async (passcode: string) => {
81
- // try {
82
- // console.warn("🚀 ~ handleSendExternalToken ~ sendExternalData:", props.sendExternalData, passcode);
83
- // setButtonStatus(BUTTON_STATUS.LOADING);
84
- // const response = await sendExternalService(props.sendExternalData);
85
- // console.warn("🚀 ~ handleSendExternalToken ~ response:", response);
86
- // if (response.success) {
87
- // confirmLayoutDrawerRef.current?.close();
88
- // setButtonStatus(BUTTON_STATUS.ENABLED);
89
- // props.onSuccess?.(response);
90
- // } else {
91
- // throw new Error("Send external failed");
92
- // }
93
- // } catch (err) {
94
- // console.error(err);
95
- // setButtonStatus(BUTTON_STATUS.ERROR);
96
- // setTimeout(() => {
97
- // setButtonStatus(BUTTON_STATUS.ENABLED);
98
- // }, 1200);
99
- // }
100
- // };
101
- // const handleOpen = () => {
102
- // if (!isAuthenticated) throw new Error("Please connect your wallet");
103
- // confirmLayoutDrawerRef.current?.open();
104
- // };
105
- // const handleClose = () => {
106
- // if (!isAuthenticated) throw new Error("Please connect your wallet");
107
- // confirmLayoutDrawerRef.current?.close();
108
- // };
109
- // useImperativeHandle(ref, () => ({
110
- // open: handleOpen,
111
- // close: handleClose,
112
- // }));
113
- // useEffect(() => {
114
- // validateAmount(props.sendExternalData);
115
- // }, [validateAmount, props.sendExternalData]);
116
- // return (
117
- // <RequireConnect>
118
- // <ConfirmLayout ref={confirmLayoutDrawerRef} action={ActionConfirm.LOCK} trigger={props.children}>
119
- // <Box sx={{ ...theme.mixins.column, gap: theme.mixins.gaps.g12 }}>
120
- // <Box
121
- // sx={{
122
- // ...theme.mixins.paper,
123
- // }}
124
- // >
125
- // <LineValue
126
- // field="Recipient address"
127
- // value={
128
- // <Text
129
- // sx={{
130
- // wordBreak: "break-all",
131
- // }}
132
- // >
133
- // {toAddress}
134
- // </Text>
135
- // }
136
- // />
137
- // <LineValue
138
- // field="Network"
139
- // value={
140
- // <Box
141
- // sx={{
142
- // ...theme.mixins.row,
143
- // gap: theme.mixins.gaps.g6,
144
- // ml: "auto",
145
- // }}
146
- // >
147
- // {/* <Icon width={20} src={props.sendExternalData.network?.icon} /> */}
148
- // <Text sx={{ ...theme.mixins.value }}>{props.sendExternalData.network}</Text>
149
- // </Box>
150
- // }
151
- // />
152
- // <LineValue field="Amount" value={<Formatter value={amount} unit={` ${token?.name}`} />} />
153
- // {!!memo && <LineValue field="Memo" value={memo} />}
154
- // {estimateFee?.feeDetail?.length && !!amount && (
155
- // <Fees feesData={JSON.stringify(estimateFee)} amount={+amount} />
156
- // )}
157
- // <LineValue
158
- // field="Receive amount estimated"
159
- // value={
160
- // <Text
161
- // sx={{
162
- // fontWeight: theme.typography.fontWeight600,
163
- // fontSize: theme.typography.fontSize16,
164
- // }}
165
- // >
166
- // <Formatter value={estimateReceive} unit={` ${selectedToken?.name}`} />
167
- // </Text>
168
- // }
169
- // />
170
- // </Box>
171
- // <ConfirmByPasscode action={ActionConfirm.LOCK} onConfirmSuccess={handleSendExternalToken}>
172
- // <Button.Primary status={!!error ? BUTTON_STATUS.DISABLED : buttonStatus} sx={{ width: "100%" }}>
173
- // Confirm
174
- // </Button.Primary>
175
- // </ConfirmByPasscode>
176
- // </Box>
177
- // </ConfirmLayout>
178
- // </RequireConnect>
179
- // );
180
- // });
181
- // SendExternalToken.displayName = "SendExternalToken";
182
- // export default SendExternalToken;
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.SendExternalTokenError = 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 type_1 = require("../ConfirmLayout/type");
93
+ var LineValue_1 = __importDefault(require("../LineValue"));
94
+ var Formatter_1 = __importDefault(require("../Formatter"));
95
+ var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
96
+ var react_1 = require("react");
97
+ var Text_1 = __importDefault(require("../Text"));
98
+ var RequireConnect_1 = __importDefault(require("../RequireConnect"));
99
+ var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
100
+ var useWithdrawData_1 = __importDefault(require("../../../hooks/useWithdrawData"));
101
+ var send_external_service_1 = __importDefault(require("../../../services/axios/send-external-service"));
102
+ var Icon_1 = __importDefault(require("../Icon"));
103
+ var Fees_1 = __importDefault(require("../Fees"));
104
+ var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
105
+ var type_2 = require("../../../services/axios/get-activities-service/type");
106
+ var SendExternalTokenError;
107
+ (function (SendExternalTokenError) {
108
+ SendExternalTokenError["TOKEN_NOT_FOUND"] = "Token not found";
109
+ SendExternalTokenError["NOT_ENOUGH_BALANCE"] = "Not enough balance";
110
+ SendExternalTokenError["MAX_AMOUNT"] = "Max amount";
111
+ SendExternalTokenError["MIN_AMOUNT"] = "Min amount";
112
+ SendExternalTokenError["FAILED"] = "Failed";
113
+ })(SendExternalTokenError || (exports.SendExternalTokenError = SendExternalTokenError = {}));
114
+ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
115
+ var _a;
116
+ var theme = (0, material_1.useTheme)();
117
+ var withdrawTokens = (0, useWithdrawData_1.default)().withdrawTokens;
118
+ var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
119
+ var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
120
+ var _b = (0, react_1.useState)(undefined), token = _b[0], setToken = _b[1];
121
+ var _c = (0, react_1.useState)(undefined), error = _c[0], setError = _c[1];
122
+ var _d = (0, react_1.useState)(undefined), errorAmount = _d[0], setErrorAmount = _d[1];
123
+ var _e = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _e[0], setButtonStatus = _e[1];
124
+ var _f = (0, react_1.useState)(props.initFeeData), estimateFee = _f[0], setEstimateFee = _f[1];
125
+ var _g = (0, react_1.useState)(false), isLoadingEstimateFee = _g[0], setIsLoadingEstimateFee = _g[1];
126
+ var amount = props.sendExternalData.amount;
127
+ var network = props.sendExternalData.network;
128
+ var memo = props.sendExternalData.memo;
129
+ var toAddress = props.sendExternalData.to_address;
130
+ var tokenSlug = props.sendExternalData.currency_slug;
131
+ var getEstimateFee = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
132
+ var response;
133
+ return __generator(this, function (_a) {
134
+ switch (_a.label) {
135
+ case 0:
136
+ if (!tokenSlug || !!errorAmount)
137
+ return [2 /*return*/];
138
+ setIsLoadingEstimateFee(true);
139
+ return [4 /*yield*/, (0, get_est_fee_service_1.default)({
140
+ amount: "".concat(amount),
141
+ transaction_type: type_2.TransactionSlug.Withdrawn,
142
+ currency: tokenSlug || "",
143
+ })];
144
+ case 1:
145
+ response = _a.sent();
146
+ setIsLoadingEstimateFee(false);
147
+ setEstimateFee(response === null || response === void 0 ? void 0 : response.data);
148
+ return [2 /*return*/];
149
+ }
150
+ });
151
+ }); }, [amount, tokenSlug, errorAmount]);
152
+ var validateAmount = (0, react_1.useCallback)(function (sendExternalData) {
153
+ var token = withdrawTokens === null || withdrawTokens === void 0 ? void 0 : withdrawTokens.find(function (token) { return token.slug === sendExternalData.currency_slug; });
154
+ console.warn("🚀 ~ validateAmount ~ lockData:", sendExternalData, withdrawTokens, token);
155
+ setToken(token);
156
+ if (!token) {
157
+ setError(SendExternalTokenError.TOKEN_NOT_FOUND);
158
+ return;
159
+ }
160
+ if (+sendExternalData.amount > token.max_value) {
161
+ setError(SendExternalTokenError.MAX_AMOUNT);
162
+ setErrorAmount(token.max_value);
163
+ return;
164
+ }
165
+ if (+sendExternalData.amount < token.min_value) {
166
+ setError(SendExternalTokenError.MIN_AMOUNT);
167
+ setErrorAmount(token.min_value);
168
+ return;
169
+ }
170
+ if (+sendExternalData.amount > +token.balance) {
171
+ setError(SendExternalTokenError.NOT_ENOUGH_BALANCE);
172
+ setErrorAmount(token.balance);
173
+ return;
174
+ }
175
+ setError(undefined);
176
+ setErrorAmount(undefined);
177
+ }, [withdrawTokens]);
178
+ var handleSendExternalToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
179
+ var response, err_1;
180
+ var _a, _b;
181
+ return __generator(this, function (_c) {
182
+ switch (_c.label) {
183
+ case 0:
184
+ _c.trys.push([0, 2, , 3]);
185
+ console.warn("🚀 ~ handleSendExternalToken ~ sendExternalData:", props.sendExternalData, passcode);
186
+ setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
187
+ return [4 /*yield*/, (0, send_external_service_1.default)(__assign(__assign({}, props.sendExternalData), { network: network === null || network === void 0 ? void 0 : network.slug }))];
188
+ case 1:
189
+ response = _c.sent();
190
+ console.warn("🚀 ~ handleSendExternalToken ~ response:", response);
191
+ if (response.success) {
192
+ (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
193
+ setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
194
+ (_b = props.onSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
195
+ }
196
+ else {
197
+ throw new Error("Send external failed");
198
+ }
199
+ return [3 /*break*/, 3];
200
+ case 2:
201
+ err_1 = _c.sent();
202
+ console.error(err_1);
203
+ setButtonStatus(Button_1.BUTTON_STATUS.ERROR);
204
+ setTimeout(function () {
205
+ setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
206
+ }, 1200);
207
+ return [3 /*break*/, 3];
208
+ case 3: return [2 /*return*/];
209
+ }
210
+ });
211
+ }); };
212
+ var handleOpen = 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.open();
217
+ };
218
+ var handleClose = function () {
219
+ var _a;
220
+ if (!isAuthenticated)
221
+ throw new Error("Please connect your wallet");
222
+ (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
223
+ };
224
+ (0, react_1.useImperativeHandle)(ref, function () { return ({
225
+ open: handleOpen,
226
+ close: handleClose,
227
+ }); });
228
+ var estimateReceive = (0, react_1.useMemo)(function () {
229
+ if (!estimateFee || !amount)
230
+ return undefined;
231
+ return +amount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeInCurrency);
232
+ }, [estimateFee, amount]);
233
+ (0, react_1.useEffect)(function () {
234
+ getEstimateFee();
235
+ }, [getEstimateFee]);
236
+ (0, react_1.useEffect)(function () {
237
+ validateAmount(props.sendExternalData);
238
+ }, [validateAmount, props.sendExternalData]);
239
+ return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsx)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: type_1.ActionConfirm.LOCK, 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: {
240
+ wordBreak: "break-all",
241
+ }, children: toAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Network", value: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6, ml: "auto" }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 20, src: network === null || network === void 0 ? void 0 : network.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: network === null || network === void 0 ? void 0 : network.name })] }) }), (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) }) }), !!memo && (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Memo", value: memo }), ((_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 })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
242
+ fontWeight: theme.typography.fontWeight600,
243
+ fontSize: theme.typography.fontSize16,
244
+ }, 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: type_1.ActionConfirm.LOCK, onConfirmSuccess: handleSendExternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee ? Button_1.BUTTON_STATUS.DISABLED : buttonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }) }) }));
245
+ });
246
+ SendExternalToken.displayName = "SendExternalToken";
247
+ exports.default = SendExternalToken;
@@ -121,6 +121,8 @@ var type_1 = require("../ConfirmLayout/type");
121
121
  var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
122
122
  var LineValue_1 = __importDefault(require("../LineValue"));
123
123
  var send_external_service_1 = __importDefault(require("../../../services/axios/send-external-service"));
124
+ var type_2 = require("../../../services/axios/get-activities-service/type");
125
+ var SendExternalToken_1 = __importDefault(require("../SendExternalToken"));
124
126
  var SendMethods;
125
127
  (function (SendMethods) {
126
128
  SendMethods["SCAN_QR_CODE"] = "scan qr code";
@@ -367,7 +369,7 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
367
369
  setIsLoadingEstimateFee(true);
368
370
  return [4 /*yield*/, (0, get_est_fee_service_1.default)({
369
371
  amount: "".concat(amount),
370
- transaction_type: "withdrawn",
372
+ transaction_type: selectedMethod === SendMethods.TRANSFER_EXTERNAL ? type_2.TransactionSlug.Withdrawn : type_2.TransactionSlug.TransferInternal,
371
373
  currency: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
372
374
  })];
373
375
  case 1:
@@ -378,7 +380,7 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
378
380
  return [2 /*return*/];
379
381
  }
380
382
  });
381
- }); }, [amount, selectedToken, amountError]);
383
+ }); }, [amount, selectedToken, amountError, selectedMethod]);
382
384
  var openScannerAddressQrCode = function () {
383
385
  var _a;
384
386
  (_a = scannerAddressQrCodeRef.current) === null || _a === void 0 ? void 0 : _a.open();
@@ -522,11 +524,14 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
522
524
  });
523
525
  }); };
524
526
  var handleSendInternal = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
525
- var response;
526
- return __generator(this, function (_a) {
527
- switch (_a.label) {
527
+ var response, err_1;
528
+ var _a, _b;
529
+ return __generator(this, function (_c) {
530
+ switch (_c.label) {
528
531
  case 0:
532
+ _c.trys.push([0, 2, , 3]);
529
533
  console.warn("withdraw internal");
534
+ setSendButtonStatus(Button_1.BUTTON_STATUS.LOADING);
530
535
  return [4 /*yield*/, (0, send_internal_service_1.default)({
531
536
  amount: "".concat(amount),
532
537
  to_address: recipientAddress || "",
@@ -534,14 +539,32 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
534
539
  passcode: passcode,
535
540
  })];
536
541
  case 1:
537
- response = _a.sent();
542
+ response = _c.sent();
538
543
  console.warn("🚀 ~ handleSendInternal ~ response:", response);
539
- return [2 /*return*/];
544
+ if (response.success) {
545
+ close();
546
+ (_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
547
+ setSendButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
548
+ (_b = props.onSendSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
549
+ }
550
+ else {
551
+ throw new Error("Send internal failed");
552
+ }
553
+ return [3 /*break*/, 3];
554
+ case 2:
555
+ err_1 = _c.sent();
556
+ console.error(err_1);
557
+ setSendButtonStatus(Button_1.BUTTON_STATUS.ERROR);
558
+ setTimeout(function () {
559
+ setSendButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
560
+ }, 1200);
561
+ return [3 /*break*/, 3];
562
+ case 3: return [2 /*return*/];
540
563
  }
541
564
  });
542
565
  }); };
543
566
  var handleSendExternal = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
544
- var response, err_1;
567
+ var response, err_2;
545
568
  var _a, _b;
546
569
  return __generator(this, function (_c) {
547
570
  switch (_c.label) {
@@ -571,8 +594,8 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
571
594
  }
572
595
  return [3 /*break*/, 3];
573
596
  case 2:
574
- err_1 = _c.sent();
575
- console.error(err_1);
597
+ err_2 = _c.sent();
598
+ console.error(err_2);
576
599
  setSendButtonStatus(Button_1.BUTTON_STATUS.ERROR);
577
600
  setTimeout(function () {
578
601
  setSendButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
@@ -653,7 +676,14 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
653
676
  placeholder: "Enter memo",
654
677
  value: memo,
655
678
  onChange: handleChangeMemo,
656
- } })] })), !!((_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 })), estimateReceive !== undefined && !amountError && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.row), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Receive amount estimated" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive }) })] })), (0, jsx_runtime_1.jsx)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: type_1.ActionConfirm.SEND, trigger: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, status: !!amountError ||
679
+ } })] })), !!((_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 })), estimateReceive !== undefined && !amountError && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.row), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Receive amount estimated" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive }) })] })), (0, jsx_runtime_1.jsx)(SendExternalToken_1.default, { initFeeData: estimateFee, sendExternalData: {
680
+ amount: "".concat(amount),
681
+ currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
682
+ to_address: recipientAddress || "",
683
+ passcode: "",
684
+ network: selectedNetwork,
685
+ memo: memo || "",
686
+ } }), (0, jsx_runtime_1.jsx)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: type_1.ActionConfirm.SEND, trigger: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, status: !!amountError ||
657
687
  !!recipientAddressError ||
658
688
  !recipientAddress ||
659
689
  !amount ||
@@ -1,6 +1,7 @@
1
+ import { TransactionSlug } from "../get-activities-service/type";
1
2
  export interface GetEstimateFeeServiceQuery {
2
3
  amount: string;
3
- transaction_type: string;
4
+ transaction_type: TransactionSlug;
4
5
  currency: string;
5
6
  }
6
7
  export interface GetEstimateFeeServiceResponse {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.464",
3
+ "version": "0.0.466",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",