@0xchain/better-link 1.1.0-beta.11 → 1.1.0-beta.113

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.
Files changed (2) hide show
  1. package/dist/index.js +89 -63
  2. package/package.json +19 -3
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const i = /* @__PURE__ */ new Map([
1
+ const chainMap = /* @__PURE__ */ new Map([
2
2
  ["bitcoin", "btc"],
3
3
  ["litecoin", "ltc"],
4
4
  ["dogecoin", "doge"],
@@ -12,90 +12,116 @@ const i = /* @__PURE__ */ new Map([
12
12
  ["binance", "bsc"],
13
13
  ["bnb chain", "bnb"]
14
14
  ]);
15
- function a(e) {
16
- return i.get(e == null ? void 0 : e.toLowerCase()) || (e == null ? void 0 : e.toLowerCase());
15
+ function getChainSymbol(chain) {
16
+ return chainMap.get(chain?.toLowerCase()) || chain?.toLowerCase();
17
17
  }
18
- function n(e) {
19
- var o;
20
- const r = {};
21
- return e && Object.keys(e).forEach((t) => {
22
- e[t] && (r[t] = e[t]);
23
- }), ((o = Object.keys(r)) == null ? void 0 : o.length) > 0 ? `?${new URLSearchParams(r).toString()}` : "";
18
+ function getSearchParams(params) {
19
+ const searchParams = {};
20
+ if (params) {
21
+ Object.keys(params).forEach((key) => {
22
+ if (params[key]) {
23
+ searchParams[key] = params[key];
24
+ }
25
+ });
26
+ }
27
+ return Object.keys(searchParams)?.length > 0 ? `?${new URLSearchParams(searchParams).toString()}` : "";
24
28
  }
25
- function u() {
29
+ function BetterLink() {
26
30
  return {
27
- gotoAddress: (e) => {
28
- const { chain: r, address: o, params: t } = e, s = n(t);
29
- return `/explorer/${a(r)}/address/${o}${s}`;
31
+ gotoAddress: (options) => {
32
+ const { chain, address, params } = options;
33
+ const searchParams = getSearchParams(params);
34
+ return `/explorer/${getChainSymbol(chain)}/address/${address}${searchParams}`;
30
35
  },
31
- gotoToken: (e) => {
32
- const { chain: r, address: o, params: t } = e, s = n(t);
33
- return `/explorer/${a(r)}/token${o && o.length > 10 ? `/${o}` : ""}${s}`;
36
+ gotoToken: (options) => {
37
+ const { chain, address, params } = options;
38
+ const searchParams = getSearchParams(params);
39
+ return `/explorer/${getChainSymbol(chain)}/token${address && address.length > 10 ? `/${address}` : ""}${searchParams}`;
34
40
  },
35
- gotoProject: (e) => {
36
- const { slug: r, params: o } = e, t = n(o);
37
- return `/project/${r}${t}`;
41
+ gotoProject: (options) => {
42
+ const { slug, params } = options;
43
+ const searchParams = getSearchParams(params);
44
+ return `/project/${slug}${searchParams}`;
38
45
  },
39
- gotoPerson: (e) => {
40
- const { slug: r, params: o } = e, t = n(o);
41
- return `/person/${r}${t}`;
46
+ gotoPerson: (options) => {
47
+ const { slug, params } = options;
48
+ const searchParams = getSearchParams(params);
49
+ return `/person/${slug}${searchParams}`;
42
50
  },
43
- gotoOrganization: (e) => {
44
- const { slug: r, params: o } = e, t = n(o);
45
- return `/organization/${r}${t}`;
51
+ gotoOrganization: (options) => {
52
+ const { slug, params } = options;
53
+ const searchParams = getSearchParams(params);
54
+ return `/organization/${slug}${searchParams}`;
46
55
  },
47
- gotoTransaction: (e) => {
48
- const { chain: r, hash: o, params: t } = e, s = n(t);
49
- return `/explorer/${a(r)}/tx/${o}${s}`;
56
+ gotoTransaction: (options) => {
57
+ const { chain, hash, params } = options;
58
+ const searchParams = getSearchParams(params);
59
+ return `/explorer/${getChainSymbol(chain)}/tx/${hash}${searchParams}`;
50
60
  },
51
- gotoBlock: (e) => {
52
- const { chain: r, height: o, type: t, params: s } = e, c = n(s), $ = typeof o == "number" ? o : o != null && o.includes("coinbase_") ? `0x${o == null ? void 0 : o.replace("coinbase_", "")}` : o;
53
- return `/explorer/${a(r)}/block${t ? `/${t}` : ""}/${$}${c}`;
61
+ gotoBlock: (options) => {
62
+ const { chain, height, type, params } = options;
63
+ const searchParams = getSearchParams(params);
64
+ const normalHeight = typeof height === "number" ? height : height?.includes("coinbase_") ? `0x${height?.replace("coinbase_", "")}` : height;
65
+ return `/explorer/${getChainSymbol(chain)}/block${type ? `/${type}` : ""}/${normalHeight}${searchParams}`;
54
66
  },
55
- gotoEntity: (e) => {
56
- const { slug: r, params: o } = e, t = n(o);
57
- return `/entity/${r}${t}`;
67
+ gotoEntity: (options) => {
68
+ const { slug, params } = options;
69
+ const searchParams = getSearchParams(params);
70
+ return `/entity/${slug}${searchParams}`;
58
71
  },
59
- gotoETF: (e) => {
60
- const { region: r, slug: o, tokenSymbol: t, params: s } = e, c = n(s), $ = r == null ? void 0 : r.toLowerCase(), l = t == null ? void 0 : t.toLowerCase(), g = `/etf/${l}-${$}`;
61
- return l === o ? `${g}${c}` : `${g}/${o}${c}`;
72
+ gotoETF: (options) => {
73
+ const { region, slug, tokenSymbol, params } = options;
74
+ const searchParams = getSearchParams(params);
75
+ const lowerCaseRegion = region?.toLowerCase();
76
+ const lowerCaseTokenSymbol = tokenSymbol?.toLowerCase();
77
+ const link = `/etf/${lowerCaseTokenSymbol}-${lowerCaseRegion}`;
78
+ if (lowerCaseTokenSymbol === slug) {
79
+ return `${link}${searchParams}`;
80
+ }
81
+ return `${link}/${slug}${searchParams}`;
62
82
  },
63
- gotoExplorer: (e) => {
64
- const { chain: r, params: o } = e, t = n(o);
65
- return `/explorer/${a(r)}${t}`;
83
+ gotoExplorer: (options) => {
84
+ const { chain, params } = options;
85
+ const searchParams = getSearchParams(params);
86
+ return `/explorer/${getChainSymbol(chain)}${searchParams}`;
66
87
  },
67
- gotoMarket: (e) => {
68
- const { page: r, params: o } = e, t = n(o);
69
- return `/market${r ? `/${r}` : ""}${t}`;
88
+ gotoMarket: (options) => {
89
+ const { page, params } = options;
90
+ const searchParams = getSearchParams(params);
91
+ return `/market${page ? `/${page}` : ""}${searchParams}`;
70
92
  },
71
- gotoNews: (e) => {
72
- const { page: r, params: o } = e, t = n(o);
73
- return `/news${r ? `/${r}` : ""}${t}`;
93
+ gotoNews: (options) => {
94
+ const { page, params } = options;
95
+ const searchParams = getSearchParams(params);
96
+ return `/news${page ? `/${page}` : ""}${searchParams}`;
74
97
  },
75
- gotoChat(e) {
76
- const { locale: r, q: o } = e, t = n({ q: o || "" });
77
- return `${process.env.NEXT_PUBLIC_BASE_URL}${r ? `/${r}` : ""}/${t}`;
98
+ gotoChat(options) {
99
+ const { locale, q } = options;
100
+ const searchParams = getSearchParams({ q: q || "" });
101
+ return `${process.env.NEXT_PUBLIC_APP_URL}${locale ? `/${locale}` : ""}/${searchParams}`;
78
102
  },
79
- gotoAISQL(e) {
80
- const { locale: r, q: o } = e, t = n({ q: o || "" });
81
- return `${process.env.NEXT_PUBLIC_BASE_URL}${r ? `/${r}` : ""}/sql${t}`;
103
+ gotoAISQL(options) {
104
+ const { locale, q } = options;
105
+ const searchParams = getSearchParams({ q: q || "" });
106
+ return `${process.env.NEXT_PUBLIC_APP_URL}${locale ? `/${locale}` : ""}/query${searchParams}`;
82
107
  },
83
- gotoExplorerSearch(e) {
84
- var o, t;
85
- return `/explorer/search${n({
86
- chain: i.get((o = e == null ? void 0 : e.chain) == null ? void 0 : o.toLowerCase()) || ((t = e == null ? void 0 : e.chain) == null ? void 0 : t.toLowerCase()) || "",
87
- q: (e == null ? void 0 : e.q) || "",
88
- type: (e == null ? void 0 : e.type) || "",
108
+ gotoExplorerSearch(params) {
109
+ const searchParams = getSearchParams({
110
+ chain: chainMap.get(params?.chain?.toLowerCase()) || params?.chain?.toLowerCase() || "",
111
+ q: params?.q || "",
112
+ type: params?.type || "",
89
113
  _t: Date.now().toString()
90
114
  // 添加时间戳强制刷新
91
- })}`;
115
+ });
116
+ return `/explorer/search${searchParams}`;
92
117
  },
93
- gotoLogin(e) {
94
- const { locale: r, redirect: o } = e, t = n({ redirect_uri: o || "" });
95
- return `${r ? `/${r}` : ""}/login${t}`;
118
+ gotoLogin(options) {
119
+ const { locale, redirect } = options;
120
+ const searchParams = getSearchParams({ redirect_uri: redirect || "" });
121
+ return `${locale ? `/${locale}` : ""}/login${searchParams}`;
96
122
  }
97
123
  };
98
124
  }
99
125
  export {
100
- u as default
126
+ BetterLink as default
101
127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xchain/better-link",
3
- "version": "1.1.0-beta.11",
3
+ "version": "1.1.0-beta.113",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -17,8 +17,24 @@
17
17
  "dist",
18
18
  "!**/*.tsbuildinfo"
19
19
  ],
20
- "dependencies": {},
20
+ "peerDependencies": {
21
+ "next": "16.1.6",
22
+ "next-intl": "4.13.0",
23
+ "react": "19.1.1",
24
+ "react-dom": "19.1.1"
25
+ },
26
+ "devDependencies": {
27
+ "next": "16.1.6",
28
+ "next-intl": "4.13.0",
29
+ "react": "19.1.1",
30
+ "react-dom": "19.1.1"
31
+ },
32
+ "nx": {
33
+ "tags": [
34
+ "type:util"
35
+ ]
36
+ },
21
37
  "publishConfig": {
22
38
  "access": "public"
23
39
  }
24
- }
40
+ }