tek-wallet 0.0.549 → 0.0.550
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.
|
@@ -27,6 +27,7 @@ var DrawerComponent_1 = __importDefault(require("../DrawerComponent"));
|
|
|
27
27
|
var ModalLayout_1 = __importDefault(require("../ModalLayout"));
|
|
28
28
|
var ActivityDetail_1 = __importDefault(require("../ActivityDetail"));
|
|
29
29
|
var SmartList_1 = __importDefault(require("../SmartList"));
|
|
30
|
+
var type_1 = require("../../../providers/ActivitiesProvider/type");
|
|
30
31
|
var Status;
|
|
31
32
|
(function (Status) {
|
|
32
33
|
Status["Loading"] = "loading";
|
|
@@ -37,7 +38,7 @@ var prefix = "activities_";
|
|
|
37
38
|
function ActivitiesTypeSlice(props) {
|
|
38
39
|
var _a, _b;
|
|
39
40
|
var theme = (0, material_1.useTheme)();
|
|
40
|
-
var _c = (0, useActivities_1.default)(), activities = _c.activities, updateActivities = _c.updateActivities, isLoadingActivities = _c.isLoadingActivities, loadMoreActivities = _c.loadMoreActivities;
|
|
41
|
+
var _c = (0, useActivities_1.default)(), activities = _c.activities, updateActivities = _c.updateActivities, isLoadingActivities = _c.isLoadingActivities, loadMoreActivities = _c.loadMoreActivities, pages = _c.pages;
|
|
41
42
|
var type = props.type, isActive = props.isActive;
|
|
42
43
|
var _d = (0, react_1.useState)(undefined), detailActivity = _d[0], setDetailActivity = _d[1];
|
|
43
44
|
var detailDrawerRef = (0, react_1.useRef)(null);
|
|
@@ -75,7 +76,7 @@ function ActivitiesTypeSlice(props) {
|
|
|
75
76
|
var loadMore = (0, react_1.useCallback)(function () {
|
|
76
77
|
loadMoreActivities(type.slug);
|
|
77
78
|
}, [loadMoreActivities, type.slug]);
|
|
78
|
-
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:
|
|
79
|
+
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) {
|
|
79
80
|
if (!activity)
|
|
80
81
|
return null;
|
|
81
82
|
var dataAsJson = JSON.stringify(activity);
|
|
@@ -97,6 +97,7 @@ exports.ActivitiesContext = exports.initialActivities = void 0;
|
|
|
97
97
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
98
98
|
var react_1 = __importStar(require("react"));
|
|
99
99
|
var useWalletData_1 = __importDefault(require("../../hooks/useWalletData"));
|
|
100
|
+
var type_1 = require("./type");
|
|
100
101
|
var get_activities_service_1 = __importDefault(require("../../services/axios/get-activities-service"));
|
|
101
102
|
var const_1 = require("./const");
|
|
102
103
|
exports.initialActivities = {
|
|
@@ -121,15 +122,15 @@ function ActivitiesProvider(_a) {
|
|
|
121
122
|
var _d = react_1.default.useState(exports.initialActivities.activityTypes), activityTypes = _d[0], setActivityTypes = _d[1];
|
|
122
123
|
var _e = (0, react_1.useState)(exports.initialActivities.pages), pages = _e[0], setPages = _e[1];
|
|
123
124
|
var updateActivities = (0, react_1.useCallback)(function (query) { return __awaiter(_this, void 0, void 0, function () {
|
|
124
|
-
var slug, response_1, error_1;
|
|
125
|
-
var _a, _b, _c;
|
|
126
|
-
return __generator(this, function (
|
|
127
|
-
switch (
|
|
125
|
+
var slug, response_1, maxPage_1, error_1;
|
|
126
|
+
var _a, _b, _c, _d, _e, _f;
|
|
127
|
+
return __generator(this, function (_g) {
|
|
128
|
+
switch (_g.label) {
|
|
128
129
|
case 0:
|
|
129
130
|
slug = (_a = query === null || query === void 0 ? void 0 : query.transaction_types) !== null && _a !== void 0 ? _a : const_1.ACTIVITIES_TYPE_ALL.slug;
|
|
130
|
-
|
|
131
|
+
_g.label = 1;
|
|
131
132
|
case 1:
|
|
132
|
-
|
|
133
|
+
_g.trys.push([1, 3, , 4]);
|
|
133
134
|
if (!isAuthenticated) {
|
|
134
135
|
throw new Error("Authenticate to get receive tokens");
|
|
135
136
|
}
|
|
@@ -141,8 +142,9 @@ function ActivitiesProvider(_a) {
|
|
|
141
142
|
});
|
|
142
143
|
return [4 /*yield*/, (0, get_activities_service_1.default)(query)];
|
|
143
144
|
case 2:
|
|
144
|
-
response_1 =
|
|
145
|
-
|
|
145
|
+
response_1 = _g.sent();
|
|
146
|
+
maxPage_1 = Math.ceil(((_d = (_c = (_b = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _b === void 0 ? void 0 : _b.paginated) === null || _c === void 0 ? void 0 : _c.number_records) !== null && _d !== void 0 ? _d : 0) / const_1.ACTIVITIES_PAGE_SIZE);
|
|
147
|
+
setActivityTypes(__spreadArray([const_1.ACTIVITIES_TYPE_ALL], ((_f = (_e = response_1 === null || response_1 === void 0 ? void 0 : response_1.data) === null || _e === void 0 ? void 0 : _e.transaction_types) !== null && _f !== void 0 ? _f : []), true));
|
|
146
148
|
setActivities(function (prev) {
|
|
147
149
|
var _a;
|
|
148
150
|
var _b, _c, _d, _e;
|
|
@@ -151,9 +153,13 @@ function ActivitiesProvider(_a) {
|
|
|
151
153
|
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; }));
|
|
152
154
|
});
|
|
153
155
|
var newActivities = __spreadArray(__spreadArray([], ((_e = prev === null || prev === void 0 ? void 0 : prev[slug]) !== null && _e !== void 0 ? _e : []), true), newestActivities, true);
|
|
156
|
+
var page = Math.floor(newActivities.length / const_1.ACTIVITIES_PAGE_SIZE);
|
|
157
|
+
if (page >= maxPage_1) {
|
|
158
|
+
page = type_1.MAX_PAGE;
|
|
159
|
+
}
|
|
154
160
|
setPages(function (prev) {
|
|
155
161
|
var _a;
|
|
156
|
-
return (__assign(__assign({}, prev), (_a = {}, _a[slug] =
|
|
162
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[slug] = page, _a)));
|
|
157
163
|
});
|
|
158
164
|
return __assign(__assign({}, (prev !== null && prev !== void 0 ? prev : {})), (_a = {}, _a[slug] = newActivities, _a));
|
|
159
165
|
});
|
|
@@ -163,7 +169,7 @@ function ActivitiesProvider(_a) {
|
|
|
163
169
|
});
|
|
164
170
|
return [3 /*break*/, 4];
|
|
165
171
|
case 3:
|
|
166
|
-
error_1 =
|
|
172
|
+
error_1 = _g.sent();
|
|
167
173
|
console.error("🚀 ~ getBalance ~ error:", error_1);
|
|
168
174
|
setIsLoadingActivities(function (prev) {
|
|
169
175
|
var _a;
|
|
@@ -175,10 +181,13 @@ function ActivitiesProvider(_a) {
|
|
|
175
181
|
});
|
|
176
182
|
}); }, [isAuthenticated]);
|
|
177
183
|
var loadMoreActivities = (0, react_1.useCallback)(function (slug) { return __awaiter(_this, void 0, void 0, function () {
|
|
178
|
-
var currentPage, response;
|
|
179
|
-
|
|
180
|
-
|
|
184
|
+
var currentPage, response, maxPage;
|
|
185
|
+
var _a, _b, _c;
|
|
186
|
+
return __generator(this, function (_d) {
|
|
187
|
+
switch (_d.label) {
|
|
181
188
|
case 0:
|
|
189
|
+
if (pages[slug] === type_1.MAX_PAGE)
|
|
190
|
+
return [2 /*return*/];
|
|
182
191
|
currentPage = (pages[slug] || 0) + 1;
|
|
183
192
|
return [4 /*yield*/, (0, get_activities_service_1.default)({
|
|
184
193
|
page: currentPage,
|
|
@@ -186,7 +195,8 @@ function ActivitiesProvider(_a) {
|
|
|
186
195
|
transaction_types: slug,
|
|
187
196
|
})];
|
|
188
197
|
case 1:
|
|
189
|
-
response =
|
|
198
|
+
response = _d.sent();
|
|
199
|
+
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);
|
|
190
200
|
setActivities(function (prev) {
|
|
191
201
|
var _a;
|
|
192
202
|
var _b, _c, _d, _e;
|
|
@@ -195,9 +205,13 @@ function ActivitiesProvider(_a) {
|
|
|
195
205
|
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; }));
|
|
196
206
|
});
|
|
197
207
|
var newActivities = __spreadArray(__spreadArray([], ((_e = prev === null || prev === void 0 ? void 0 : prev[slug]) !== null && _e !== void 0 ? _e : []), true), newestActivities, true);
|
|
208
|
+
var page = Math.floor(newActivities.length / const_1.ACTIVITIES_PAGE_SIZE);
|
|
209
|
+
if (page >= maxPage) {
|
|
210
|
+
page = type_1.MAX_PAGE;
|
|
211
|
+
}
|
|
198
212
|
setPages(function (prev) {
|
|
199
213
|
var _a;
|
|
200
|
-
return (__assign(__assign({}, prev), (_a = {}, _a[slug] =
|
|
214
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[slug] = page, _a)));
|
|
201
215
|
});
|
|
202
216
|
return __assign(__assign({}, (prev !== null && prev !== void 0 ? prev : {})), (_a = {}, _a[slug] = newActivities, _a));
|
|
203
217
|
});
|
|
@@ -206,13 +220,13 @@ function ActivitiesProvider(_a) {
|
|
|
206
220
|
});
|
|
207
221
|
}); }, [pages]);
|
|
208
222
|
(0, react_1.useEffect)(function () {
|
|
209
|
-
if (!!activities)
|
|
223
|
+
if (!!activities || pages[const_1.ACTIVITIES_TYPE_ALL.slug] === type_1.MAX_PAGE)
|
|
210
224
|
return;
|
|
211
225
|
updateActivities({
|
|
212
226
|
page: pages[const_1.ACTIVITIES_TYPE_ALL.slug],
|
|
213
227
|
take: const_1.ACTIVITIES_PAGE_SIZE,
|
|
214
228
|
});
|
|
215
|
-
}, [updateActivities, activities]);
|
|
229
|
+
}, [updateActivities, activities, pages]);
|
|
216
230
|
return ((0, jsx_runtime_1.jsx)(exports.ActivitiesContext.Provider, { value: {
|
|
217
231
|
isLoadingActivities: isLoadingActivities,
|
|
218
232
|
activities: activities,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { GetActivitiesServiceQuery, Transaction, TransactionSlug, TransactionType } from "../../services/axios/get-activities-service/type";
|
|
2
|
+
export declare const MAX_PAGE = "MAX_PAGE";
|
|
2
3
|
export interface ActivitiesProviderDataType {
|
|
3
4
|
isLoadingActivities: Partial<Record<TransactionSlug, boolean>>;
|
|
4
5
|
activities: Activities | undefined;
|
|
5
6
|
updateActivities: (query?: GetActivitiesServiceQuery) => Promise<void>;
|
|
6
7
|
activityTypes: ActivityTypes[] | undefined;
|
|
7
|
-
pages: Partial<Record<TransactionSlug, number>>;
|
|
8
|
+
pages: Partial<Record<TransactionSlug, number | typeof MAX_PAGE>>;
|
|
8
9
|
loadMoreActivities: (slug: TransactionSlug) => Promise<void>;
|
|
9
10
|
}
|
|
10
11
|
export type Activities = Partial<Record<TransactionSlug, Transaction[]>>;
|