tek-wallet 0.0.85 → 0.0.87

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.
@@ -1,10 +1,19 @@
1
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
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
14
  var jsx_runtime_1 = require("react/jsx-runtime");
4
15
  var system_1 = require("@mui/system");
5
- var StyledImage = (0, system_1.styled)("img")(function () { return ({
6
- display: "block",
7
- }); });
16
+ var StyledImage = (0, system_1.styled)("img")(function (sx) { return (__assign({ display: "block" }, sx)); });
8
17
  var Image = function (props) {
9
18
  return ((0, jsx_runtime_1.jsx)(StyledImage, { onClick: props.onClick, src: props.src, alt: props.alt, sx: props.sx }));
10
19
  };
@@ -20,7 +20,7 @@ var StatusDisplayType;
20
20
  StatusDisplayType["Normal"] = "normal";
21
21
  })(StatusDisplayType || (exports.StatusDisplayType = StatusDisplayType = {}));
22
22
  var StatusDisplay = function (props) {
23
- return ((0, jsx_runtime_1.jsxs)("div", { className: (0, cn_1.default)("flex items-center gap-1", props.className), children: [(0, jsx_runtime_1.jsx)(Image_1.default, { src: (0, getIcon_1.default)("status_".concat(props.status), "gif"), className: "size-6" }), (0, jsx_runtime_1.jsx)(Text_1.default, { className: (0, clsx_1.default)("text-13", {
23
+ return ((0, jsx_runtime_1.jsxs)("div", { className: (0, cn_1.default)("flex items-center gap-1", props.className), children: [(0, jsx_runtime_1.jsx)(Image_1.default, { src: (0, getIcon_1.default)("status_".concat(props.status), "gif"), sx: { width: "1.5rem", height: "1.5rem" } }), (0, jsx_runtime_1.jsx)(Text_1.default, { className: (0, clsx_1.default)("text-13", {
24
24
  "text-ui-text-error": props.status === StatusDisplayType.Error,
25
25
  "text-ui-text-warning": props.status === StatusDisplayType.Warning,
26
26
  "text-ui-text-success": props.status === StatusDisplayType.Success,
@@ -107,6 +107,14 @@ var CreateWalletView = function (props) {
107
107
  gotoStep(CreateWalletViewStep.CONFIRM_PASSCODE);
108
108
  }
109
109
  };
110
+ var handleCreateWalletError = function () {
111
+ var _a;
112
+ (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showError();
113
+ setTimeout(function () {
114
+ var _a;
115
+ (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showNormal();
116
+ }, 1500);
117
+ };
110
118
  var handleConfirmOtpChange = function (value) {
111
119
  setConfirmOtp(value);
112
120
  /**
@@ -122,10 +130,7 @@ var CreateWalletView = function (props) {
122
130
  }, function () {
123
131
  var _a;
124
132
  (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showSuccess();
125
- }, function () {
126
- var _a;
127
- (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showError();
128
- });
133
+ }, handleCreateWalletError);
129
134
  }
130
135
  };
131
136
  return ((0, jsx_runtime_1.jsx)(ChildPageLayout_1.default, { ref: childPageLayoutRef, header: (0, jsx_runtime_1.jsx)(PageHeader_1.default, { overrideBack: handleBack, title: "Passcode" }), children: (0, jsx_runtime_1.jsx)(DefaultPageLayout_1.default, { sx: __assign({ display: "flex", flexDirection: "column", gap: "1rem", height: "100%" }, props.sx), children: (0, jsx_runtime_1.jsxs)(SwiperControlled_1.default, { ref: swiperControlledRef, disableSwipe: true, sx: { height: "100%" }, children: [(0, jsx_runtime_1.jsx)(react_1.SwiperSlide, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
@@ -61,8 +61,8 @@ var PageHeader_1 = __importDefault(require("../../../components/ui/PageHeader"))
61
61
  var react_2 = require("react");
62
62
  var Text_1 = __importDefault(require("../../../components/ui/Text"));
63
63
  var Button_1 = __importDefault(require("../../ui/Button"));
64
- var importWalletIntenalService_1 = __importDefault(require("../../../services/axios/import-wallet-service/importWalletIntenalService"));
65
64
  var material_1 = require("@mui/material");
65
+ var useWalletData_1 = __importDefault(require("../../../hooks/useWalletData"));
66
66
  var ImportWalletViewStep;
67
67
  (function (ImportWalletViewStep) {
68
68
  ImportWalletViewStep[ImportWalletViewStep["CREATE_PASSCODE"] = 0] = "CREATE_PASSCODE";
@@ -72,36 +72,36 @@ var ImportWalletView = function (props) {
72
72
  var _a = (0, react_2.useState)(""), seedPhrase = _a[0], setSeedPhrase = _a[1];
73
73
  var swiperControlledRef = (0, react_2.useRef)(null);
74
74
  var childPageLayoutRef = (0, react_2.useRef)(null);
75
+ var importWallet = (0, useWalletData_1.default)().importWallet;
75
76
  var handleChangeSeedPhrase = function (event) {
76
77
  setSeedPhrase(event.target.value);
77
78
  };
79
+ var handleImportWalletError = function () {
80
+ var _a;
81
+ (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showError();
82
+ setTimeout(function () {
83
+ var _a;
84
+ (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showNormal();
85
+ }, 1500);
86
+ };
78
87
  var handleImportWallet = function () { return __awaiter(void 0, void 0, void 0, function () {
79
- var delay, response;
80
88
  var _a;
81
89
  return __generator(this, function (_b) {
82
90
  switch (_b.label) {
83
91
  case 0:
84
92
  (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showLoading();
85
- delay = new Promise(function (resolve) { return setTimeout(resolve, 1000); });
86
- return [4 /*yield*/, (0, importWalletIntenalService_1.default)({
93
+ return [4 /*yield*/, importWallet({
87
94
  seed_pharse: seedPhrase,
88
95
  app_slugs: [process.env.NEXT_PUBLIC_TEK_WALLET_APP_SLUG || ""],
89
- })];
96
+ }, function () {
97
+ var _a;
98
+ (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showLoading();
99
+ }, function () {
100
+ var _a;
101
+ (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showSuccess();
102
+ }, handleImportWalletError)];
90
103
  case 1:
91
- response = _b.sent();
92
- Promise.allSettled([delay, response]).then(function (result) { return __awaiter(void 0, void 0, void 0, function () {
93
- var data;
94
- var _a;
95
- return __generator(this, function (_b) {
96
- if (result[1].status === "fulfilled") {
97
- data = result[1].value;
98
- if (!(data === null || data === void 0 ? void 0 : data.success)) {
99
- (_a = childPageLayoutRef.current) === null || _a === void 0 ? void 0 : _a.showError();
100
- }
101
- }
102
- return [2 /*return*/];
103
- });
104
- }); });
104
+ _b.sent();
105
105
  return [2 /*return*/];
106
106
  }
107
107
  });
@@ -109,7 +109,6 @@ var ImportWalletView = function (props) {
109
109
  return ((0, jsx_runtime_1.jsx)(ChildPageLayout_1.default, { ref: childPageLayoutRef, header: (0, jsx_runtime_1.jsx)(PageHeader_1.default, { overrideBack: props.onBack, title: "Import wallet" }), children: (0, jsx_runtime_1.jsx)(DefaultPageLayout_1.default, { sx: __assign({ display: "flex", flexDirection: "column", gap: "1rem", height: "100%" }, props.sx), children: (0, jsx_runtime_1.jsx)(SwiperControlled_1.default, { ref: swiperControlledRef, disableSwipe: true, sx: { height: "100%" }, children: (0, jsx_runtime_1.jsx)(react_1.SwiperSlide, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
110
110
  display: "flex",
111
111
  flexDirection: "column",
112
- justifyContent: "center",
113
112
  alignItems: "center",
114
113
  height: "100%",
115
114
  gap: "1rem",
@@ -125,6 +124,7 @@ var ImportWalletView = function (props) {
125
124
  backgroundColor: "ui.background.primary",
126
125
  borderRadius: "lg",
127
126
  padding: "1rem",
128
- } }) }), (0, jsx_runtime_1.jsx)(Text_1.default, { className: "text-ui-text-white font-400 text-13 text-center", children: "Your seed phrase is a list of words that are used to create your wallet. It is important to keep it safe and private." }), (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { className: "w-full mt-auto", onClick: handleImportWallet, children: "Import" })] }) }) }) }) }));
127
+ color: "text.white",
128
+ } }) }), (0, jsx_runtime_1.jsx)(Text_1.default, { className: "text-ui-text-white font-400 text-13 text-center", children: "Your seed phrase is a list of words that are used to create your wallet. It is important to keep it safe and private." }), (0, jsx_runtime_1.jsx)(Button_1.default.Primary, { sx: { width: "100%", marginTop: "auto" }, onClick: handleImportWallet, children: "Import" })] }) }) }) }) }));
129
129
  };
130
130
  exports.default = ImportWalletView;
@@ -82,6 +82,7 @@ var getBalanceService_1 = __importDefault(require("../../services/axios/get-bala
82
82
  var loginIntenalService_2 = __importDefault(require("../../services/axios/sign-out-internal/loginIntenalService"));
83
83
  var const_1 = require("../../handlers/const");
84
84
  var createWalletInternalService_1 = __importDefault(require("../../services/axios/create-wallet-service/createWalletInternalService"));
85
+ var importWalletIntenalService_1 = __importDefault(require("../../services/axios/import-wallet-service/importWalletIntenalService"));
85
86
  exports.initialWalletData = {
86
87
  isAuthenticated: false,
87
88
  session: undefined,
@@ -94,6 +95,7 @@ exports.initialWalletData = {
94
95
  updateBalance: function () { },
95
96
  disconnect: function () { },
96
97
  createWallet: function () { return Promise.resolve({}); },
98
+ importWallet: function () { return Promise.resolve({}); },
97
99
  };
98
100
  exports.WalletDataContext = react_1.default.createContext(exports.initialWalletData);
99
101
  function WalletDataProvider(_a) {
@@ -175,14 +177,44 @@ function WalletDataProvider(_a) {
175
177
  if (result[1].status === "fulfilled") {
176
178
  data = result[1].value;
177
179
  if (data.success) {
178
- // childPageLayoutRef.current?.showSuccess();
179
180
  setTimeout(function () {
180
181
  updateLogin();
181
182
  }, 1000);
182
183
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
183
184
  }
184
185
  else {
185
- // childPageLayoutRef.current?.showError();
186
+ onError === null || onError === void 0 ? void 0 : onError(new Error("Create wallet failed"));
187
+ }
188
+ }
189
+ else {
190
+ onError === null || onError === void 0 ? void 0 : onError(new Error("Create wallet failed"));
191
+ }
192
+ return [2 /*return*/];
193
+ });
194
+ }); });
195
+ return [2 /*return*/, response];
196
+ });
197
+ }); };
198
+ var importWallet = function (body, onStart, onSuccess, onError) { return __awaiter(_this, void 0, void 0, function () {
199
+ var delay, response;
200
+ var _this = this;
201
+ return __generator(this, function (_a) {
202
+ // childPageLayoutRef.current?.showLoading();
203
+ onStart === null || onStart === void 0 ? void 0 : onStart();
204
+ delay = new Promise(function (resolve) { return setTimeout(resolve, 1000); });
205
+ response = (0, importWalletIntenalService_1.default)(body);
206
+ Promise.allSettled([delay, response]).then(function (result) { return __awaiter(_this, void 0, void 0, function () {
207
+ var data;
208
+ return __generator(this, function (_a) {
209
+ if (result[1].status === "fulfilled") {
210
+ data = result[1].value;
211
+ if (data.success) {
212
+ setTimeout(function () {
213
+ updateLogin();
214
+ }, 1000);
215
+ onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
216
+ }
217
+ else {
186
218
  onError === null || onError === void 0 ? void 0 : onError(new Error("Create wallet failed"));
187
219
  }
188
220
  }
@@ -256,6 +288,7 @@ function WalletDataProvider(_a) {
256
288
  updateBalance: updateBalance,
257
289
  disconnect: disconnect,
258
290
  createWallet: createWallet,
291
+ importWallet: importWallet,
259
292
  }, children: children }));
260
293
  }
261
294
  exports.default = WalletDataProvider;
@@ -59,6 +59,7 @@ export interface WalletProviderDataType {
59
59
  updateBalance: () => void;
60
60
  disconnect: () => void;
61
61
  createWallet: (body: CreateWalletServiceBody, onStart?: () => void, onSuccess?: (data?: CreateWalletServiceResponse) => void, onError?: (error?: Error) => void) => Promise<CreateWalletServiceResponse>;
62
+ importWallet: (body: importWalletServiceBody, onStart?: () => void, onSuccess?: (data?: ImportWalletServiceResponse) => void, onError?: (error?: Error) => void) => Promise<ImportWalletServiceResponse>;
62
63
  }
63
64
  export interface LoginInfo {
64
65
  accessToken: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.85",
3
+ "version": "0.0.87",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",