@0xchain/header 1.1.0-beta.90 → 1.1.0-beta.93
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.
- package/dist/index.js +3 -3
- package/dist/lib/PointsEntry.js +36 -5
- package/dist/lib/Right.js +2 -2
- package/dist/lib/headerPoints.js +40 -3
- package/package.json +15 -15
package/dist/index.js
CHANGED
|
@@ -41,8 +41,8 @@ async function HeaderBar({
|
|
|
41
41
|
}
|
|
42
42
|
return /* @__PURE__ */ jsxs(HeaderProvider, { brand, children: [
|
|
43
43
|
/* @__PURE__ */ jsxs("div", { className: twMerge("sticky left-0 right-0 top-0 bg-background h-16 z-999", source === HeaderSource.CHAT ? "hidden md:block flex-1" : "block", className), children: [
|
|
44
|
-
/* @__PURE__ */ jsxs("div", { className: "md:bg-card h-13 text-center flex flex-
|
|
45
|
-
/* @__PURE__ */ jsxs("div", { className: twMerge("items-center gap-6", source === HeaderSource.CHAT ? "hidden md:flex" : "flex"), children: [
|
|
44
|
+
/* @__PURE__ */ jsxs("div", { className: "md:bg-card h-13 w-full text-center flex flex-nowrap justify-between items-center gap-2 md:gap-10 px-4", children: [
|
|
45
|
+
/* @__PURE__ */ jsxs("div", { className: twMerge("items-center gap-6 shrink-0", source === HeaderSource.CHAT ? "hidden md:flex" : "flex"), children: [
|
|
46
46
|
/* @__PURE__ */ jsx(Logo, {}),
|
|
47
47
|
children
|
|
48
48
|
] }),
|
|
@@ -50,7 +50,7 @@ async function HeaderBar({
|
|
|
50
50
|
] }),
|
|
51
51
|
extra
|
|
52
52
|
] }),
|
|
53
|
-
/* @__PURE__ */ jsx("div", { className: twMerge(source === HeaderSource.CHAT ? "
|
|
53
|
+
/* @__PURE__ */ jsx("div", { className: twMerge(source === HeaderSource.CHAT ? "flex justify-end md:hidden" : "hidden"), children: /* @__PURE__ */ jsx(Right, { hideNews, source, hideLogin, user: userInfo?.data || {} }) })
|
|
54
54
|
] });
|
|
55
55
|
}
|
|
56
56
|
export {
|
package/dist/lib/PointsEntry.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
3
4
|
import LinkBar from "@0xchain/link";
|
|
4
5
|
import Translation from "@0xchain/translation";
|
|
5
6
|
import ImageBar from "@0xchain/image";
|
|
7
|
+
import request from "@0xchain/request";
|
|
6
8
|
import { twMerge } from "tailwind-merge";
|
|
7
|
-
import {
|
|
8
|
-
import { HEADER_POINTS_ICON, formatHeaderPoints } from "./headerPoints.js";
|
|
9
|
+
import { headerPointsShowAmount, hasTrustedHeaderPoints, formatHeaderPoints, HEADER_POINTS_ICON, HEADER_POINTS_OVERVIEW_PATH, pointsTextFromOverview } from "./headerPoints.js";
|
|
9
10
|
import { useIsChaindigg } from "./context.js";
|
|
10
11
|
function PointsEntry({
|
|
11
12
|
userInfo,
|
|
@@ -13,7 +14,37 @@ function PointsEntry({
|
|
|
13
14
|
onClick
|
|
14
15
|
}) {
|
|
15
16
|
const isChaindigg = useIsChaindigg();
|
|
16
|
-
|
|
17
|
+
const showAmount = headerPointsShowAmount(userInfo);
|
|
18
|
+
const [pointsText, setPointsText] = useState(
|
|
19
|
+
() => showAmount && hasTrustedHeaderPoints(userInfo) ? formatHeaderPoints(userInfo) : ""
|
|
20
|
+
);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isChaindigg || !showAmount) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let cancelled = false;
|
|
26
|
+
const load = () => {
|
|
27
|
+
request.get(HEADER_POINTS_OVERVIEW_PATH).then((res) => {
|
|
28
|
+
if (cancelled) return;
|
|
29
|
+
const next = pointsTextFromOverview(res);
|
|
30
|
+
if (next != null) {
|
|
31
|
+
setPointsText(next);
|
|
32
|
+
}
|
|
33
|
+
}).catch(() => void 0);
|
|
34
|
+
};
|
|
35
|
+
load();
|
|
36
|
+
const onRefresh = () => load();
|
|
37
|
+
window.addEventListener("user-profile-updated", onRefresh);
|
|
38
|
+
window.addEventListener("xchain-response-toast", onRefresh);
|
|
39
|
+
window.addEventListener("focus", onRefresh);
|
|
40
|
+
return () => {
|
|
41
|
+
cancelled = true;
|
|
42
|
+
window.removeEventListener("user-profile-updated", onRefresh);
|
|
43
|
+
window.removeEventListener("xchain-response-toast", onRefresh);
|
|
44
|
+
window.removeEventListener("focus", onRefresh);
|
|
45
|
+
};
|
|
46
|
+
}, [isChaindigg, showAmount, userInfo?.id, userInfo?.userId]);
|
|
47
|
+
if (isChaindigg) {
|
|
17
48
|
return null;
|
|
18
49
|
}
|
|
19
50
|
return /* @__PURE__ */ jsxs(
|
|
@@ -39,9 +70,9 @@ function PointsEntry({
|
|
|
39
70
|
),
|
|
40
71
|
/* @__PURE__ */ jsxs("span", { className: "text-foreground", children: [
|
|
41
72
|
/* @__PURE__ */ jsx(Translation, { value: "points", parentKey: "account" }),
|
|
42
|
-
": "
|
|
73
|
+
showAmount ? ": " : null
|
|
43
74
|
] }),
|
|
44
|
-
/* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children:
|
|
75
|
+
showAmount ? /* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children: pointsText }) : null
|
|
45
76
|
]
|
|
46
77
|
}
|
|
47
78
|
);
|
package/dist/lib/Right.js
CHANGED
|
@@ -21,8 +21,8 @@ function Right({
|
|
|
21
21
|
const { userInfo } = useHeaderUser(user);
|
|
22
22
|
const showPoints = !hideLogin;
|
|
23
23
|
return /* @__PURE__ */ jsxs("div", { className: twMerge(
|
|
24
|
-
"flex items-center gap-2 z-1001",
|
|
25
|
-
source === "chat" ? "" : "md:flex-1 md:justify-start md:gap-10"
|
|
24
|
+
"flex items-center justify-end gap-2 z-1001 ml-auto shrink-0",
|
|
25
|
+
source === "chat" ? "" : "md:flex-1 md:ml-0 md:justify-start md:gap-10"
|
|
26
26
|
), children: [
|
|
27
27
|
showPoints ? /* @__PURE__ */ jsx(PointsEntry, { userInfo, className: "md:hidden" }) : null,
|
|
28
28
|
/* @__PURE__ */ jsx(Drawer, { hideLogin, hideNews, user: userInfo }),
|
package/dist/lib/headerPoints.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
const HEADER_POINTS_OVERVIEW_PATH = "/api/account/points/overview";
|
|
2
|
+
const HEADER_POINTS_ICON = `${process.env.NEXT_PUBLIC_CDN_URL || ""}/uploads/2026/08/31/6a952e3b78f30.png`;
|
|
1
3
|
function formatHeaderPoints(userInfo) {
|
|
2
4
|
const display = userInfo?.displayBalance;
|
|
3
5
|
if (typeof display === "string" && display.trim()) {
|
|
4
6
|
return display.trim();
|
|
5
7
|
}
|
|
6
|
-
const points = Number(userInfo?.points);
|
|
8
|
+
const points = Number(userInfo?.points ?? userInfo?.balance);
|
|
7
9
|
if (!Number.isFinite(points) || points < 0) {
|
|
8
10
|
return "0";
|
|
9
11
|
}
|
|
@@ -12,8 +14,43 @@ function formatHeaderPoints(userInfo) {
|
|
|
12
14
|
}
|
|
13
15
|
return String(Math.trunc(points));
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
function headerPointsShowAmount(userInfo) {
|
|
18
|
+
return Boolean(userInfo?.id || userInfo?.userId);
|
|
19
|
+
}
|
|
20
|
+
function hasTrustedHeaderPoints(userInfo) {
|
|
21
|
+
if (typeof userInfo?.displayBalance === "string" && userInfo.displayBalance.trim() && userInfo.displayBalance !== "0") {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
const points = Number(userInfo?.points ?? userInfo?.balance);
|
|
25
|
+
return Number.isFinite(points) && points > 0;
|
|
26
|
+
}
|
|
27
|
+
function pointsTextFromOverview(res) {
|
|
28
|
+
if (!res || typeof res !== "object") {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const root = res;
|
|
32
|
+
const statusCode = Number(root.status?.code);
|
|
33
|
+
if (Number.isFinite(statusCode) && statusCode !== 0 && statusCode !== 200) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const payload = root.data && typeof root.data === "object" ? root.data : root;
|
|
37
|
+
if (!payload || typeof payload !== "object") {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const data = payload;
|
|
41
|
+
if (typeof data.balance === "undefined" && typeof data.displayBalance !== "string") {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return formatHeaderPoints({
|
|
45
|
+
displayBalance: data.displayBalance,
|
|
46
|
+
points: data.balance
|
|
47
|
+
});
|
|
48
|
+
}
|
|
16
49
|
export {
|
|
17
50
|
HEADER_POINTS_ICON,
|
|
18
|
-
|
|
51
|
+
HEADER_POINTS_OVERVIEW_PATH,
|
|
52
|
+
formatHeaderPoints,
|
|
53
|
+
hasTrustedHeaderPoints,
|
|
54
|
+
headerPointsShowAmount,
|
|
55
|
+
pointsTextFromOverview
|
|
19
56
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xchain/header",
|
|
3
|
-
"version": "1.1.0-beta.
|
|
3
|
+
"version": "1.1.0-beta.93",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"react": "19.1.1",
|
|
27
27
|
"react-dom": "19.1.1",
|
|
28
28
|
"tailwind-merge": "3.3.1",
|
|
29
|
-
"@0xchain/with-login": "1.1.0-beta.
|
|
29
|
+
"@0xchain/with-login": "1.1.0-beta.93"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@0xchain/next-themes": "1.0.0",
|
|
@@ -41,21 +41,21 @@
|
|
|
41
41
|
"react-dom": "19.1.1",
|
|
42
42
|
"rollup-plugin-preserve-use-client": "3.0.1",
|
|
43
43
|
"tailwind-merge": "3.3.1",
|
|
44
|
-
"@0xchain/with-login": "1.1.0-beta.
|
|
44
|
+
"@0xchain/with-login": "1.1.0-beta.93"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@0xchain/
|
|
48
|
-
"@0xchain/
|
|
49
|
-
"@0xchain/iconfont": "1.1.0-beta.
|
|
50
|
-
"@0xchain/
|
|
51
|
-
"@0xchain/i18n": "1.1.0-beta.
|
|
52
|
-
"@0xchain/
|
|
53
|
-
"@0xchain/
|
|
54
|
-
"@0xchain/
|
|
55
|
-
"@0xchain/
|
|
56
|
-
"@0xchain/
|
|
57
|
-
"@0xchain/
|
|
58
|
-
"@0xchain/
|
|
47
|
+
"@0xchain/better-link": "1.1.0-beta.93",
|
|
48
|
+
"@0xchain/avatar": "1.1.0-beta.93",
|
|
49
|
+
"@0xchain/iconfont": "1.1.0-beta.93",
|
|
50
|
+
"@0xchain/image": "1.1.0-beta.93",
|
|
51
|
+
"@0xchain/i18n": "1.1.0-beta.93",
|
|
52
|
+
"@0xchain/theme-toggle": "1.1.0-beta.93",
|
|
53
|
+
"@0xchain/link": "1.1.0-beta.93",
|
|
54
|
+
"@0xchain/request": "1.1.0-beta.93",
|
|
55
|
+
"@0xchain/tooltip": "1.1.0-beta.93",
|
|
56
|
+
"@0xchain/auth": "1.1.0-beta.93",
|
|
57
|
+
"@0xchain/translation": "1.1.0-beta.93",
|
|
58
|
+
"@0xchain/ui": "1.1.0-beta.93"
|
|
59
59
|
},
|
|
60
60
|
"nx": {
|
|
61
61
|
"tags": [
|