@0xchain/header 1.1.0-beta.7 → 1.1.0-beta.70

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present 0xchain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -1,56 +1,62 @@
1
- import { jsxs as t, jsx as o } from "react/jsx-runtime";
2
- import { twMerge as i } from "tailwind-merge";
3
- import k from "@0xchain/request";
4
- import l, { HeaderSource as a } from "./lib/Right.js";
5
- import g from "./lib/Logo.js";
6
- import { cookies as v } from "next/headers";
7
- import { HeaderProvider as E } from "./lib/context.js";
8
- import { USER_EVENTS as w, emitUserEvent as j, onUserEvent as G } from "./lib/events.js";
9
- async function R({
10
- extra: f,
11
- children: p,
12
- className: h,
13
- hideNews: d = !1,
14
- hideLogin: c = !1,
15
- source: r = a.DEFAULT,
16
- brand: s = "iChatGo"
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { twMerge } from "tailwind-merge";
3
+ import request from "@0xchain/request";
4
+ import Right, { HeaderSource } from "./lib/Right.js";
5
+ import Logo from "./lib/Logo.js";
6
+ import { cookies } from "next/headers";
7
+ import { HeaderProvider } from "./lib/context.js";
8
+ import { createSessionFromCookieGetter } from "@0xchain/auth";
9
+ import { USER_EVENTS, emitUserEvent, onUserEvent } from "./lib/events.js";
10
+ async function HeaderBar({
11
+ extra,
12
+ children,
13
+ className,
14
+ hideNews = false,
15
+ hideLogin = false,
16
+ source = HeaderSource.DEFAULT,
17
+ brand = "iChatGo"
17
18
  }) {
18
- var n;
19
- let e = {
19
+ let userInfo = {
20
20
  data: {}
21
21
  };
22
- if (s !== "CHAINDIGG")
22
+ if (brand !== "CHAINDIGG") {
23
23
  try {
24
- const m = (n = (await v()).get("refresh_token")) == null ? void 0 : n.value;
25
- if (typeof m < "u" && m !== "")
24
+ const cookieStore = await cookies();
25
+ const session = createSessionFromCookieGetter(
26
+ (key) => cookieStore.get(key)?.value ?? null
27
+ );
28
+ if (session.isLoggedIn) {
26
29
  try {
27
- e = await k.get("/v2/users/profile", {
30
+ userInfo = await request.get("/v2/users/profile", {
28
31
  baseURL: process.env.AUTH_INNER_API_URL
29
32
  });
30
- } catch (x) {
31
- console.error(x), e = { data: {} };
33
+ } catch (error) {
34
+ console.error(error);
35
+ userInfo = { data: {} };
32
36
  }
37
+ }
33
38
  } catch {
34
- e = { data: {} };
39
+ userInfo = { data: {} };
35
40
  }
36
- return /* @__PURE__ */ t(E, { brand: s, children: [
37
- /* @__PURE__ */ t("div", { className: i("sticky left-0 right-0 top-0 bg-background h-16 z-999", r === a.CHAT ? "hidden md:block" : "block", h), children: [
38
- /* @__PURE__ */ t("div", { className: "md:bg-card h-13 text-center flex flex-wrap justify-between items-center gap-2 px-4", children: [
39
- /* @__PURE__ */ t("div", { className: i("items-center flex-1 gap-6", r === a.CHAT ? "hidden md:flex" : "flex"), children: [
40
- /* @__PURE__ */ o(g, {}),
41
- p
41
+ }
42
+ 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 === HeaderSource.CHAT ? "hidden md:block flex-1" : "block", className), children: [
44
+ /* @__PURE__ */ jsxs("div", { className: "md:bg-card h-13 text-center flex flex-wrap justify-between items-center gap-2 md:gap-10 px-4", children: [
45
+ /* @__PURE__ */ jsxs("div", { className: twMerge("items-center gap-6", source === HeaderSource.CHAT ? "hidden md:flex" : "flex"), children: [
46
+ /* @__PURE__ */ jsx(Logo, {}),
47
+ children
42
48
  ] }),
43
- /* @__PURE__ */ o(l, { hideNews: d, hideLogin: c, user: (e == null ? void 0 : e.data) || {} })
49
+ /* @__PURE__ */ jsx(Right, { hideNews, hideLogin, user: userInfo?.data || {} })
44
50
  ] }),
45
- f
51
+ extra
46
52
  ] }),
47
- /* @__PURE__ */ o("div", { className: i(r === a.CHAT ? "block md:hidden" : "hidden"), children: /* @__PURE__ */ o(l, { hideNews: d, source: r, hideLogin: c, user: (e == null ? void 0 : e.data) || {} }) })
53
+ /* @__PURE__ */ jsx("div", { className: twMerge(source === HeaderSource.CHAT ? "block md:hidden" : "hidden"), children: /* @__PURE__ */ jsx(Right, { hideNews, source, hideLogin, user: userInfo?.data || {} }) })
48
54
  ] });
49
55
  }
50
56
  export {
51
- a as HeaderSource,
52
- w as USER_EVENTS,
53
- R as default,
54
- j as emitUserEvent,
55
- G as onUserEvent
57
+ HeaderSource,
58
+ USER_EVENTS,
59
+ HeaderBar as default,
60
+ emitUserEvent,
61
+ onUserEvent
56
62
  };
@@ -1,42 +1,46 @@
1
1
  'use client';
2
- import { jsx as o, jsxs as c } from "react/jsx-runtime";
3
- import d from "rc-drawer";
4
- import { Menu as f, X as m } from "lucide-react";
5
- import p from "./Nav.js";
6
- import { useState as u } from "react";
7
- import { useIsChaindigg as g } from "./context.js";
8
- function N({
9
- hideLogin: s = !1,
10
- hideNews: n = !1,
11
- user: i
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import RcDrawer from "rc-drawer";
4
+ import { Menu, X } from "lucide-react";
5
+ import Nav from "./Nav.js";
6
+ import { useState } from "react";
7
+ import { useIsChaindigg } from "./context.js";
8
+ function Drawer({
9
+ hideLogin = false,
10
+ hideNews = false,
11
+ user
12
12
  }) {
13
- const e = g(), [a, t] = u(!1);
14
- if (!a)
15
- return /* @__PURE__ */ o(
16
- f,
13
+ const isChaindigg = useIsChaindigg();
14
+ const [open, setOpen] = useState(false);
15
+ if (!open) {
16
+ return /* @__PURE__ */ jsx(
17
+ Menu,
17
18
  {
18
- onClick: () => t(!0),
19
+ onClick: () => setOpen(true),
19
20
  size: 32,
20
21
  style: { color: "var(--foreground)" },
21
22
  className: "md:hidden bg-card rounded-lg p-[4px]"
22
23
  }
23
24
  );
24
- const l = (r) => {
25
- r == null || r.preventDefault(), r == null || r.stopPropagation(), t(!1);
25
+ }
26
+ const handleClose = (e) => {
27
+ e?.preventDefault();
28
+ e?.stopPropagation();
29
+ setOpen(false);
26
30
  };
27
- return /* @__PURE__ */ o(
28
- d,
31
+ return /* @__PURE__ */ jsx(
32
+ RcDrawer,
29
33
  {
30
- open: a,
34
+ open,
31
35
  placement: "right",
32
- className: `block md:hidden fixed top-0 bottom-0 left-0 right-0 z-1001 p-2 ${e ? "bg-background" : "bg-background/70 h-screen"}`,
33
- children: /* @__PURE__ */ c("div", { className: `w-full overflow-y-auto p-3 bg-card rounded-lg ${e ? "max-h-full" : "max-h-[calc(100svh-16px)]"}`, children: [
34
- /* @__PURE__ */ o("div", { className: "flex justify-end items-center p-2", children: /* @__PURE__ */ o(m, { size: 24, style: { color: "var(--foreground)" }, onClick: (r) => l(r) }) }),
35
- /* @__PURE__ */ o(p, { onClick: (r) => l(r), hideLogin: s, hideNews: n, user: i })
36
+ className: `block md:hidden fixed top-0 bottom-0 left-0 right-0 z-1001 p-2 bg-card ${isChaindigg ? "bg-background" : "bg-background/70 h-screen"}`,
37
+ children: /* @__PURE__ */ jsxs("div", { className: `w-full overflow-y-auto p-3 bg-card rounded-lg ${isChaindigg ? "max-h-full" : "max-h-[calc(100svh-16px)]"}`, children: [
38
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end items-center p-2", children: /* @__PURE__ */ jsx(X, { size: 24, style: { color: "var(--foreground)" }, onClick: (e) => handleClose(e) }) }),
39
+ /* @__PURE__ */ jsx(Nav, { onClick: (e) => handleClose(e), hideLogin, hideNews, user })
36
40
  ] })
37
41
  }
38
42
  );
39
43
  }
40
44
  export {
41
- N as default
45
+ Drawer as default
42
46
  };
@@ -1,94 +1,105 @@
1
1
  'use client';
2
- import { jsxs as t, Fragment as w, jsx as r } from "react/jsx-runtime";
3
- import m from "@0xchain/translation";
4
- import { Dropdown as b } from "antd";
5
- import { useState as f, useEffect as y } from "react";
6
- import N from "@0xchain/request";
7
- import x from "@0xchain/better-link";
8
- import j from "@0xchain/image";
9
- import { usePathname as A, useRouter as I } from "next/navigation";
10
- import { Accordion as S, AccordionItem as L, AccordionTrigger as P } from "@0xchain/ui/accordion";
11
- function q({ onClick: a = () => {
12
- }, onExpandChange: n }) {
13
- A();
14
- const p = I(), { gotoExplorer: h } = x(), [s, v] = f([]), [c, i] = f(""), g = async () => {
15
- const e = await N.get("/api/v2/chains/all-chain-list/basic");
16
- v(e.data);
17
- }, d = (e, o) => {
18
- e == null || e.preventDefault(), e == null || e.stopPropagation(), a == null || a(), i("");
19
- const l = h({ chain: o.chainSymbol });
20
- p.push(l);
2
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
3
+ import Translation from "@0xchain/translation";
4
+ import { Dropdown } from "antd";
5
+ import { useState, useEffect } from "react";
6
+ import request from "@0xchain/request";
7
+ import BetterLink from "@0xchain/better-link";
8
+ import ImageBar from "@0xchain/image";
9
+ import { Accordion, AccordionItem, AccordionTrigger } from "@0xchain/ui/accordion";
10
+ function Explorer({ onClick = () => void 0, onExpandChange }) {
11
+ const { gotoExplorer } = BetterLink();
12
+ const [list, setList] = useState([]);
13
+ const [accordionValue, setAccordionValue] = useState("");
14
+ const getList = async () => {
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
+ }
21
22
  };
22
- y(() => {
23
- g();
23
+ const handleClick = (e, item) => {
24
+ e?.preventDefault();
25
+ e?.stopPropagation();
26
+ onClick?.();
27
+ setAccordionValue("");
28
+ const url = gotoExplorer({ chain: item.chainSymbol });
29
+ const baseUrl = process.env.NEXT_PUBLIC_APP_URL || "";
30
+ window.location.href = `${baseUrl}${url}`;
31
+ };
32
+ useEffect(() => {
33
+ getList();
24
34
  }, []);
25
- const u = (e) => {
26
- var o, l;
27
- return /* @__PURE__ */ t(
35
+ const renderItemContent = (item) => {
36
+ return /* @__PURE__ */ jsxs(
28
37
  "div",
29
38
  {
30
39
  className: "w-full h-full flex items-center gap-2 py-2 cursor-pointer font-medium",
31
40
  children: [
32
- /* @__PURE__ */ r(
33
- j,
41
+ /* @__PURE__ */ jsx(
42
+ ImageBar,
34
43
  {
35
- src: e != null && e.chainIconUrl ? e == null ? void 0 : e.chainIconUrl : `//cdn.ichaingo.com/module/cryptos/${(l = (o = e == null ? void 0 : e.chain) == null ? void 0 : o.toLowerCase()) == null ? void 0 : l.replace(" ", "-")}.png?format=auto&width=20&height=20`,
44
+ src: item?.chainIconUrl ? item?.chainIconUrl : `//cdn.ichaingo.com/module/cryptos/${item?.chain?.toLowerCase()?.replace(" ", "-")}.png?format=auto&width=20&height=20`,
36
45
  className: "w-5 h-5",
37
46
  objectFit: "contain"
38
47
  }
39
48
  ),
40
- /* @__PURE__ */ r("div", { className: "flex-1", children: e == null ? void 0 : e.chainSymbol })
49
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: item?.chainSymbol })
41
50
  ]
42
51
  }
43
52
  );
44
53
  };
45
- return /* @__PURE__ */ t(w, { children: [
46
- /* @__PURE__ */ r("div", { className: "hidden md:block", children: /* @__PURE__ */ r(
47
- b,
54
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
55
+ /* @__PURE__ */ jsx("div", { className: "hidden md:block", children: /* @__PURE__ */ jsx(
56
+ Dropdown,
48
57
  {
49
58
  getPopupContainer: () => document.body,
50
59
  classNames: {
51
60
  root: "w-50"
52
61
  },
53
- arrow: { pointAtCenter: !0 },
62
+ arrow: { pointAtCenter: true },
54
63
  placement: "bottom",
55
64
  menu: {
56
- items: s.map((e) => ({
57
- label: u(e),
58
- key: e.chainSymbol,
59
- onClick: (o) => d(o.domEvent, e)
65
+ items: list.map((item) => ({
66
+ label: renderItemContent(item),
67
+ key: item.chainSymbol,
68
+ onClick: (info) => handleClick(info.domEvent, item)
60
69
  }))
61
70
  },
62
- children: /* @__PURE__ */ r("div", { className: "whitespace-nowrap flex items-center gap-1 rounded-lg", children: /* @__PURE__ */ r(m, { value: "title", parentKey: "browser" }) })
71
+ children: /* @__PURE__ */ jsx("div", { className: "whitespace-nowrap flex items-center gap-1 rounded-lg", children: /* @__PURE__ */ jsx(Translation, { value: "title", parentKey: "browser" }) })
63
72
  }
64
73
  ) }),
65
- /* @__PURE__ */ r("div", { className: "md:hidden w-full", children: /* @__PURE__ */ t("div", { onClick: (e) => {
66
- e.preventDefault(), e.stopPropagation();
74
+ /* @__PURE__ */ jsx("div", { className: "md:hidden w-full", children: /* @__PURE__ */ jsxs("div", { onClick: (e) => {
75
+ e.preventDefault();
76
+ e.stopPropagation();
67
77
  }, children: [
68
- /* @__PURE__ */ r(
69
- S,
78
+ /* @__PURE__ */ jsx(
79
+ Accordion,
70
80
  {
71
81
  type: "single",
72
- collapsible: !0,
82
+ collapsible: true,
73
83
  className: "w-full",
74
- value: c,
75
- onValueChange: (e) => {
76
- i(e), n == null || n(!!e);
84
+ value: accordionValue,
85
+ onValueChange: (value) => {
86
+ setAccordionValue(value);
87
+ onExpandChange?.(!!value);
77
88
  },
78
- children: /* @__PURE__ */ r(L, { value: "explorer", className: "border-0", children: /* @__PURE__ */ r(P, { className: "rounded-lg font-medium h-11 w-full flex py-2 justify-between items-center hover:no-underline focus-visible:ring-0 focus-visible:ring-offset-0", children: /* @__PURE__ */ r("div", { className: "flex w-full justify-between items-center", children: /* @__PURE__ */ r("span", { className: "text-foreground", children: /* @__PURE__ */ r(m, { value: "title", parentKey: "browser" }) }) }) }) })
89
+ children: /* @__PURE__ */ jsx(AccordionItem, { value: "explorer", className: "border-0", children: /* @__PURE__ */ jsx(AccordionTrigger, { className: "rounded-lg font-medium h-11 w-full flex py-2 justify-between items-center hover:no-underline focus-visible:ring-0 focus-visible:ring-offset-0", children: /* @__PURE__ */ jsx("div", { className: "flex w-full justify-between items-center", children: /* @__PURE__ */ jsx("span", { className: "text-foreground", children: /* @__PURE__ */ jsx(Translation, { value: "title", parentKey: "browser" }) }) }) }) })
79
90
  }
80
91
  ),
81
- /* @__PURE__ */ r(
92
+ /* @__PURE__ */ jsx(
82
93
  "div",
83
94
  {
84
95
  className: "grid transition-[grid-template-rows] duration-300 ease-in-out",
85
- style: { gridTemplateRows: c ? "1fr" : "0fr" },
86
- children: /* @__PURE__ */ r("div", { className: "overflow-hidden", children: /* @__PURE__ */ r("div", { className: "mt-3 rounded-lg flex flex-col gap-2 max-h-[60vh] overflow-auto", children: s.map((e) => /* @__PURE__ */ r("div", { className: "w-full", onClick: (o) => d(o, e), children: u(e) }, e.chainSymbol)) }) })
96
+ style: { gridTemplateRows: accordionValue ? "1fr" : "0fr" },
97
+ children: /* @__PURE__ */ jsx("div", { className: "overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "mt-3 rounded-lg flex flex-col gap-2 max-h-[60vh] overflow-auto", children: list.map((item) => /* @__PURE__ */ jsx("div", { className: "w-full", onClick: (e) => handleClick(e, item), children: renderItemContent(item) }, item.chainSymbol)) }) })
87
98
  }
88
99
  )
89
100
  ] }) })
90
101
  ] });
91
102
  }
92
103
  export {
93
- q as default
104
+ Explorer as default
94
105
  };
package/dist/lib/Logo.js CHANGED
@@ -1,65 +1,80 @@
1
1
  'use client';
2
- import { jsxs as t, jsx as r } from "react/jsx-runtime";
3
- import o from "@0xchain/image";
4
- import e from "@0xchain/link";
5
- import { twMerge as i } from "tailwind-merge";
6
- import { useIsChaindigg as s } from "./context.js";
7
- function g() {
8
- return s() ? /* @__PURE__ */ t(
9
- e,
2
+ import { jsxs, jsx } from "react/jsx-runtime";
3
+ import ImageBar from "@0xchain/image";
4
+ import LinkBar from "@0xchain/link";
5
+ import { twMerge } from "tailwind-merge";
6
+ import { useIsChaindigg } from "./context.js";
7
+ function Logo() {
8
+ const isChaindigg = useIsChaindigg();
9
+ if (isChaindigg) {
10
+ return /* @__PURE__ */ jsxs(
11
+ LinkBar,
12
+ {
13
+ suppressHydrationWarning: true,
14
+ href: `/explorer`,
15
+ baseUrl: "",
16
+ className: twMerge("w-auto shrink-0 block cursor-pointer"),
17
+ children: [
18
+ /* @__PURE__ */ jsx(
19
+ ImageBar,
20
+ {
21
+ className: "block dark:hidden",
22
+ src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/01/07/695dcb36c177e.png`,
23
+ width: 154,
24
+ height: 32,
25
+ alt: "logo",
26
+ objectFit: "contain",
27
+ priority: true
28
+ }
29
+ ),
30
+ /* @__PURE__ */ jsx(
31
+ ImageBar,
32
+ {
33
+ className: "hidden dark:block",
34
+ src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/01/07/695dcf43c95d8.png`,
35
+ width: 154,
36
+ height: 32,
37
+ alt: "logo",
38
+ objectFit: "contain",
39
+ priority: true
40
+ }
41
+ )
42
+ ]
43
+ }
44
+ );
45
+ }
46
+ return /* @__PURE__ */ jsxs(
47
+ LinkBar,
10
48
  {
11
- suppressHydrationWarning: !0,
12
- href: "/explorer",
13
- baseUrl: "",
14
- className: i("w-auto shrink-0 block cursor-pointer"),
49
+ suppressHydrationWarning: true,
50
+ href: `/`,
51
+ baseUrl: process.env.NEXT_PUBLIC_APP_URL,
52
+ className: twMerge("w-auto shrink-0 block cursor-pointer"),
15
53
  children: [
16
- /* @__PURE__ */ r(
17
- o,
54
+ /* @__PURE__ */ jsx(
55
+ ImageBar,
18
56
  {
19
57
  className: "block dark:hidden",
20
- src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/01/07/695dcb36c177e.png`,
21
- width: 154,
22
- height: 32,
58
+ src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/04/01/69ccb9c05c2c6.png`,
59
+ width: 136,
23
60
  alt: "logo",
24
- objectFit: "contain",
25
- priority: !0
61
+ priority: true
26
62
  }
27
63
  ),
28
- /* @__PURE__ */ r(
29
- o,
64
+ /* @__PURE__ */ jsx(
65
+ ImageBar,
30
66
  {
31
67
  className: "hidden dark:block",
32
- src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/01/07/695dcf43c95d8.png`,
33
- width: 154,
34
- height: 32,
68
+ src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/04/01/69ccb9bd7787f.png`,
69
+ width: 136,
35
70
  alt: "logo",
36
- objectFit: "contain",
37
- priority: !0
71
+ priority: true
38
72
  }
39
73
  )
40
74
  ]
41
75
  }
42
- ) : /* @__PURE__ */ r(
43
- e,
44
- {
45
- suppressHydrationWarning: !0,
46
- href: "/",
47
- baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
48
- className: i("w-auto shrink-0 block cursor-pointer"),
49
- children: /* @__PURE__ */ r(
50
- o,
51
- {
52
- src: `${process.env.NEXT_PUBLIC_CDN_URL}/logo.png`,
53
- width: 154,
54
- height: 32,
55
- alt: "logo",
56
- objectFit: "contain",
57
- priority: !0
58
- }
59
- )
60
- }
61
76
  );
62
77
  }
63
78
  export {
64
- g as default
79
+ Logo as default
65
80
  };