@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.
- package/dist/index.js +89 -63
- package/package.json +19 -3
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
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
|
|
16
|
-
return
|
|
15
|
+
function getChainSymbol(chain) {
|
|
16
|
+
return chainMap.get(chain?.toLowerCase()) || chain?.toLowerCase();
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
29
|
+
function BetterLink() {
|
|
26
30
|
return {
|
|
27
|
-
gotoAddress: (
|
|
28
|
-
const { chain
|
|
29
|
-
|
|
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: (
|
|
32
|
-
const { chain
|
|
33
|
-
|
|
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: (
|
|
36
|
-
const { slug
|
|
37
|
-
|
|
41
|
+
gotoProject: (options) => {
|
|
42
|
+
const { slug, params } = options;
|
|
43
|
+
const searchParams = getSearchParams(params);
|
|
44
|
+
return `/project/${slug}${searchParams}`;
|
|
38
45
|
},
|
|
39
|
-
gotoPerson: (
|
|
40
|
-
const { slug
|
|
41
|
-
|
|
46
|
+
gotoPerson: (options) => {
|
|
47
|
+
const { slug, params } = options;
|
|
48
|
+
const searchParams = getSearchParams(params);
|
|
49
|
+
return `/person/${slug}${searchParams}`;
|
|
42
50
|
},
|
|
43
|
-
gotoOrganization: (
|
|
44
|
-
const { slug
|
|
45
|
-
|
|
51
|
+
gotoOrganization: (options) => {
|
|
52
|
+
const { slug, params } = options;
|
|
53
|
+
const searchParams = getSearchParams(params);
|
|
54
|
+
return `/organization/${slug}${searchParams}`;
|
|
46
55
|
},
|
|
47
|
-
gotoTransaction: (
|
|
48
|
-
const { chain
|
|
49
|
-
|
|
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: (
|
|
52
|
-
const { chain
|
|
53
|
-
|
|
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: (
|
|
56
|
-
const { slug
|
|
57
|
-
|
|
67
|
+
gotoEntity: (options) => {
|
|
68
|
+
const { slug, params } = options;
|
|
69
|
+
const searchParams = getSearchParams(params);
|
|
70
|
+
return `/entity/${slug}${searchParams}`;
|
|
58
71
|
},
|
|
59
|
-
gotoETF: (
|
|
60
|
-
const { region
|
|
61
|
-
|
|
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: (
|
|
64
|
-
const { chain
|
|
65
|
-
|
|
83
|
+
gotoExplorer: (options) => {
|
|
84
|
+
const { chain, params } = options;
|
|
85
|
+
const searchParams = getSearchParams(params);
|
|
86
|
+
return `/explorer/${getChainSymbol(chain)}${searchParams}`;
|
|
66
87
|
},
|
|
67
|
-
gotoMarket: (
|
|
68
|
-
const { page
|
|
69
|
-
|
|
88
|
+
gotoMarket: (options) => {
|
|
89
|
+
const { page, params } = options;
|
|
90
|
+
const searchParams = getSearchParams(params);
|
|
91
|
+
return `/market${page ? `/${page}` : ""}${searchParams}`;
|
|
70
92
|
},
|
|
71
|
-
gotoNews: (
|
|
72
|
-
const { page
|
|
73
|
-
|
|
93
|
+
gotoNews: (options) => {
|
|
94
|
+
const { page, params } = options;
|
|
95
|
+
const searchParams = getSearchParams(params);
|
|
96
|
+
return `/news${page ? `/${page}` : ""}${searchParams}`;
|
|
74
97
|
},
|
|
75
|
-
gotoChat(
|
|
76
|
-
const { locale
|
|
77
|
-
|
|
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(
|
|
80
|
-
const { locale
|
|
81
|
-
|
|
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(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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(
|
|
94
|
-
const { locale
|
|
95
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
"
|
|
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
|
+
}
|