@0xchain/header 1.1.0-beta.91 → 1.1.0-beta.94
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 +6 -5
- package/dist/lib/PointsEntry.js +47 -29
- package/dist/lib/Right.js +4 -10
- package/dist/lib/headerPoints.js +4 -0
- package/dist/lib/headerSource.js +13 -0
- package/package.json +15 -15
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { twMerge } from "tailwind-merge";
|
|
3
3
|
import request from "@0xchain/request";
|
|
4
|
-
import Right
|
|
4
|
+
import Right 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
8
|
import { createSessionFromCookieGetter } from "@0xchain/auth";
|
|
9
|
+
import { isChatHeaderSource, HeaderSource } from "./lib/headerSource.js";
|
|
9
10
|
import { USER_EVENTS, emitUserEvent, onUserEvent } from "./lib/events.js";
|
|
10
11
|
async function HeaderBar({
|
|
11
12
|
extra,
|
|
@@ -40,9 +41,9 @@ async function HeaderBar({
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
return /* @__PURE__ */ jsxs(HeaderProvider, { brand, children: [
|
|
43
|
-
/* @__PURE__ */ jsxs("div", { className: twMerge("sticky left-0 right-0 top-0 bg-background h-16 z-999", source
|
|
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
|
|
44
|
+
/* @__PURE__ */ jsxs("div", { className: twMerge("sticky left-0 right-0 top-0 bg-background h-16 z-999", isChatHeaderSource(source) ? "hidden md:block flex-1" : "block", className), children: [
|
|
45
|
+
/* @__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: [
|
|
46
|
+
/* @__PURE__ */ jsxs("div", { className: twMerge("items-center gap-6 shrink-0", isChatHeaderSource(source) ? "hidden md:flex" : "flex"), children: [
|
|
46
47
|
/* @__PURE__ */ jsx(Logo, {}),
|
|
47
48
|
children
|
|
48
49
|
] }),
|
|
@@ -50,7 +51,7 @@ async function HeaderBar({
|
|
|
50
51
|
] }),
|
|
51
52
|
extra
|
|
52
53
|
] }),
|
|
53
|
-
/* @__PURE__ */ jsx("div", { className: twMerge(source
|
|
54
|
+
/* @__PURE__ */ jsx("div", { className: twMerge(isChatHeaderSource(source) ? "flex justify-end md:hidden" : "hidden"), children: /* @__PURE__ */ jsx(Right, { hideNews, source, hideLogin, user: userInfo?.data || {} }) })
|
|
54
55
|
] });
|
|
55
56
|
}
|
|
56
57
|
export {
|
package/dist/lib/PointsEntry.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsxs,
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useEffect } from "react";
|
|
4
4
|
import LinkBar from "@0xchain/link";
|
|
5
5
|
import Translation from "@0xchain/translation";
|
|
6
6
|
import ImageBar from "@0xchain/image";
|
|
7
7
|
import request from "@0xchain/request";
|
|
8
|
+
import { useLogin, OpenLoginType } from "@0xchain/with-login";
|
|
8
9
|
import { twMerge } from "tailwind-merge";
|
|
9
|
-
import {
|
|
10
|
-
import { hasTrustedHeaderPoints, formatHeaderPoints, HEADER_POINTS_ICON, HEADER_POINTS_OVERVIEW_PATH, pointsTextFromOverview } from "./headerPoints.js";
|
|
10
|
+
import { headerPointsShowAmount, hasTrustedHeaderPoints, formatHeaderPoints, HEADER_POINTS_OVERVIEW_PATH, pointsTextFromOverview, HEADER_POINTS_ICON } from "./headerPoints.js";
|
|
11
11
|
import { useIsChaindigg } from "./context.js";
|
|
12
12
|
function PointsEntry({
|
|
13
13
|
userInfo,
|
|
@@ -15,11 +15,13 @@ function PointsEntry({
|
|
|
15
15
|
onClick
|
|
16
16
|
}) {
|
|
17
17
|
const isChaindigg = useIsChaindigg();
|
|
18
|
+
const { openLogin } = useLogin();
|
|
19
|
+
const showAmount = headerPointsShowAmount(userInfo);
|
|
18
20
|
const [pointsText, setPointsText] = useState(
|
|
19
|
-
() => hasTrustedHeaderPoints(userInfo) ? formatHeaderPoints(userInfo) : ""
|
|
21
|
+
() => showAmount && hasTrustedHeaderPoints(userInfo) ? formatHeaderPoints(userInfo) : ""
|
|
20
22
|
);
|
|
21
23
|
useEffect(() => {
|
|
22
|
-
if (isChaindigg || !
|
|
24
|
+
if (isChaindigg || !showAmount) {
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
27
|
let cancelled = false;
|
|
@@ -43,37 +45,53 @@ function PointsEntry({
|
|
|
43
45
|
window.removeEventListener("xchain-response-toast", onRefresh);
|
|
44
46
|
window.removeEventListener("focus", onRefresh);
|
|
45
47
|
};
|
|
46
|
-
}, [isChaindigg, userInfo?.id, userInfo?.userId]);
|
|
47
|
-
if (isChaindigg
|
|
48
|
+
}, [isChaindigg, showAmount, userInfo?.id, userInfo?.userId]);
|
|
49
|
+
if (isChaindigg) {
|
|
48
50
|
return null;
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
const classNames = twMerge(
|
|
53
|
+
"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 cursor-pointer",
|
|
54
|
+
className
|
|
55
|
+
);
|
|
56
|
+
const content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
57
|
+
/* @__PURE__ */ jsx(
|
|
58
|
+
ImageBar,
|
|
59
|
+
{
|
|
60
|
+
src: HEADER_POINTS_ICON,
|
|
61
|
+
width: 16,
|
|
62
|
+
height: 16,
|
|
63
|
+
alt: "",
|
|
64
|
+
className: "shrink-0"
|
|
65
|
+
}
|
|
66
|
+
),
|
|
67
|
+
/* @__PURE__ */ jsxs("span", { className: "text-foreground", children: [
|
|
68
|
+
/* @__PURE__ */ jsx(Translation, { value: "points", parentKey: "account" }),
|
|
69
|
+
showAmount ? ": " : null
|
|
70
|
+
] }),
|
|
71
|
+
showAmount ? /* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children: pointsText }) : null
|
|
72
|
+
] });
|
|
73
|
+
if (!showAmount) {
|
|
74
|
+
return /* @__PURE__ */ jsx(
|
|
75
|
+
"button",
|
|
76
|
+
{
|
|
77
|
+
type: "button",
|
|
78
|
+
className: classNames,
|
|
79
|
+
onClick: (e) => {
|
|
80
|
+
onClick?.(e);
|
|
81
|
+
openLogin(OpenLoginType.LOGIN);
|
|
82
|
+
},
|
|
83
|
+
children: content
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return /* @__PURE__ */ jsx(
|
|
51
88
|
LinkBar,
|
|
52
89
|
{
|
|
53
90
|
href: "/user-center/points",
|
|
54
91
|
baseUrl: process.env.NEXT_PUBLIC_AUTH_URL,
|
|
55
92
|
onClick,
|
|
56
|
-
className:
|
|
57
|
-
|
|
58
|
-
className
|
|
59
|
-
),
|
|
60
|
-
children: [
|
|
61
|
-
/* @__PURE__ */ jsx(
|
|
62
|
-
ImageBar,
|
|
63
|
-
{
|
|
64
|
-
src: HEADER_POINTS_ICON,
|
|
65
|
-
width: 16,
|
|
66
|
-
height: 16,
|
|
67
|
-
alt: "",
|
|
68
|
-
className: "shrink-0"
|
|
69
|
-
}
|
|
70
|
-
),
|
|
71
|
-
/* @__PURE__ */ jsxs("span", { className: "text-foreground", children: [
|
|
72
|
-
/* @__PURE__ */ jsx(Translation, { value: "points", parentKey: "account" }),
|
|
73
|
-
": "
|
|
74
|
-
] }),
|
|
75
|
-
/* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children: pointsText })
|
|
76
|
-
]
|
|
93
|
+
className: classNames,
|
|
94
|
+
children: content
|
|
77
95
|
}
|
|
78
96
|
);
|
|
79
97
|
}
|
package/dist/lib/Right.js
CHANGED
|
@@ -5,24 +5,18 @@ import Drawer from "./Drawer.js";
|
|
|
5
5
|
import PointsEntry from "./PointsEntry.js";
|
|
6
6
|
import { twMerge } from "tailwind-merge";
|
|
7
7
|
import { useHeaderUser } from "./useHeaderUser.js";
|
|
8
|
-
|
|
9
|
-
HeaderSource2["EXPLORER"] = "explorer";
|
|
10
|
-
HeaderSource2["CHAT"] = "chat";
|
|
11
|
-
HeaderSource2["DEFAULT"] = "default";
|
|
12
|
-
return HeaderSource2;
|
|
13
|
-
})(HeaderSource || {});
|
|
8
|
+
import { isChatHeaderSource, HeaderSource } from "./headerSource.js";
|
|
14
9
|
function Right({
|
|
15
10
|
hideNews = false,
|
|
16
11
|
hideLogin = false,
|
|
17
12
|
user,
|
|
18
|
-
source =
|
|
19
|
-
/* DEFAULT */
|
|
13
|
+
source = HeaderSource.DEFAULT
|
|
20
14
|
}) {
|
|
21
15
|
const { userInfo } = useHeaderUser(user);
|
|
22
16
|
const showPoints = !hideLogin;
|
|
23
17
|
return /* @__PURE__ */ jsxs("div", { className: twMerge(
|
|
24
|
-
"flex items-center gap-2 z-1001",
|
|
25
|
-
source
|
|
18
|
+
"flex items-center justify-end gap-2 z-1001 ml-auto shrink-0",
|
|
19
|
+
isChatHeaderSource(source) ? "" : "md:flex-1 md:ml-0 md:justify-start md:gap-10"
|
|
26
20
|
), children: [
|
|
27
21
|
showPoints ? /* @__PURE__ */ jsx(PointsEntry, { userInfo, className: "md:hidden" }) : null,
|
|
28
22
|
/* @__PURE__ */ jsx(Drawer, { hideLogin, hideNews, user: userInfo }),
|
package/dist/lib/headerPoints.js
CHANGED
|
@@ -14,6 +14,9 @@ function formatHeaderPoints(userInfo) {
|
|
|
14
14
|
}
|
|
15
15
|
return String(Math.trunc(points));
|
|
16
16
|
}
|
|
17
|
+
function headerPointsShowAmount(userInfo) {
|
|
18
|
+
return Boolean(userInfo?.id || userInfo?.userId);
|
|
19
|
+
}
|
|
17
20
|
function hasTrustedHeaderPoints(userInfo) {
|
|
18
21
|
if (typeof userInfo?.displayBalance === "string" && userInfo.displayBalance.trim() && userInfo.displayBalance !== "0") {
|
|
19
22
|
return true;
|
|
@@ -48,5 +51,6 @@ export {
|
|
|
48
51
|
HEADER_POINTS_OVERVIEW_PATH,
|
|
49
52
|
formatHeaderPoints,
|
|
50
53
|
hasTrustedHeaderPoints,
|
|
54
|
+
headerPointsShowAmount,
|
|
51
55
|
pointsTextFromOverview
|
|
52
56
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var HeaderSource = /* @__PURE__ */ ((HeaderSource2) => {
|
|
2
|
+
HeaderSource2["EXPLORER"] = "explorer";
|
|
3
|
+
HeaderSource2["CHAT"] = "chat";
|
|
4
|
+
HeaderSource2["DEFAULT"] = "default";
|
|
5
|
+
return HeaderSource2;
|
|
6
|
+
})(HeaderSource || {});
|
|
7
|
+
function isChatHeaderSource(source) {
|
|
8
|
+
return source === "chat";
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
HeaderSource,
|
|
12
|
+
isChatHeaderSource
|
|
13
|
+
};
|
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.94",
|
|
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.94"
|
|
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.94"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@0xchain/auth": "1.1.0-beta.
|
|
48
|
-
"@0xchain/
|
|
49
|
-
"@0xchain/
|
|
50
|
-
"@0xchain/
|
|
51
|
-
"@0xchain/
|
|
52
|
-
"@0xchain/
|
|
53
|
-
"@0xchain/
|
|
54
|
-
"@0xchain/
|
|
55
|
-
"@0xchain/
|
|
56
|
-
"@0xchain/
|
|
57
|
-
"@0xchain/
|
|
58
|
-
"@0xchain/
|
|
47
|
+
"@0xchain/auth": "1.1.0-beta.94",
|
|
48
|
+
"@0xchain/avatar": "1.1.0-beta.94",
|
|
49
|
+
"@0xchain/better-link": "1.1.0-beta.94",
|
|
50
|
+
"@0xchain/i18n": "1.1.0-beta.94",
|
|
51
|
+
"@0xchain/theme-toggle": "1.1.0-beta.94",
|
|
52
|
+
"@0xchain/image": "1.1.0-beta.94",
|
|
53
|
+
"@0xchain/link": "1.1.0-beta.94",
|
|
54
|
+
"@0xchain/ui": "1.1.0-beta.94",
|
|
55
|
+
"@0xchain/request": "1.1.0-beta.94",
|
|
56
|
+
"@0xchain/iconfont": "1.1.0-beta.94",
|
|
57
|
+
"@0xchain/tooltip": "1.1.0-beta.94",
|
|
58
|
+
"@0xchain/translation": "1.1.0-beta.94"
|
|
59
59
|
},
|
|
60
60
|
"nx": {
|
|
61
61
|
"tags": [
|