@0xchain/header 1.1.0-beta.46 → 1.1.0-beta.48
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 +5 -3
- package/dist/lib/Explorer.js +7 -2
- package/dist/lib/Nav.js +27 -12
- package/dist/lib/events.js +0 -4
- package/package.json +14 -14
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import Right, { HeaderSource } from "./lib/Right.js";
|
|
|
5
5
|
import Logo from "./lib/Logo.js";
|
|
6
6
|
import { cookies } from "next/headers";
|
|
7
7
|
import { HeaderProvider } from "./lib/context.js";
|
|
8
|
+
import { createSessionFromCookieGetter } from "@0xchain/auth";
|
|
8
9
|
import { USER_EVENTS, emitUserEvent, onUserEvent } from "./lib/events.js";
|
|
9
10
|
async function HeaderBar({
|
|
10
11
|
extra,
|
|
@@ -21,9 +22,10 @@ async function HeaderBar({
|
|
|
21
22
|
if (brand !== "CHAINDIGG") {
|
|
22
23
|
try {
|
|
23
24
|
const cookieStore = await cookies();
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const session = createSessionFromCookieGetter(
|
|
26
|
+
(key) => cookieStore.get(key)?.value ?? null
|
|
27
|
+
);
|
|
28
|
+
if (session.isLoggedIn) {
|
|
27
29
|
try {
|
|
28
30
|
userInfo = await request.get("/v2/users/profile", {
|
|
29
31
|
baseURL: process.env.AUTH_INNER_API_URL
|
package/dist/lib/Explorer.js
CHANGED
|
@@ -12,8 +12,13 @@ function Explorer({ onClick = () => void 0, onExpandChange }) {
|
|
|
12
12
|
const [list, setList] = useState([]);
|
|
13
13
|
const [accordionValue, setAccordionValue] = useState("");
|
|
14
14
|
const getList = async () => {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
try {
|
|
16
|
+
const res = await request.get("/api/v2/chains/all-chain-list/basic");
|
|
17
|
+
setList(Array.isArray(res.data) ? res.data : []);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error);
|
|
20
|
+
setList([]);
|
|
21
|
+
}
|
|
17
22
|
};
|
|
18
23
|
const handleClick = (e, item) => {
|
|
19
24
|
e?.preventDefault();
|
package/dist/lib/Nav.js
CHANGED
|
@@ -10,8 +10,8 @@ import { useLocale } from "@0xchain/i18n/react";
|
|
|
10
10
|
import Logout from "./User/Logout.js";
|
|
11
11
|
import { useState, useCallback, useEffect } from "react";
|
|
12
12
|
import SignIn from "./User/SignIn.js";
|
|
13
|
-
import {
|
|
14
|
-
import { onUserEvent, USER_EVENTS
|
|
13
|
+
import { getRuntimeLoginState } from "@0xchain/auth";
|
|
14
|
+
import { onUserEvent, USER_EVENTS } from "./events.js";
|
|
15
15
|
import { usePathname } from "next/navigation";
|
|
16
16
|
import Explorer from "./Explorer.js";
|
|
17
17
|
import Products from "./Products.js";
|
|
@@ -100,22 +100,37 @@ function Nav({ onClick = () => void 0, hideNews = false, hideLogin = false, user
|
|
|
100
100
|
}
|
|
101
101
|
];
|
|
102
102
|
const NavList = isChaindigg ? chaindiggNavList : ichaingoNavList;
|
|
103
|
-
const updateUserInfo = useCallback(() => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
resolve(res);
|
|
103
|
+
const updateUserInfo = useCallback(async () => {
|
|
104
|
+
try {
|
|
105
|
+
const response = await fetch("/api/auth/profile", {
|
|
106
|
+
credentials: "include",
|
|
107
|
+
cache: "no-store"
|
|
109
108
|
});
|
|
110
|
-
|
|
109
|
+
if (!response.ok) {
|
|
110
|
+
throw new Error(`Failed to load profile: ${response.status}`);
|
|
111
|
+
}
|
|
112
|
+
const res = await response.json();
|
|
113
|
+
setUserInfo(res || {});
|
|
114
|
+
setUserKey((/* @__PURE__ */ new Date()).getTime().toString());
|
|
115
|
+
return res;
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(error);
|
|
118
|
+
setUserInfo({});
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
111
121
|
}, []);
|
|
112
122
|
useEffect(() => {
|
|
113
123
|
if (isChaindigg) return;
|
|
114
|
-
onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
124
|
+
const cleanProfileUpdated = onUserEvent(USER_EVENTS.PROFILE_UPDATED, updateUserInfo);
|
|
125
|
+
const cleanLoggedIn = onUserEvent(USER_EVENTS.LOGGED_IN, updateUserInfo);
|
|
126
|
+
if (!userInfo?.id && getRuntimeLoginState() === true) {
|
|
127
|
+
updateUserInfo();
|
|
128
|
+
}
|
|
115
129
|
return () => {
|
|
116
|
-
|
|
130
|
+
cleanProfileUpdated();
|
|
131
|
+
cleanLoggedIn();
|
|
117
132
|
};
|
|
118
|
-
}, [isChaindigg]);
|
|
133
|
+
}, [isChaindigg, updateUserInfo, userInfo?.id]);
|
|
119
134
|
if (isChaindigg) {
|
|
120
135
|
return /* @__PURE__ */ jsxs(
|
|
121
136
|
"nav",
|
package/dist/lib/events.js
CHANGED
|
@@ -15,12 +15,8 @@ function onUserEvent(eventName, callback) {
|
|
|
15
15
|
window.addEventListener(eventName, handler);
|
|
16
16
|
return () => window.removeEventListener(eventName, handler);
|
|
17
17
|
}
|
|
18
|
-
function cleanUserEvent(type, handler) {
|
|
19
|
-
window.removeEventListener(type, handler);
|
|
20
|
-
}
|
|
21
18
|
export {
|
|
22
19
|
USER_EVENTS,
|
|
23
|
-
cleanUserEvent,
|
|
24
20
|
emitUserEvent,
|
|
25
21
|
onUserEvent
|
|
26
22
|
};
|
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.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -42,19 +42,19 @@
|
|
|
42
42
|
"tailwind-merge": "3.3.1"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@0xchain/i18n": "1.1.0-beta.
|
|
46
|
-
"@0xchain/auth": "1.1.0-beta.
|
|
47
|
-
"@0xchain/
|
|
48
|
-
"@0xchain/
|
|
49
|
-
"@0xchain/
|
|
50
|
-
"@0xchain/
|
|
51
|
-
"@0xchain/
|
|
52
|
-
"@0xchain/
|
|
53
|
-
"@0xchain/
|
|
54
|
-
"@0xchain/
|
|
55
|
-
"@0xchain/request": "1.1.0-beta.
|
|
56
|
-
"@0xchain/
|
|
57
|
-
"@0xchain/
|
|
45
|
+
"@0xchain/i18n": "1.1.0-beta.48",
|
|
46
|
+
"@0xchain/auth": "1.1.0-beta.48",
|
|
47
|
+
"@0xchain/avatar": "1.1.0-beta.48",
|
|
48
|
+
"@0xchain/better-link": "1.1.0-beta.48",
|
|
49
|
+
"@0xchain/link": "1.1.0-beta.48",
|
|
50
|
+
"@0xchain/translation": "1.1.0-beta.48",
|
|
51
|
+
"@0xchain/ui": "1.1.0-beta.48",
|
|
52
|
+
"@0xchain/theme-toggle": "1.1.0-beta.48",
|
|
53
|
+
"@0xchain/iconfont": "1.1.0-beta.48",
|
|
54
|
+
"@0xchain/image": "1.1.0-beta.48",
|
|
55
|
+
"@0xchain/request": "1.1.0-beta.48",
|
|
56
|
+
"@0xchain/with-login": "1.1.0-beta.48",
|
|
57
|
+
"@0xchain/tooltip": "1.1.0-beta.48"
|
|
58
58
|
},
|
|
59
59
|
"nx": {
|
|
60
60
|
"tags": [
|