@0xchain/header 1.1.0-beta.90 → 1.1.0-beta.91

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,11 +1,13 @@
1
1
  'use client';
2
2
  import { jsxs, jsx } from "react/jsx-runtime";
3
+ import { useState, useEffect } from "react";
3
4
  import LinkBar from "@0xchain/link";
4
5
  import Translation from "@0xchain/translation";
5
6
  import ImageBar from "@0xchain/image";
7
+ import request from "@0xchain/request";
6
8
  import { twMerge } from "tailwind-merge";
7
9
  import { hasProfileIdentity } from "./authProfile.js";
8
- import { HEADER_POINTS_ICON, formatHeaderPoints } from "./headerPoints.js";
10
+ import { hasTrustedHeaderPoints, formatHeaderPoints, HEADER_POINTS_ICON, HEADER_POINTS_OVERVIEW_PATH, pointsTextFromOverview } from "./headerPoints.js";
9
11
  import { useIsChaindigg } from "./context.js";
10
12
  function PointsEntry({
11
13
  userInfo,
@@ -13,6 +15,35 @@ function PointsEntry({
13
15
  onClick
14
16
  }) {
15
17
  const isChaindigg = useIsChaindigg();
18
+ const [pointsText, setPointsText] = useState(
19
+ () => hasTrustedHeaderPoints(userInfo) ? formatHeaderPoints(userInfo) : ""
20
+ );
21
+ useEffect(() => {
22
+ if (isChaindigg || !hasProfileIdentity(userInfo)) {
23
+ return;
24
+ }
25
+ let cancelled = false;
26
+ const load = () => {
27
+ request.get(HEADER_POINTS_OVERVIEW_PATH).then((res) => {
28
+ if (cancelled) return;
29
+ const next = pointsTextFromOverview(res);
30
+ if (next != null) {
31
+ setPointsText(next);
32
+ }
33
+ }).catch(() => void 0);
34
+ };
35
+ load();
36
+ const onRefresh = () => load();
37
+ window.addEventListener("user-profile-updated", onRefresh);
38
+ window.addEventListener("xchain-response-toast", onRefresh);
39
+ window.addEventListener("focus", onRefresh);
40
+ return () => {
41
+ cancelled = true;
42
+ window.removeEventListener("user-profile-updated", onRefresh);
43
+ window.removeEventListener("xchain-response-toast", onRefresh);
44
+ window.removeEventListener("focus", onRefresh);
45
+ };
46
+ }, [isChaindigg, userInfo?.id, userInfo?.userId]);
16
47
  if (isChaindigg || !hasProfileIdentity(userInfo)) {
17
48
  return null;
18
49
  }
@@ -41,7 +72,7 @@ function PointsEntry({
41
72
  /* @__PURE__ */ jsx(Translation, { value: "points", parentKey: "account" }),
42
73
  ": "
43
74
  ] }),
44
- /* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children: formatHeaderPoints(userInfo) })
75
+ /* @__PURE__ */ jsx("span", { className: "text-primary font-medium", children: pointsText })
45
76
  ]
46
77
  }
47
78
  );
@@ -1,9 +1,11 @@
1
+ const HEADER_POINTS_OVERVIEW_PATH = "/api/account/points/overview";
2
+ const HEADER_POINTS_ICON = `${process.env.NEXT_PUBLIC_CDN_URL || ""}/uploads/2026/08/31/6a952e3b78f30.png`;
1
3
  function formatHeaderPoints(userInfo) {
2
4
  const display = userInfo?.displayBalance;
3
5
  if (typeof display === "string" && display.trim()) {
4
6
  return display.trim();
5
7
  }
6
- const points = Number(userInfo?.points);
8
+ const points = Number(userInfo?.points ?? userInfo?.balance);
7
9
  if (!Number.isFinite(points) || points < 0) {
8
10
  return "0";
9
11
  }
@@ -12,8 +14,39 @@ function formatHeaderPoints(userInfo) {
12
14
  }
13
15
  return String(Math.trunc(points));
14
16
  }
15
- const HEADER_POINTS_ICON = `${process.env.NEXT_PUBLIC_CDN_URL || ""}/uploads/2026/08/31/6a952e3b78f30.png`;
17
+ function hasTrustedHeaderPoints(userInfo) {
18
+ if (typeof userInfo?.displayBalance === "string" && userInfo.displayBalance.trim() && userInfo.displayBalance !== "0") {
19
+ return true;
20
+ }
21
+ const points = Number(userInfo?.points ?? userInfo?.balance);
22
+ return Number.isFinite(points) && points > 0;
23
+ }
24
+ function pointsTextFromOverview(res) {
25
+ if (!res || typeof res !== "object") {
26
+ return null;
27
+ }
28
+ const root = res;
29
+ const statusCode = Number(root.status?.code);
30
+ if (Number.isFinite(statusCode) && statusCode !== 0 && statusCode !== 200) {
31
+ return null;
32
+ }
33
+ const payload = root.data && typeof root.data === "object" ? root.data : root;
34
+ if (!payload || typeof payload !== "object") {
35
+ return null;
36
+ }
37
+ const data = payload;
38
+ if (typeof data.balance === "undefined" && typeof data.displayBalance !== "string") {
39
+ return null;
40
+ }
41
+ return formatHeaderPoints({
42
+ displayBalance: data.displayBalance,
43
+ points: data.balance
44
+ });
45
+ }
16
46
  export {
17
47
  HEADER_POINTS_ICON,
18
- formatHeaderPoints
48
+ HEADER_POINTS_OVERVIEW_PATH,
49
+ formatHeaderPoints,
50
+ hasTrustedHeaderPoints,
51
+ pointsTextFromOverview
19
52
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xchain/header",
3
- "version": "1.1.0-beta.90",
3
+ "version": "1.1.0-beta.91",
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.90"
29
+ "@0xchain/with-login": "1.1.0-beta.91"
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.90"
44
+ "@0xchain/with-login": "1.1.0-beta.91"
45
45
  },
46
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"
47
+ "@0xchain/auth": "1.1.0-beta.91",
48
+ "@0xchain/iconfont": "1.1.0-beta.91",
49
+ "@0xchain/image": "1.1.0-beta.91",
50
+ "@0xchain/link": "1.1.0-beta.91",
51
+ "@0xchain/request": "1.1.0-beta.91",
52
+ "@0xchain/avatar": "1.1.0-beta.91",
53
+ "@0xchain/theme-toggle": "1.1.0-beta.91",
54
+ "@0xchain/i18n": "1.1.0-beta.91",
55
+ "@0xchain/tooltip": "1.1.0-beta.91",
56
+ "@0xchain/better-link": "1.1.0-beta.91",
57
+ "@0xchain/translation": "1.1.0-beta.91",
58
+ "@0xchain/ui": "1.1.0-beta.91"
59
59
  },
60
60
  "nx": {
61
61
  "tags": [