tek-wallet 0.0.468 → 0.0.470
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/SendExternalToken/index.d.ts +1 -0
- package/dist/components/ui/SendInternalToken/index.d.ts +24 -0
- package/dist/components/ui/SendInternalToken/index.js +244 -0
- package/dist/components/ui/SendInternalToken/type.d.ts +4 -0
- package/dist/components/ui/SendInternalToken/type.js +2 -0
- package/dist/components/ui/WithdrawFunction/index.js +36 -130
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ interface SendExternalTokenProps extends Omit<ConfirmLayoutProps, "action"> {
|
|
|
9
9
|
sendExternalData: SendExternalDataType;
|
|
10
10
|
onSuccess?: (data: SendExternalResponse) => any;
|
|
11
11
|
initFeeData?: FeesDataType;
|
|
12
|
+
onStart?: () => void;
|
|
12
13
|
}
|
|
13
14
|
export interface SendExternalTokenRef {
|
|
14
15
|
open: () => void;
|
|
@@ -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,244 @@
|
|
|
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 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 Fees_1 = __importDefault(require("../Fees"));
|
|
102
|
+
var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
|
|
103
|
+
var type_2 = require("../../../services/axios/get-activities-service/type");
|
|
104
|
+
var send_internal_service_1 = __importDefault(require("../../../services/axios/send-internal-service"));
|
|
105
|
+
var SendInternalTokenError;
|
|
106
|
+
(function (SendInternalTokenError) {
|
|
107
|
+
SendInternalTokenError["TOKEN_NOT_FOUND"] = "Token not found";
|
|
108
|
+
SendInternalTokenError["NOT_ENOUGH_BALANCE"] = "Not enough balance";
|
|
109
|
+
SendInternalTokenError["MAX_AMOUNT"] = "Max amount";
|
|
110
|
+
SendInternalTokenError["MIN_AMOUNT"] = "Min amount";
|
|
111
|
+
SendInternalTokenError["FAILED"] = "Failed";
|
|
112
|
+
})(SendInternalTokenError || (exports.SendInternalTokenError = SendInternalTokenError = {}));
|
|
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: type_2.TransactionSlug.TransferInternal,
|
|
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
|
+
console.warn("🚀 ~ validateAmount ~ lockData:", sendInternalData, withdrawTokens, token);
|
|
152
|
+
setToken(token);
|
|
153
|
+
if (!token) {
|
|
154
|
+
setError(SendInternalTokenError.TOKEN_NOT_FOUND);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (+sendInternalData.amount > token.max_value) {
|
|
158
|
+
setError(SendInternalTokenError.MAX_AMOUNT);
|
|
159
|
+
setErrorAmount(token.max_value);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (+sendInternalData.amount < token.min_value) {
|
|
163
|
+
setError(SendInternalTokenError.MIN_AMOUNT);
|
|
164
|
+
setErrorAmount(token.min_value);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (+sendInternalData.amount > +token.balance) {
|
|
168
|
+
setError(SendInternalTokenError.NOT_ENOUGH_BALANCE);
|
|
169
|
+
setErrorAmount(token.balance);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
setError(undefined);
|
|
173
|
+
setErrorAmount(undefined);
|
|
174
|
+
}, [withdrawTokens]);
|
|
175
|
+
var handleSendInternalToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
176
|
+
var response, err_1;
|
|
177
|
+
var _a, _b;
|
|
178
|
+
return __generator(this, function (_c) {
|
|
179
|
+
switch (_c.label) {
|
|
180
|
+
case 0:
|
|
181
|
+
_c.trys.push([0, 2, , 3]);
|
|
182
|
+
console.warn("🚀 ~ handleSendInternalToken ~ sendInternalData:", props.sendInternalData, passcode);
|
|
183
|
+
setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
184
|
+
return [4 /*yield*/, (0, send_internal_service_1.default)(__assign(__assign({}, props.sendInternalData), { passcode: passcode }))];
|
|
185
|
+
case 1:
|
|
186
|
+
response = _c.sent();
|
|
187
|
+
console.warn("🚀 ~ handleSendInternalToken ~ response:", response);
|
|
188
|
+
if (response.success) {
|
|
189
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
190
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
191
|
+
(_b = props.onSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw new Error("Send external failed");
|
|
195
|
+
}
|
|
196
|
+
return [3 /*break*/, 3];
|
|
197
|
+
case 2:
|
|
198
|
+
err_1 = _c.sent();
|
|
199
|
+
console.error(err_1);
|
|
200
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ERROR);
|
|
201
|
+
setTimeout(function () {
|
|
202
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
203
|
+
}, 1200);
|
|
204
|
+
return [3 /*break*/, 3];
|
|
205
|
+
case 3: return [2 /*return*/];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}); };
|
|
209
|
+
var handleOpen = function () {
|
|
210
|
+
var _a;
|
|
211
|
+
if (!isAuthenticated)
|
|
212
|
+
throw new Error("Please connect your wallet");
|
|
213
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
214
|
+
};
|
|
215
|
+
var handleClose = function () {
|
|
216
|
+
var _a;
|
|
217
|
+
if (!isAuthenticated)
|
|
218
|
+
throw new Error("Please connect your wallet");
|
|
219
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
220
|
+
};
|
|
221
|
+
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
222
|
+
open: handleOpen,
|
|
223
|
+
close: handleClose,
|
|
224
|
+
}); });
|
|
225
|
+
var estimateReceive = (0, react_1.useMemo)(function () {
|
|
226
|
+
if (!estimateFee || !amount)
|
|
227
|
+
return undefined;
|
|
228
|
+
return +amount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeInCurrency);
|
|
229
|
+
}, [estimateFee, amount]);
|
|
230
|
+
(0, react_1.useEffect)(function () {
|
|
231
|
+
getEstimateFee();
|
|
232
|
+
}, [getEstimateFee]);
|
|
233
|
+
(0, react_1.useEffect)(function () {
|
|
234
|
+
validateAmount(props.sendInternalData);
|
|
235
|
+
}, [validateAmount, props.sendInternalData]);
|
|
236
|
+
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: {
|
|
237
|
+
wordBreak: "break-all",
|
|
238
|
+
}, 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 })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
239
|
+
fontWeight: theme.typography.fontWeight600,
|
|
240
|
+
fontSize: theme.typography.fontSize16,
|
|
241
|
+
}, 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: 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" }) })] }) }) }));
|
|
242
|
+
});
|
|
243
|
+
SendInternalToken.displayName = "SendInternalToken";
|
|
244
|
+
exports.default = SendInternalToken;
|
|
@@ -113,16 +113,11 @@ var AppBackDrop_1 = __importDefault(require("../AppBackDrop"));
|
|
|
113
113
|
var DialogContentLayout_1 = __importDefault(require("../DialogContentLayout"));
|
|
114
114
|
var AppDialog_1 = __importDefault(require("../AppDialog"));
|
|
115
115
|
var Formatter_1 = __importDefault(require("../Formatter"));
|
|
116
|
-
var send_internal_service_1 = __importDefault(require("../../../services/axios/send-internal-service"));
|
|
117
116
|
var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
|
|
118
117
|
var Fees_1 = __importDefault(require("../Fees"));
|
|
119
|
-
var
|
|
120
|
-
var type_1 = require("../ConfirmLayout/type");
|
|
121
|
-
var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
|
|
122
|
-
var LineValue_1 = __importDefault(require("../LineValue"));
|
|
123
|
-
var send_external_service_1 = __importDefault(require("../../../services/axios/send-external-service"));
|
|
124
|
-
var type_2 = require("../../../services/axios/get-activities-service/type");
|
|
118
|
+
var type_1 = require("../../../services/axios/get-activities-service/type");
|
|
125
119
|
var SendExternalToken_1 = __importDefault(require("../SendExternalToken"));
|
|
120
|
+
var SendInternalToken_1 = __importDefault(require("../SendInternalToken"));
|
|
126
121
|
var SendMethods;
|
|
127
122
|
(function (SendMethods) {
|
|
128
123
|
SendMethods["SCAN_QR_CODE"] = "scan qr code";
|
|
@@ -151,36 +146,34 @@ var AmountError;
|
|
|
151
146
|
AmountError["MIN_LIMIT"] = "The minimum amount is";
|
|
152
147
|
})(AmountError || (exports.AmountError = AmountError = {}));
|
|
153
148
|
var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
154
|
-
var _a
|
|
149
|
+
var _a;
|
|
155
150
|
var drawerRef = (0, react_1.useRef)(null);
|
|
156
151
|
var swiperRef = (0, react_1.useRef)(null);
|
|
157
|
-
var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
|
|
158
152
|
var theme = (0, material_1.useTheme)();
|
|
159
|
-
var
|
|
160
|
-
var
|
|
161
|
-
var
|
|
153
|
+
var _b = (0, react_1.useState)(WithdrawStep.SELECT_METHOD), currentStep = _b[0], setCurrentStep = _b[1];
|
|
154
|
+
var _c = (0, react_1.useState)(), selectedToken = _c[0], setSelectedToken = _c[1];
|
|
155
|
+
var _d = (0, react_1.useState)(), selectedNetwork = _d[0], setSelectedNetwork = _d[1];
|
|
162
156
|
var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
|
|
163
|
-
var
|
|
164
|
-
var
|
|
165
|
-
var
|
|
166
|
-
var
|
|
167
|
-
var
|
|
168
|
-
var
|
|
169
|
-
var
|
|
170
|
-
var
|
|
157
|
+
var _e = (0, useWithdrawData_1.default)(), withdrawTokens = _e.withdrawTokens, updateWithdrawToken = _e.updateWithdrawToken, updateSendInternalToken = _e.updateSendInternalToken, sendInternalTokens = _e.sendInternalTokens;
|
|
158
|
+
var _f = (0, react_1.useState)(), infoDialogContent = _f[0], setInfoDialogContent = _f[1];
|
|
159
|
+
var _g = (0, react_1.useState)(""), amount = _g[0], setAmount = _g[1];
|
|
160
|
+
var _h = (0, react_1.useState)(undefined), memo = _h[0], setMemo = _h[1];
|
|
161
|
+
var _j = (0, react_1.useState)(undefined), recipientAddress = _j[0], setRecipientAddress = _j[1];
|
|
162
|
+
var _k = (0, react_1.useState)(), amountErrorMessage = _k[0], setAmountErrorMessage = _k[1];
|
|
163
|
+
var _l = (0, react_1.useState)(true), hiddenError = _l[0], setHiddenError = _l[1];
|
|
164
|
+
var _m = (0, react_1.useState)(), amountError = _m[0], setAmountError = _m[1];
|
|
171
165
|
var scannerAllQrCodeRef = (0, react_1.useRef)(null);
|
|
172
166
|
var scannerAddressQrCodeRef = (0, react_1.useRef)(null);
|
|
173
167
|
var backDropRef = (0, react_1.useRef)(null);
|
|
174
168
|
var suggestUseTransferInternalDialogRef = (0, react_1.useRef)(null);
|
|
175
169
|
var suggestUseTransferExternalDialogRef = (0, react_1.useRef)(null);
|
|
176
|
-
var
|
|
177
|
-
var
|
|
178
|
-
var
|
|
179
|
-
var
|
|
180
|
-
var
|
|
181
|
-
var
|
|
170
|
+
var _o = (0, react_1.useState)(), selectedMethod = _o[0], setSelectedMethod = _o[1];
|
|
171
|
+
var _p = (0, react_1.useState)(), sendInfoGet = _p[0], setSendInfoGet = _p[1];
|
|
172
|
+
var _q = (0, react_1.useState)(false), isLoadingEstimateFee = _q[0], setIsLoadingEstimateFee = _q[1];
|
|
173
|
+
var _r = (0, react_1.useState)(false), isValidatingAddress = _r[0], setIsValidatingAddress = _r[1];
|
|
174
|
+
var _s = (0, react_1.useState)(), estimateFee = _s[0], setEstimateFee = _s[1];
|
|
175
|
+
var _t = (0, react_1.useState)(), recipientAddressError = _t[0], setRecipientAddressError = _t[1];
|
|
182
176
|
var onlyChangeAddress = (0, react_1.useRef)(false);
|
|
183
|
-
var _v = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), sendButtonStatus = _v[0], setSendButtonStatus = _v[1];
|
|
184
177
|
var withdrawToken = (0, react_1.useMemo)(function () {
|
|
185
178
|
return selectedMethod === SendMethods.TRANSFER_EXTERNAL ? withdrawTokens : sendInternalTokens;
|
|
186
179
|
}, [withdrawTokens, sendInternalTokens, selectedMethod]);
|
|
@@ -369,7 +362,7 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
369
362
|
setIsLoadingEstimateFee(true);
|
|
370
363
|
return [4 /*yield*/, (0, get_est_fee_service_1.default)({
|
|
371
364
|
amount: "".concat(amount),
|
|
372
|
-
transaction_type: selectedMethod === SendMethods.TRANSFER_EXTERNAL ?
|
|
365
|
+
transaction_type: selectedMethod === SendMethods.TRANSFER_EXTERNAL ? type_1.TransactionSlug.Withdrawn : type_1.TransactionSlug.TransferInternal,
|
|
373
366
|
currency: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
|
|
374
367
|
})];
|
|
375
368
|
case 1:
|
|
@@ -523,100 +516,6 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
523
516
|
return [2 /*return*/];
|
|
524
517
|
});
|
|
525
518
|
}); };
|
|
526
|
-
var handleSendInternal = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
527
|
-
var response, err_1;
|
|
528
|
-
var _a, _b;
|
|
529
|
-
return __generator(this, function (_c) {
|
|
530
|
-
switch (_c.label) {
|
|
531
|
-
case 0:
|
|
532
|
-
_c.trys.push([0, 2, , 3]);
|
|
533
|
-
console.warn("withdraw internal");
|
|
534
|
-
setSendButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
535
|
-
return [4 /*yield*/, (0, send_internal_service_1.default)({
|
|
536
|
-
amount: "".concat(amount),
|
|
537
|
-
to_address: recipientAddress || "",
|
|
538
|
-
currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
|
|
539
|
-
passcode: passcode,
|
|
540
|
-
})];
|
|
541
|
-
case 1:
|
|
542
|
-
response = _c.sent();
|
|
543
|
-
console.warn("🚀 ~ handleSendInternal ~ response:", response);
|
|
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*/];
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
}); };
|
|
566
|
-
var handleSendExternal = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
567
|
-
var response, err_2;
|
|
568
|
-
var _a, _b;
|
|
569
|
-
return __generator(this, function (_c) {
|
|
570
|
-
switch (_c.label) {
|
|
571
|
-
case 0:
|
|
572
|
-
_c.trys.push([0, 2, , 3]);
|
|
573
|
-
console.warn("withdraw external");
|
|
574
|
-
setSendButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
575
|
-
return [4 /*yield*/, (0, send_external_service_1.default)({
|
|
576
|
-
amount: "".concat(amount),
|
|
577
|
-
to_address: recipientAddress || "",
|
|
578
|
-
currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
|
|
579
|
-
passcode: passcode,
|
|
580
|
-
network: (selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.slug) || "",
|
|
581
|
-
memo: memo || "",
|
|
582
|
-
})];
|
|
583
|
-
case 1:
|
|
584
|
-
response = _c.sent();
|
|
585
|
-
console.warn("🚀 ~ handleSendExternal ~ response:", response);
|
|
586
|
-
if (response.success) {
|
|
587
|
-
close();
|
|
588
|
-
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
589
|
-
setSendButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
590
|
-
(_b = props.onSendSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
|
|
591
|
-
}
|
|
592
|
-
else {
|
|
593
|
-
throw new Error("Send external failed");
|
|
594
|
-
}
|
|
595
|
-
return [3 /*break*/, 3];
|
|
596
|
-
case 2:
|
|
597
|
-
err_2 = _c.sent();
|
|
598
|
-
console.error(err_2);
|
|
599
|
-
setSendButtonStatus(Button_1.BUTTON_STATUS.ERROR);
|
|
600
|
-
setTimeout(function () {
|
|
601
|
-
setSendButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
602
|
-
}, 1200);
|
|
603
|
-
return [3 /*break*/, 3];
|
|
604
|
-
case 3: return [2 /*return*/];
|
|
605
|
-
}
|
|
606
|
-
});
|
|
607
|
-
}); };
|
|
608
|
-
var handleSend = function (passcode) {
|
|
609
|
-
switch (selectedMethod) {
|
|
610
|
-
case SendMethods.TRANSFER_INTERNAL:
|
|
611
|
-
handleSendInternal(passcode);
|
|
612
|
-
break;
|
|
613
|
-
case SendMethods.TRANSFER_EXTERNAL:
|
|
614
|
-
handleSendExternal(passcode);
|
|
615
|
-
break;
|
|
616
|
-
default:
|
|
617
|
-
break;
|
|
618
|
-
}
|
|
619
|
-
};
|
|
620
519
|
(0, react_1.useEffect)(function () {
|
|
621
520
|
if (isAuthenticated && !withdrawTokens) {
|
|
622
521
|
updateWithdrawToken();
|
|
@@ -676,13 +575,25 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
676
575
|
placeholder: "Enter memo",
|
|
677
576
|
value: memo,
|
|
678
577
|
onChange: handleChangeMemo,
|
|
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: {
|
|
578
|
+
} })] })), !!((_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 }) })] })), selectedMethod === SendMethods.TRANSFER_EXTERNAL && ((0, jsx_runtime_1.jsx)(SendExternalToken_1.default, { initFeeData: estimateFee, sendExternalData: {
|
|
680
579
|
amount: "".concat(amount),
|
|
681
580
|
currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
|
|
682
581
|
to_address: recipientAddress || "",
|
|
683
582
|
network: selectedNetwork,
|
|
684
583
|
memo: memo || "",
|
|
685
|
-
},
|
|
584
|
+
}, onSuccess: close, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!amountError ||
|
|
585
|
+
!!recipientAddressError ||
|
|
586
|
+
!recipientAddress ||
|
|
587
|
+
!amount ||
|
|
588
|
+
!selectedToken ||
|
|
589
|
+
isLoadingEstimateFee ||
|
|
590
|
+
isValidatingAddress
|
|
591
|
+
? Button_1.BUTTON_STATUS.DISABLED
|
|
592
|
+
: Button_1.BUTTON_STATUS.ENABLED, children: "Continue" }) })), selectedMethod === SendMethods.TRANSFER_INTERNAL && ((0, jsx_runtime_1.jsx)(SendInternalToken_1.default, { initFeeData: estimateFee, sendInternalData: {
|
|
593
|
+
amount: "".concat(amount),
|
|
594
|
+
currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
|
|
595
|
+
to_address: recipientAddress || "",
|
|
596
|
+
}, onSuccess: close, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!amountError ||
|
|
686
597
|
!!recipientAddressError ||
|
|
687
598
|
!recipientAddress ||
|
|
688
599
|
!amount ||
|
|
@@ -690,12 +601,7 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
690
601
|
isLoadingEstimateFee ||
|
|
691
602
|
isValidatingAddress
|
|
692
603
|
? Button_1.BUTTON_STATUS.DISABLED
|
|
693
|
-
: Button_1.BUTTON_STATUS.ENABLED, children: "Continue" }),
|
|
694
|
-
wordBreak: "break-all",
|
|
695
|
-
}, children: recipientAddress }) }), selectedMethod === SendMethods.TRANSFER_EXTERNAL && ((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: selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: selectedNetwork === null || selectedNetwork === void 0 ? void 0 : selectedNetwork.name })] }) })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.name) }) }), !!memo && selectedMethod === SendMethods.TRANSFER_EXTERNAL && ((0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Memo", value: memo })), !!((_b = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _b === void 0 ? void 0 : _b.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: {
|
|
696
|
-
fontWeight: theme.typography.fontWeight600,
|
|
697
|
-
fontSize: theme.typography.fontSize16,
|
|
698
|
-
}, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.name) }) }) })] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: type_1.ActionConfirm.SEND, onConfirmSuccess: handleSend, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: sendButtonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }) })] }) }, WithdrawStep.FORM)] }), (0, jsx_runtime_1.jsx)(QrCodeReader_1.default, { ref: scannerAllQrCodeRef, onResult: handleScanAllQrCode }), (0, jsx_runtime_1.jsx)(QrCodeReader_1.default, { ref: scannerAddressQrCodeRef, onResult: handleScanAddressQrCode }), (0, jsx_runtime_1.jsx)(AppBackDrop_1.default, { ref: backDropRef }), (0, jsx_runtime_1.jsx)(AppDialog_1.default, { overrideOpen: !!infoDialogContent, children: (0, jsx_runtime_1.jsx)(DialogContentLayout_1.default, { content: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
604
|
+
: Button_1.BUTTON_STATUS.ENABLED, children: "Continue" }) }))] }) }, WithdrawStep.FORM)] }), (0, jsx_runtime_1.jsx)(QrCodeReader_1.default, { ref: scannerAllQrCodeRef, onResult: handleScanAllQrCode }), (0, jsx_runtime_1.jsx)(QrCodeReader_1.default, { ref: scannerAddressQrCodeRef, onResult: handleScanAddressQrCode }), (0, jsx_runtime_1.jsx)(AppBackDrop_1.default, { ref: backDropRef }), (0, jsx_runtime_1.jsx)(AppDialog_1.default, { overrideOpen: !!infoDialogContent, children: (0, jsx_runtime_1.jsx)(DialogContentLayout_1.default, { content: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
699
605
|
textAlign: "center",
|
|
700
606
|
display: "inline-block",
|
|
701
607
|
width: "100%",
|