tek-wallet 0.0.356 → 0.0.358

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.
@@ -113,6 +113,8 @@ var AppBackDrop_1 = __importDefault(require("../AppBackDrop"));
113
113
  var DialogContentLayout_1 = __importDefault(require("../DialogContentLayout"));
114
114
  var AppDialog_1 = __importDefault(require("../AppDialog"));
115
115
  var Formatter_1 = __importDefault(require("../Formatter"));
116
+ var send_internal_service_1 = __importDefault(require("../../../services/axios/send-internal-service"));
117
+ var get_est_fee_service_1 = __importDefault(require("../../../services/axios/get-est-fee-service"));
116
118
  var SendMethods;
117
119
  (function (SendMethods) {
118
120
  SendMethods["SCAN_QR_CODE"] = "scan qr code";
@@ -162,8 +164,10 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
162
164
  var suggestUseTransferInternalDialogRef = (0, react_1.useRef)(null);
163
165
  var _m = (0, react_1.useState)(), selectedMethod = _m[0], setSelectedMethod = _m[1];
164
166
  var _o = (0, react_1.useState)(), sendInfoGet = _o[0], setSendInfoGet = _o[1];
165
- var _p = (0, react_1.useState)(), recipientAddressError = _p[0], setRecipientAddressError = _p[1];
166
- var _q = (0, react_1.useState)(), recipientAddressInternal = _q[0], setRecipientAddressInternal = _q[1];
167
+ var _p = (0, react_1.useState)(false), isLoadingEstimateFee = _p[0], setIsLoadingEstimateFee = _p[1];
168
+ // const [estimateFee, setEstimateFee] = useState<number>();
169
+ var _q = (0, react_1.useState)(), recipientAddressError = _q[0], setRecipientAddressError = _q[1];
170
+ var _r = (0, react_1.useState)(), recipientAddressInternal = _r[0], setRecipientAddressInternal = _r[1];
167
171
  var onlyChangeAddress = (0, react_1.useRef)(false);
168
172
  var networks = (0, react_1.useMemo)(function () {
169
173
  console.warn("🚀 ~ networks ~ selectedToken:", selectedToken);
@@ -330,6 +334,25 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
330
334
  break;
331
335
  }
332
336
  };
337
+ var handleGetEstimateFee = function () { return __awaiter(void 0, void 0, void 0, function () {
338
+ var response;
339
+ return __generator(this, function (_a) {
340
+ switch (_a.label) {
341
+ case 0:
342
+ setIsLoadingEstimateFee(true);
343
+ return [4 /*yield*/, (0, get_est_fee_service_1.default)({
344
+ amount: "".concat(amount),
345
+ transaction_type: "withdrawn",
346
+ currency: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
347
+ })];
348
+ case 1:
349
+ response = _a.sent();
350
+ console.warn("🚀 ~ handleGetEstimateFee ~ response:", response);
351
+ setIsLoadingEstimateFee(false);
352
+ return [2 /*return*/];
353
+ }
354
+ });
355
+ }); };
333
356
  var openScannerAddressQrCode = function () {
334
357
  var _a;
335
358
  (_a = scannerAddressQrCodeRef.current) === null || _a === void 0 ? void 0 : _a.open();
@@ -463,19 +486,38 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
463
486
  return [2 /*return*/];
464
487
  });
465
488
  }); };
466
- var handleWithdrawInternal = function () {
467
- console.warn("withdraw internal");
468
- };
469
- var handleWithdrawExternal = function () {
470
- console.warn("withdraw external");
471
- };
472
- var handleWithdraw = function () {
489
+ var handleSendInternal = function () { return __awaiter(void 0, void 0, void 0, function () {
490
+ var response;
491
+ return __generator(this, function (_a) {
492
+ switch (_a.label) {
493
+ case 0:
494
+ console.warn("withdraw internal");
495
+ return [4 /*yield*/, (0, send_internal_service_1.default)({
496
+ amount: "".concat(amount),
497
+ to_address: recipientAddress || "",
498
+ currency_slug: (selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug) || "",
499
+ passcode: "111111",
500
+ })];
501
+ case 1:
502
+ response = _a.sent();
503
+ console.warn("🚀 ~ handleSendInternal ~ response:", response);
504
+ return [2 /*return*/];
505
+ }
506
+ });
507
+ }); };
508
+ var handleSendExternal = function () { return __awaiter(void 0, void 0, void 0, function () {
509
+ return __generator(this, function (_a) {
510
+ console.warn("withdraw external");
511
+ return [2 /*return*/];
512
+ });
513
+ }); };
514
+ var handleSend = function () {
473
515
  switch (selectedMethod) {
474
516
  case SendMethods.TRANSFER_INTERNAL:
475
- handleWithdrawInternal();
517
+ handleSendInternal();
476
518
  break;
477
519
  case SendMethods.TRANSFER_EXTERNAL:
478
- handleWithdrawExternal();
520
+ handleSendExternal();
479
521
  break;
480
522
  default:
481
523
  break;
@@ -490,6 +532,9 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
490
532
  (0, react_1.useEffect)(function () {
491
533
  validateAmount();
492
534
  }, [validateAmount]);
535
+ (0, react_1.useEffect)(function () {
536
+ handleGetEstimateFee();
537
+ }, [amount, selectedToken === null || selectedToken === void 0 ? void 0 : selectedToken.slug]);
493
538
  return ((0, jsx_runtime_1.jsx)(RequireConnect_1.default, { children: (0, jsx_runtime_1.jsx)(DrawerComponent_1.default, { ref: drawerRef, trigger: props.children, onOpen: props.onOpen, onClose: handleOnClose, children: (0, jsx_runtime_1.jsxs)(ModalLayout_1.default, { overrideHeader: (0, jsx_runtime_1.jsx)(BackHeader_1.default, { sx: {
494
539
  width: "100%",
495
540
  display: "flex",
@@ -537,11 +582,12 @@ var WithdrawFunction = (0, react_1.forwardRef)(function (props, ref) {
537
582
  placeholder: "Enter memo",
538
583
  value: memo,
539
584
  onChange: handleChangeMemo,
540
- } })] })), (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, onClick: handleWithdraw, status: !!amountError ||
585
+ } })] })), (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%" }, onClick: handleSend, status: !!amountError ||
541
586
  !recipientAddress ||
542
587
  !amount ||
543
588
  !selectedToken ||
544
- !!recipientAddressError
589
+ !!recipientAddressError ||
590
+ isLoadingEstimateFee
545
591
  ? Button_1.BUTTON_STATUS.DISABLED
546
592
  : Button_1.BUTTON_STATUS.ENABLED, children: "Continue" })] }) }, WithdrawStep.FORM)] }, withdrawTokens === null || withdrawTokens === void 0 ? void 0 : withdrawTokens.length), (0, jsx_runtime_1.jsx)(QrCodeReader_1.default, { ref: scannerAllQrCodeRef, onResult: handleScanAllQrCode }), (0, jsx_runtime_1.jsx)(QrCodeReader_1.default, { ref: scannerAddressQrCodeRef, onResult: handleScanAddressQrCode }), (0, jsx_runtime_1.jsx)(AppBackDrop_1.default, { ref: backDropRef }), (0, jsx_runtime_1.jsx)(AppDialog_1.default, { overrideOpen: !!infoDialogContent, children: (0, jsx_runtime_1.jsx)(DialogContentLayout_1.default, { content: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
547
593
  textAlign: "center",
@@ -84,16 +84,21 @@ function RealtimeProvider(_a) {
84
84
  setNotifications(function (prev) { return __spreadArray(__spreadArray([], prev, true), [notification], false); });
85
85
  };
86
86
  (0, react_1.useEffect)(function () {
87
- if (!masterWallet)
88
- return;
89
- var ablyService = new ably_service_1.AblyService();
90
- console.warn("Connecting to realtime");
91
- ablyService.listenMessage(masterWallet, function (message) {
92
- // eslint-disable-next-line no-console
93
- console.log("🚀 ~ ablyService.listenMessage ~ message:", message);
94
- setIsConnected(true);
95
- setTransaction(message);
96
- });
87
+ try {
88
+ if (!masterWallet)
89
+ return;
90
+ var ablyService = new ably_service_1.AblyService();
91
+ console.warn("Connecting to realtime");
92
+ ablyService.listenMessage(masterWallet, function (message) {
93
+ // eslint-disable-next-line no-console
94
+ console.log("🚀 ~ ablyService.listenMessage ~ message:", message);
95
+ setIsConnected(true);
96
+ setTransaction(message);
97
+ });
98
+ }
99
+ catch (error) {
100
+ console.error("🚀 ~ TEK-WALLET: Error connecting to realtime", error);
101
+ }
97
102
  }, [masterWallet]);
98
103
  return ((0, jsx_runtime_1.jsxs)(exports.RealtimeContext.Provider, { value: {
99
104
  isConnected: isConnected,
@@ -0,0 +1,3 @@
1
+ import { GetEstimateFeeServiceResponse } from "./type";
2
+ import { GetEstimateFeeServiceQuery } from "./type";
3
+ export default function getEstimateFeeService(query: GetEstimateFeeServiceQuery): Promise<GetEstimateFeeServiceResponse>;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ 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);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.default = getEstimateFeeService;
43
+ var userClientRequest_1 = __importDefault(require("../clients/userClientRequest"));
44
+ function getEstimateFeeService(query) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var response;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0: return [4 /*yield*/, userClientRequest_1.default.get("/fee/calculate?amount=".concat(query.amount, "&transaction_type=").concat(query.transaction_type, "&currency=").concat(query.currency), {
50
+ params: query,
51
+ })];
52
+ case 1:
53
+ response = _a.sent();
54
+ console.warn("🚀 ~ getEstimateFeeService response:", response);
55
+ return [2 /*return*/, response.data];
56
+ }
57
+ });
58
+ });
59
+ }
@@ -0,0 +1,31 @@
1
+ export interface GetEstimateFeeServiceQuery {
2
+ amount: string;
3
+ transaction_type: string;
4
+ currency: string;
5
+ }
6
+ export interface GetEstimateFeeServiceResponse {
7
+ success: boolean;
8
+ message: string;
9
+ data: Data;
10
+ timestamp: string;
11
+ }
12
+ interface Data {
13
+ feeInUSD: number;
14
+ feeInCurrency: number;
15
+ originalAmountInUSD: number;
16
+ originalAmountInCurrency: number;
17
+ originalCurrency: string;
18
+ feeDetail: FeeDetail[];
19
+ }
20
+ interface FeeDetail {
21
+ feeType: FeeType;
22
+ feeInUSD: number;
23
+ feeInCurrency: number;
24
+ feePercent: number;
25
+ feeFixed: number;
26
+ }
27
+ interface FeeType {
28
+ name: string;
29
+ slug: string;
30
+ }
31
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.356",
3
+ "version": "0.0.358",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",