tek-wallet 0.0.750 → 0.0.753
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/README.md +18 -10
- package/dist/components/TekWallet/components/index.d.ts +8 -0
- package/dist/components/TekWallet/components/index.js +8 -0
- package/dist/components/TekWallet/components/layouts/ChildPageLayout/index.js +14 -3
- package/dist/components/TekWallet/components/ui/BackHeader/index.js +5 -1
- package/dist/components/TekWallet/components/ui/BottomActionLayout/index.d.ts +3 -3
- package/dist/components/TekWallet/components/ui/BottomActionLayout/index.js +24 -6
- package/dist/components/TekWallet/components/ui/Button/index.js +2 -2
- package/dist/components/TekWallet/components/ui/ConfirmByPasscode/index.js +2 -6
- package/dist/components/TekWallet/components/ui/ConfirmSendExternal/index.d.ts +20 -0
- package/dist/components/TekWallet/components/ui/ConfirmSendExternal/index.js +173 -0
- package/dist/components/TekWallet/components/ui/ConfirmSendInternal/index.d.ts +17 -0
- package/dist/components/TekWallet/components/ui/ConfirmSendInternal/index.js +100 -0
- package/dist/components/TekWallet/components/ui/ConfirmSwapToken/Result.d.ts +8 -0
- package/dist/components/TekWallet/components/ui/ConfirmSwapToken/Result.js +112 -0
- package/dist/components/TekWallet/components/ui/ConfirmSwapToken/index.d.ts +18 -0
- package/dist/components/TekWallet/components/ui/ConfirmSwapToken/index.js +169 -0
- package/dist/components/TekWallet/components/ui/ConfirmTransaction/index.d.ts +6 -2
- package/dist/components/TekWallet/components/ui/ConfirmTransaction/index.js +11 -6
- package/dist/components/TekWallet/components/ui/ConfirmTransfer/index.d.ts +28 -0
- package/dist/components/TekWallet/components/ui/ConfirmTransfer/index.js +253 -0
- package/dist/components/TekWallet/components/ui/ConfirmTransfer/type.d.ts +16 -0
- package/dist/components/TekWallet/components/ui/ConfirmTransfer/type.js +2 -0
- package/dist/components/TekWallet/components/ui/CopyableText/index.js +1 -1
- package/dist/components/TekWallet/components/ui/DetailSwap/index.js +1 -1
- package/dist/components/TekWallet/components/ui/Fees/index.d.ts +1 -1
- package/dist/components/TekWallet/components/ui/Fees/index.js +51 -41
- package/dist/components/TekWallet/components/ui/FeesAutoDebounce/index.d.ts +10 -0
- package/dist/components/TekWallet/components/ui/FeesAutoDebounce/index.js +223 -0
- package/dist/components/TekWallet/components/ui/FiatDeposit/components/shareAction.js +2 -2
- package/dist/components/TekWallet/components/ui/FiatDeposit/components/shareImage.js +13 -13
- package/dist/components/TekWallet/components/ui/FiatDeposit/index.js +6 -4
- package/dist/components/TekWallet/components/ui/Formatter/index.d.ts +1 -0
- package/dist/components/TekWallet/components/ui/Formatter/index.js +4 -2
- package/dist/components/TekWallet/components/ui/FunctionItem/index.js +5 -4
- package/dist/components/TekWallet/components/ui/Icon/index.d.ts +4 -2
- package/dist/components/TekWallet/components/ui/Icon/index.js +44 -3
- package/dist/components/TekWallet/components/ui/Input/index.js +3 -3
- package/dist/components/TekWallet/components/ui/ListItemCustom/index.d.ts +2 -1
- package/dist/components/TekWallet/components/ui/ListItemCustom/index.js +3 -3
- package/dist/components/TekWallet/components/ui/QRCode/index.js +1 -1
- package/dist/components/TekWallet/components/ui/SendExternalToken/index.js +1 -1
- package/dist/components/TekWallet/components/ui/SendExternalTokenWithdrawn/index.d.ts +2 -5
- package/dist/components/TekWallet/components/ui/SvgPath/index.d.ts +12 -0
- package/dist/components/TekWallet/components/ui/SvgPath/index.js +27 -15
- package/dist/components/TekWallet/components/ui/SwapFunction/index.js +4 -4
- package/dist/components/TekWallet/components/ui/SwapToken/index.d.ts +2 -3
- package/dist/components/TekWallet/components/ui/TokensBoard/index.js +1 -3
- package/dist/components/TekWallet/components/ui/ValidateWalletAddress/index.d.ts +5 -0
- package/dist/components/TekWallet/components/ui/ValidateWalletAddress/index.js +67 -0
- package/dist/components/TekWallet/components/ui/WaitingData/index.d.ts +1 -0
- package/dist/components/TekWallet/components/ui/WaitingData/index.js +10 -6
- package/dist/components/TekWallet/components/ui/WithdrawFunction/index.d.ts +1 -1
- package/dist/components/TekWallet/components/ui/WithdrawFunction/index.js +70 -32
- package/dist/components/TekWallet/components/views/AssetView/Menu.d.ts +7 -0
- package/dist/components/TekWallet/components/views/AssetView/Menu.js +25 -0
- package/dist/components/TekWallet/components/views/AssetView/index.js +25 -26
- package/dist/components/TekWallet/components/views/NotFoundView/index.d.ts +2 -0
- package/dist/components/TekWallet/components/views/NotFoundView/index.js +7 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/Form.d.ts +11 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/Form.js +450 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/Result.d.ts +14 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/Result.js +140 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/SelectNetwork.d.ts +10 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/SelectNetwork.js +34 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/SelectToken.d.ts +8 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/SelectToken.js +173 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/Summary.d.ts +12 -0
- package/dist/components/TekWallet/components/views/SendExternalView/components/Summary.js +131 -0
- package/dist/components/TekWallet/components/views/SendExternalView/index.d.ts +23 -0
- package/dist/components/TekWallet/components/views/SendExternalView/index.js +143 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/AmountForm.d.ts +11 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/AmountForm.js +380 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/Form.d.ts +11 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/Form.js +381 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/Result.d.ts +13 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/Result.js +128 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/SelectToken.d.ts +8 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/SelectToken.js +173 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/Summary.d.ts +11 -0
- package/dist/components/TekWallet/components/views/SendInternalView/components/Summary.js +126 -0
- package/dist/components/TekWallet/components/views/SendInternalView/index.d.ts +24 -0
- package/dist/components/TekWallet/components/views/SendInternalView/index.js +155 -0
- package/dist/components/TekWallet/components/views/SwapView/components/CardTo/index.d.ts +11 -0
- package/dist/components/TekWallet/components/views/SwapView/components/CardTo/index.js +111 -0
- package/dist/components/TekWallet/components/views/SwapView/components/FromCard/index.d.ts +14 -0
- package/dist/components/TekWallet/components/views/SwapView/components/FromCard/index.js +180 -0
- package/dist/components/TekWallet/components/views/SwapView/components/SelectToken.d.ts +9 -0
- package/dist/components/TekWallet/components/views/SwapView/components/SelectToken.js +173 -0
- package/dist/components/TekWallet/components/views/SwapView/components/Summary.d.ts +14 -0
- package/dist/components/TekWallet/components/views/SwapView/components/Summary.js +239 -0
- package/dist/components/TekWallet/components/views/SwapView/functions/convertTokensRate.d.ts +3 -0
- package/dist/components/TekWallet/components/views/SwapView/functions/convertTokensRate.js +14 -0
- package/dist/components/TekWallet/components/views/SwapView/index.d.ts +11 -0
- package/dist/components/TekWallet/components/views/SwapView/index.js +218 -0
- package/dist/components/TekWallet/components/views/TekWalletView/expose.d.ts +2 -0
- package/dist/components/TekWallet/components/views/TekWalletView/expose.js +18 -0
- package/dist/components/TekWallet/components/views/TekWalletView/index.d.ts +3 -0
- package/dist/components/TekWallet/components/views/TekWalletView/index.js +16 -0
- package/dist/components/TekWallet/components/views/TekWalletView/routes.d.ts +9 -0
- package/dist/components/TekWallet/components/views/TekWalletView/routes.js +74 -0
- package/dist/components/TekWallet/hooks/useValidateAmount.d.ts +26 -0
- package/dist/components/TekWallet/hooks/useValidateAmount.js +103 -0
- package/dist/components/TekWallet/providers/EventHandlerProvider/index.js +5 -0
- package/dist/components/TekWallet/providers/RealtimeProvider/index.js +2 -2
- package/dist/components/TekWallet/providers/TekWalletProvider/index.d.ts +3 -0
- package/dist/components/TekWallet/providers/TekWalletProvider/index.js +8 -2
- package/dist/components/TekWallet/providers/WithdrawProvider/index.js +36 -0
- package/dist/components/TekWallet/services/axios/get-est-fee-service/type.d.ts +5 -4
- package/dist/components/TekWallet/services/axios/send-external-service/type.d.ts +5 -30
- package/dist/components/TekWallet/services/axios/swap-service/type.d.ts +4 -0
- package/dist/components/TekWallet/services/axios/transfer-internal-service/type.d.ts +4 -32
- package/dist/components/TekWallet/theme/mui/deposit-fiat-theme/components.js +3 -3
- package/dist/components/TekWallet/theme/mui/deposit-fiat-theme/palette.js +3 -3
- package/dist/components/TekWallet/theme/mui/theme.js +9 -9
- package/dist/components/TekWallet/utils/stop.d.ts +3 -0
- package/dist/components/TekWallet/utils/stop.js +6 -0
- package/package.json +2 -2
- package/dist/components/TekWallet/components/ui/CardFrom/index.d.ts +0 -10
- package/dist/components/TekWallet/components/ui/CardFrom/index.js +0 -91
- package/dist/components/TekWallet/components/ui/CardTo/index.d.ts +0 -10
- package/dist/components/TekWallet/components/ui/CardTo/index.js +0 -39
- package/dist/components/TekWallet/components/ui/ConfirmLayout copy/index.d.ts +0 -7
- package/dist/components/TekWallet/components/ui/ConfirmLayout copy/index.js +0 -67
- package/dist/components/TekWallet/components/views/HelpView/index.d.ts +0 -2
- package/dist/components/TekWallet/components/views/HelpView/index.js +0 -7
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.default = Result;
|
|
18
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
19
|
+
var material_1 = require("@mui/material");
|
|
20
|
+
var Text_1 = __importDefault(require("../Text"));
|
|
21
|
+
var react_1 = require("react");
|
|
22
|
+
var Button_1 = __importDefault(require("../Button"));
|
|
23
|
+
var providers_1 = require("../../../providers");
|
|
24
|
+
var Formatter_1 = __importDefault(require("../Formatter"));
|
|
25
|
+
var Icon_1 = __importDefault(require("../Icon"));
|
|
26
|
+
var useFormatter_1 = __importDefault(require("../../../hooks/useFormatter"));
|
|
27
|
+
var type_1 = require("../../../services/axios/get-activities-service/type");
|
|
28
|
+
var InlineTitleValue_1 = __importDefault(require("../InlineTitleValue"));
|
|
29
|
+
var convertTokensRate_1 = __importDefault(require("../../views/SwapView/functions/convertTokensRate"));
|
|
30
|
+
function Result(props) {
|
|
31
|
+
var theme = (0, providers_1.useTheme)();
|
|
32
|
+
var formatDate = (0, useFormatter_1.default)().formatDate;
|
|
33
|
+
var transaction = props.transaction, onDone = props.onDone;
|
|
34
|
+
var status = (0, react_1.useMemo)(function () { return (transaction === null || transaction === void 0 ? void 0 : transaction.transaction_status) || "failed"; }, [transaction === null || transaction === void 0 ? void 0 : transaction.transaction_status]);
|
|
35
|
+
var amount = (0, react_1.useMemo)(function () { return transaction === null || transaction === void 0 ? void 0 : transaction.amount; }, [transaction === null || transaction === void 0 ? void 0 : transaction.amount]);
|
|
36
|
+
var toAmount = 1;
|
|
37
|
+
var fromToken = (0, react_1.useMemo)(function () { return transaction === null || transaction === void 0 ? void 0 : transaction.currency_data; }, [transaction === null || transaction === void 0 ? void 0 : transaction.currency_data]);
|
|
38
|
+
var toToken = (0, react_1.useMemo)(function () { return transaction === null || transaction === void 0 ? void 0 : transaction.to_currency_data; }, [transaction === null || transaction === void 0 ? void 0 : transaction.to_currency_data]);
|
|
39
|
+
var toTokenRate = (0, react_1.useMemo)(function () {
|
|
40
|
+
if (!fromToken || !toToken)
|
|
41
|
+
return 0;
|
|
42
|
+
return (0, convertTokensRate_1.default)(fromToken, toToken, 1);
|
|
43
|
+
}, [fromToken, toToken]);
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
45
|
+
display: "flex",
|
|
46
|
+
flexDirection: "column",
|
|
47
|
+
gap: 3,
|
|
48
|
+
height: "100%",
|
|
49
|
+
}, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
50
|
+
display: "flex",
|
|
51
|
+
flexDirection: "column",
|
|
52
|
+
alignItems: "center",
|
|
53
|
+
gap: theme.mixins.gaps.g16,
|
|
54
|
+
my: "auto",
|
|
55
|
+
backgroundColor: theme.palette.background.tertiary,
|
|
56
|
+
borderRadius: theme.mixins.customRadius.r16,
|
|
57
|
+
padding: theme.mixins.customPadding.p16,
|
|
58
|
+
paddingTop: "0px",
|
|
59
|
+
}, children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { iconKey: status === "success" ? "IC_CHECK_CIRCLE" : "IC_ERROR_CIRCLE", width: 100, sx: {
|
|
60
|
+
transform: "translateY(-50%)",
|
|
61
|
+
} }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
62
|
+
display: "flex",
|
|
63
|
+
flexDirection: "column",
|
|
64
|
+
alignItems: "center",
|
|
65
|
+
}, children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
66
|
+
fontSize: theme.typography.fontSize13,
|
|
67
|
+
color: theme.palette.text.accent2,
|
|
68
|
+
}, children: "Swap" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
69
|
+
color: status === type_1.TransactionStatus.Success
|
|
70
|
+
? theme.palette.text.successStatus
|
|
71
|
+
: theme.palette.text.errorStatus,
|
|
72
|
+
textTransform: "capitalize",
|
|
73
|
+
fontWeight: 600,
|
|
74
|
+
fontSize: theme.typography.fontSize24,
|
|
75
|
+
}, children: status })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { width: "100%", borderTop: "1px ".concat(theme.palette.border.accent3, " solid") } }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
76
|
+
width: "100%",
|
|
77
|
+
position: "relative",
|
|
78
|
+
}, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
79
|
+
display: "flex",
|
|
80
|
+
alignItems: "center",
|
|
81
|
+
gap: theme.mixins.gaps.g4,
|
|
82
|
+
position: "relative",
|
|
83
|
+
zIndex: 1,
|
|
84
|
+
}, children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { src: fromToken === null || fromToken === void 0 ? void 0 : fromToken.link, sx: {
|
|
85
|
+
width: 20,
|
|
86
|
+
height: 20,
|
|
87
|
+
borderRadius: "999px",
|
|
88
|
+
} }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { color: "inherit" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount }) }), (0, jsx_runtime_1.jsx)(Icon_1.default, { iconKey: "IC_SWAP", sx: {
|
|
89
|
+
width: 16,
|
|
90
|
+
height: 16,
|
|
91
|
+
mx: "auto",
|
|
92
|
+
transform: "rotate(-90deg)",
|
|
93
|
+
} }), (0, jsx_runtime_1.jsx)(Icon_1.default, { src: toToken === null || toToken === void 0 ? void 0 : toToken.link, sx: {
|
|
94
|
+
width: 20,
|
|
95
|
+
height: 20,
|
|
96
|
+
borderRadius: "999px",
|
|
97
|
+
} }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { color: "inherit" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: toAmount }) })] }) }), (0, jsx_runtime_1.jsx)(InlineTitleValue_1.default, { title: "Price", titleStyle: {
|
|
98
|
+
fontSize: "0.6875rem",
|
|
99
|
+
fontWeight: 500,
|
|
100
|
+
color: "gray.700",
|
|
101
|
+
}, value: !!toTokenRate && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: ["1 ", fromToken === null || fromToken === void 0 ? void 0 : fromToken.name, " ~ ", (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: toTokenRate, unit: toToken === null || toToken === void 0 ? void 0 : toToken.name })] })), isAligned: true }), !!(transaction === null || transaction === void 0 ? void 0 : transaction.date_created) && ((0, jsx_runtime_1.jsx)(InlineTitleValue_1.default, { title: "Date", titleStyle: {
|
|
102
|
+
fontSize: "0.6875rem",
|
|
103
|
+
fontWeight: 500,
|
|
104
|
+
color: "gray.700",
|
|
105
|
+
}, value: !!toTokenRate && ((0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: formatDate(transaction === null || transaction === void 0 ? void 0 : transaction.date_created, true) })), isAligned: true }))] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
106
|
+
marginTop: "auto",
|
|
107
|
+
width: "100%",
|
|
108
|
+
display: "grid",
|
|
109
|
+
gridTemplateColumns: "1fr",
|
|
110
|
+
gap: theme.mixins.gaps.g8,
|
|
111
|
+
}, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, onClick: onDone, children: "Done" }) })] }) }));
|
|
112
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SxProps } from "@mui/material";
|
|
2
|
+
import { ConfirmLayoutProps } from "../ConfirmLayout";
|
|
3
|
+
import { ReactEventHandler } from "react";
|
|
4
|
+
import { SwapBody, SwapResponse } from "../../../services/axios/swap-service/type";
|
|
5
|
+
export interface SwapDataType extends Omit<SwapBody, "passcode" | "network"> {
|
|
6
|
+
}
|
|
7
|
+
export interface ConfirmSwapTokenProps extends Omit<ConfirmLayoutProps, "action"> {
|
|
8
|
+
payload: SwapDataType;
|
|
9
|
+
onSuccess?: (data: SwapResponse) => any;
|
|
10
|
+
onStart?: () => void;
|
|
11
|
+
onFinally?: () => void;
|
|
12
|
+
onError?: (error: Error | unknown) => void;
|
|
13
|
+
onDone?: ReactEventHandler;
|
|
14
|
+
sx?: SxProps;
|
|
15
|
+
children?: React.ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export declare const ConfirmSwapToken: (props: ConfirmSwapTokenProps) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export default ConfirmSwapToken;
|
|
@@ -0,0 +1,169 @@
|
|
|
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.ConfirmSwapToken = void 0;
|
|
88
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
89
|
+
var DrawerComponent_1 = __importStar(require("../DrawerComponent"));
|
|
90
|
+
var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
|
|
91
|
+
var react_1 = require("react");
|
|
92
|
+
var swap_service_1 = __importDefault(require("../../../services/axios/swap-service"));
|
|
93
|
+
var ChildPageLayout_1 = __importDefault(require("../../layouts/ChildPageLayout"));
|
|
94
|
+
var stop_1 = __importDefault(require("../../../utils/stop"));
|
|
95
|
+
var DefaultPageLayout_1 = __importDefault(require("../../layouts/DefaultPageLayout"));
|
|
96
|
+
var Result_1 = __importDefault(require("./Result"));
|
|
97
|
+
var useRealtime_1 = __importDefault(require("../../../hooks/useRealtime"));
|
|
98
|
+
var ConfirmSwapToken = function (props) {
|
|
99
|
+
var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
|
|
100
|
+
var sx = props.sx, children = props.children, onSuccess = props.onSuccess, onStart = props.onStart, onFinally = props.onFinally, onError = props.onError, payload = props.payload, onDone = props.onDone;
|
|
101
|
+
var _a = (0, react_1.useState)(null), response = _a[0], setResponse = _a[1];
|
|
102
|
+
var pushNotification = (0, useRealtime_1.default)().pushNotification;
|
|
103
|
+
var openResult = function () {
|
|
104
|
+
var _a;
|
|
105
|
+
(_a = resultRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
106
|
+
};
|
|
107
|
+
var closeResult = function () {
|
|
108
|
+
var _a;
|
|
109
|
+
(_a = resultRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
110
|
+
};
|
|
111
|
+
var handleConfirmSwapToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
+
var response_1, err_1, time;
|
|
113
|
+
var _a, _b;
|
|
114
|
+
return __generator(this, function (_c) {
|
|
115
|
+
switch (_c.label) {
|
|
116
|
+
case 0:
|
|
117
|
+
_c.trys.push([0, 2, 3, 4]);
|
|
118
|
+
onStart === null || onStart === void 0 ? void 0 : onStart();
|
|
119
|
+
return [4 /*yield*/, (0, swap_service_1.default)(__assign(__assign({}, payload), { passcode: passcode, await_completion: true }))];
|
|
120
|
+
case 1:
|
|
121
|
+
response_1 = _c.sent();
|
|
122
|
+
if (response_1.success) {
|
|
123
|
+
setResponse(response_1);
|
|
124
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response_1);
|
|
125
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
126
|
+
openResult();
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
throw new Error("Swap internal failed");
|
|
130
|
+
}
|
|
131
|
+
return [3 /*break*/, 4];
|
|
132
|
+
case 2:
|
|
133
|
+
err_1 = _c.sent();
|
|
134
|
+
time = Date.now();
|
|
135
|
+
pushNotification({
|
|
136
|
+
id: "swap-failed-".concat(time),
|
|
137
|
+
message: "Something went wrong, please try again later",
|
|
138
|
+
type: "error",
|
|
139
|
+
});
|
|
140
|
+
onError === null || onError === void 0 ? void 0 : onError(err_1);
|
|
141
|
+
return [3 /*break*/, 4];
|
|
142
|
+
case 3:
|
|
143
|
+
onFinally === null || onFinally === void 0 ? void 0 : onFinally();
|
|
144
|
+
(_b = confirmLayoutDrawerRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
145
|
+
return [7 /*endfinally*/];
|
|
146
|
+
case 4: return [2 /*return*/];
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}); };
|
|
150
|
+
var resultRef = (0, react_1.useRef)(null);
|
|
151
|
+
var handleCloseResult = function (e) {
|
|
152
|
+
closeResult();
|
|
153
|
+
onDone === null || onDone === void 0 ? void 0 : onDone(e);
|
|
154
|
+
};
|
|
155
|
+
return ((0, jsx_runtime_1.jsxs)(ConfirmByPasscode_1.default, { sx: sx, onConfirmSuccess: handleConfirmSwapToken, children: [children, (0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { ref: resultRef, sx: {
|
|
156
|
+
width: 0,
|
|
157
|
+
height: 0,
|
|
158
|
+
position: "absolute",
|
|
159
|
+
top: 0,
|
|
160
|
+
left: 0,
|
|
161
|
+
}, direction: DrawerComponent_1.DRAWER_DIRECTION.RIGHT, children: (0, jsx_runtime_1.jsx)(ChildPageLayout_1.default, { sx: {
|
|
162
|
+
height: "100dvh",
|
|
163
|
+
width: "100dvw",
|
|
164
|
+
}, onClick: stop_1.default, children: (0, jsx_runtime_1.jsx)(DefaultPageLayout_1.default, { sx: {
|
|
165
|
+
height: "100%",
|
|
166
|
+
}, children: (0, jsx_runtime_1.jsx)(Result_1.default, { transaction: response === null || response === void 0 ? void 0 : response.data, onDone: handleCloseResult }) }) }) })] }));
|
|
167
|
+
};
|
|
168
|
+
exports.ConfirmSwapToken = ConfirmSwapToken;
|
|
169
|
+
exports.default = exports.ConfirmSwapToken;
|
|
@@ -2,13 +2,17 @@ import React, { PropsWithChildren, HTMLAttributes } from "react";
|
|
|
2
2
|
import { BUTTON_STATUS } from "../Button";
|
|
3
3
|
import { InstructionBody } from "../../../services/axios/instructions-service/type";
|
|
4
4
|
import { GeneralProps } from "../../../types/ui";
|
|
5
|
+
import { InstructionResponse } from "../../../services/axios/instructions-service/response.type";
|
|
5
6
|
type ConfirmTransactionProps = {
|
|
6
7
|
transactionSlug: string;
|
|
7
8
|
transactionData: Omit<InstructionBody, "passcode">;
|
|
8
9
|
renderChildren: (props: PropsWithChildren<HTMLAttributes<HTMLElement>> & {
|
|
9
10
|
status: BUTTON_STATUS;
|
|
10
11
|
}) => React.ReactElement<any>;
|
|
11
|
-
|
|
12
|
+
onSuccess?: (data: InstructionResponse) => void;
|
|
13
|
+
onError?: (error: any) => void;
|
|
14
|
+
onStart?: () => void;
|
|
15
|
+
onFinally?: () => void;
|
|
12
16
|
} & GeneralProps;
|
|
13
|
-
export declare function ConfirmTransaction({ renderChildren, transactionSlug, transactionData,
|
|
17
|
+
export declare function ConfirmTransaction({ renderChildren, transactionSlug, transactionData, onSuccess, onError, onStart, onFinally, }: ConfirmTransactionProps): import("react/jsx-runtime").JSX.Element;
|
|
14
18
|
export default ConfirmTransaction;
|
|
@@ -59,35 +59,40 @@ var Button_1 = require("../Button");
|
|
|
59
59
|
var instructions_service_1 = __importDefault(require("../../../services/axios/instructions-service"));
|
|
60
60
|
function ConfirmTransaction(_a) {
|
|
61
61
|
var _this = this;
|
|
62
|
-
var renderChildren = _a.renderChildren, transactionSlug = _a.transactionSlug, transactionData = _a.transactionData,
|
|
62
|
+
var renderChildren = _a.renderChildren, transactionSlug = _a.transactionSlug, transactionData = _a.transactionData, onSuccess = _a.onSuccess, onError = _a.onError, onStart = _a.onStart, onFinally = _a.onFinally;
|
|
63
63
|
var _b = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _b[0], setButtonStatus = _b[1];
|
|
64
64
|
var handleConfirmPasscode = function (passcode) { return __awaiter(_this, void 0, void 0, function () {
|
|
65
65
|
var response, err_1;
|
|
66
66
|
return __generator(this, function (_a) {
|
|
67
67
|
switch (_a.label) {
|
|
68
68
|
case 0:
|
|
69
|
-
_a.trys.push([0, 2, ,
|
|
69
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
70
70
|
setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
71
|
+
onStart === null || onStart === void 0 ? void 0 : onStart();
|
|
71
72
|
return [4 /*yield*/, (0, instructions_service_1.default)(__assign(__assign({}, transactionData), { passcode: passcode }))];
|
|
72
73
|
case 1:
|
|
73
74
|
response = _a.sent();
|
|
74
75
|
if (response.success) {
|
|
75
76
|
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
76
|
-
|
|
77
|
+
onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(response);
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
80
|
throw new Error("Send internal failed");
|
|
80
81
|
}
|
|
81
|
-
return [3 /*break*/,
|
|
82
|
+
return [3 /*break*/, 4];
|
|
82
83
|
case 2:
|
|
83
84
|
err_1 = _a.sent();
|
|
84
85
|
console.error(err_1);
|
|
86
|
+
onError === null || onError === void 0 ? void 0 : onError(err_1);
|
|
85
87
|
setButtonStatus(Button_1.BUTTON_STATUS.ERROR);
|
|
86
88
|
setTimeout(function () {
|
|
87
89
|
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
88
90
|
}, 1200);
|
|
89
|
-
return [3 /*break*/,
|
|
90
|
-
case 3:
|
|
91
|
+
return [3 /*break*/, 4];
|
|
92
|
+
case 3:
|
|
93
|
+
onFinally === null || onFinally === void 0 ? void 0 : onFinally();
|
|
94
|
+
return [7 /*endfinally*/];
|
|
95
|
+
case 4: return [2 /*return*/];
|
|
91
96
|
}
|
|
92
97
|
});
|
|
93
98
|
}); };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ConfirmLayoutProps } from "../ConfirmLayout";
|
|
2
|
+
import { SendInternalResponse } from "../../../services/axios/send-internal-service/type";
|
|
3
|
+
import { InstructionBody } from "../../../services/axios/instructions-service/type";
|
|
4
|
+
export type TransferConfirmationData = InstructionBody & {
|
|
5
|
+
amount: number;
|
|
6
|
+
currency_slug: string;
|
|
7
|
+
to_address: string;
|
|
8
|
+
isEnoughBalance: boolean;
|
|
9
|
+
};
|
|
10
|
+
interface TransferConfirmationProps extends Omit<ConfirmLayoutProps, "action"> {
|
|
11
|
+
transferData: TransferConfirmationData;
|
|
12
|
+
transferContent: React.ReactNode;
|
|
13
|
+
titleHeader: string;
|
|
14
|
+
onTransferSuccess?: (data: SendInternalResponse) => any;
|
|
15
|
+
}
|
|
16
|
+
export interface TransferConfirmationTokenRef {
|
|
17
|
+
open: () => void;
|
|
18
|
+
close: () => void;
|
|
19
|
+
}
|
|
20
|
+
export declare enum TransferConfirmationError {
|
|
21
|
+
TOKEN_NOT_FOUND = "\u24D8 Token not found",
|
|
22
|
+
NOT_ENOUGH_BALANCE = "\u24D8 Not enough balance",
|
|
23
|
+
MAX_AMOUNT = "\u24D8 Max amount",
|
|
24
|
+
MIN_AMOUNT = "\u24D8 Min amount",
|
|
25
|
+
FAILED = "\u24D8 Failed"
|
|
26
|
+
}
|
|
27
|
+
export declare const TransferConfirmation: import("react").ForwardRefExoticComponent<Omit<TransferConfirmationProps, "ref"> & import("react").RefAttributes<TransferConfirmationTokenRef>>;
|
|
28
|
+
export default TransferConfirmation;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
"use client";
|
|
4
|
+
var __assign = (this && this.__assign) || function () {
|
|
5
|
+
__assign = Object.assign || function(t) {
|
|
6
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
7
|
+
s = arguments[i];
|
|
8
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
9
|
+
t[p] = s[p];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
return __assign.apply(this, arguments);
|
|
14
|
+
};
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
49
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
50
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
51
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
52
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
53
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
54
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
58
|
+
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);
|
|
59
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
60
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
61
|
+
function step(op) {
|
|
62
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
63
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
64
|
+
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;
|
|
65
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
66
|
+
switch (op[0]) {
|
|
67
|
+
case 0: case 1: t = op; break;
|
|
68
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
69
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
70
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
71
|
+
default:
|
|
72
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
73
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
74
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
75
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
76
|
+
if (t[2]) _.ops.pop();
|
|
77
|
+
_.trys.pop(); continue;
|
|
78
|
+
}
|
|
79
|
+
op = body.call(thisArg, _);
|
|
80
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
81
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
85
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
86
|
+
};
|
|
87
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
88
|
+
exports.TransferConfirmation = exports.TransferConfirmationError = void 0;
|
|
89
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
90
|
+
var Button_1 = __importStar(require("../Button"));
|
|
91
|
+
var DrawerComponent_1 = require("../DrawerComponent");
|
|
92
|
+
var ConfirmLayout_1 = __importDefault(require("../ConfirmLayout"));
|
|
93
|
+
var Formatter_1 = __importDefault(require("../Formatter"));
|
|
94
|
+
var react_1 = require("react");
|
|
95
|
+
var Text_1 = __importDefault(require("../Text"));
|
|
96
|
+
var RequireConnect_1 = __importDefault(require("../RequireConnect"));
|
|
97
|
+
var type_1 = require("../../../services/axios/get-activities-service/type");
|
|
98
|
+
var validate_wallet_address_service_1 = __importDefault(require("../../../services/axios/validate-wallet-address-service"));
|
|
99
|
+
var type_2 = require("../../../services/axios/validate-wallet-address-service/type");
|
|
100
|
+
var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
|
|
101
|
+
var instructions_service_1 = __importDefault(require("../../../services/axios/instructions-service"));
|
|
102
|
+
var providers_1 = require("../../../providers");
|
|
103
|
+
var useWallet_1 = __importDefault(require("../../../hooks/useWallet"));
|
|
104
|
+
var TransferConfirmationError;
|
|
105
|
+
(function (TransferConfirmationError) {
|
|
106
|
+
TransferConfirmationError["TOKEN_NOT_FOUND"] = "\u24D8 Token not found";
|
|
107
|
+
TransferConfirmationError["NOT_ENOUGH_BALANCE"] = "\u24D8 Not enough balance";
|
|
108
|
+
TransferConfirmationError["MAX_AMOUNT"] = "\u24D8 Max amount";
|
|
109
|
+
TransferConfirmationError["MIN_AMOUNT"] = "\u24D8 Min amount";
|
|
110
|
+
TransferConfirmationError["FAILED"] = "\u24D8 Failed";
|
|
111
|
+
})(TransferConfirmationError || (exports.TransferConfirmationError = TransferConfirmationError = {}));
|
|
112
|
+
exports.TransferConfirmation = (0, react_1.forwardRef)(function (props, ref) {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
var theme = (0, providers_1.useTheme)();
|
|
115
|
+
var transferData = props.transferData, transferContent = props.transferContent;
|
|
116
|
+
var _c = (0, useWallet_1.default)(), isInitPasscode = _c.isInitPasscode, sendInternalTokens = _c.sendInternalTokens, updateSendInternalToken = _c.updateSendInternalToken;
|
|
117
|
+
var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
|
|
118
|
+
var _d = (0, react_1.useState)(undefined), error = _d[0], setError = _d[1];
|
|
119
|
+
var _e = (0, react_1.useState)(undefined), errorAmount = _e[0], setErrorAmount = _e[1];
|
|
120
|
+
var _f = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _f[0], setButtonStatus = _f[1];
|
|
121
|
+
var _g = (0, react_1.useState)(false), isValidatingAddress = _g[0], setIsValidatingAddress = _g[1];
|
|
122
|
+
var _h = (0, react_1.useState)(undefined), errorAddress = _h[0], setErrorAddress = _h[1];
|
|
123
|
+
var toAddress = transferData.to_address;
|
|
124
|
+
var amount = transferData.amount;
|
|
125
|
+
var currencySlug = transferData.currency_slug;
|
|
126
|
+
var isEnoughBalance = transferData.isEnoughBalance;
|
|
127
|
+
var token = (0, react_1.useMemo)(function () {
|
|
128
|
+
return sendInternalTokens === null || sendInternalTokens === void 0 ? void 0 : sendInternalTokens.find(function (token) { return token.slug === currencySlug; });
|
|
129
|
+
}, [currencySlug, sendInternalTokens]);
|
|
130
|
+
var validateAmount = (0, react_1.useCallback)(function () {
|
|
131
|
+
if (!token) {
|
|
132
|
+
setError(TransferConfirmationError.TOKEN_NOT_FOUND);
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
if (amount > token.max_value) {
|
|
136
|
+
setError(TransferConfirmationError.MAX_AMOUNT);
|
|
137
|
+
setErrorAmount(token.max_value);
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (amount < token.min_value) {
|
|
141
|
+
setError(TransferConfirmationError.MIN_AMOUNT);
|
|
142
|
+
setErrorAmount(token.min_value);
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
if (!isEnoughBalance) {
|
|
146
|
+
setError(TransferConfirmationError.NOT_ENOUGH_BALANCE);
|
|
147
|
+
setErrorAmount(token.balance);
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
setError(undefined);
|
|
151
|
+
setErrorAmount(undefined);
|
|
152
|
+
return true;
|
|
153
|
+
}, [token, amount]);
|
|
154
|
+
var validateAddress = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
155
|
+
var message;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
setIsValidatingAddress(true);
|
|
160
|
+
return [4 /*yield*/, (0, validate_wallet_address_service_1.default)({
|
|
161
|
+
address: toAddress,
|
|
162
|
+
})];
|
|
163
|
+
case 1:
|
|
164
|
+
message = (_a.sent()).message;
|
|
165
|
+
setIsValidatingAddress(false);
|
|
166
|
+
if (message === type_2.ValidateWalletAddressResultMessage.INTERNAL_WALLET ||
|
|
167
|
+
message === type_2.ValidateWalletAddressResultMessage.EXTERNAL_WALLET_BUT_ALSO_INTERNAL_WALLET) {
|
|
168
|
+
setErrorAddress(undefined);
|
|
169
|
+
return [2 /*return*/, true];
|
|
170
|
+
}
|
|
171
|
+
setErrorAddress("ⓘ This address is not a valid internal wallet address");
|
|
172
|
+
return [2 /*return*/, false];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}); }, [toAddress]);
|
|
176
|
+
var validateAll = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
177
|
+
var isAmountValid;
|
|
178
|
+
return __generator(this, function (_a) {
|
|
179
|
+
switch (_a.label) {
|
|
180
|
+
case 0:
|
|
181
|
+
isAmountValid = validateAmount();
|
|
182
|
+
if (!isAmountValid)
|
|
183
|
+
return [2 /*return*/, false];
|
|
184
|
+
return [4 /*yield*/, validateAddress()];
|
|
185
|
+
case 1:
|
|
186
|
+
_a.sent();
|
|
187
|
+
return [2 /*return*/];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}); }, [validateAmount, validateAddress]);
|
|
191
|
+
var handleSendInternalToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
192
|
+
var response, err_1;
|
|
193
|
+
var _a, _b;
|
|
194
|
+
return __generator(this, function (_c) {
|
|
195
|
+
switch (_c.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
_c.trys.push([0, 2, , 3]);
|
|
198
|
+
setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
199
|
+
return [4 /*yield*/, (0, instructions_service_1.default)(__assign(__assign({}, transferData), { passcode: passcode }))];
|
|
200
|
+
case 1:
|
|
201
|
+
response = _c.sent();
|
|
202
|
+
if (response.success) {
|
|
203
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
204
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
205
|
+
(_b = props.onTransferSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
|
|
206
|
+
updateSendInternalToken();
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
throw new Error("ⓘ Send internal failed");
|
|
210
|
+
}
|
|
211
|
+
return [3 /*break*/, 3];
|
|
212
|
+
case 2:
|
|
213
|
+
err_1 = _c.sent();
|
|
214
|
+
console.error(err_1);
|
|
215
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ERROR);
|
|
216
|
+
setTimeout(function () {
|
|
217
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
218
|
+
}, 1200);
|
|
219
|
+
return [3 /*break*/, 3];
|
|
220
|
+
case 3: return [2 /*return*/];
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}); };
|
|
224
|
+
var handleOpen = function () {
|
|
225
|
+
var _a;
|
|
226
|
+
if (!isInitPasscode)
|
|
227
|
+
throw new Error("Please connect your wallet");
|
|
228
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
229
|
+
validateAll();
|
|
230
|
+
};
|
|
231
|
+
var handleClose = function () {
|
|
232
|
+
var _a;
|
|
233
|
+
if (!isInitPasscode)
|
|
234
|
+
throw new Error("Please connect your wallet");
|
|
235
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
236
|
+
};
|
|
237
|
+
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
238
|
+
open: handleOpen,
|
|
239
|
+
close: handleClose,
|
|
240
|
+
}); });
|
|
241
|
+
(0, react_1.useEffect)(function () {
|
|
242
|
+
if (!sendInternalTokens && isInitPasscode) {
|
|
243
|
+
updateSendInternalToken();
|
|
244
|
+
}
|
|
245
|
+
}, [sendInternalTokens, updateSendInternalToken, isInitPasscode]);
|
|
246
|
+
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsxs)(ConfirmLayout_1.default, { ref: confirmLayoutDrawerRef, action: props.titleHeader, trigger: props.children, onOpen: validateAll, confirmAction: (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: type_1.TransactionSlug.TRANSFER_INTERNAL, onConfirmSuccess: handleSendInternalToken, triggerStatus: !!error || isValidatingAddress || errorAddress || !isEnoughBalance
|
|
247
|
+
? DrawerComponent_1.DRAWER_TRIGGER_STATUS.DISABLED
|
|
248
|
+
: DrawerComponent_1.DRAWER_TRIGGER_STATUS.ENABLED, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isValidatingAddress || errorAddress || !isEnoughBalance
|
|
249
|
+
? Button_1.BUTTON_STATUS.DISABLED
|
|
250
|
+
: buttonStatus, sx: { width: "100%" }, children: "Confirm" }) }), children: [transferContent, !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: (_a = theme.mixins.gaps) === null || _a === void 0 ? void 0 : _a.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) })] })), !!errorAddress && ((0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: (_b = theme.mixins.gaps) === null || _b === void 0 ? void 0 : _b.g6 }), children: errorAddress }))] }) }));
|
|
251
|
+
});
|
|
252
|
+
exports.TransferConfirmation.displayName = "TransferConfirmation";
|
|
253
|
+
exports.default = exports.TransferConfirmation;
|