@0xchain/header 1.1.0-beta.17 → 1.1.0-beta.19

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,60 @@
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 { USER_EVENTS, emitUserEvent, onUserEvent } from "./lib/events.js";
9
+ async function HeaderBar({
10
+ extra,
11
+ children,
12
+ className,
13
+ hideNews = false,
14
+ hideLogin = false,
15
+ source = HeaderSource.DEFAULT,
16
+ brand = "iChatGo"
17
17
  }) {
18
- var n;
19
- let e = {
18
+ let userInfo = {
20
19
  data: {}
21
20
  };
22
- if (s !== "CHAINDIGG")
21
+ if (brand !== "CHAINDIGG") {
23
22
  try {
24
- const m = (n = (await v()).get("refresh_token")) == null ? void 0 : n.value;
25
- if (typeof m < "u" && m !== "")
23
+ const cookieStore = await cookies();
24
+ const tokenExpire = cookieStore.get("refresh_token")?.value;
25
+ const hasTokenExpire = typeof tokenExpire !== "undefined" && tokenExpire !== "";
26
+ if (hasTokenExpire) {
26
27
  try {
27
- e = await k.get("/v2/users/profile", {
28
+ userInfo = await request.get("/v2/users/profile", {
28
29
  baseURL: process.env.AUTH_INNER_API_URL
29
30
  });
30
- } catch (x) {
31
- console.error(x), e = { data: {} };
31
+ } catch (error) {
32
+ console.error(error);
33
+ userInfo = { data: {} };
32
34
  }
35
+ }
33
36
  } catch {
34
- e = { data: {} };
37
+ userInfo = { data: {} };
35
38
  }
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
39
+ }
40
+ return /* @__PURE__ */ jsxs(HeaderProvider, { brand, children: [
41
+ /* @__PURE__ */ jsxs("div", { className: twMerge("sticky left-0 right-0 top-0 bg-background h-16 z-999", source === HeaderSource.CHAT ? "hidden md:block" : "block", className), children: [
42
+ /* @__PURE__ */ jsxs("div", { className: "md:bg-card h-13 text-center flex flex-wrap justify-between items-center gap-2 px-4", children: [
43
+ /* @__PURE__ */ jsxs("div", { className: twMerge("items-center flex-1 gap-6", source === HeaderSource.CHAT ? "hidden md:flex" : "flex"), children: [
44
+ /* @__PURE__ */ jsx(Logo, {}),
45
+ children
42
46
  ] }),
43
- /* @__PURE__ */ o(l, { hideNews: d, hideLogin: c, user: (e == null ? void 0 : e.data) || {} })
47
+ /* @__PURE__ */ jsx(Right, { hideNews, hideLogin, user: userInfo?.data || {} })
44
48
  ] }),
45
- f
49
+ extra
46
50
  ] }),
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) || {} }) })
51
+ /* @__PURE__ */ jsx("div", { className: twMerge(source === HeaderSource.CHAT ? "block md:hidden" : "hidden"), children: /* @__PURE__ */ jsx(Right, { hideNews, source, hideLogin, user: userInfo?.data || {} }) })
48
52
  ] });
49
53
  }
50
54
  export {
51
- a as HeaderSource,
52
- w as USER_EVENTS,
53
- R as default,
54
- j as emitUserEvent,
55
- G as onUserEvent
55
+ HeaderSource,
56
+ USER_EVENTS,
57
+ HeaderBar as default,
58
+ emitUserEvent,
59
+ onUserEvent
56
60
  };
@@ -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 ${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,100 @@
1
1
  'use client';
2
- import { jsxs as s, Fragment as g, 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 N } from "react";
6
- import y from "@0xchain/request";
7
- import x from "@0xchain/better-link";
8
- import A from "@0xchain/image";
9
- import { usePathname as I } from "next/navigation";
10
- import { Accordion as L, AccordionItem as S, AccordionTrigger as j } from "@0xchain/ui/accordion";
11
- function C({ onClick: a = () => {
12
- }, onExpandChange: n }) {
13
- I();
14
- const { gotoExplorer: p } = x(), [t, h] = f([]), [c, i] = f(""), v = async () => {
15
- const e = await y.get("/api/v2/chains/all-chain-list/basic");
16
- h(e.data);
17
- }, d = (e, o) => {
18
- e == null || e.preventDefault(), e == null || e.stopPropagation(), a == null || a(), i("");
19
- const l = p({ chain: o.chainSymbol }), w = process.env.NEXT_PUBLIC_BASE_URL || "";
20
- window.location.href = `${w}${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
+ const res = await request.get("/api/v2/chains/all-chain-list/basic");
16
+ setList(res.data);
21
17
  };
22
- N(() => {
23
- v();
18
+ const handleClick = (e, item) => {
19
+ e?.preventDefault();
20
+ e?.stopPropagation();
21
+ onClick?.();
22
+ setAccordionValue("");
23
+ const url = gotoExplorer({ chain: item.chainSymbol });
24
+ const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || "";
25
+ window.location.href = `${baseUrl}${url}`;
26
+ };
27
+ useEffect(() => {
28
+ getList();
24
29
  }, []);
25
- const u = (e) => {
26
- var o, l;
27
- return /* @__PURE__ */ s(
30
+ const renderItemContent = (item) => {
31
+ return /* @__PURE__ */ jsxs(
28
32
  "div",
29
33
  {
30
34
  className: "w-full h-full flex items-center gap-2 py-2 cursor-pointer font-medium",
31
35
  children: [
32
- /* @__PURE__ */ r(
33
- A,
36
+ /* @__PURE__ */ jsx(
37
+ ImageBar,
34
38
  {
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`,
39
+ src: item?.chainIconUrl ? item?.chainIconUrl : `//cdn.ichaingo.com/module/cryptos/${item?.chain?.toLowerCase()?.replace(" ", "-")}.png?format=auto&width=20&height=20`,
36
40
  className: "w-5 h-5",
37
41
  objectFit: "contain"
38
42
  }
39
43
  ),
40
- /* @__PURE__ */ r("div", { className: "flex-1", children: e == null ? void 0 : e.chainSymbol })
44
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: item?.chainSymbol })
41
45
  ]
42
46
  }
43
47
  );
44
48
  };
45
- return /* @__PURE__ */ s(g, { children: [
46
- /* @__PURE__ */ r("div", { className: "hidden md:block", children: /* @__PURE__ */ r(
47
- b,
49
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
50
+ /* @__PURE__ */ jsx("div", { className: "hidden md:block", children: /* @__PURE__ */ jsx(
51
+ Dropdown,
48
52
  {
49
53
  getPopupContainer: () => document.body,
50
54
  classNames: {
51
55
  root: "w-50"
52
56
  },
53
- arrow: { pointAtCenter: !0 },
57
+ arrow: { pointAtCenter: true },
54
58
  placement: "bottom",
55
59
  menu: {
56
- items: t.map((e) => ({
57
- label: u(e),
58
- key: e.chainSymbol,
59
- onClick: (o) => d(o.domEvent, e)
60
+ items: list.map((item) => ({
61
+ label: renderItemContent(item),
62
+ key: item.chainSymbol,
63
+ onClick: (info) => handleClick(info.domEvent, item)
60
64
  }))
61
65
  },
62
- children: /* @__PURE__ */ r("div", { className: "whitespace-nowrap flex items-center gap-1 rounded-lg", children: /* @__PURE__ */ r(m, { value: "title", parentKey: "browser" }) })
66
+ children: /* @__PURE__ */ jsx("div", { className: "whitespace-nowrap flex items-center gap-1 rounded-lg", children: /* @__PURE__ */ jsx(Translation, { value: "title", parentKey: "browser" }) })
63
67
  }
64
68
  ) }),
65
- /* @__PURE__ */ r("div", { className: "md:hidden w-full", children: /* @__PURE__ */ s("div", { onClick: (e) => {
66
- e.preventDefault(), e.stopPropagation();
69
+ /* @__PURE__ */ jsx("div", { className: "md:hidden w-full", children: /* @__PURE__ */ jsxs("div", { onClick: (e) => {
70
+ e.preventDefault();
71
+ e.stopPropagation();
67
72
  }, children: [
68
- /* @__PURE__ */ r(
69
- L,
73
+ /* @__PURE__ */ jsx(
74
+ Accordion,
70
75
  {
71
76
  type: "single",
72
- collapsible: !0,
77
+ collapsible: true,
73
78
  className: "w-full",
74
- value: c,
75
- onValueChange: (e) => {
76
- i(e), n == null || n(!!e);
79
+ value: accordionValue,
80
+ onValueChange: (value) => {
81
+ setAccordionValue(value);
82
+ onExpandChange?.(!!value);
77
83
  },
78
- children: /* @__PURE__ */ r(S, { value: "explorer", className: "border-0", children: /* @__PURE__ */ r(j, { 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" }) }) }) }) })
84
+ 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
85
  }
80
86
  ),
81
- /* @__PURE__ */ r(
87
+ /* @__PURE__ */ jsx(
82
88
  "div",
83
89
  {
84
90
  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: t.map((e) => /* @__PURE__ */ r("div", { className: "w-full", onClick: (o) => d(o, e), children: u(e) }, e.chainSymbol)) }) })
91
+ style: { gridTemplateRows: accordionValue ? "1fr" : "0fr" },
92
+ 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
93
  }
88
94
  )
89
95
  ] }) })
90
96
  ] });
91
97
  }
92
98
  export {
93
- C as default
99
+ Explorer as default
94
100
  };
package/dist/lib/Logo.js CHANGED
@@ -1,65 +1,69 @@
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__ */ jsx(
47
+ LinkBar,
10
48
  {
11
- suppressHydrationWarning: !0,
12
- href: "/explorer",
13
- baseUrl: "",
14
- className: i("w-auto shrink-0 block cursor-pointer"),
15
- children: [
16
- /* @__PURE__ */ r(
17
- o,
18
- {
19
- className: "block dark:hidden",
20
- src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/01/07/695dcb36c177e.png`,
21
- width: 154,
22
- height: 32,
23
- alt: "logo",
24
- objectFit: "contain",
25
- priority: !0
26
- }
27
- ),
28
- /* @__PURE__ */ r(
29
- o,
30
- {
31
- className: "hidden dark:block",
32
- src: `${process.env.NEXT_PUBLIC_CDN_URL}/uploads/2026/01/07/695dcf43c95d8.png`,
33
- width: 154,
34
- height: 32,
35
- alt: "logo",
36
- objectFit: "contain",
37
- priority: !0
38
- }
39
- )
40
- ]
41
- }
42
- ) : /* @__PURE__ */ r(
43
- e,
44
- {
45
- suppressHydrationWarning: !0,
46
- href: "/",
49
+ suppressHydrationWarning: true,
50
+ href: `/`,
47
51
  baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
48
- className: i("w-auto shrink-0 block cursor-pointer"),
49
- children: /* @__PURE__ */ r(
50
- o,
52
+ className: twMerge("w-auto shrink-0 block cursor-pointer"),
53
+ children: /* @__PURE__ */ jsx(
54
+ ImageBar,
51
55
  {
52
56
  src: `${process.env.NEXT_PUBLIC_CDN_URL}/logo.png`,
53
57
  width: 154,
54
58
  height: 32,
55
59
  alt: "logo",
56
60
  objectFit: "contain",
57
- priority: !0
61
+ priority: true
58
62
  }
59
63
  )
60
64
  }
61
65
  );
62
66
  }
63
67
  export {
64
- g as default
68
+ Logo as default
65
69
  };