tek-wallet 0.0.390 → 0.0.391
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.
|
@@ -37,36 +37,46 @@ var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
|
|
|
37
37
|
var react_1 = require("react");
|
|
38
38
|
var ReceiveFunction_1 = __importDefault(require("../ReceiveFunction"));
|
|
39
39
|
function Fees(props) {
|
|
40
|
-
var
|
|
41
|
-
var sx = props.sx, rest = __rest(props, ["sx"]);
|
|
40
|
+
var sx = props.sx, amount = props.amount, rest = __rest(props, ["sx", "amount"]);
|
|
42
41
|
var theme = (0, material_1.useTheme)();
|
|
43
42
|
var feesData = (0, parsePropsData_1.default)(props === null || props === void 0 ? void 0 : props.feesData);
|
|
44
43
|
var tokens = (0, useWalletData_1.default)().tokens;
|
|
44
|
+
var tokensFee = (0, react_1.useMemo)(function () {
|
|
45
|
+
var _a;
|
|
46
|
+
var result = [];
|
|
47
|
+
(_a = feesData === null || feesData === void 0 ? void 0 : feesData.feeDetail) === null || _a === void 0 ? void 0 : _a.forEach(function (fee) {
|
|
48
|
+
var _a, _b, _c, _d;
|
|
49
|
+
var index = result === null || result === void 0 ? void 0 : result.findIndex(function (feeDetail) { var _a, _b; return ((_a = feeDetail.currency) === null || _a === void 0 ? void 0 : _a.slug) === ((_b = fee === null || fee === void 0 ? void 0 : fee.currency) === null || _b === void 0 ? void 0 : _b.slug); });
|
|
50
|
+
if (index === -1) {
|
|
51
|
+
result.push(fee);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// const rate = fee.feeInUSD / fee.feeInCurrency;
|
|
55
|
+
result[index].feeFixed += fee.feeFixed;
|
|
56
|
+
result[index].feeInCurrency += fee.feeInCurrency;
|
|
57
|
+
result[index].feeInUSD += fee.feeInUSD;
|
|
58
|
+
result[index].feePercent += fee.feePercent;
|
|
59
|
+
result[index].feePercentInCurrency =
|
|
60
|
+
((_a = result[index].feeInCurrency) !== null && _a !== void 0 ? _a : 0) + amount * (fee.feePercent / 100);
|
|
61
|
+
var totalFeeInCurrency = ((_b = result[index].feeInCurrency) !== null && _b !== void 0 ? _b : 0) +
|
|
62
|
+
((_c = result[index].feePercentInCurrency) !== null && _c !== void 0 ? _c : 0);
|
|
63
|
+
var token = tokens === null || tokens === void 0 ? void 0 : tokens.find(function (token) { var _a; return token.currency_slug === ((_a = fee === null || fee === void 0 ? void 0 : fee.currency) === null || _a === void 0 ? void 0 : _a.slug); });
|
|
64
|
+
result[index].isEnoughBalanceToPay =
|
|
65
|
+
+((_d = token === null || token === void 0 ? void 0 : token.current_value) !== null && _d !== void 0 ? _d : 0) >= totalFeeInCurrency;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return result;
|
|
69
|
+
}, [tokens, feesData === null || feesData === void 0 ? void 0 : feesData.feeDetail, amount]);
|
|
70
|
+
var feeCheckedBalance = (0, react_1.useMemo)(function () {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
return ((_b = (_a = feesData === null || feesData === void 0 ? void 0 : feesData.feeDetail) === null || _a === void 0 ? void 0 : _a.map(function (fee) {
|
|
73
|
+
var theFee = tokensFee === null || tokensFee === void 0 ? void 0 : tokensFee.find(function (feeDetail) { var _a, _b; return ((_a = feeDetail.currency) === null || _a === void 0 ? void 0 : _a.slug) === ((_b = fee === null || fee === void 0 ? void 0 : fee.currency) === null || _b === void 0 ? void 0 : _b.slug); });
|
|
74
|
+
return __assign(__assign({}, fee), { isEnoughBalanceToPay: theFee === null || theFee === void 0 ? void 0 : theFee.isEnoughBalanceToPay });
|
|
75
|
+
})) !== null && _b !== void 0 ? _b : []);
|
|
76
|
+
}, [tokensFee, feesData === null || feesData === void 0 ? void 0 : feesData.feeDetail]);
|
|
45
77
|
var isEnoughBalanceToPayFee = (0, react_1.useMemo)(function () {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// const index = tokensFee?.findIndex(
|
|
49
|
-
// (token) => token.currencySlug === fee?.currencySlug
|
|
50
|
-
// );
|
|
51
|
-
// if (index === -1) {
|
|
52
|
-
// tokensFee.push(fee);
|
|
53
|
-
// } else {
|
|
54
|
-
// if (+tokensFee[index]?.feeFixed < fee?.feeInCurrency) {
|
|
55
|
-
// tokensFee[index] = { ...fee, isEnoughBalance: false };
|
|
56
|
-
// }
|
|
57
|
-
// }
|
|
58
|
-
// });
|
|
59
|
-
// for (let i = 0; i < length; i++) {
|
|
60
|
-
// const fee = feesData?.feeDetail[i] as FeeDetail;
|
|
61
|
-
// const token = tokens?.find(
|
|
62
|
-
// (token) => token.currency_slug === fee?.currencySlug
|
|
63
|
-
// );
|
|
64
|
-
// if (!token || +token?.current_value < (fee?.feeInCurrency ?? 0)) {
|
|
65
|
-
// tokensFee.push({ ...fee, isEnoughBalance: false });
|
|
66
|
-
// }
|
|
67
|
-
// }
|
|
68
|
-
return true;
|
|
69
|
-
}, [tokens]);
|
|
78
|
+
return feeCheckedBalance === null || feeCheckedBalance === void 0 ? void 0 : feeCheckedBalance.some(function (fee) { return !fee.isEnoughBalanceToPay; });
|
|
79
|
+
}, [feeCheckedBalance]);
|
|
70
80
|
return ((0, jsx_runtime_1.jsxs)(material_1.Accordion, __assign({ defaultExpanded: true }, rest, { sx: __assign({ "&.MuiAccordion-root": {
|
|
71
81
|
backgroundColor: "transparent",
|
|
72
82
|
margin: 0,
|
|
@@ -85,15 +95,15 @@ function Fees(props) {
|
|
|
85
95
|
}, "& .MuiAccordionDetails-root": {
|
|
86
96
|
paddingLeft: theme.mixins.customPadding.p12,
|
|
87
97
|
paddingRight: theme.mixins.customPadding.p12,
|
|
88
|
-
} }, sx), children: [(0, jsx_runtime_1.jsx)(material_1.AccordionSummary, { expandIcon: (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("arrow_down"), width: 20 }), children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { width: "100%" }), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Total fees" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: 1000 }) })] }) }), (0, jsx_runtime_1.jsx)(material_1.AccordionDetails, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g8 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { alignItems: "stretch" }), children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { width: "fit-content", gap: theme.mixins.gaps.g8, alignItems: "center" }), children:
|
|
98
|
+
} }, sx), children: [(0, jsx_runtime_1.jsx)(material_1.AccordionSummary, { expandIcon: (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("arrow_down"), width: 20 }), children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { width: "100%" }), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Total fees" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: 1000 }) })] }) }), (0, jsx_runtime_1.jsx)(material_1.AccordionDetails, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g8 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { alignItems: "stretch" }), children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { width: "fit-content", gap: theme.mixins.gaps.g8, alignItems: "center" }), children: feeCheckedBalance === null || feeCheckedBalance === void 0 ? void 0 : feeCheckedBalance.map(function (item, index) {
|
|
89
99
|
var _a;
|
|
90
100
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_2.Fragment, { children: [index !== 0 && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
91
101
|
borderRight: "1px dashed ".concat(theme.palette.border.white24),
|
|
92
102
|
flex: 1,
|
|
93
103
|
} })), (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("timeline_dot"), width: 16 })] }, (_a = item.feeType) === null || _a === void 0 ? void 0 : _a.name));
|
|
94
|
-
}) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { flex: 1, gap: theme.mixins.gaps.g8 }), children:
|
|
95
|
-
var _a, _b;
|
|
96
|
-
return ((0, jsx_runtime_1.jsx)(FeeDetail, { feeName: (_a = item.feeType) === null || _a === void 0 ? void 0 : _a.name, feeInCurrency: item.feeInCurrency, feeInUSD: item.feeInUSD, currencyName:
|
|
104
|
+
}) }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { flex: 1, gap: theme.mixins.gaps.g8 }), children: feeCheckedBalance === null || feeCheckedBalance === void 0 ? void 0 : feeCheckedBalance.map(function (item) {
|
|
105
|
+
var _a, _b, _c;
|
|
106
|
+
return ((0, jsx_runtime_1.jsx)(FeeDetail, { feeName: (_a = item.feeType) === null || _a === void 0 ? void 0 : _a.name, feeInCurrency: item.feeInCurrency, feeInUSD: item.feeInUSD, currencyName: (_b = item.currency) === null || _b === void 0 ? void 0 : _b.name }, (_c = item.feeType) === null || _c === void 0 ? void 0 : _c.name));
|
|
97
107
|
}) })] }), isEnoughBalanceToPayFee && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign({}, theme.mixins.validationError), children: ["You don't have enough balance to pay the fee, please ", " ", (0, jsx_runtime_1.jsxs)(ReceiveFunction_1.default, { children: [" ", (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
98
108
|
textDecoration: "underline",
|
|
99
109
|
}, children: "Topup more" })] }), " ", "to continue"] }))] }) })] })));
|
|
@@ -614,7 +614,7 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
614
614
|
placeholder: "Enter memo",
|
|
615
615
|
value: memo,
|
|
616
616
|
onChange: handleChangeMemo,
|
|
617
|
-
} })] })), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee) })), estimateReceive !== undefined && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.row), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Estimate receive" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive }) })] })), (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, onClick: handleSend, status: !!amountError ||
|
|
617
|
+
} })] })), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount })), estimateReceive !== undefined && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.row), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Estimate receive" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive }) })] })), (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, onClick: handleSend, status: !!amountError ||
|
|
618
618
|
!!recipientAddressError ||
|
|
619
619
|
!recipientAddress ||
|
|
620
620
|
!amount ||
|
|
@@ -15,18 +15,22 @@ export interface FeesDataType {
|
|
|
15
15
|
originalAmountInUSD: number;
|
|
16
16
|
originalAmountInCurrency: number;
|
|
17
17
|
originalCurrency: string;
|
|
18
|
-
feeDetail:
|
|
18
|
+
feeDetail: FeeDetailType[];
|
|
19
19
|
}
|
|
20
|
-
export interface
|
|
20
|
+
export interface FeeDetailType {
|
|
21
21
|
feeType: FeeType;
|
|
22
22
|
feeInUSD: number;
|
|
23
23
|
feeInCurrency: number;
|
|
24
24
|
feePercent: number;
|
|
25
25
|
currency: Currency;
|
|
26
26
|
feeFixed: number;
|
|
27
|
+
feePercentInUSD?: number;
|
|
28
|
+
feePercentInCurrency?: number;
|
|
29
|
+
isEnoughBalanceToPay?: boolean;
|
|
27
30
|
}
|
|
28
31
|
export interface Currency {
|
|
29
32
|
id: number;
|
|
33
|
+
name: string;
|
|
30
34
|
slug: string;
|
|
31
35
|
full_name: string;
|
|
32
36
|
icon: string;
|