@0xchain/header 1.1.0-beta.89 → 1.1.0-beta.90
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/lib/Nav.js +5 -32
- package/dist/lib/PointsEntry.js +51 -0
- package/dist/lib/Right.js +12 -3
- package/dist/lib/headerPoints.js +19 -0
- package/dist/lib/useHeaderUser.js +44 -0
- package/package.json +15 -15
package/dist/lib/Nav.js
CHANGED
|
@@ -8,23 +8,20 @@ import { twMerge } from "tailwind-merge";
|
|
|
8
8
|
import BetterLink from "@0xchain/better-link";
|
|
9
9
|
import { useLocale } from "@0xchain/i18n/react";
|
|
10
10
|
import Logout from "./User/Logout.js";
|
|
11
|
-
import { useState
|
|
11
|
+
import { useState } from "react";
|
|
12
12
|
import SignIn from "./User/SignIn.js";
|
|
13
|
-
import { getClientSession, getRuntimeLoginState } from "@0xchain/auth";
|
|
14
|
-
import { onUserEvent, USER_EVENTS } from "./events.js";
|
|
15
13
|
import { usePathname } from "next/navigation";
|
|
16
14
|
import Explorer from "./Explorer.js";
|
|
17
15
|
import Products from "./Products.js";
|
|
16
|
+
import PointsEntry from "./PointsEntry.js";
|
|
18
17
|
import { useIsChaindigg } from "./context.js";
|
|
19
|
-
import {
|
|
18
|
+
import { useHeaderUser } from "./useHeaderUser.js";
|
|
20
19
|
function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user }) {
|
|
21
20
|
const isChaindigg = useIsChaindigg();
|
|
22
21
|
const { gotoAISQL, gotoChat } = BetterLink();
|
|
23
22
|
const locale = useLocale();
|
|
24
23
|
const pathname = usePathname();
|
|
25
|
-
const
|
|
26
|
-
const [userInfo, setUserInfo] = useState(user);
|
|
27
|
-
const hasUserProfile = hasProfileIdentity(userInfo);
|
|
24
|
+
const { userInfo, hasUserProfile, userKey } = useHeaderUser(user);
|
|
28
25
|
const [, setExplorerExpanded] = useState(false);
|
|
29
26
|
const ichaingoNavList = [
|
|
30
27
|
{
|
|
@@ -105,31 +102,6 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
105
102
|
}
|
|
106
103
|
];
|
|
107
104
|
const NavList = isChaindigg ? chaindiggNavList : ichaingoNavList;
|
|
108
|
-
const updateUserInfo = useCallback(async () => {
|
|
109
|
-
try {
|
|
110
|
-
const profile = await fetchHeaderProfile();
|
|
111
|
-
setUserInfo(profile || {});
|
|
112
|
-
setUserKey((/* @__PURE__ */ new Date()).getTime().toString());
|
|
113
|
-
return profile;
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.error(error);
|
|
116
|
-
setUserInfo({});
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
}, []);
|
|
120
|
-
useEffect(() => {
|
|
121
|
-
if (isChaindigg) return;
|
|
122
|
-
const cleanProfileUpdated = onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
123
|
-
const cleanLoggedIn = onUserEvent(USER_EVENTS.LOGGED_IN, updateUserInfo);
|
|
124
|
-
const cookieLoggedIn = getClientSession().isLoggedIn;
|
|
125
|
-
if (!hasUserProfile && (cookieLoggedIn || getRuntimeLoginState() === true)) {
|
|
126
|
-
updateUserInfo();
|
|
127
|
-
}
|
|
128
|
-
return () => {
|
|
129
|
-
cleanProfileUpdated();
|
|
130
|
-
cleanLoggedIn();
|
|
131
|
-
};
|
|
132
|
-
}, [hasUserProfile, isChaindigg, updateUserInfo]);
|
|
133
105
|
if (isChaindigg) {
|
|
134
106
|
return /* @__PURE__ */ jsxs(
|
|
135
107
|
"nav",
|
|
@@ -228,6 +200,7 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
228
200
|
})
|
|
229
201
|
}
|
|
230
202
|
),
|
|
203
|
+
!pathname.includes("/login") && !hideLogin ? /* @__PURE__ */ jsx(PointsEntry, { userInfo, className: "hidden md:inline-flex", onClick }) : null,
|
|
231
204
|
/* @__PURE__ */ jsx(Setting, { onClick }),
|
|
232
205
|
!pathname.includes("/login") && !hideLogin ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
233
206
|
/* @__PURE__ */ jsx(UserControl, { onClick, userInfo }, userKey),
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
3
|
+
import LinkBar from "@0xchain/link";
|
|
4
|
+
import Translation from "@0xchain/translation";
|
|
5
|
+
import ImageBar from "@0xchain/image";
|
|
6
|
+
import { twMerge } from "tailwind-merge";
|
|
7
|
+
import { hasProfileIdentity } from "./authProfile.js";
|
|
8
|
+
import { HEADER_POINTS_ICON, formatHeaderPoints } from "./headerPoints.js";
|
|
9
|
+
import { useIsChaindigg } from "./context.js";
|
|
10
|
+
function PointsEntry({
|
|
11
|
+
userInfo,
|
|
12
|
+
className,
|
|
13
|
+
onClick
|
|
14
|
+
}) {
|
|
15
|
+
const isChaindigg = useIsChaindigg();
|
|
16
|
+
if (isChaindigg || !hasProfileIdentity(userInfo)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return /* @__PURE__ */ jsxs(
|
|
20
|
+
LinkBar,
|
|
21
|
+
{
|
|
22
|
+
href: "/user-center/points",
|
|
23
|
+
baseUrl: process.env.NEXT_PUBLIC_AUTH_URL,
|
|
24
|
+
onClick,
|
|
25
|
+
className: twMerge(
|
|
26
|
+
"inline-flex shrink-0 items-center gap-1 h-8 px-3 rounded-full border border-primary/30 bg-background hover:bg-primary/5 text-sm whitespace-nowrap",
|
|
27
|
+
className
|
|
28
|
+
),
|
|
29
|
+
children: [
|
|
30
|
+
/* @__PURE__ */ jsx(
|
|
31
|
+
ImageBar,
|
|
32
|
+
{
|
|
33
|
+
src: HEADER_POINTS_ICON,
|
|
34
|
+
width: 16,
|
|
35
|
+
height: 16,
|
|
36
|
+
alt: "",
|
|
37
|
+
className: "shrink-0"
|
|
38
|
+
}
|
|
39
|
+
),
|
|
40
|
+
/* @__PURE__ */ jsxs("span", { className: "text-foreground", children: [
|
|
41
|
+
/* @__PURE__ */ jsx(Translation, { value: "points", parentKey: "account" }),
|
|
42
|
+
": "
|
|
43
|
+
] }),
|
|
44
|
+
/* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children: formatHeaderPoints(userInfo) })
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
PointsEntry as default
|
|
51
|
+
};
|
package/dist/lib/Right.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
3
|
import Nav from "./Nav.js";
|
|
3
4
|
import Drawer from "./Drawer.js";
|
|
5
|
+
import PointsEntry from "./PointsEntry.js";
|
|
4
6
|
import { twMerge } from "tailwind-merge";
|
|
7
|
+
import { useHeaderUser } from "./useHeaderUser.js";
|
|
5
8
|
var HeaderSource = /* @__PURE__ */ ((HeaderSource2) => {
|
|
6
9
|
HeaderSource2["EXPLORER"] = "explorer";
|
|
7
10
|
HeaderSource2["CHAT"] = "chat";
|
|
@@ -15,9 +18,15 @@ function Right({
|
|
|
15
18
|
source = "default"
|
|
16
19
|
/* DEFAULT */
|
|
17
20
|
}) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const { userInfo } = useHeaderUser(user);
|
|
22
|
+
const showPoints = !hideLogin;
|
|
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"
|
|
26
|
+
), children: [
|
|
27
|
+
showPoints ? /* @__PURE__ */ jsx(PointsEntry, { userInfo, className: "md:hidden" }) : null,
|
|
28
|
+
/* @__PURE__ */ jsx(Drawer, { hideLogin, hideNews, user: userInfo }),
|
|
29
|
+
/* @__PURE__ */ jsx("div", { className: "hidden md:block flex-1", children: /* @__PURE__ */ jsx(Nav, { hideNews, hideLogin, user: userInfo }) })
|
|
21
30
|
] });
|
|
22
31
|
}
|
|
23
32
|
export {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function formatHeaderPoints(userInfo) {
|
|
2
|
+
const display = userInfo?.displayBalance;
|
|
3
|
+
if (typeof display === "string" && display.trim()) {
|
|
4
|
+
return display.trim();
|
|
5
|
+
}
|
|
6
|
+
const points = Number(userInfo?.points);
|
|
7
|
+
if (!Number.isFinite(points) || points < 0) {
|
|
8
|
+
return "0";
|
|
9
|
+
}
|
|
10
|
+
if (points > 99999) {
|
|
11
|
+
return "99999";
|
|
12
|
+
}
|
|
13
|
+
return String(Math.trunc(points));
|
|
14
|
+
}
|
|
15
|
+
const HEADER_POINTS_ICON = `${process.env.NEXT_PUBLIC_CDN_URL || ""}/uploads/2026/08/31/6a952e3b78f30.png`;
|
|
16
|
+
export {
|
|
17
|
+
HEADER_POINTS_ICON,
|
|
18
|
+
formatHeaderPoints
|
|
19
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useState, useCallback, useEffect } from "react";
|
|
3
|
+
import { getClientSession, getRuntimeLoginState } from "@0xchain/auth";
|
|
4
|
+
import { hasProfileIdentity, fetchHeaderProfile } from "./authProfile.js";
|
|
5
|
+
import { onUserEvent, USER_EVENTS } from "./events.js";
|
|
6
|
+
import { useIsChaindigg } from "./context.js";
|
|
7
|
+
function useHeaderUser(user) {
|
|
8
|
+
const isChaindigg = useIsChaindigg();
|
|
9
|
+
const [userKey, setUserKey] = useState("");
|
|
10
|
+
const [userInfo, setUserInfo] = useState(user);
|
|
11
|
+
const hasUserProfile = hasProfileIdentity(userInfo);
|
|
12
|
+
const updateUserInfo = useCallback(async () => {
|
|
13
|
+
try {
|
|
14
|
+
const profile = await fetchHeaderProfile();
|
|
15
|
+
setUserInfo(profile || {});
|
|
16
|
+
setUserKey((/* @__PURE__ */ new Date()).getTime().toString());
|
|
17
|
+
return profile;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error);
|
|
20
|
+
setUserInfo({});
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}, []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
setUserInfo(user);
|
|
26
|
+
}, [user]);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (isChaindigg) return;
|
|
29
|
+
const cleanProfileUpdated = onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
30
|
+
const cleanLoggedIn = onUserEvent(USER_EVENTS.LOGGED_IN, updateUserInfo);
|
|
31
|
+
const cookieLoggedIn = getClientSession().isLoggedIn;
|
|
32
|
+
if (!hasUserProfile && (cookieLoggedIn || getRuntimeLoginState() === true)) {
|
|
33
|
+
updateUserInfo();
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
cleanProfileUpdated();
|
|
37
|
+
cleanLoggedIn();
|
|
38
|
+
};
|
|
39
|
+
}, [hasUserProfile, isChaindigg, updateUserInfo]);
|
|
40
|
+
return { userInfo, hasUserProfile, userKey };
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
useHeaderUser
|
|
44
|
+
};
|
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.90",
|
|
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.90"
|
|
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.90"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@0xchain/auth": "1.1.0-beta.
|
|
48
|
-
"@0xchain/
|
|
49
|
-
"@0xchain/
|
|
50
|
-
"@0xchain/
|
|
51
|
-
"@0xchain/
|
|
52
|
-
"@0xchain/
|
|
53
|
-
"@0xchain/request": "1.1.0-beta.
|
|
54
|
-
"@0xchain/
|
|
55
|
-
"@0xchain/
|
|
56
|
-
"@0xchain/translation": "1.1.0-beta.
|
|
57
|
-
"@0xchain/ui": "1.1.0-beta.
|
|
58
|
-
"@0xchain/
|
|
47
|
+
"@0xchain/auth": "1.1.0-beta.90",
|
|
48
|
+
"@0xchain/better-link": "1.1.0-beta.90",
|
|
49
|
+
"@0xchain/iconfont": "1.1.0-beta.90",
|
|
50
|
+
"@0xchain/avatar": "1.1.0-beta.90",
|
|
51
|
+
"@0xchain/i18n": "1.1.0-beta.90",
|
|
52
|
+
"@0xchain/image": "1.1.0-beta.90",
|
|
53
|
+
"@0xchain/request": "1.1.0-beta.90",
|
|
54
|
+
"@0xchain/theme-toggle": "1.1.0-beta.90",
|
|
55
|
+
"@0xchain/link": "1.1.0-beta.90",
|
|
56
|
+
"@0xchain/translation": "1.1.0-beta.90",
|
|
57
|
+
"@0xchain/ui": "1.1.0-beta.90",
|
|
58
|
+
"@0xchain/tooltip": "1.1.0-beta.90"
|
|
59
59
|
},
|
|
60
60
|
"nx": {
|
|
61
61
|
"tags": [
|