tek-wallet 0.0.443 → 0.0.445

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,16 +1,5 @@
1
1
  "use strict";
2
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
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
4
  if (k2 === undefined) k2 = k;
16
5
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -59,14 +48,11 @@ var SwiperControlled_1 = __importDefault(require("../SwiperControlled"));
59
48
  var useActivities_1 = __importDefault(require("../../../hooks/useActivities"));
60
49
  var material_1 = require("@mui/material");
61
50
  var react_2 = require("swiper/react");
62
- var ActivityItem_1 = __importDefault(require("../ActivityItem"));
63
- var EmptyData_1 = __importDefault(require("../EmptyData"));
64
- var getIcon_1 = __importDefault(require("../../../utils/getIcon"));
65
- var prefix = "activities_";
51
+ var ActivitiesTypeSlice_1 = __importDefault(require("../ActivitiesTypeSlice"));
66
52
  var Activities = (0, react_1.forwardRef)(function (props, ref) {
67
53
  var drawerRef = (0, react_1.useRef)(null);
68
54
  var theme = (0, material_1.useTheme)();
69
- var _a = (0, useActivities_1.default)(), activityTypes = _a.activityTypes, activities = _a.activities;
55
+ var activityTypes = (0, useActivities_1.default)().activityTypes;
70
56
  var open = function () {
71
57
  var _a;
72
58
  (_a = drawerRef.current) === null || _a === void 0 ? void 0 : _a.open();
@@ -92,7 +78,7 @@ var Activities = (0, react_1.forwardRef)(function (props, ref) {
92
78
  spaceBetween: 40,
93
79
  }, tabs: activityTypes === null || activityTypes === void 0 ? void 0 : activityTypes.map(function (type, index) {
94
80
  return ((0, jsx_runtime_1.jsx)(material_1.Tab, { label: type.name, value: index, "data-index": index, sx: {
95
- padding: "0 ".concat(theme.mixins.customPadding.p16, " ").concat(theme.mixins.customPadding.p8),
81
+ padding: "".concat(theme.mixins.customPadding.p16, " ").concat(theme.mixins.customPadding.p8),
96
82
  minHeight: "unset",
97
83
  minWidth: "unset",
98
84
  textTransform: "capitalize",
@@ -108,17 +94,9 @@ var Activities = (0, react_1.forwardRef)(function (props, ref) {
108
94
  }, swiperStyle: {
109
95
  flex: 1,
110
96
  }, children: activityTypes === null || activityTypes === void 0 ? void 0 : activityTypes.map(function (type, index) {
111
- var _a;
112
- var activitiesByType = activities === null || activities === void 0 ? void 0 : activities[type.slug];
113
- var isEmpty = !(activitiesByType === null || activitiesByType === void 0 ? void 0 : activitiesByType.length);
114
- return ((0, jsx_runtime_1.jsxs)(react_2.SwiperSlide, { style: {
97
+ return ((0, jsx_runtime_1.jsx)(react_2.SwiperSlide, { style: {
115
98
  display: "flex",
116
- }, children: [isEmpty && ((0, jsx_runtime_1.jsx)(EmptyData_1.default, { icon: (0, getIcon_1.default)(prefix + "empty_" + type.slug), description: "No ".concat((_a = type.name) === null || _a === void 0 ? void 0 : _a.toLowerCase(), " activity") })), !isEmpty && ((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) {
117
- if (!activity)
118
- return null;
119
- var dataAsJson = JSON.stringify(activity);
120
- return (0, jsx_runtime_1.jsx)(ActivityItem_1.default, { data: dataAsJson }, index);
121
- }) }))] }, index));
99
+ }, children: (0, jsx_runtime_1.jsx)(ActivitiesTypeSlice_1.default, { type: type, isActive: true }) }, index));
122
100
  }) }) }) }) }) }));
123
101
  });
124
102
  Activities.displayName = "Activities";
@@ -0,0 +1,12 @@
1
+ import { TransactionType } from "../../../services/axios/get-activities-service/type";
2
+ export interface ActivitiesTypeSlicePropsType {
3
+ type: TransactionType;
4
+ isActive?: boolean;
5
+ }
6
+ export declare enum Status {
7
+ Loading = "loading",
8
+ Empty = "empty",
9
+ Filled = "filled"
10
+ }
11
+ declare function ActivitiesTypeSlice(props: ActivitiesTypeSlicePropsType): import("react/jsx-runtime").JSX.Element;
12
+ export default ActivitiesTypeSlice;
@@ -0,0 +1,67 @@
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
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Status = void 0;
18
+ var jsx_runtime_1 = require("react/jsx-runtime");
19
+ var material_1 = require("@mui/material");
20
+ var getIcon_1 = __importDefault(require("../../../utils/getIcon"));
21
+ var EmptyData_1 = __importDefault(require("../EmptyData"));
22
+ var ActivityItem_1 = __importDefault(require("../ActivityItem"));
23
+ var useActivities_1 = __importDefault(require("../../../hooks/useActivities"));
24
+ var react_1 = require("react");
25
+ var Status;
26
+ (function (Status) {
27
+ Status["Loading"] = "loading";
28
+ Status["Empty"] = "empty";
29
+ Status["Filled"] = "filled";
30
+ })(Status || (exports.Status = Status = {}));
31
+ var prefix = "activities_";
32
+ function ActivitiesTypeSlice(props) {
33
+ var _a;
34
+ var theme = (0, material_1.useTheme)();
35
+ var _b = (0, useActivities_1.default)(), activities = _b.activities, updateActivities = _b.updateActivities;
36
+ var type = props.type, isActive = props.isActive;
37
+ var activitiesByType = (0, react_1.useMemo)(function () {
38
+ if (!(type === null || type === void 0 ? void 0 : type.slug))
39
+ return undefined;
40
+ return activities === null || activities === void 0 ? void 0 : activities[type.slug];
41
+ }, [type, activities]);
42
+ var status = (0, react_1.useMemo)(function () {
43
+ if (!(type === null || type === void 0 ? void 0 : type.slug) || !activitiesByType)
44
+ return Status.Loading;
45
+ if (!!(activitiesByType === null || activitiesByType === void 0 ? void 0 : activitiesByType.length))
46
+ return Status.Filled;
47
+ return Status.Empty;
48
+ }, [type, activitiesByType]);
49
+ (0, react_1.useEffect)(function () {
50
+ if (!isActive || !type)
51
+ return;
52
+ if (!!activitiesByType)
53
+ return;
54
+ updateActivities({
55
+ transaction_type: type.slug,
56
+ page: 1,
57
+ take: 10,
58
+ });
59
+ }, [isActive, type, activitiesByType, updateActivities]);
60
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [status === Status.Empty && ((0, jsx_runtime_1.jsx)(EmptyData_1.default, { 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.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) {
61
+ if (!activity)
62
+ return null;
63
+ var dataAsJson = JSON.stringify(activity);
64
+ return (0, jsx_runtime_1.jsx)(ActivityItem_1.default, { data: dataAsJson }, index);
65
+ }) }))] }));
66
+ }
67
+ exports.default = ActivitiesTypeSlice;
@@ -100,7 +100,7 @@ var useWalletData_1 = __importDefault(require("../../hooks/useWalletData"));
100
100
  var get_activities_service_1 = __importDefault(require("../../services/axios/get-activities-service"));
101
101
  var const_1 = require("./const");
102
102
  exports.initialActivities = {
103
- isLoadingActivities: true,
103
+ isLoadingActivities: {},
104
104
  activities: undefined,
105
105
  updateActivities: function () { },
106
106
  activityTypes: [const_1.ACTIVITIES_TYPE_ALL],
@@ -112,7 +112,7 @@ function ActivitiesProvider(_a) {
112
112
  var _this = this;
113
113
  var children = _a.children;
114
114
  var isAuthenticated = (0, useWalletData_1.default)().isAuthenticated;
115
- var _b = (0, react_1.useState)(true), isLoadingActivities = _b[0], setIsLoadingActivities = _b[1];
115
+ var _b = (0, react_1.useState)({}), isLoadingActivities = _b[0], setIsLoadingActivities = _b[1];
116
116
  var _c = react_1.default.useState(undefined), activities = _c[0], setActivities = _c[1];
117
117
  var _d = react_1.default.useState(undefined), activityTypes = _d[0], setActivityTypes = _d[1];
118
118
  var _e = (0, react_1.useState)(1), page = _e[0], setPage = _e[1];
@@ -120,48 +120,59 @@ function ActivitiesProvider(_a) {
120
120
  setPage(page);
121
121
  }, []);
122
122
  var updateActivities = (0, react_1.useCallback)(function (query) { return __awaiter(_this, void 0, void 0, function () {
123
- var response_1, error_1;
124
- var _a, _b;
125
- return __generator(this, function (_c) {
126
- switch (_c.label) {
123
+ var slug, response_1, error_1;
124
+ var _a, _b, _c;
125
+ return __generator(this, function (_d) {
126
+ switch (_d.label) {
127
127
  case 0:
128
- _c.trys.push([0, 2, , 3]);
128
+ slug = (_a = query === null || query === void 0 ? void 0 : query.transaction_type) !== null && _a !== void 0 ? _a : const_1.ACTIVITIES_TYPE_ALL.slug;
129
+ _d.label = 1;
130
+ case 1:
131
+ _d.trys.push([1, 3, , 4]);
129
132
  if (!isAuthenticated) {
130
133
  throw new Error("Authenticate to get receive tokens");
131
134
  }
132
- setIsLoadingActivities(true);
135
+ setIsLoadingActivities(function (prev) {
136
+ var _a;
137
+ return (__assign(__assign({}, prev), (_a = {}, _a[slug] = true, _a)));
138
+ });
133
139
  return [4 /*yield*/, (0, get_activities_service_1.default)(query)];
134
- case 1:
135
- response_1 = _c.sent();
140
+ case 2:
141
+ response_1 = _d.sent();
136
142
  console.warn("🚀 ~ getBalance ~ response:", response_1);
137
143
  setActivityTypes(__spreadArray([
138
144
  const_1.ACTIVITIES_TYPE_ALL
139
- ], ((_b = (_a = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _a === void 0 ? void 0 : _a.transaction_types) !== null && _b !== void 0 ? _b : []), true));
145
+ ], ((_c = (_b = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _b === void 0 ? void 0 : _b.transaction_types) !== null && _c !== void 0 ? _c : []), true));
140
146
  setActivities(function (prev) {
141
147
  var _a;
142
148
  var _b, _c, _d;
143
- var slug = (query === null || query === void 0 ? void 0 : query.transaction_type) || const_1.ACTIVITIES_TYPE_ALL.slug;
144
149
  return __assign(__assign({}, (prev !== null && prev !== void 0 ? prev : {})), (_a = {}, _a[slug] = __spreadArray(__spreadArray([], ((_b = prev === null || prev === void 0 ? void 0 : prev[slug]) !== null && _b !== void 0 ? _b : []), true), ((_d = (_c = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _c === void 0 ? void 0 : _c.transactions) !== null && _d !== void 0 ? _d : []), true), _a));
145
150
  });
146
- setIsLoadingActivities(false);
147
- return [3 /*break*/, 3];
148
- case 2:
149
- error_1 = _c.sent();
151
+ setIsLoadingActivities(function (prev) {
152
+ var _a;
153
+ return (__assign(__assign({}, prev), (_a = {}, _a[slug] = false, _a)));
154
+ });
155
+ return [3 /*break*/, 4];
156
+ case 3:
157
+ error_1 = _d.sent();
150
158
  console.error("🚀 ~ getBalance ~ error:", error_1);
151
- setIsLoadingActivities(false);
152
- return [3 /*break*/, 3];
153
- case 3: return [2 /*return*/];
159
+ setIsLoadingActivities(function (prev) {
160
+ var _a;
161
+ return (__assign(__assign({}, prev), (_a = {}, _a[slug] = false, _a)));
162
+ });
163
+ return [3 /*break*/, 4];
164
+ case 4: return [2 /*return*/];
154
165
  }
155
166
  });
156
167
  }); }, [isAuthenticated]);
157
168
  (0, react_1.useEffect)(function () {
158
- if (isAuthenticated && !activities) {
159
- updateActivities({
160
- page: page,
161
- take: const_1.ACTIVITIES_PAGE_SIZE,
162
- });
163
- }
164
- }, [isAuthenticated, activities]);
169
+ if (!!activities)
170
+ return;
171
+ updateActivities({
172
+ page: page,
173
+ take: const_1.ACTIVITIES_PAGE_SIZE,
174
+ });
175
+ }, [updateActivities]);
165
176
  return ((0, jsx_runtime_1.jsx)(exports.ActivitiesContext.Provider, { value: {
166
177
  isLoadingActivities: isLoadingActivities,
167
178
  activities: activities,
@@ -1,8 +1,8 @@
1
- import { Transaction, TransactionSlug, TransactionType } from "../../services/axios/get-activities-service/type";
1
+ import { GetActivitiesServiceQuery, Transaction, TransactionSlug, TransactionType } from "../../services/axios/get-activities-service/type";
2
2
  export interface ActivitiesProviderDataType {
3
- isLoadingActivities: boolean;
3
+ isLoadingActivities: Partial<Record<TransactionSlug, boolean>>;
4
4
  activities: Activities | undefined;
5
- updateActivities: () => void;
5
+ updateActivities: (query?: GetActivitiesServiceQuery) => void;
6
6
  activityTypes: ActivityTypes[] | undefined;
7
7
  page: number;
8
8
  gotoPage: (page: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tek-wallet",
3
- "version": "0.0.443",
3
+ "version": "0.0.445",
4
4
  "description": "A custom React provider with TypeScript support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",