tek-wallet 0.0.557 → 0.0.559

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.
@@ -38,7 +38,7 @@ var prefix = "activities_";
38
38
  function ActivitiesTypeSlice(props) {
39
39
  var _a, _b;
40
40
  var theme = (0, material_1.useTheme)();
41
- var _c = (0, useActivities_1.default)(), activities = _c.activities, updateActivities = _c.updateActivities, loadMoreActivities = _c.loadMoreActivities, pages = _c.pages;
41
+ var _c = (0, useActivities_1.default)(), activities = _c.activities, loadActivities = _c.loadActivities, pages = _c.pages;
42
42
  var type = props.type, isActive = props.isActive;
43
43
  var _d = (0, react_1.useState)(undefined), detailActivity = _d[0], setDetailActivity = _d[1];
44
44
  var detailDrawerRef = (0, react_1.useRef)(null);
@@ -67,15 +67,11 @@ function ActivitiesTypeSlice(props) {
67
67
  (0, react_1.useEffect)(function () {
68
68
  if (!isActive || !!activitiesByType)
69
69
  return;
70
- updateActivities({
71
- transaction_types: type.slug,
72
- page: 1,
73
- take: 10,
74
- });
75
- }, [isActive, activitiesByType]);
70
+ loadActivities(type.slug);
71
+ }, [isActive, activitiesByType, loadActivities, type === null || type === void 0 ? void 0 : type.slug]);
76
72
  var loadMore = (0, react_1.useCallback)(function () {
77
- loadMoreActivities(type.slug);
78
- }, [loadMoreActivities, type.slug]);
73
+ loadActivities(type.slug);
74
+ }, [loadActivities, type.slug]);
79
75
  return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { width: "100%", height: "100%", display: "flex" }, children: [status === Status.Loading && (0, jsx_runtime_1.jsx)(WaitingData_1.default, { sx: { margin: "auto" } }), status === Status.Empty && ((0, jsx_runtime_1.jsx)(EmptyData_1.default, { sx: { margin: "auto" }, icon: (0, getIcon_1.default)(prefix + "empty_" + type.slug), description: "No ".concat((_a = type.name) === null || _a === void 0 ? void 0 : _a.toLowerCase(), " activity") })), status === Status.Filled && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SmartList_1.default, { items: activitiesByType || [], loadMoreData: loadMore, hasMore: pages[type.slug] !== type_1.MAX_PAGE, loadingComponent: (0, jsx_runtime_1.jsx)(WaitingData_1.default, { sx: { margin: "auto" } }), children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.column), { gap: theme.mixins.gaps.g12, paddingTop: theme.mixins.customPadding.p16 }), children: activitiesByType === null || activitiesByType === void 0 ? void 0 : activitiesByType.map(function (activity, index) {
80
76
  if (!activity)
81
77
  return null;
@@ -140,7 +140,7 @@ var SwapToken = (0, react_1.forwardRef)(function (props, ref) {
140
140
  var toAmount = (0, react_1.useMemo)(function () {
141
141
  if (!toToken)
142
142
  return undefined;
143
- return +amount * +toToken.usd_rate;
143
+ return +amount / +toToken.usd_rate;
144
144
  }, [toToken, amount]);
145
145
  var getEstimateFee = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
146
146
  var response;
@@ -259,7 +259,7 @@ var SwapToken = (0, react_1.forwardRef)(function (props, ref) {
259
259
  return undefined;
260
260
  return +toAmount - +(estimateFee === null || estimateFee === void 0 ? void 0 : estimateFee.feeInCurrency);
261
261
  }, [estimateFee, toAmount]);
262
- 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: [!!fromToken && !!toToken && ((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.column), { alignItems: "start", gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16, width: "100%" }), 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(__assign({}, theme.mixins.value), { fontWeight: theme.typography.fontWeight600 }), 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 }) })] }), (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("swap-one-direction"), width: 24 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16, width: "100%" }), 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(__assign({}, theme.mixins.value), { fontWeight: theme.typography.fontWeight600 }), 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 }) })] })] }), (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, " ~ ", (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: 1 / +(toToken === null || toToken === void 0 ? void 0 : toToken.usd_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 })), !estimateFee && !!amount && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g8, width: "100%" }), children: [(0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 16, sx: { color: theme.palette.text.white } }), (0, jsx_runtime_1.jsx)(Text_1.default, { children: "Calculating fee..." })] })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
262
+ 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: [!!fromToken && !!toToken && ((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.column), { alignItems: "start", gap: theme.mixins.gaps.g12 }), children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16, width: "100%" }), 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(__assign({}, theme.mixins.value), { fontWeight: theme.typography.fontWeight600 }), 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 }) })] }), (0, jsx_runtime_1.jsx)(Icon_1.default, { src: (0, getIcon_1.default)("swap-one-direction"), width: 24 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g16, width: "100%" }), 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(__assign({}, theme.mixins.value), { fontWeight: theme.typography.fontWeight600 }), 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 }) })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign(__assign({}, theme.mixins.row), theme.mixins.valueDescription), { width: "100%", justifyContent: "center" }), children: ["1 ", fromToken === null || fromToken === void 0 ? void 0 : fromToken.name, " ~ ", (0, jsx_runtime_1.jsx)(Formatter_1.default, { value: 1 / +(toToken === null || toToken === void 0 ? void 0 : toToken.usd_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 })), !estimateFee && !!amount && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.row), { gap: theme.mixins.gaps.g8, width: "100%" }), children: [(0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 16, sx: { color: theme.palette.text.white } }), (0, jsx_runtime_1.jsx)(Text_1.default, { children: "Calculating fee..." })] })), (0, jsx_runtime_1.jsx)(LineValue_1.default, { field: "Receive amount estimated", value: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: {
263
263
  fontWeight: theme.typography.fontWeight600,
264
264
  fontSize: theme.typography.fontSize16,
265
265
  }, 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" }) })] })), (!fromToken || !toToken) && ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: __assign(__assign({}, theme.mixins.paper), { alignItems: "center", justifyContent: "center" }), children: (0, jsx_runtime_1.jsx)(Text_1.default, { sx: __assign(__assign({}, theme.mixins.validationError), { fontSize: theme.typography.fontSize16 }), children: SwapTokenError.TOKEN_NOT_FOUND }) }))] }) }));
@@ -108,7 +108,7 @@ exports.initialActivities = {
108
108
  }); }); },
109
109
  activityTypes: [const_1.ACTIVITIES_TYPE_ALL],
110
110
  pages: {},
111
- loadMoreActivities: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
111
+ loadActivities: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
112
112
  return [2 /*return*/];
113
113
  }); }); },
114
114
  };
@@ -121,6 +121,23 @@ function ActivitiesProvider(_a) {
121
121
  var _c = react_1.default.useState(exports.initialActivities.activities), activities = _c[0], setActivities = _c[1];
122
122
  var _d = react_1.default.useState(exports.initialActivities.activityTypes), activityTypes = _d[0], setActivityTypes = _d[1];
123
123
  var _e = (0, react_1.useState)(exports.initialActivities.pages), pages = _e[0], setPages = _e[1];
124
+ var updateActivityTypes = (0, react_1.useCallback)(function () { return __awaiter(_this, void 0, void 0, function () {
125
+ var response, newActivityTypes;
126
+ var _a, _b;
127
+ return __generator(this, function (_c) {
128
+ switch (_c.label) {
129
+ case 0: return [4 /*yield*/, (0, get_activities_service_1.default)({
130
+ page: 1,
131
+ take: 0,
132
+ })];
133
+ case 1:
134
+ response = _c.sent();
135
+ newActivityTypes = __spreadArray([const_1.ACTIVITIES_TYPE_ALL], ((_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.transaction_types) !== null && _b !== void 0 ? _b : []), true);
136
+ setActivityTypes(newActivityTypes);
137
+ return [2 /*return*/];
138
+ }
139
+ });
140
+ }); }, []);
124
141
  var updateActivities = (0, react_1.useCallback)(function (query) { return __awaiter(_this, void 0, void 0, function () {
125
142
  var slug, response_1, maxPage_1, error_1;
126
143
  var _a, _b, _c, _d, _e, _f;
@@ -186,65 +203,56 @@ function ActivitiesProvider(_a) {
186
203
  }
187
204
  });
188
205
  }); }, [isAuthenticated]);
189
- var loadMoreActivities = (0, react_1.useCallback)(function (slug) { return __awaiter(_this, void 0, void 0, function () {
190
- var currentPage, response, maxPage;
191
- var _a, _b, _c;
192
- return __generator(this, function (_d) {
193
- switch (_d.label) {
206
+ var loadActivities = (0, react_1.useCallback)(function (slug) { return __awaiter(_this, void 0, void 0, function () {
207
+ var page, response, activitiesLoaded, newActivities;
208
+ var _a, _b, _c, _d;
209
+ return __generator(this, function (_e) {
210
+ switch (_e.label) {
194
211
  case 0:
195
- if (pages[slug] === type_1.MAX_PAGE)
212
+ if (!isAuthenticated)
196
213
  return [2 /*return*/];
197
- currentPage = (pages[slug] || 1) + 1;
198
- console.warn("🚀 ~ loadMoreActivities slug:", slug);
214
+ page = ((_a = pages[slug]) !== null && _a !== void 0 ? _a : 0) + 1;
199
215
  return [4 /*yield*/, (0, get_activities_service_1.default)({
200
- page: currentPage,
216
+ page: page,
201
217
  take: const_1.ACTIVITIES_PAGE_SIZE,
202
218
  transaction_types: slug,
203
219
  })];
204
220
  case 1:
205
- response = _d.sent();
206
- maxPage = Math.ceil(((_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.paginated) === null || _b === void 0 ? void 0 : _b.number_records) !== null && _c !== void 0 ? _c : 0) / const_1.ACTIVITIES_PAGE_SIZE);
207
- setActivities(function (prev) {
208
- var _a;
209
- var _b, _c, _d, _e;
210
- var newestActivities = (_d = ((_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.transactions) !== null && _c !== void 0 ? _c : [])) === null || _d === void 0 ? void 0 : _d.filter(function (activity) {
211
- var _a;
212
- return !((_a = prev === null || prev === void 0 ? void 0 : prev[slug]) === null || _a === void 0 ? void 0 : _a.some(function (prevActivity) { return prevActivity.id === activity.id; }));
213
- });
214
- console.warn("🚀 ~ newestActivities ~ newestActivities:", newestActivities);
215
- var newActivities = __spreadArray(__spreadArray([], ((_e = prev === null || prev === void 0 ? void 0 : prev[slug]) !== null && _e !== void 0 ? _e : []), true), newestActivities, true);
216
- console.warn("🚀 ~ setActivities ~ newActivities:", newActivities);
217
- var page = Math.floor(newActivities.length / const_1.ACTIVITIES_PAGE_SIZE);
218
- if (page >= maxPage) {
219
- page = type_1.MAX_PAGE;
220
- }
221
- console.warn("🚀 ~ setActivities ~ page:", page);
221
+ response = _e.sent();
222
+ activitiesLoaded = (_c = (_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.transactions) !== null && _c !== void 0 ? _c : [];
223
+ if (activitiesLoaded.length === 0) {
222
224
  setPages(function (prev) {
223
225
  var _a;
224
- return (__assign(__assign({}, prev), (_a = {}, _a[slug] = page, _a)));
226
+ return (__assign(__assign({}, prev), (_a = {}, _a[slug] = type_1.MAX_PAGE, _a)));
225
227
  });
226
- return __assign(__assign({}, (prev !== null && prev !== void 0 ? prev : {})), (_a = {}, _a[slug] = newActivities, _a));
228
+ return [2 /*return*/];
229
+ }
230
+ newActivities = __spreadArray(__spreadArray([], ((_d = activities === null || activities === void 0 ? void 0 : activities[slug]) !== null && _d !== void 0 ? _d : []), true), activitiesLoaded, true);
231
+ setActivities(function (prev) {
232
+ var _a;
233
+ return (__assign(__assign({}, prev), (_a = {}, _a[slug] = newActivities, _a)));
234
+ });
235
+ setPages(function (prev) {
236
+ var _a;
237
+ return (__assign(__assign({}, prev), (_a = {}, _a[slug] = page, _a)));
227
238
  });
228
239
  return [2 /*return*/];
229
240
  }
230
241
  });
231
- }); }, [pages]);
242
+ }); }, [isAuthenticated, activities, pages]);
232
243
  (0, react_1.useEffect)(function () {
233
- var _a;
234
- if (!!activities)
244
+ if (!!activityTypes || !isAuthenticated)
235
245
  return;
236
- updateActivities({
237
- page: (_a = pages[const_1.ACTIVITIES_TYPE_ALL.slug]) !== null && _a !== void 0 ? _a : 1,
238
- take: const_1.ACTIVITIES_PAGE_SIZE,
239
- });
240
- }, [isAuthenticated]);
246
+ updateActivityTypes();
247
+ // eslint-disable-next-line react-hooks/exhaustive-deps
248
+ }, [isAuthenticated, activityTypes]);
241
249
  return ((0, jsx_runtime_1.jsx)(exports.ActivitiesContext.Provider, { value: {
242
250
  isLoadingActivities: isLoadingActivities,
243
251
  activities: activities,
244
252
  updateActivities: updateActivities,
245
253
  activityTypes: activityTypes,
246
254
  pages: pages,
247
- loadMoreActivities: loadMoreActivities,
255
+ loadActivities: loadActivities,
248
256
  }, children: children }));
249
257
  }
250
258
  exports.default = ActivitiesProvider;
@@ -6,7 +6,7 @@ export interface ActivitiesProviderDataType {
6
6
  updateActivities: (query?: GetActivitiesServiceQuery) => Promise<void>;
7
7
  activityTypes: ActivityTypes[] | undefined;
8
8
  pages: Partial<Record<TransactionSlug, number | typeof MAX_PAGE>>;
9
- loadMoreActivities: (slug: TransactionSlug) => Promise<void>;
9
+ loadActivities: (slug: TransactionSlug) => Promise<void>;
10
10
  }
11
11
  export type Activities = Partial<Record<TransactionSlug, Transaction[]>>;
12
12
  export interface ActivityTypes extends TransactionType {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.557",
3
+ "version": "0.0.559",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",