tek-wallet 0.0.530 → 0.0.533
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/layouts/DefaultPageLayout/index.d.ts +2 -2
- package/dist/components/ui/AnalyticGroup/index.js +1 -0
- package/dist/components/ui/SendExternalToken/index.js +1 -1
- package/dist/components/ui/SendInternalToken/index.js +2 -2
- package/dist/components/ui/SwapToken/index.d.ts +26 -0
- package/dist/components/ui/SwapToken/index.js +267 -0
- package/dist/components/ui/WithdrawFunction/index.js +1 -1
- package/dist/components/views/AssetView/index.d.ts +2 -1
- package/dist/components/views/AssetView/index.js +3 -3
- package/dist/hooks/useSwapData.d.ts +3 -0
- package/dist/hooks/useSwapData.js +16 -0
- package/dist/hooks/useWallet.js +4 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/providers/SwapProvider/index.d.ts +8 -0
- package/dist/{services/axios/get-receive-external-tokens-list-service copy/index.js → providers/SwapProvider/index.js} +56 -26
- package/dist/providers/SwapProvider/type.d.ts +6 -0
- package/dist/providers/SwapProvider/type.js +2 -0
- package/dist/providers/TekWalletProvider/index.js +2 -1
- package/dist/services/axios/get-activities-service/type.js +0 -20
- package/dist/services/axios/get-config-tokens-list-service/index.d.ts +2 -6
- package/dist/services/axios/get-config-tokens-list-service/index.js +0 -7
- package/dist/services/axios/get-lock-tokens-list-service/index.js +6 -35
- package/dist/services/axios/get-receive-external-tokens-list-service/index.js +6 -35
- package/dist/services/axios/get-receive-internal-tokens-list-service/index.js +6 -35
- package/dist/services/axios/get-swap-tokens-list-service/index.d.ts +5 -0
- package/dist/services/axios/{get-receive-internal-tokens-list-service copy/index.js → get-swap-tokens-list-service/index.js} +9 -38
- package/dist/services/axios/get-swap-tokens-list-service/type.d.ts +52 -0
- package/dist/services/axios/get-swap-tokens-list-service/type.js +2 -0
- package/dist/services/axios/get-withdraw-tokens-list-service/index.js +6 -35
- package/dist/services/axios/swap-service/index.d.ts +3 -0
- package/dist/services/axios/swap-service/index.js +58 -0
- package/dist/services/axios/swap-service/type.d.ts +35 -0
- package/dist/services/axios/swap-service/type.js +2 -0
- package/dist/services/axios/type.d.ts +1 -0
- package/dist/theme/mui/theme.js +6 -0
- package/dist/types/expose-type.d.ts +2 -1
- package/package.json +2 -2
- package/dist/components/ui/SendInternalToken/index copy.d.ts +0 -24
- package/dist/components/ui/SendInternalToken/index copy.js +0 -241
- package/dist/services/axios/get-receive-external-tokens-list-service copy/index.d.ts +0 -5
- package/dist/services/axios/get-receive-internal-tokens-list-service copy/index.d.ts +0 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface DefaultPageLayoutProps extends
|
|
1
|
+
import { BoxProps } from "@mui/material";
|
|
2
|
+
interface DefaultPageLayoutProps extends BoxProps {
|
|
3
3
|
}
|
|
4
4
|
declare const DefaultPageLayout: (props: DefaultPageLayoutProps) => import("react/jsx-runtime").JSX.Element;
|
|
5
5
|
export default DefaultPageLayout;
|
|
@@ -31,6 +31,7 @@ var AnalyticGroup = function (props) {
|
|
|
31
31
|
leading: theme.typography.leading140,
|
|
32
32
|
fontSize: theme.typography.fontSize14,
|
|
33
33
|
textTransform: "capitalize",
|
|
34
|
+
color: theme.palette.text.white,
|
|
34
35
|
}, children: props.timeRange }), (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("arrow_increase"), width: 12 }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { color: theme.palette.text.increase, borderBottom: "1px dashed currentColor" }), children: "5.63 (+3,22%)" })] })] }));
|
|
35
36
|
};
|
|
36
37
|
exports.default = AnalyticGroup;
|
|
@@ -274,7 +274,7 @@ var SendExternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
274
274
|
}, [estimateFee, amount]);
|
|
275
275
|
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsxs)(ConfirmLayout_1.default, { onOpen: validateAll, ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Recipient address", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
276
276
|
wordBreak: "break-all",
|
|
277
|
-
}, children: toAddress }), valueDescription: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.validationError), children: errorAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Network", value: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6, ml: "auto" }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 20, src: network === null || network === void 0 ? void 0 : network.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: network === null || network === void 0 ? void 0 : network.name })] }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), !!memo && (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Memo", value: memo }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
277
|
+
}, children: toAddress }), valueDescription: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.validationError), children: errorAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Network", value: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g6, ml: "auto" }), children: [(0, jsx_runtime_1.jsx)(Icon_1.default, { width: 20, src: network === null || network === void 0 ? void 0 : network.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), children: network === null || network === void 0 ? void 0 : network.name })] }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), !!memo && (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Memo", value: memo }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { isFeePaidByAmount: true, feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
278
278
|
fontWeight: theme.typography.fontWeight600,
|
|
279
279
|
fontSize: theme.typography.fontSize16,
|
|
280
280
|
}, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.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) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSendExternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee || isValidatingAddress || errorAddress
|
|
@@ -113,7 +113,7 @@ var SendInternalTokenError;
|
|
|
113
113
|
SendInternalTokenError["MIN_AMOUNT"] = "Min amount";
|
|
114
114
|
SendInternalTokenError["FAILED"] = "Failed";
|
|
115
115
|
})(SendInternalTokenError || (exports.SendInternalTokenError = SendInternalTokenError = {}));
|
|
116
|
-
var transactionSlug = type_1.TransactionSlug.
|
|
116
|
+
var transactionSlug = type_1.TransactionSlug.TransferInternal;
|
|
117
117
|
var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
118
118
|
var _a;
|
|
119
119
|
var theme = (0, material_1.useTheme)();
|
|
@@ -272,7 +272,7 @@ var SendInternalToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
272
272
|
}, [estimateFee, amount]);
|
|
273
273
|
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsxs)(ConfirmLayout_1.default, { onOpen: validateAll, ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Recipient address", value: (0, jsx_runtime_1.jsx)(CopyTextComponent_1.default, { value: toAddress, children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
274
274
|
wordBreak: "break-all",
|
|
275
|
-
}, children: toAddress }) }), valueDescription: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.validationError), children: errorAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
275
|
+
}, children: toAddress }) }), valueDescription: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.validationError), children: errorAddress }) }), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Amount", value: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { isFeePaidByAmount: true, feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: tokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
276
276
|
fontWeight: theme.typography.fontWeight600,
|
|
277
277
|
fontSize: theme.typography.fontSize16,
|
|
278
278
|
}, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.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) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSendInternalToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee || isValidatingAddress || errorAddress
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ConfirmLayoutProps } from "../ConfirmLayout";
|
|
2
|
+
import { FeesDataType } from "../../../services/axios/get-est-fee-service/type";
|
|
3
|
+
import { SwapBody, SwapResponse } from "../../../services/axios/swap-service/type";
|
|
4
|
+
import { NetworkData } from "../../../services/axios/type";
|
|
5
|
+
interface SwapDataType extends Omit<SwapBody, "passcode" | "network"> {
|
|
6
|
+
network: NetworkData;
|
|
7
|
+
}
|
|
8
|
+
interface SwapTokenProps extends Omit<ConfirmLayoutProps, "action"> {
|
|
9
|
+
sendData: SwapDataType;
|
|
10
|
+
onSuccess?: (data: SwapResponse) => any;
|
|
11
|
+
initFeeData?: FeesDataType;
|
|
12
|
+
onStart?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export interface SwapTokenRef {
|
|
15
|
+
open: () => void;
|
|
16
|
+
close: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare enum SwapTokenError {
|
|
19
|
+
TOKEN_NOT_FOUND = "Token not found",
|
|
20
|
+
NOT_ENOUGH_BALANCE = "Not enough balance",
|
|
21
|
+
MAX_AMOUNT = "Max amount",
|
|
22
|
+
MIN_AMOUNT = "Min amount",
|
|
23
|
+
FAILED = "Failed"
|
|
24
|
+
}
|
|
25
|
+
declare const SwapToken: import("react").ForwardRefExoticComponent<Omit<SwapTokenProps, "ref"> & import("react").RefAttributes<SwapTokenRef>>;
|
|
26
|
+
export default SwapToken;
|
|
@@ -0,0 +1,267 @@
|
|
|
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.SwapTokenError = void 0;
|
|
88
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
89
|
+
var material_1 = require("@mui/material");
|
|
90
|
+
var Button_1 = __importStar(require("../../ui/Button"));
|
|
91
|
+
var ConfirmLayout_1 = __importDefault(require("../ConfirmLayout"));
|
|
92
|
+
var LineValue_1 = __importDefault(require("../LineValue"));
|
|
93
|
+
var Formatter_1 = __importDefault(require("../Formatter"));
|
|
94
|
+
var ConfirmByPasscode_1 = __importDefault(require("../ConfirmByPasscode"));
|
|
95
|
+
var react_1 = require("react");
|
|
96
|
+
var Text_1 = __importDefault(require("../Text"));
|
|
97
|
+
var RequireConnect_1 = __importDefault(require("../RequireConnect"));
|
|
98
|
+
var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
|
|
99
|
+
var Fees_1 = __importDefault(require("../Fees"));
|
|
100
|
+
var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
|
|
101
|
+
var type_1 = require("../../../services/axios/get-activities-service/type");
|
|
102
|
+
var Activities_1 = __importDefault(require("../Activities"));
|
|
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 getIcon_1 = __importDefault(require("../../../utils/getIcon"));
|
|
107
|
+
var SwapTokenError;
|
|
108
|
+
(function (SwapTokenError) {
|
|
109
|
+
SwapTokenError["TOKEN_NOT_FOUND"] = "Token not found";
|
|
110
|
+
SwapTokenError["NOT_ENOUGH_BALANCE"] = "Not enough balance";
|
|
111
|
+
SwapTokenError["MAX_AMOUNT"] = "Max amount";
|
|
112
|
+
SwapTokenError["MIN_AMOUNT"] = "Min amount";
|
|
113
|
+
SwapTokenError["FAILED"] = "Failed";
|
|
114
|
+
})(SwapTokenError || (exports.SwapTokenError = SwapTokenError = {}));
|
|
115
|
+
var transactionSlug = type_1.TransactionSlug.Swap;
|
|
116
|
+
var SwapToken = (0, react_1.forwardRef)(function (props, ref) {
|
|
117
|
+
var _a;
|
|
118
|
+
var theme = (0, material_1.useTheme)();
|
|
119
|
+
var fromTokens = (0, useSwapData_1.default)().fromTokens;
|
|
120
|
+
var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
|
|
121
|
+
var confirmLayoutDrawerRef = (0, react_1.useRef)(null);
|
|
122
|
+
var _b = (0, react_1.useState)(undefined), error = _b[0], setError = _b[1];
|
|
123
|
+
var _c = (0, react_1.useState)(undefined), errorAmount = _c[0], setErrorAmount = _c[1];
|
|
124
|
+
var _d = (0, react_1.useState)(Button_1.BUTTON_STATUS.ENABLED), buttonStatus = _d[0], setButtonStatus = _d[1];
|
|
125
|
+
var _e = (0, react_1.useState)(props.initFeeData), estimateFee = _e[0], setEstimateFee = _e[1];
|
|
126
|
+
var _f = (0, react_1.useState)(false), isLoadingEstimateFee = _f[0], setIsLoadingEstimateFee = _f[1];
|
|
127
|
+
var activitiesRef = (0, react_1.useRef)(null);
|
|
128
|
+
var amount = props.sendData.amount;
|
|
129
|
+
var network = props.sendData.network;
|
|
130
|
+
var fromTokenSlug = props.sendData.currency_slug;
|
|
131
|
+
var toTokenSlug = props.sendData.to_currency_slug;
|
|
132
|
+
var fromToken = (0, react_1.useMemo)(function () {
|
|
133
|
+
return fromTokens === null || fromTokens === void 0 ? void 0 : fromTokens.find(function (token) { return token.slug === fromTokenSlug; });
|
|
134
|
+
}, [fromTokenSlug, fromTokens]);
|
|
135
|
+
var toToken = (0, react_1.useMemo)(function () {
|
|
136
|
+
if (!fromToken)
|
|
137
|
+
return undefined;
|
|
138
|
+
return fromToken.outputs.find(function (token) { return token.slug === toTokenSlug; });
|
|
139
|
+
}, [toTokenSlug, fromToken]);
|
|
140
|
+
var toAmount = (0, react_1.useMemo)(function () {
|
|
141
|
+
if (!toToken)
|
|
142
|
+
return undefined;
|
|
143
|
+
return +amount * toToken.rate;
|
|
144
|
+
}, [toToken, amount]);
|
|
145
|
+
var getEstimateFee = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
146
|
+
var response;
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
switch (_a.label) {
|
|
149
|
+
case 0:
|
|
150
|
+
if (!fromTokenSlug)
|
|
151
|
+
return [2 /*return*/];
|
|
152
|
+
setIsLoadingEstimateFee(true);
|
|
153
|
+
return [4 /*yield*/, (0, get_est_fee_service_1.default)({
|
|
154
|
+
amount: "".concat(amount),
|
|
155
|
+
transaction_type: transactionSlug,
|
|
156
|
+
currency: fromTokenSlug || "",
|
|
157
|
+
})];
|
|
158
|
+
case 1:
|
|
159
|
+
response = _a.sent();
|
|
160
|
+
setIsLoadingEstimateFee(false);
|
|
161
|
+
setEstimateFee(response === null || response === void 0 ? void 0 : response.data);
|
|
162
|
+
return [2 /*return*/, true];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); }, [amount, fromTokenSlug]);
|
|
166
|
+
var token = (0, react_1.useMemo)(function () {
|
|
167
|
+
return fromTokens === null || fromTokens === void 0 ? void 0 : fromTokens.find(function (token) { return token.slug === fromTokenSlug; });
|
|
168
|
+
}, [fromTokenSlug, fromTokens]);
|
|
169
|
+
var validateAmount = (0, react_1.useCallback)(function () {
|
|
170
|
+
if (!token) {
|
|
171
|
+
setError(SwapTokenError.TOKEN_NOT_FOUND);
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (+amount > token.max_value) {
|
|
175
|
+
setError(SwapTokenError.MAX_AMOUNT);
|
|
176
|
+
setErrorAmount(token.max_value);
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (+amount < token.min_value) {
|
|
180
|
+
setError(SwapTokenError.MIN_AMOUNT);
|
|
181
|
+
setErrorAmount(token.min_value);
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (+amount > +token.balance) {
|
|
185
|
+
setError(SwapTokenError.NOT_ENOUGH_BALANCE);
|
|
186
|
+
setErrorAmount(token.balance);
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
setError(undefined);
|
|
190
|
+
setErrorAmount(undefined);
|
|
191
|
+
return true;
|
|
192
|
+
}, [amount, token]);
|
|
193
|
+
var validateAll = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
194
|
+
var isAmountValid;
|
|
195
|
+
return __generator(this, function (_a) {
|
|
196
|
+
isAmountValid = validateAmount();
|
|
197
|
+
if (!isAmountValid)
|
|
198
|
+
return [2 /*return*/, false];
|
|
199
|
+
getEstimateFee();
|
|
200
|
+
return [2 /*return*/];
|
|
201
|
+
});
|
|
202
|
+
}); }, [validateAmount, getEstimateFee]);
|
|
203
|
+
var handleSwapToken = function (passcode) { return __awaiter(void 0, void 0, void 0, function () {
|
|
204
|
+
var response, err_1;
|
|
205
|
+
var _a, _b;
|
|
206
|
+
return __generator(this, function (_c) {
|
|
207
|
+
switch (_c.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
_c.trys.push([0, 2, , 3]);
|
|
210
|
+
setButtonStatus(Button_1.BUTTON_STATUS.LOADING);
|
|
211
|
+
return [4 /*yield*/, (0, swap_service_1.default)(__assign(__assign({}, props.sendData), { passcode: passcode, network: network.slug }))];
|
|
212
|
+
case 1:
|
|
213
|
+
response = _c.sent();
|
|
214
|
+
if (response.success) {
|
|
215
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
216
|
+
setButtonStatus(Button_1.BUTTON_STATUS.ENABLED);
|
|
217
|
+
(_b = props.onSuccess) === null || _b === void 0 ? void 0 : _b.call(props, response);
|
|
218
|
+
setTimeout(function () {
|
|
219
|
+
var _a;
|
|
220
|
+
(_a = activitiesRef.current) === null || _a === void 0 ? void 0 : _a.openTab(0);
|
|
221
|
+
}, 200);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
throw new Error("Swap internal failed");
|
|
225
|
+
}
|
|
226
|
+
return [3 /*break*/, 3];
|
|
227
|
+
case 2:
|
|
228
|
+
err_1 = _c.sent();
|
|
229
|
+
console.error(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*/, 3];
|
|
235
|
+
case 3: return [2 /*return*/];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}); };
|
|
239
|
+
var handleOpen = function () {
|
|
240
|
+
var _a;
|
|
241
|
+
if (!isAuthenticated)
|
|
242
|
+
throw new Error("Please connect your wallet");
|
|
243
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
|
|
244
|
+
validateAll();
|
|
245
|
+
};
|
|
246
|
+
var handleClose = function () {
|
|
247
|
+
var _a;
|
|
248
|
+
if (!isAuthenticated)
|
|
249
|
+
throw new Error("Please connect your wallet");
|
|
250
|
+
(_a = confirmLayoutDrawerRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
251
|
+
};
|
|
252
|
+
(0, react_1.useImperativeHandle)(ref, function () { return ({
|
|
253
|
+
open: handleOpen,
|
|
254
|
+
close: handleClose,
|
|
255
|
+
}); });
|
|
256
|
+
var estimateReceive = (0, react_1.useMemo)(function () {
|
|
257
|
+
if (!estimateFee || !toAmount)
|
|
258
|
+
return undefined;
|
|
259
|
+
return +toAmount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeInCurrency);
|
|
260
|
+
}, [estimateFee, toAmount]);
|
|
261
|
+
return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsxs)(ConfirmLayout_1.default, { onOpen: validateAll, ref: confirmLayoutDrawerRef, action: transactionSlug, trigger: props.children, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.paper), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.paper), { alignItems: "center", gap: 0 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16 }), 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.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), 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" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: amount, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) })] }), (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("swap-one-direction"), width: 32 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16 }), 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.icon }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.value), 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" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: toAmount, unit: " ".concat(toToken === null || toToken === void 0 ? void 0 : toToken.name) }) })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign(__assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g12 }), theme.mixins.valueDescription), { width: "100%", justifyContent: "center" }), children: ["1 ", fromToken === null || fromToken === void 0 ? void 0 : fromToken.name, " ~ ", toToken === null || toToken === void 0 ? void 0 : toToken.rate, " ", toToken === null || toToken === void 0 ? void 0 : toToken.name] }), ((_a = estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeDetail) === null || _a === void 0 ? void 0 : _a.length) && !!amount && ((0, jsx_runtime_1.jsx)(Fees_1.default, { isFeePaidByAmount: true, feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: fromTokenSlug })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
|
|
262
|
+
fontWeight: theme.typography.fontWeight600,
|
|
263
|
+
fontSize: theme.typography.fontSize16,
|
|
264
|
+
}, children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive, unit: " ".concat(token === null || token === void 0 ? void 0 : token.name) }) }) }), !!error && ((0, jsx_runtime_1.jsxs)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { mt: theme.mixins.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) })] }))] }), (0, jsx_runtime_1.jsx)(ConfirmByPasscode_1.default, { action: transactionSlug, onConfirmSuccess: handleSwapToken, children: (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { status: !!error || isLoadingEstimateFee ? Button_1.BUTTON_STATUS.DISABLED : buttonStatus, sx: { width: "100%" }, children: "Confirm" }) })] }), (0, jsx_runtime_1.jsx)(Activities_1.default, { ref: activitiesRef })] }) }));
|
|
265
|
+
});
|
|
266
|
+
SwapToken.displayName = "SwapToken";
|
|
267
|
+
exports.default = SwapToken;
|
|
@@ -587,7 +587,7 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
|
|
|
587
587
|
placeholder: "Enter memo",
|
|
588
588
|
value: memo,
|
|
589
589
|
onChange: handleChangeMemo,
|
|
590
|
-
} })] })), !!((_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, tokenSlug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "" })), estimateReceive !== undefined && !amountError && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.row), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Receive amount estimated" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive }) })] })), selectedMethod === SendMethods.TRANSFER_EXTERNAL && ((0, jsx_runtime_1.jsx)(SendExternalToken_1.default, { initFeeData: estimateFee, sendExternalData: {
|
|
590
|
+
} })] })), !!((_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, { isFeePaidByAmount: true, feesData: JSON.stringify(estimateFee), amount: +amount, tokenSlug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "" })), estimateReceive !== undefined && !amountError && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign({}, theme.mixins.row), children: [(0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.fieldTitle), children: "Receive amount estimated" }), (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.value), { ml: "auto" }), children: (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: estimateReceive }) })] })), selectedMethod === SendMethods.TRANSFER_EXTERNAL && ((0, jsx_runtime_1.jsx)(SendExternalToken_1.default, { initFeeData: estimateFee, sendExternalData: {
|
|
591
591
|
amount: "".concat(amount),
|
|
592
592
|
currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
|
|
593
593
|
to_address: recipientAddress || "",
|
|
@@ -27,16 +27,16 @@ var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
|
|
|
27
27
|
var Text_1 = __importDefault(require("../../ui/Text"));
|
|
28
28
|
var material_2 = require("@mui/material");
|
|
29
29
|
var AmountGroupAndChart_1 = __importDefault(require("../../ui/AmountGroupAndChart"));
|
|
30
|
-
var AssetView = function () {
|
|
30
|
+
var AssetView = function (props) {
|
|
31
31
|
var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
|
|
32
32
|
var theme = (0, material_2.useTheme)();
|
|
33
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!isAuthenticated && ((0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.sessionDescription), children: "Please connect your wallet to get asset information" })), !!isAuthenticated && ((0, jsx_runtime_1.jsxs)(DefaultPageLayout_1.default, { children: [(0, jsx_runtime_1.jsx)(AmountGroupAndChart_1.default, {}), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
33
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!isAuthenticated && ((0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign({}, theme.mixins.sessionDescription), children: "Please connect your wallet to get asset information" })), !!isAuthenticated && ((0, jsx_runtime_1.jsxs)(DefaultPageLayout_1.default, __assign({}, props, { children: [(0, jsx_runtime_1.jsx)(AmountGroupAndChart_1.default, {}), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
34
34
|
display: "grid",
|
|
35
35
|
gridTemplateColumns: "repeat(4, 1fr)",
|
|
36
36
|
gap: theme.mixins.gaps.g12,
|
|
37
37
|
position: "relative",
|
|
38
38
|
zIndex: 50,
|
|
39
39
|
my: theme.mixins.customMargin.m20,
|
|
40
|
-
}, children: [(0, jsx_runtime_1.jsx)(ReceiveFunction_1.default, { children: (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("receive"), label: "Receive", sx: { width: "100%" } }) }) }), (0, jsx_runtime_1.jsx)(WithdrawFunction_1.default, { children: (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("withdraw"), label: "Withdraw", sx: { width: "100%" } }) }) }), (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("fortune", "gif"), label: "Fortune", sx: { width: "100%" } }) }), (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("p2p", "gif"), label: "P2P", sx: { width: "100%" } }) })] }), (0, jsx_runtime_1.jsx)(TokensBoard_1.default, {})] }))] }));
|
|
40
|
+
}, children: [(0, jsx_runtime_1.jsx)(ReceiveFunction_1.default, { children: (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("receive"), label: "Receive", sx: { width: "100%" } }) }) }), (0, jsx_runtime_1.jsx)(WithdrawFunction_1.default, { children: (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("withdraw"), label: "Withdraw", sx: { width: "100%" } }) }) }), (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("fortune", "gif"), label: "Fortune", sx: { width: "100%" } }) }), (0, jsx_runtime_1.jsx)(material_1.ListItem, { children: (0, jsx_runtime_1.jsx)(FunctionItem_1.default, { icon: (0, getIcon_1.default)("p2p", "gif"), label: "P2P", sx: { width: "100%" } }) })] }), (0, jsx_runtime_1.jsx)(TokensBoard_1.default, {})] })))] }));
|
|
41
41
|
};
|
|
42
42
|
exports.default = AssetView;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
var SwapProvider_1 = require("../providers/SwapProvider");
|
|
5
|
+
var SwapProvider_2 = require("../providers/SwapProvider");
|
|
6
|
+
function useSwapData() {
|
|
7
|
+
try {
|
|
8
|
+
var data = (0, react_1.useContext)(SwapProvider_2.SwapContext);
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error("🚀 ~ useSwapData ~ error:", error);
|
|
13
|
+
return SwapProvider_1.initialSwap;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = useSwapData;
|
package/dist/hooks/useWallet.js
CHANGED
|
@@ -18,6 +18,7 @@ var LockTokenProvider_1 = require("../providers/LockTokenProvider");
|
|
|
18
18
|
var WithdrawProvider_1 = require("../providers/WithdrawProvider");
|
|
19
19
|
var RealtimeProvider_1 = require("../providers/RealtimeProvider");
|
|
20
20
|
var ActivitiesProvider_1 = require("../providers/ActivitiesProvider");
|
|
21
|
+
var SwapProvider_1 = require("../providers/SwapProvider");
|
|
21
22
|
function useWallet() {
|
|
22
23
|
var receiveData = (0, react_1.useContext)(ReceiveProvider_1.ReceiveContext);
|
|
23
24
|
var withdrawData = (0, react_1.useContext)(WithdrawProvider_1.WithdrawContext);
|
|
@@ -25,14 +26,15 @@ function useWallet() {
|
|
|
25
26
|
var lockTokensData = (0, react_1.useContext)(LockTokenProvider_1.LockTokensContext);
|
|
26
27
|
var realtimeData = (0, react_1.useContext)(RealtimeProvider_1.RealtimeContext);
|
|
27
28
|
var activitiesData = (0, react_1.useContext)(ActivitiesProvider_1.ActivitiesContext);
|
|
29
|
+
var swapData = (0, react_1.useContext)(SwapProvider_1.SwapContext);
|
|
28
30
|
try {
|
|
29
31
|
delete walletData.session;
|
|
30
|
-
return __assign(__assign(__assign(__assign(__assign(__assign({}, walletData), receiveData), lockTokensData), withdrawData), realtimeData), activitiesData);
|
|
32
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, walletData), receiveData), lockTokensData), withdrawData), realtimeData), activitiesData), swapData);
|
|
31
33
|
}
|
|
32
34
|
catch (error) {
|
|
33
35
|
console.error("🚀 ~ useWallet ~ error:", error);
|
|
34
36
|
delete WalletDataProvider_1.initialWalletData.session;
|
|
35
|
-
return __assign(__assign(__assign(__assign(__assign(__assign({}, WalletDataProvider_1.initialWalletData), ReceiveProvider_1.initialReceive), LockTokenProvider_1.initialLockTokens), WithdrawProvider_1.initialWithdraw), RealtimeProvider_1.initialRealtime), ActivitiesProvider_1.initialActivities);
|
|
37
|
+
return __assign(__assign(__assign(__assign(__assign(__assign(__assign({}, WalletDataProvider_1.initialWalletData), ReceiveProvider_1.initialReceive), LockTokenProvider_1.initialLockTokens), WithdrawProvider_1.initialWithdraw), RealtimeProvider_1.initialRealtime), ActivitiesProvider_1.initialActivities), SwapProvider_1.initialSwap);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
exports.default = useWallet;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,6 @@ import LockToken from "./components/ui/LockToken";
|
|
|
7
7
|
import AssetView from "./components/views/AssetView";
|
|
8
8
|
import useWallet from "./hooks/useWallet";
|
|
9
9
|
import Activities from "./components/ui/Activities";
|
|
10
|
+
import SwapToken from "./components/ui/SwapToken";
|
|
10
11
|
export * from "./types/expose-type";
|
|
11
|
-
export { TekWalletProvider, tekWalletHandler, RequireConnect, GetWalletSeedPhrase, ReceiveFunction, useWallet, LockToken, AssetView, Activities, };
|
|
12
|
+
export { TekWalletProvider, tekWalletHandler, RequireConnect, GetWalletSeedPhrase, ReceiveFunction, useWallet, LockToken, AssetView, Activities, SwapToken, };
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Activities = exports.AssetView = exports.LockToken = exports.useWallet = exports.ReceiveFunction = exports.GetWalletSeedPhrase = exports.RequireConnect = exports.tekWalletHandler = exports.TekWalletProvider = void 0;
|
|
20
|
+
exports.SwapToken = exports.Activities = exports.AssetView = exports.LockToken = exports.useWallet = exports.ReceiveFunction = exports.GetWalletSeedPhrase = exports.RequireConnect = exports.tekWalletHandler = exports.TekWalletProvider = void 0;
|
|
21
21
|
var TekWalletProvider_1 = __importDefault(require("./providers/TekWalletProvider"));
|
|
22
22
|
exports.TekWalletProvider = TekWalletProvider_1.default;
|
|
23
23
|
var handlers_1 = __importDefault(require("./handlers"));
|
|
@@ -36,5 +36,6 @@ var useWallet_1 = __importDefault(require("./hooks/useWallet"));
|
|
|
36
36
|
exports.useWallet = useWallet_1.default;
|
|
37
37
|
var Activities_1 = __importDefault(require("./components/ui/Activities"));
|
|
38
38
|
exports.Activities = Activities_1.default;
|
|
39
|
+
var SwapToken_1 = __importDefault(require("./components/ui/SwapToken"));
|
|
40
|
+
exports.SwapToken = SwapToken_1.default;
|
|
39
41
|
__exportStar(require("./types/expose-type"), exports);
|
|
40
|
-
//
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SwapProviderDataType } from "./type";
|
|
3
|
+
export declare const initialSwap: SwapProviderDataType;
|
|
4
|
+
export declare const SwapContext: React.Context<SwapProviderDataType>;
|
|
5
|
+
declare function SwapProvider({ children }: {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default SwapProvider;
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
-
};
|
|
2
|
+
"use client";
|
|
13
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
4
|
if (k2 === undefined) k2 = k;
|
|
15
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -79,19 +69,59 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
79
69
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
70
|
}
|
|
81
71
|
};
|
|
72
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
73
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
74
|
+
};
|
|
82
75
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
83
|
-
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
76
|
+
exports.SwapContext = exports.initialSwap = void 0;
|
|
77
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
78
|
+
var react_1 = __importStar(require("react"));
|
|
79
|
+
var useWalletData_1 = __importDefault(require("../../hooks/useWalletData"));
|
|
80
|
+
var get_swap_tokens_list_service_1 = __importDefault(require("../../services/axios/get-swap-tokens-list-service"));
|
|
81
|
+
exports.initialSwap = {
|
|
82
|
+
isLoadingSwapToken: false,
|
|
83
|
+
fromTokens: undefined,
|
|
84
|
+
updateSwapTokens: function () { },
|
|
85
|
+
};
|
|
86
|
+
exports.SwapContext = react_1.default.createContext(exports.initialSwap);
|
|
87
|
+
function SwapProvider(_a) {
|
|
88
|
+
var _this = this;
|
|
89
|
+
var children = _a.children;
|
|
90
|
+
var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
|
|
91
|
+
var _b = (0, react_1.useState)(exports.initialSwap.isLoadingSwapToken), isLoadingSwapToken = _b[0], setIsLoadingSwapToken = _b[1];
|
|
92
|
+
var _c = (0, react_1.useState)(exports.initialSwap.fromTokens), fromTokens = _c[0], setFromTokens = _c[1];
|
|
93
|
+
var updateSwapTokens = (0, react_1.useCallback)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
94
|
+
var response, error_1;
|
|
95
|
+
var _a;
|
|
96
|
+
return __generator(this, function (_b) {
|
|
97
|
+
switch (_b.label) {
|
|
98
|
+
case 0:
|
|
99
|
+
_b.trys.push([0, 2, , 3]);
|
|
100
|
+
if (isLoadingSwapToken)
|
|
101
|
+
return [2 /*return*/];
|
|
102
|
+
if (!isAuthenticated) {
|
|
103
|
+
throw new Error("Authenticate to get swap tokens");
|
|
104
|
+
}
|
|
105
|
+
setIsLoadingSwapToken(true);
|
|
106
|
+
return [4 /*yield*/, (0, get_swap_tokens_list_service_1.default)()];
|
|
107
|
+
case 1:
|
|
108
|
+
response = _b.sent();
|
|
109
|
+
setFromTokens((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.supported_tokens);
|
|
110
|
+
setIsLoadingSwapToken(false);
|
|
111
|
+
return [3 /*break*/, 3];
|
|
112
|
+
case 2:
|
|
113
|
+
error_1 = _b.sent();
|
|
114
|
+
console.error("🚀 ~ getBalance ~ error:", error_1);
|
|
115
|
+
setIsLoadingSwapToken(false);
|
|
116
|
+
return [3 /*break*/, 3];
|
|
117
|
+
case 3: return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}); }, [isAuthenticated, isLoadingSwapToken]);
|
|
121
|
+
return ((0, jsx_runtime_1.jsx)(exports.SwapContext.Provider, { value: {
|
|
122
|
+
isLoadingSwapToken: isLoadingSwapToken,
|
|
123
|
+
fromTokens: fromTokens,
|
|
124
|
+
updateSwapTokens: updateSwapTokens,
|
|
125
|
+
}, children: children }));
|
|
126
|
+
}
|
|
127
|
+
exports.default = SwapProvider;
|
|
@@ -13,8 +13,9 @@ var WithdrawProvider_1 = __importDefault(require("../WithdrawProvider"));
|
|
|
13
13
|
var RealtimeProvider_1 = __importDefault(require("../RealtimeProvider"));
|
|
14
14
|
var ActivitiesProvider_1 = __importDefault(require("../ActivitiesProvider"));
|
|
15
15
|
var EventHandlerProvider_1 = __importDefault(require("../EventHandlerProvider"));
|
|
16
|
+
var SwapProvider_1 = __importDefault(require("../SwapProvider"));
|
|
16
17
|
function TekWalletProvider(_a) {
|
|
17
18
|
var children = _a.children;
|
|
18
|
-
return ((0, jsx_runtime_1.jsx)(WalletDataProvider_1.default, { children: (0, jsx_runtime_1.jsx)(mui_1.default, { children: (0, jsx_runtime_1.jsx)(RealtimeProvider_1.default, { children: (0, jsx_runtime_1.jsx)(ActivitiesProvider_1.default, { children: (0, jsx_runtime_1.jsx)(ReceiveProvider_1.default, { children: (0, jsx_runtime_1.jsx)(LockTokenProvider_1.default, { children: (0, jsx_runtime_1.jsx)(WithdrawProvider_1.default, { children: (0, jsx_runtime_1.jsx)(EventHandlerProvider_1.default, { children: children }) }) }) }) }) }) }) }));
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(WalletDataProvider_1.default, { children: (0, jsx_runtime_1.jsx)(mui_1.default, { children: (0, jsx_runtime_1.jsx)(RealtimeProvider_1.default, { children: (0, jsx_runtime_1.jsx)(ActivitiesProvider_1.default, { children: (0, jsx_runtime_1.jsx)(ReceiveProvider_1.default, { children: (0, jsx_runtime_1.jsx)(LockTokenProvider_1.default, { children: (0, jsx_runtime_1.jsx)(WithdrawProvider_1.default, { children: (0, jsx_runtime_1.jsx)(SwapProvider_1.default, { children: (0, jsx_runtime_1.jsx)(EventHandlerProvider_1.default, { children: children }) }) }) }) }) }) }) }) }));
|
|
19
20
|
}
|
|
20
21
|
exports.default = TekWalletProvider;
|