@0xchain/header 1.1.0-beta.9 → 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.
@@ -1,24 +1,22 @@
1
- const E = {
1
+ const USER_EVENTS = {
2
2
  PROFILE_UPDATED: "user-profile-updated",
3
3
  LOGGED_IN: "user-logged-in",
4
4
  LOGGED_OUT: "user-logged-out"
5
5
  };
6
- function i(e, n) {
7
- const t = new CustomEvent(e, { detail: n });
8
- window.dispatchEvent(t);
6
+ function emitUserEvent(eventName, data) {
7
+ const event = new CustomEvent(eventName, { detail: data });
8
+ window.dispatchEvent(event);
9
9
  }
10
- function r(e, n) {
11
- const t = (o) => {
12
- n(o.detail);
10
+ function onUserEvent(eventName, callback) {
11
+ const handler = (event) => {
12
+ const customEvent = event;
13
+ callback(customEvent.detail);
13
14
  };
14
- return window.addEventListener(e, t), () => window.removeEventListener(e, t);
15
- }
16
- function d(e, n) {
17
- window.removeEventListener(e, n);
15
+ window.addEventListener(eventName, handler);
16
+ return () => window.removeEventListener(eventName, handler);
18
17
  }
19
18
  export {
20
- E as USER_EVENTS,
21
- d as cleanUserEvent,
22
- i as emitUserEvent,
23
- r as onUserEvent
19
+ USER_EVENTS,
20
+ emitUserEvent,
21
+ onUserEvent
24
22
  };
@@ -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.9",
3
+ "version": "1.1.0-beta.90",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -17,34 +17,50 @@
17
17
  "dist",
18
18
  "!**/*.tsbuildinfo"
19
19
  ],
20
- "devDependencies": {
21
- "rollup-plugin-preserve-use-client": "3.0.1",
22
- "@types/js-cookie": "3.0.6"
20
+ "peerDependencies": {
21
+ "antd": "6.1.1",
22
+ "lucide-react": "0.539.0",
23
+ "next": "16.1.6",
24
+ "next-intl": "4.13.0",
25
+ "rc-drawer": "7.3.0",
26
+ "react": "19.1.1",
27
+ "react-dom": "19.1.1",
28
+ "tailwind-merge": "3.3.1",
29
+ "@0xchain/with-login": "1.1.0-beta.90"
23
30
  },
24
- "dependencies": {
31
+ "devDependencies": {
32
+ "@0xchain/next-themes": "1.0.0",
33
+ "@types/js-cookie": "3.0.6",
34
+ "antd": "6.1.1",
25
35
  "js-cookie": "3.0.5",
26
36
  "lucide-react": "0.539.0",
27
- "next-intl": "4.8.2",
28
- "@0xchain/next-themes": "1.0.0",
37
+ "next": "16.1.6",
38
+ "next-intl": "4.13.0",
29
39
  "rc-drawer": "7.3.0",
30
40
  "react": "19.1.1",
31
41
  "react-dom": "19.1.1",
42
+ "rollup-plugin-preserve-use-client": "3.0.1",
32
43
  "tailwind-merge": "3.3.1",
33
- "next": "16.1.6",
34
- "antd": "6.1.1",
35
- "@0xchain/auth": "1.1.0-beta.9",
36
- "@0xchain/better-link": "1.1.0-beta.9",
37
- "@0xchain/image": "1.1.0-beta.9",
38
- "@0xchain/translation": "1.1.0-beta.9",
39
- "@0xchain/link": "1.1.0-beta.9",
40
- "@0xchain/avatar": "1.1.0-beta.9",
41
- "@0xchain/ui": "1.1.0-beta.9",
42
- "@0xchain/theme-toggle": "1.1.0-beta.9",
43
- "@0xchain/iconfont": "1.1.0-beta.9",
44
- "@0xchain/with-login": "1.1.0-beta.9",
45
- "@0xchain/token": "1.1.0-beta.9",
46
- "@0xchain/request": "1.1.0-beta.9",
47
- "@0xchain/tooltip": "1.1.0-beta.9"
44
+ "@0xchain/with-login": "1.1.0-beta.90"
45
+ },
46
+ "dependencies": {
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
+ },
60
+ "nx": {
61
+ "tags": [
62
+ "type:feature"
63
+ ]
48
64
  },
49
65
  "publishConfig": {
50
66
  "access": "public"