tek-wallet 0.0.756 → 0.0.758
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/TekWallet/components/ui/CopyTextComponent/index.js +1 -1
- package/dist/components/TekWallet/components/ui/FiatDeposit/index.js +34 -38
- package/dist/components/TekWallet/components/ui/NeonLineChart/index.js +6 -6
- package/dist/components/TekWallet/components/ui/ReceiveFunction/index.js +4 -3
- package/dist/components/TekWallet/providers/RealtimeProvider/index.js +1 -1
- package/package.json +1 -1
- package/dist/components/TekWallet/components/ui/SwapToken copy/index.d.ts +0 -32
- package/dist/components/TekWallet/components/ui/SwapToken copy/index.js +0 -293
|
@@ -104,7 +104,7 @@ var CopyTextComponent = function (_a) {
|
|
|
104
104
|
? "opacity 0.5s linear, transform 0.17s linear"
|
|
105
105
|
: "opacity 0.15s linear, transform 0.1s linear",
|
|
106
106
|
}, children: [iconSuccess || (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: "1rem", height: "1rem" }, children: SvgPath_1.IC_SUCCESS }), !hideTextMessage && ((0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
107
|
-
color:
|
|
107
|
+
color: "#01FF00",
|
|
108
108
|
fontSize: theme.typography.fontSize14,
|
|
109
109
|
lineHeight: theme.typography.leading100,
|
|
110
110
|
}, children: "Copied" }))] })] }));
|
|
@@ -71,6 +71,9 @@ var Text_1 = __importDefault(require("../Text"));
|
|
|
71
71
|
var style_1 = require("./style");
|
|
72
72
|
var palette_1 = require("../../../theme/mui/deposit-fiat-theme/palette");
|
|
73
73
|
var type_1 = require("../../../services/axios/get-activities-service/type");
|
|
74
|
+
var CopyTextComponent_1 = __importDefault(require("../CopyTextComponent"));
|
|
75
|
+
var Formatter_1 = __importDefault(require("../Formatter"));
|
|
76
|
+
var PageHeader_1 = __importDefault(require("../PageHeader"));
|
|
74
77
|
// Because PageHeader component don't work
|
|
75
78
|
var BackArrow = function (props) {
|
|
76
79
|
return ((0, jsx_runtime_1.jsxs)("svg", __assign({ xmlns: "http://www.w3.org/2000/svg", width: "24", height: "24", viewBox: "0 0 24 24", fill: "none" }, props, { children: [(0, jsx_runtime_1.jsx)("mask", { id: "mask0_6061_2295", style: { maskType: "alpha" }, maskUnits: "userSpaceOnUse", x: "0", y: "0", width: "24", height: "24", children: (0, jsx_runtime_1.jsx)("rect", { width: "24", height: "24", fill: "#D9D9D9" }) }), (0, jsx_runtime_1.jsx)("g", { mask: "url(#mask0_6061_2295)", children: (0, jsx_runtime_1.jsx)("path", { d: "M14 17.6538L8.34619 12L14 6.34619L15.0538 7.40002L10.4538 12L15.0538 16.6L14 17.6538Z", fill: "#121212" }) })] })));
|
|
@@ -82,29 +85,29 @@ var Header = function (_a) {
|
|
|
82
85
|
gridTemplateColumns: "1fr 1fr 1fr",
|
|
83
86
|
gridTemplateRows: "1fr",
|
|
84
87
|
alignItems: "center",
|
|
85
|
-
}, children: [(0, jsx_runtime_1.jsx)(material_1.Grid2, { children: (0, jsx_runtime_1.jsx)(BackArrow, { onClick: handleBack }) }), (0, jsx_runtime_1.jsx)(material_1.Grid2, { display: "flex", children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, style_1.title01), { width: "100%", textAlign: "center" }), children: "Top up" }) }), (0, jsx_runtime_1.jsx)(material_1.Grid2, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", justifyContent: "end", gap: ".5rem", children: [(0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 20, height: 20 }, children: SvgPath_1.IC_HELP }), (0, jsx_runtime_1.jsx)(material_1.Divider, { flexItem: true, sx: { width: "1px" } }), (0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { ref: historyRef, trigger: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 20, height: 20, display: "block" }, children: SvgPath_1.IC_HISTORY }), direction: DrawerComponent_1.DRAWER_DIRECTION.RIGHT, children: (0, jsx_runtime_1.jsx)(ReceiveHistory_1.default, { onClose: function () { var _a; return (_a = historyRef.current) === null || _a === void 0 ? void 0 : _a.close(); } }) })] }) })] }));
|
|
88
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Grid2, { children: (0, jsx_runtime_1.jsx)(BackArrow, { onClick: handleBack }) }), (0, jsx_runtime_1.jsx)(material_1.Grid2, { display: "flex", children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, style_1.title01), { width: "100%", textAlign: "center" }), children: "Top up" }) }), false && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(material_1.Grid2, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", alignItems: "center", justifyContent: "end", gap: ".5rem", children: [(0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 20, height: 20 }, children: SvgPath_1.IC_HELP }), (0, jsx_runtime_1.jsx)(material_1.Divider, { flexItem: true, sx: { width: "1px" } }), (0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { ref: historyRef, trigger: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 20, height: 20, display: "block" }, children: SvgPath_1.IC_HISTORY }), direction: DrawerComponent_1.DRAWER_DIRECTION.RIGHT, children: (0, jsx_runtime_1.jsx)(ReceiveHistory_1.default, { onClose: function () { var _a; return (_a = historyRef.current) === null || _a === void 0 ? void 0 : _a.close(); } }) })] }) }) }))] }));
|
|
86
89
|
};
|
|
87
90
|
var CopyIcon = function () {
|
|
88
91
|
return ((0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "17", height: "16", viewBox: "0 0 17 16", fill: "none", children: (0, jsx_runtime_1.jsx)("path", { d: "M11 11.5V13.75C11 14.164 10.664 14.5 10.25 14.5H3.75C3.55109 14.5 3.36032 14.421 3.21967 14.2803C3.07902 14.1397 3 13.9489 3 13.75V5.25C3 4.836 3.336 4.5 3.75 4.5H5C5.33505 4.49977 5.66954 4.52742 6 4.58267M11 11.5H13.25C13.664 11.5 14 11.164 14 10.75V7.5C14 4.52667 11.838 2.05933 9 1.58267C8.66954 1.52742 8.33505 1.49977 8 1.5H6.75C6.336 1.5 6 1.836 6 2.25V4.58267M11 11.5H6.75C6.55109 11.5 6.36032 11.421 6.21967 11.2803C6.07902 11.1397 6 10.9489 6 10.75V4.58267M14 9V7.75C14 7.15326 13.7629 6.58097 13.341 6.15901C12.919 5.73705 12.3467 5.5 11.75 5.5H10.75C10.5511 5.5 10.3603 5.42098 10.2197 5.28033C10.079 5.13968 10 4.94891 10 4.75V3.75C10 3.45453 9.9418 3.16195 9.82873 2.88896C9.71566 2.61598 9.54992 2.36794 9.34099 2.15901C9.13206 1.95008 8.88402 1.78435 8.61104 1.67127C8.33806 1.5582 8.04547 1.5 7.75 1.5H7", stroke: "#1C461D", strokeWidth: "1.25", strokeLinecap: "round", strokeLinejoin: "round" }) }));
|
|
89
92
|
};
|
|
90
93
|
exports.CopyIcon = CopyIcon;
|
|
91
94
|
function FiatDeposit(_a) {
|
|
92
|
-
var _b, _c, _d, _e, _f, _g, _h, _j
|
|
95
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
93
96
|
var children = _a.children;
|
|
94
97
|
var amountInputRef = (0, react_1.useRef)(null);
|
|
95
|
-
var
|
|
96
|
-
var
|
|
97
|
-
var
|
|
98
|
-
var
|
|
98
|
+
var _k = (0, useWallet_1.default)(), masterWallet = _k.masterWallet, transaction = _k.transaction, receiveExternalTokens = _k.receiveExternalTokens, tokens = _k.tokens;
|
|
99
|
+
var _l = (0, react_1.useState)(false), open = _l[0], setOpen = _l[1];
|
|
100
|
+
var _m = (0, react_1.useState)(false), openQR = _m[0], setOpenQR = _m[1];
|
|
101
|
+
var _o = (0, react_1.useState)(false), openShare = _o[0], setOpenShare = _o[1];
|
|
99
102
|
var keyboardId = (0, useUniqueId_1.useUniqueId)("receive-function-keyboard");
|
|
100
|
-
var
|
|
101
|
-
var
|
|
102
|
-
var
|
|
103
|
-
var
|
|
104
|
-
var
|
|
105
|
-
var
|
|
103
|
+
var _p = (0, react_1.useState)(""), inputAmount = _p[0], setInputAmount = _p[1];
|
|
104
|
+
var _q = (0, react_1.useState)(null), depositData = _q[0], setDepositData = _q[1];
|
|
105
|
+
var _r = (0, react_1.useState)(false), loading = _r[0], setLoading = _r[1];
|
|
106
|
+
var _s = (0, react_1.useState)(null), error = _s[0], setError = _s[1];
|
|
107
|
+
var _t = (0, react_1.useState)(false), copySuccess = _t[0], setCopySuccess = _t[1];
|
|
108
|
+
var _u = (0, usehooks_ts_1.useCountdown)({
|
|
106
109
|
countStart: 600,
|
|
107
|
-
}), count =
|
|
110
|
+
}), count = _u[0], _v = _u[1], startCountdown = _v.startCountdown, resetCountdown = _v.resetCountdown;
|
|
108
111
|
var handleChangeAmount = function (value) {
|
|
109
112
|
var amountNumber = Number(value);
|
|
110
113
|
if (isNaN(amountNumber)) {
|
|
@@ -162,34 +165,20 @@ function FiatDeposit(_a) {
|
|
|
162
165
|
return function () { return clearTimeout(timeout_1); };
|
|
163
166
|
}
|
|
164
167
|
}, [copySuccess]);
|
|
165
|
-
var handleCopyLink = function (text) {
|
|
166
|
-
if (!(depositData === null || depositData === void 0 ? void 0 : depositData.id) || copySuccess)
|
|
167
|
-
return;
|
|
168
|
-
navigator.clipboard
|
|
169
|
-
.writeText(text)
|
|
170
|
-
.then(function () {
|
|
171
|
-
setCopySuccess(true);
|
|
172
|
-
})
|
|
173
|
-
.catch(function (err) {
|
|
174
|
-
console.error("Failed to copy link:", err);
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
168
|
(0, react_1.useEffect)(function () {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
var _a;
|
|
170
|
+
console.warn("🚀 ~ hhhhh FiatDeposit ~ transaction:", transaction, depositData);
|
|
171
|
+
// return;
|
|
172
|
+
if ((transaction === null || transaction === void 0 ? void 0 : transaction.transaction_status) === type_1.TransactionStatus.Success &&
|
|
173
|
+
((_a = transaction === null || transaction === void 0 ? void 0 : transaction.transaction_type) === null || _a === void 0 ? void 0 : _a.slug) === type_1.TransactionSlug.RECEIVE &&
|
|
174
|
+
(depositData === null || depositData === void 0 ? void 0 : depositData.orderId) === (transaction === null || transaction === void 0 ? void 0 : transaction.order_id)) {
|
|
181
175
|
setOpen(false);
|
|
182
176
|
setOpenQR(false);
|
|
183
177
|
setOpenShare(false);
|
|
184
178
|
setInputAmount("");
|
|
185
|
-
|
|
186
|
-
message: "Deposit successful!",
|
|
187
|
-
type: "success",
|
|
188
|
-
id: "deposit-fiat-success",
|
|
189
|
-
});
|
|
179
|
+
setDepositData(null);
|
|
190
180
|
}
|
|
191
|
-
|
|
192
|
-
}, [transaction]);
|
|
181
|
+
}, [transaction, depositData]);
|
|
193
182
|
(0, react_1.useEffect)(function () {
|
|
194
183
|
if (inputAmount && !isNaN(Number(inputAmount)) && validateInput(inputAmount.toString())) {
|
|
195
184
|
setError(null);
|
|
@@ -202,7 +191,9 @@ function FiatDeposit(_a) {
|
|
|
202
191
|
}, children: children }), (0, jsx_runtime_1.jsxs)(material_1.Drawer, { classes: { paper: "w-full" }, open: open, onClose: function () {
|
|
203
192
|
setOpen(false);
|
|
204
193
|
setInputAmount("");
|
|
205
|
-
}, anchor: "right", keepMounted: false, onClick: function (e) { return e.stopPropagation(); }, children: [(0, jsx_runtime_1.jsx)(
|
|
194
|
+
}, anchor: "right", keepMounted: false, onClick: function (e) { return e.stopPropagation(); }, children: [(0, jsx_runtime_1.jsx)(PageHeader_1.default, { sx: {
|
|
195
|
+
height: "fit-content",
|
|
196
|
+
}, title: "Top up", overrideBack: function () {
|
|
206
197
|
setOpen(false);
|
|
207
198
|
setInputAmount("");
|
|
208
199
|
} }), (0, jsx_runtime_1.jsx)(xhub_keyboard_1.Keyboard, { id: keyboardId, onChange: handleChangeAmount, keyboardType: xhub_keyboard_1.KeyboardType.Double, value: inputAmount === null || inputAmount === void 0 ? void 0 : inputAmount.toString(), keyboardId: "amount-keyboard-id", classNames: {
|
|
@@ -246,11 +237,16 @@ function FiatDeposit(_a) {
|
|
|
246
237
|
display: "flex",
|
|
247
238
|
alignItems: "center",
|
|
248
239
|
flexDirection: "column",
|
|
249
|
-
|
|
240
|
+
color: theme_1.default.palette.primary.main,
|
|
241
|
+
}, children: [(0, jsx_runtime_1.jsx)(Formatter_1.default, { value: depositData === null || depositData === void 0 ? void 0 : depositData.amount, unit: "VND", hideUnitOutSide: true }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
250
242
|
fontSize: "0.938rem",
|
|
251
243
|
fontWeight: 500,
|
|
252
244
|
lineHeight: "140%",
|
|
253
|
-
},
|
|
245
|
+
}, children: "VND" })] }), (0, jsx_runtime_1.jsxs)(Text_1.default, { display: "flex", alignItems: "center", gap: "0.375rem", sx: __assign({}, style_1.title03), color: (_g = palette_1.palette.accent2) === null || _g === void 0 ? void 0 : _g.main, children: ["Top up time left", (0, jsx_runtime_1.jsx)(TimeText_1.default, { seconds: count }), (0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: (0, jsx_runtime_1.jsx)("path", { d: "M7 5V7.5M13 7C13 7.78793 12.8448 8.56815 12.5433 9.2961C12.2417 10.0241 11.7998 10.6855 11.2426 11.2426C10.6855 11.7998 10.0241 12.2417 9.2961 12.5433C8.56815 12.8448 7.78793 13 7 13C6.21207 13 5.43185 12.8448 4.7039 12.5433C3.97595 12.2417 3.31451 11.7998 2.75736 11.2426C2.20021 10.6855 1.75825 10.0241 1.45672 9.2961C1.15519 8.56815 1 7.78793 1 7C1 5.4087 1.63214 3.88258 2.75736 2.75736C3.88258 1.63214 5.4087 1 7 1C8.5913 1 10.1174 1.63214 11.2426 2.75736C12.3679 3.88258 13 5.4087 13 7ZM7 9.5H7.00533V9.50533H7V9.5Z", stroke: "#1C461D", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), (0, jsx_runtime_1.jsx)(material_1.Divider, { flexItem: true }), (0, jsx_runtime_1.jsxs)(Text_1.default, { display: "flex", flexDirection: "column", alignItems: "center", gap: "0.375rem", sx: __assign({}, style_1.title01), children: [depositData === null || depositData === void 0 ? void 0 : depositData.metadata.bank_account.account_name, (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, style_1.content02), color: (_h = palette_1.palette.accent2) === null || _h === void 0 ? void 0 : _h.main, children: depositData === null || depositData === void 0 ? void 0 : depositData.metadata.bank_account.bank_name }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, style_1.title02), display: "flex", alignItems: "center", gap: "0.25rem", children: (0, jsx_runtime_1.jsxs)(CopyTextComponent_1.default, { sx: {
|
|
246
|
+
display: "flex",
|
|
247
|
+
alignItems: "center",
|
|
248
|
+
gap: 1,
|
|
249
|
+
}, value: (depositData === null || depositData === void 0 ? void 0 : depositData.metadata.bank_account.account_number) || "", children: [depositData === null || depositData === void 0 ? void 0 : depositData.metadata.bank_account.account_number, " ", (0, jsx_runtime_1.jsx)(exports.CopyIcon, {})] }) }), (0, jsx_runtime_1.jsx)(link_1.default, { href: (_j = depositData === null || depositData === void 0 ? void 0 : depositData._link.payment_link.href) !== null && _j !== void 0 ? _j : "#", target: "_blank", rel: "noopener noreferrer", style: {
|
|
254
250
|
marginTop: "-0.5rem",
|
|
255
251
|
}, children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, style_1.content02), { textDecoration: "underline", fontStyle: "italic" }), children: "Transfer" }) })] })] }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { pt: "0.75rem", pb: "1rem", width: "100%", children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { disabled: loading, loading: loading, onClick: function () {
|
|
256
252
|
if (count === 0) {
|
|
@@ -26,8 +26,8 @@ var material_1 = require("@mui/material");
|
|
|
26
26
|
var ThemeProvider_1 = require("../../../providers/ThemeProvider");
|
|
27
27
|
var formatDate_1 = __importDefault(require("../../../utils/formatDate"));
|
|
28
28
|
function NeonLineChart(_a) {
|
|
29
|
-
var _b, _c, _d
|
|
30
|
-
var series = _a.series, categories = _a.categories,
|
|
29
|
+
var _b, _c, _d;
|
|
30
|
+
var series = _a.series, categories = _a.categories, _e = _a.showMinMaxValues, showMinMaxValues = _e === void 0 ? false : _e, children = _a.children, sx = _a.sx;
|
|
31
31
|
var chartComponentRef = (0, react_1.useRef)(null);
|
|
32
32
|
var formatValue = (0, useFormatter_1.default)().formatValue;
|
|
33
33
|
var theme = (0, ThemeProvider_1.useTheme)();
|
|
@@ -97,7 +97,7 @@ function NeonLineChart(_a) {
|
|
|
97
97
|
var data = (0, react_1.useMemo)(function () {
|
|
98
98
|
var _a, _b;
|
|
99
99
|
return (_b = (_a = series === null || series === void 0 ? void 0 : series[0]) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : [];
|
|
100
|
-
}, [(
|
|
100
|
+
}, [(_d = series === null || series === void 0 ? void 0 : series[0]) === null || _d === void 0 ? void 0 : _d.data]);
|
|
101
101
|
var chartLength = (0, react_1.useMemo)(function () {
|
|
102
102
|
try {
|
|
103
103
|
var length_1 = data === null || data === void 0 ? void 0 : data.length;
|
|
@@ -124,7 +124,7 @@ function NeonLineChart(_a) {
|
|
|
124
124
|
catch (_a) {
|
|
125
125
|
return -1;
|
|
126
126
|
}
|
|
127
|
-
}, [maxValue]);
|
|
127
|
+
}, [maxValue, data]);
|
|
128
128
|
var minValue = (0, react_1.useMemo)(function () {
|
|
129
129
|
try {
|
|
130
130
|
var min = Math.min.apply(Math, (data !== null && data !== void 0 ? data : []));
|
|
@@ -142,7 +142,7 @@ function NeonLineChart(_a) {
|
|
|
142
142
|
catch (_a) {
|
|
143
143
|
return -1;
|
|
144
144
|
}
|
|
145
|
-
}, [minValue]);
|
|
145
|
+
}, [minValue, data]);
|
|
146
146
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({ position: "relative" }, sx), children: [showMinMaxValues && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { className: "absolute top-0 w-fit z-50", style: {
|
|
147
147
|
left: "".concat((maxIndex / chartLength) * 100, "%"),
|
|
148
148
|
}, initial: {
|
|
@@ -159,7 +159,7 @@ function NeonLineChart(_a) {
|
|
|
159
159
|
duration: 0.4,
|
|
160
160
|
ease: "easeInOut",
|
|
161
161
|
delay: 0.4,
|
|
162
|
-
}, children: (0, jsx_runtime_1.jsx)(Text_1.default, {
|
|
162
|
+
}, children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: maxValue }) }) }), (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { className: "absolute bottom-0 w-fit z-50", style: {
|
|
163
163
|
left: "".concat((minIndex / chartLength) * 100, "%"),
|
|
164
164
|
}, initial: {
|
|
165
165
|
scale: 0,
|
|
@@ -266,6 +266,7 @@ exports.ReceiveFunction = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
266
266
|
(_a = chooseNetworkSupportDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
267
267
|
};
|
|
268
268
|
var handleSelectMethod = function (method) {
|
|
269
|
+
close();
|
|
269
270
|
setSelectedMethod(method);
|
|
270
271
|
switch (method) {
|
|
271
272
|
case ReceiveMethods.RECEIVE_INTERNAL:
|
|
@@ -430,14 +431,14 @@ exports.ReceiveFunction = (0, react_1.forwardRef)(function (_a, ref) {
|
|
|
430
431
|
};
|
|
431
432
|
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { sx: props.sx, children: (0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { ref: drawerRef, trigger: props.children, onOpen: props.onOpen, onClose: handleOnClose, sx: props.sx, children: (0, jsx_runtime_1.jsx)(ModalLayout_1.default, { title: RECEIVE_STEP_NAME[ReceiveStep.SELECT_METHOD], onClose: close, children: (0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { ref: stepDrawerRef, direction: DrawerComponent_1.DRAWER_DIRECTION.RIGHT, sx: {
|
|
432
433
|
width: "100%",
|
|
433
|
-
}, trigger: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12, height: "fit-content", width: "100%" }), children: [functionsList.includes(ReceiveMethods.RECEIVE_INTERNAL) && ((0, jsx_runtime_1.jsx)(ListItemCustom_1.default, { title: "Top up via internal transfer", description: "Receive crypto from other Ting users", icon: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 24, height: 24 }, children: SvgPath_1.IC_RECEIVE_INTERNAL }), onClick: function () { return handleSelectMethod(ReceiveMethods.RECEIVE_INTERNAL); }, recommended: true })), functionsList.includes(ReceiveMethods.RECEIVE_EXTERNAL) && ((0, jsx_runtime_1.jsx)(ListItemCustom_1.default, { title: "Top up via blockchain", description: "Deposit using a Web3 or an Exchange wallet", icon: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 24, height: 24 }, children: SvgPath_1.IC_RECEIVE_EXTERNAL }), onClick: function () { return handleSelectMethod(ReceiveMethods.RECEIVE_EXTERNAL); }, recommended: true })), functionsList.includes(ReceiveMethods.RECEIVE_FIAT) && ((0, jsx_runtime_1.jsx)(FiatDeposit_1.default, { children: (0, jsx_runtime_1.jsx)(ListItemCustom_1.default, { title: "Fiat-Gateway", description: "Experimental deposit via bank transfer", icon: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 24, height: 24 }, children: SvgPath_1.IC_RECEIVE_EXTERNAL }), recommended: false }) }))] }), children: (0, jsx_runtime_1.jsx)(ChildPageLayout_1.default, { sx: {
|
|
434
|
+
}, trigger: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12, height: "fit-content", width: "100%" }), children: [functionsList.includes(ReceiveMethods.RECEIVE_INTERNAL) && ((0, jsx_runtime_1.jsx)(ListItemCustom_1.default, { title: "Top up via internal transfer", description: "Receive crypto from other Ting users", icon: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 24, height: 24 }, children: SvgPath_1.IC_RECEIVE_INTERNAL }), onClick: function () { return handleSelectMethod(ReceiveMethods.RECEIVE_INTERNAL); }, recommended: true })), functionsList.includes(ReceiveMethods.RECEIVE_EXTERNAL) && ((0, jsx_runtime_1.jsx)(ListItemCustom_1.default, { title: "Top up via blockchain", description: "Deposit using a Web3 or an Exchange wallet", icon: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 24, height: 24 }, children: SvgPath_1.IC_RECEIVE_EXTERNAL }), onClick: function () { return handleSelectMethod(ReceiveMethods.RECEIVE_EXTERNAL); }, recommended: true })), functionsList.includes(ReceiveMethods.RECEIVE_FIAT) && ((0, jsx_runtime_1.jsx)(FiatDeposit_1.default, { children: (0, jsx_runtime_1.jsx)(ListItemCustom_1.default, { title: "Fiat-Gateway", description: "Experimental deposit via bank transfer", icon: (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 24, height: 24 }, children: SvgPath_1.IC_RECEIVE_EXTERNAL }), recommended: false, onClick: function () { return handleSelectMethod(ReceiveMethods.RECEIVE_FIAT); } }) }))] }), children: (0, jsx_runtime_1.jsx)(ChildPageLayout_1.default, { sx: {
|
|
434
435
|
position: "relative",
|
|
435
436
|
sx: "100dvh",
|
|
436
|
-
}, header: (0, jsx_runtime_1.jsx)(PageHeader_1.default, { title: RECEIVE_STEP_NAME[Math.max(currentStep, ReceiveStep.SELECT_TOKEN)], overrideBack: handleBack, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g8, marginLeft: "auto" }), children: [(0, jsx_runtime_1.jsx)(HelpButton_1.default, {}), !!handleGotoHistory && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Divider, { orientation: "vertical", sx: {
|
|
437
|
+
}, header: (0, jsx_runtime_1.jsx)(PageHeader_1.default, { title: RECEIVE_STEP_NAME[Math.max(currentStep, ReceiveStep.SELECT_TOKEN)], overrideBack: handleBack, children: false && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g8, marginLeft: "auto" }), children: [(0, jsx_runtime_1.jsx)(HelpButton_1.default, {}), !!handleGotoHistory && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Divider, { orientation: "vertical", sx: {
|
|
437
438
|
height: "1rem",
|
|
438
439
|
width: "1px",
|
|
439
440
|
backgroundColor: theme.palette.border.accent3,
|
|
440
|
-
} }), (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 20, height: 20, display: "block" }, onClick: handleGotoHistory, children: SvgPath_1.IC_HISTORY })] }))] }) }), footer: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
441
|
+
} }), (0, jsx_runtime_1.jsx)(material_1.SvgIcon, { sx: { width: 20, height: 20, display: "block" }, onClick: handleGotoHistory, children: SvgPath_1.IC_HISTORY })] }))] })) }), footer: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
441
442
|
maxHeight: currentStep === ReceiveStep.SHOW_QR_CODE ? "120px" : 0,
|
|
442
443
|
overflow: "hidden",
|
|
443
444
|
transition: currentStep === ReceiveStep.SHOW_QR_CODE
|
|
@@ -128,7 +128,7 @@ function RealtimeProvider(_a) {
|
|
|
128
128
|
horizontal: (_e = (_d = notification === null || notification === void 0 ? void 0 : notification.anchorOrigin) === null || _d === void 0 ? void 0 : _d.horizontal) !== null && _e !== void 0 ? _e : "right",
|
|
129
129
|
}, onClose: function () {
|
|
130
130
|
closeNotification(notification.id);
|
|
131
|
-
}, slots: { transition: GrowTransition }, autoHideDuration: (_f = notification.duration) !== null && _f !== void 0 ? _f :
|
|
131
|
+
}, slots: { transition: GrowTransition }, autoHideDuration: (_f = notification.duration) !== null && _f !== void 0 ? _f : 5000, children: (0, jsx_runtime_1.jsx)(material_1.Alert, { icon: false, severity: notification.type, sx: {
|
|
132
132
|
width: "fit-content",
|
|
133
133
|
borderRadius: theme.mixins.customRadius.r6,
|
|
134
134
|
mx: "auto",
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { SxProps } from "@mui/material";
|
|
2
|
-
import { ConfirmLayoutProps } from "../ConfirmLayout";
|
|
3
|
-
import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
|
|
4
|
-
import { SwapBody, SwapResponse } from "../../../services/axios/swap-service/type";
|
|
5
|
-
export interface SwapDataType extends Omit<SwapBody, "passcode" | "network"> {
|
|
6
|
-
}
|
|
7
|
-
interface SwapTokenProps extends Omit<ConfirmLayoutProps, "action"> {
|
|
8
|
-
sendData: SwapDataType;
|
|
9
|
-
onSuccess?: (data: SwapResponse) => any;
|
|
10
|
-
initFeeData?: FeesDataType;
|
|
11
|
-
onStart?: () => void;
|
|
12
|
-
onFinish?: () => void;
|
|
13
|
-
onError?: (error: Error | unknown) => void;
|
|
14
|
-
sx?: SxProps;
|
|
15
|
-
btnConfirm?: React.ReactNode;
|
|
16
|
-
children?: React.ReactNode;
|
|
17
|
-
trigger?: React.ReactNode;
|
|
18
|
-
overrideHeader?: React.ReactNode;
|
|
19
|
-
}
|
|
20
|
-
export interface SwapTokenRef {
|
|
21
|
-
open: () => void;
|
|
22
|
-
close: () => void;
|
|
23
|
-
}
|
|
24
|
-
export declare enum SwapTokenError {
|
|
25
|
-
TOKEN_NOT_FOUND = "Token not found",
|
|
26
|
-
NOT_ENOUGH_BALANCE = "Not enough balance",
|
|
27
|
-
MAX_AMOUNT = "Max amount",
|
|
28
|
-
MIN_AMOUNT = "Min amount",
|
|
29
|
-
FAILED = "Failed"
|
|
30
|
-
}
|
|
31
|
-
export declare const SwapToken: import("react").ForwardRefExoticComponent<Omit<SwapTokenProps, "ref"> & import("react").RefAttributes<SwapTokenRef>>;
|
|
32
|
-
export default SwapToken;
|
|
@@ -1,293 +0,0 @@
|
|
|
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.SwapToken = exports.SwapTokenError = void 0;
|
|
88
|
-
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
89
|
-
var material_1 = require("@mui/material");
|
|
90
|
-
var ThemeProvider_1 = require("../../../providers/ThemeProvider");
|
|
91
|
-
var Button_1 = __importStar(require("../Button"));
|
|
92
|
-
var ConfirmLayout_1 = __importDefault(require("../ConfirmLayout"));
|
|
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 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 useSwapData_1 = __importDefault(require("../../../hooks/useSwapData"));
|
|
104
|
-
var swap_service_1 = __importDefault(require("../../../services/axios/swap-service"));
|
|
105
|
-
var Icon_1 = __importDefault(require("../Icon"));
|
|
106
|
-
var roundToTwoSignificantDecimals_1 = __importDefault(require("../../../utils/roundToTwoSignificantDecimals"));
|
|
107
|
-
var getImage_1 = __importDefault(require("../../../utils/getImage"));
|
|
108
|
-
var getIcon_1 = __importDefault(require("../../../utils/getIcon"));
|
|
109
|
-
var SwapTokenError;
|
|
110
|
-
(function (SwapTokenError) {
|
|
111
|
-
SwapTokenError["TOKEN_NOT_FOUND"] = "Token not found";
|
|
112
|
-
SwapTokenError["NOT_ENOUGH_BALANCE"] = "Not enough balance";
|
|
113
|
-
SwapTokenError["MAX_AMOUNT"] = "Max amount";
|
|
114
|
-
SwapTokenError["MIN_AMOUNT"] = "Min amount";
|
|
115
|
-
SwapTokenError["FAILED"] = "Failed";
|
|
116
|
-
})(SwapTokenError || (exports.SwapTokenError = SwapTokenError = {}));
|
|
117
|
-
var transactionSlug = type_1.TransactionSlug.SWAP;
|
|
118
|
-
exports.SwapToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
119
|
-
var _a;
|
|
120
|
-
var theme = (0, ThemeProvider_1.useTheme)();
|
|
121
|
-
var _b = (0, useSwapData_1.default)(), fromTokens = _b.fromTokens, updateSwapTokens = _b.updateSwapTokens;
|
|
122
|
-
var isInitPasscode = (0, useWalletData_1.default)().isInitPasscode;
|
|
123
|
-
var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
|
|
124
|
-
var _c = (0, react_1.useState)(undefined), error = _c[0], setError = _c[1];
|
|
125
|
-
var _d = (0, react_1.useState)(undefined), errorAmount = _d[0], setErrorAmount = _d[1];
|
|
126
|
-
var _e = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _e[0], setButtonStatus = _e[1];
|
|
127
|
-
var _f = (0, react_1.useState)(props.initFeeData), estimateFee = _f[0], setEstimateFee = _f[1];
|
|
128
|
-
var _g = (0, react_1.useState)(false), isLoadingEstimateFee = _g[0], setIsLoadingEstimateFee = _g[1];
|
|
129
|
-
var amount = props.sendData.amount;
|
|
130
|
-
var fromTokenSlug = props.sendData.currency_slug;
|
|
131
|
-
var toTokenSlug = props.sendData.to_currency_slug;
|
|
132
|
-
var sx = props.sx, children = props.children, btnConfirm = props.btnConfirm, trigger = props.trigger, overrideHeader = props.overrideHeader;
|
|
133
|
-
var fromToken = (0, react_1.useMemo)(function () {
|
|
134
|
-
return fromTokens === null || fromTokens === void 0 ? void 0 : fromTokens.find(function (token) { return token.slug === fromTokenSlug; });
|
|
135
|
-
}, [fromTokenSlug, fromTokens]);
|
|
136
|
-
var toToken = (0, react_1.useMemo)(function () {
|
|
137
|
-
var _a;
|
|
138
|
-
if (!fromToken)
|
|
139
|
-
return undefined;
|
|
140
|
-
return (_a = fromToken.outputs) === null || _a === void 0 ? void 0 : _a.find(function (token) { return token.slug === toTokenSlug; });
|
|
141
|
-
}, [toTokenSlug, fromToken]);
|
|
142
|
-
var toAmount = (0, react_1.useMemo)(function () {
|
|
143
|
-
if (!toToken)
|
|
144
|
-
return undefined;
|
|
145
|
-
return +amount / +toToken.usd_rate;
|
|
146
|
-
}, [toToken, amount]);
|
|
147
|
-
var getEstimateFee = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
148
|
-
var response;
|
|
149
|
-
return __generator(this, function (_a) {
|
|
150
|
-
switch (_a.label) {
|
|
151
|
-
case 0:
|
|
152
|
-
if (!fromTokenSlug)
|
|
153
|
-
return [2 /*return*/];
|
|
154
|
-
setIsLoadingEstimateFee(true);
|
|
155
|
-
return [4 /*yield*/, (0, get_est_fee_service_1.default)({
|
|
156
|
-
amount: "".concat(amount),
|
|
157
|
-
transaction_type: transactionSlug,
|
|
158
|
-
currency: fromTokenSlug || "",
|
|
159
|
-
to_currency_slug: toTokenSlug || "",
|
|
160
|
-
})];
|
|
161
|
-
case 1:
|
|
162
|
-
response = _a.sent();
|
|
163
|
-
setIsLoadingEstimateFee(false);
|
|
164
|
-
setEstimateFee(response === null || response === void 0 ? void 0 : response.data);
|
|
165
|
-
return [2 /*return*/, true];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}); }, [amount, fromTokenSlug]);
|
|
169
|
-
var token = (0, react_1.useMemo)(function () {
|
|
170
|
-
return fromTokens === null || fromTokens === void 0 ? void 0 : fromTokens.find(function (token) { return token.slug === fromTokenSlug; });
|
|
171
|
-
}, [fromTokenSlug, fromTokens]);
|
|
172
|
-
var validateAmount = (0, react_1.useCallback)(function () {
|
|
173
|
-
if (!token) {
|
|
174
|
-
setError(SwapTokenError.TOKEN_NOT_FOUND);
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
if (+amount > token.max_value) {
|
|
178
|
-
setError(SwapTokenError.MAX_AMOUNT);
|
|
179
|
-
setErrorAmount(token.max_value);
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
if (+amount < token.min_value) {
|
|
183
|
-
setError(SwapTokenError.MIN_AMOUNT);
|
|
184
|
-
setErrorAmount(token.min_value);
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if (+amount > +token.balance) {
|
|
188
|
-
setError(SwapTokenError.NOT_ENOUGH_BALANCE);
|
|
189
|
-
setErrorAmount(token.balance);
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
setError(undefined);
|
|
193
|
-
setErrorAmount(undefined);
|
|
194
|
-
return true;
|
|
195
|
-
}, [amount, token]);
|
|
196
|
-
var validateAll = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
197
|
-
var isAmountValid;
|
|
198
|
-
return __generator(this, function (_a) {
|
|
199
|
-
isAmountValid = validateAmount();
|
|
200
|
-
if (!isAmountValid)
|
|
201
|
-
return [2 /*return*/, false];
|
|
202
|
-
getEstimateFee();
|
|
203
|
-
return [2 /*return*/];
|
|
204
|
-
});
|
|
205
|
-
}); }, [validateAmount, getEstimateFee]);
|
|
206
|
-
var handleSwapToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
207
|
-
var response, err_1;
|
|
208
|
-
var _a, _b, _c, _d, _e;
|
|
209
|
-
return __generator(this, function (_f) {
|
|
210
|
-
switch (_f.label) {
|
|
211
|
-
case 0:
|
|
212
|
-
_f.trys.push([0, 2, 3, 4]);
|
|
213
|
-
(_a = props.onStart) === null || _a === void 0 ? void 0 : _a.call(props);
|
|
214
|
-
setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
215
|
-
return [4 /*yield*/, (0, swap_service_1.default)(__assign(__assign({}, props.sendData), { passcode: passcode }))];
|
|
216
|
-
case 1:
|
|
217
|
-
response = _f.sent();
|
|
218
|
-
if (response.success) {
|
|
219
|
-
(_b = confirmLayoutDrawerRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
220
|
-
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
221
|
-
(_c = props.onSuccess) === null || _c === void 0 ? void 0 : _c.call(props, response);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
throw new Error("Swap internal failed");
|
|
225
|
-
}
|
|
226
|
-
return [3 /*break*/, 4];
|
|
227
|
-
case 2:
|
|
228
|
-
err_1 = _f.sent();
|
|
229
|
-
(_d = props.onError) === null || _d === void 0 ? void 0 : _d.call(props, err_1);
|
|
230
|
-
setButtonStatus(Button_1.BUTTON_STATUS.ERROR);
|
|
231
|
-
setTimeout(function () {
|
|
232
|
-
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
233
|
-
}, 1200);
|
|
234
|
-
return [3 /*break*/, 4];
|
|
235
|
-
case 3:
|
|
236
|
-
(_e = props.onFinish) === null || _e === void 0 ? void 0 : _e.call(props);
|
|
237
|
-
return [7 /*endfinally*/];
|
|
238
|
-
case 4: return [2 /*return*/];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}); };
|
|
242
|
-
var handleOpen = function () {
|
|
243
|
-
var _a;
|
|
244
|
-
if (!isInitPasscode)
|
|
245
|
-
throw new Error("Please connect your wallet");
|
|
246
|
-
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
247
|
-
validateAll();
|
|
248
|
-
};
|
|
249
|
-
var handleClose = function () {
|
|
250
|
-
var _a;
|
|
251
|
-
if (!isInitPasscode)
|
|
252
|
-
throw new Error("Please connect your wallet");
|
|
253
|
-
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
254
|
-
};
|
|
255
|
-
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
256
|
-
open: handleOpen,
|
|
257
|
-
close: handleClose,
|
|
258
|
-
}); });
|
|
259
|
-
var estimateReceive = (0, react_1.useMemo)(function () {
|
|
260
|
-
if (!estimateFee || !amount || !(toToken === null || toToken === void 0 ? void 0 : toToken.usd_rate))
|
|
261
|
-
return undefined;
|
|
262
|
-
return (+amount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.fee_in_currency)) / +(toToken === null || toToken === void 0 ? void 0 : toToken.usd_rate);
|
|
263
|
-
}, [estimateFee, toToken, amount]);
|
|
264
|
-
(0, react_1.useEffect)(function () {
|
|
265
|
-
if (isInitPasscode && !fromTokens) {
|
|
266
|
-
updateSwapTokens();
|
|
267
|
-
}
|
|
268
|
-
}, [isInitPasscode, fromTokens]);
|
|
269
|
-
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsx)(ConfirmLayout_1.default, { onOpen: validateAll, trigger: trigger, ref: confirmLayoutDrawerRef, action: transactionSlug, header: {
|
|
270
|
-
title: overrideHeader,
|
|
271
|
-
}, sx: sx, confirmAction: (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSwapToken, children: btnConfirm !== null && btnConfirm !== void 0 ? btnConfirm : ((0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee ? Button_1.BUTTON_STATUS.DISABLED : buttonStatus, sx: { width: "100%" }, children: "Swap" })) }), children: children !== null && children !== void 0 ? children : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!!fromToken && !!toToken && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: "flex", gap: theme.mixins.gaps.g12, flexDirection: "column" }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { alignItems: "start", gap: theme.mixins.gaps.g12, backgroundColor: theme.palette.background.primary, backgroundImage: "url(".concat((0, getImage_1.default)("logo_transfer", "png"), ")"), backgroundPosition: "right", backgroundRepeat: "no-repeat", padding: theme.mixins.customPadding.p16, borderRadius: theme.mixins.customRadius.r16 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16, width: "100%" }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6 }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { src: fromToken === null || fromToken === void 0 ? void 0 : fromToken.link, width: 20, height: 20, className: "rounded-full" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { fontWeight: theme.typography.fontWeight600, color: theme.palette.text.white }), children: fromToken === null || fromToken === void 0 ? void 0 : fromToken.name })] }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.bigValue), { ml: "auto", color: theme.palette.text.white }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount }) })] }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", gap: theme.mixins.gaps.g2, sx: {
|
|
272
|
-
width: "100%",
|
|
273
|
-
mt: theme.mixins.customMargin.m4,
|
|
274
|
-
mb: theme.mixins.customMargin.m4,
|
|
275
|
-
}, children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("swap_up"), width: 18, height: 18, color: theme.palette.text.primary }), (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: {
|
|
276
|
-
width: "95%",
|
|
277
|
-
borderStyle: "dashed",
|
|
278
|
-
borderColor: theme.palette.border.white16,
|
|
279
|
-
} })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16, width: "100%" }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6 }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { src: toToken === null || toToken === void 0 ? void 0 : toToken.link, width: 20, height: 20, className: "rounded-full" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { fontWeight: theme.typography.fontWeight600, color: theme.palette.text.white }), children: toToken === null || toToken === void 0 ? void 0 : toToken.name })] }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.bigValue), { ml: "auto", color: theme.palette.text.white }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: toAmount }) })] })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { mt: theme.mixins.customMargin.m12 }), children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
280
|
-
fontSize: theme.typography.fontSize18,
|
|
281
|
-
fontWeight: theme.typography.fontWeight700,
|
|
282
|
-
color: theme.palette.text.black,
|
|
283
|
-
}, children: "Transfer Summary" }) }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.fee_detail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { isFeePaidByAmount: true, feesData: estimateFee, amount: +amount, tokenSlug: fromTokenSlug })), !estimateFee && !!amount && isLoadingEstimateFee && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g8, width: "100%" }), children: [(0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 16, sx: { color: theme.palette.text.white } }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: { color: "text.white" }, children: "Calculating fee" })] })), !!estimateReceive && !error && ((0, jsx_runtime_1.jsx)(LineValue_1.default, { value: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign(__assign({}, theme.mixins.row), theme.mixins.valueDescription), { width: "100%", justifyContent: "center", color: theme.palette.text.black, fontWeight: theme.typography.fontWeight500, gap: theme.mixins.gaps.g2 }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("ellipse"), width: 12, height: 12 }), "1", " ", fromToken === null || fromToken === void 0 ? void 0 : fromToken.name, " =", (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g2 }), children: [(0, jsx_runtime_1.jsx)(Formatter_1.default, { value: 1 / +(toToken === null || toToken === void 0 ? void 0 : toToken.usd_rate) }), " ", toToken === null || toToken === void 0 ? void 0 : toToken.name] })] }), field: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
284
|
-
color: theme.palette.text.black,
|
|
285
|
-
fontWeight: theme.typography.fontWeight600,
|
|
286
|
-
}, children: "Best Price" }) })), !!estimateReceive && !error && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { width: "100%", gap: theme.mixins.gaps.g8, mt: theme.mixins.customMargin.m8 }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("warning"), width: 18, height: 18 }), (0, jsx_runtime_1.jsxs)(Text_1.default, { sx: {
|
|
287
|
-
color: theme.palette.text.primary,
|
|
288
|
-
fontWeight: theme.typography.fontWeight600,
|
|
289
|
-
fontSize: theme.typography.fontSize13,
|
|
290
|
-
}, children: ["You will receive at least ", "".concat(estimateReceive, " ").concat(toToken === null || toToken === void 0 ? void 0 : toToken.name), " ", "(~".concat((0, roundToTwoSignificantDecimals_1.default)(estimateReceive), ")"), " or the transaction will refunded"] })] })), !!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) })] }))] }) })), (!fromToken || !toToken) && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.paper), { alignItems: "center", justifyContent: "center" }), children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { fontSize: theme.typography.fontSize16 }), children: SwapTokenError.TOKEN_NOT_FOUND }) }))] })) }) }));
|
|
291
|
-
});
|
|
292
|
-
exports.SwapToken.displayName = "SwapToken";
|
|
293
|
-
exports.default = exports.SwapToken;
|