@blocklet/did-space-react 0.5.75 → 0.5.77
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/cjs/components/preview-space-nft/index.js +1 -1
- package/dist/cjs/components/space-card/index.d.ts +1 -0
- package/dist/cjs/components/space-card/index.js +40 -5
- package/dist/cjs/hooks/use-space-info.d.ts +10 -8
- package/dist/cjs/hooks/use-space-info.js +41 -7
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/libs/util.d.ts +2 -3
- package/dist/cjs/libs/util.js +4 -10
- package/dist/cjs/locales/en.js +5 -2
- package/dist/cjs/locales/zh.js +7 -1
- package/dist/cjs/package.json.js +5 -0
- package/dist/es/components/preview-space-nft/index.js +1 -1
- package/dist/es/components/space-card/index.d.ts +1 -0
- package/dist/es/components/space-card/index.js +43 -8
- package/dist/es/hooks/use-space-info.d.ts +10 -8
- package/dist/es/hooks/use-space-info.js +41 -7
- package/dist/es/index.js +1 -1
- package/dist/es/libs/util.d.ts +2 -3
- package/dist/es/libs/util.js +4 -9
- package/dist/es/locales/en.js +5 -2
- package/dist/es/locales/zh.js +7 -1
- package/dist/es/package.json.js +3 -0
- package/package.json +8 -7
|
@@ -17,7 +17,7 @@ function PreviewSpaceNft({
|
|
|
17
17
|
const handleClose = () => setOpen(false);
|
|
18
18
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
19
19
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, onClick: handleOpen, children: [
|
|
20
|
-
/* @__PURE__ */ jsxRuntime.jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsxRuntime.jsx(emptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width
|
|
20
|
+
/* @__PURE__ */ jsxRuntime.jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsxRuntime.jsx(emptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width, height } }) }),
|
|
21
21
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
22
22
|
"div",
|
|
23
23
|
{
|
|
@@ -10,6 +10,8 @@ const Theme = require('@arcblock/ux/lib/Theme');
|
|
|
10
10
|
const React = require('react');
|
|
11
11
|
const axios = require('axios');
|
|
12
12
|
const ahooks = require('ahooks');
|
|
13
|
+
const compareVersions = require('compare-versions');
|
|
14
|
+
const _package = require('../../package.json.js');
|
|
13
15
|
const constants = require('../../libs/constants.js');
|
|
14
16
|
const useMobile = require('../../hooks/use-mobile.js');
|
|
15
17
|
const useSpaceInfo = require('../../hooks/use-space-info.js');
|
|
@@ -140,8 +142,9 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
140
142
|
if (isUndefined(isCompact)) {
|
|
141
143
|
isCompact = isMobile;
|
|
142
144
|
}
|
|
143
|
-
const spaceDid = util.
|
|
144
|
-
const spaceUrl = util.
|
|
145
|
+
const spaceDid = util.getSpaceDidFromEndpoint(endpoint);
|
|
146
|
+
const spaceUrl = util.getSpaceUrlFromEndpoint(endpoint);
|
|
147
|
+
const spaceOrigin = new URL(endpoint).origin;
|
|
145
148
|
const gatewayUrl = util.getSpaceGatewayUrlFromEndpoint(endpoint);
|
|
146
149
|
const [refreshSpaceInfo, setRefreshSpaceInfo] = React.useState(false);
|
|
147
150
|
const refresh = () => setRefreshSpaceInfo((p) => !p);
|
|
@@ -161,7 +164,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
161
164
|
spaceStatus.current = index.SpaceStatus.LOADING;
|
|
162
165
|
spaceName = /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
|
|
163
166
|
} else if (spaceInfo) {
|
|
164
|
-
spaceName = spaceInfo.
|
|
167
|
+
spaceName = spaceInfo.name;
|
|
165
168
|
if (!isAvailable) {
|
|
166
169
|
spaceStatus.current = index.SpaceStatus.UNAVAILABLE;
|
|
167
170
|
errorCode = spaceInfo.errorCode;
|
|
@@ -180,6 +183,8 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
180
183
|
errorCode = constants.SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR;
|
|
181
184
|
}
|
|
182
185
|
}
|
|
186
|
+
const spaceVersion = spaceInfo?.version;
|
|
187
|
+
const isLegacySpace = !!spaceInfo && (!spaceVersion || compareVersions.compareVersions(spaceVersion, _package.version) < 0);
|
|
183
188
|
const renderAction = () => {
|
|
184
189
|
if (loading)
|
|
185
190
|
return null;
|
|
@@ -187,7 +192,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
187
192
|
return action({
|
|
188
193
|
spaceGateway: {
|
|
189
194
|
did: spaceDid,
|
|
190
|
-
name: spaceInfo?.
|
|
195
|
+
name: spaceInfo?.name ?? "",
|
|
191
196
|
url: gatewayUrl,
|
|
192
197
|
endpoint,
|
|
193
198
|
ownerDid: spaceInfo?.ownerDid ?? ""
|
|
@@ -196,6 +201,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
196
201
|
errorCode,
|
|
197
202
|
selected,
|
|
198
203
|
compat: isCompact,
|
|
204
|
+
isLegacySpace,
|
|
199
205
|
refresh
|
|
200
206
|
});
|
|
201
207
|
}
|
|
@@ -211,7 +217,36 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
211
217
|
...rest,
|
|
212
218
|
children: [
|
|
213
219
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", children: [
|
|
214
|
-
/* @__PURE__ */ jsxRuntime.
|
|
220
|
+
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { position: "relative" }, children: [
|
|
221
|
+
isLegacySpace && /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { position: "absolute", top: 0, right: 0, zIndex: 2, transform: "translate(40%, -50%)" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
222
|
+
material.Tooltip,
|
|
223
|
+
{
|
|
224
|
+
title: /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { whiteSpace: "pre-wrap" }, children: [
|
|
225
|
+
t("storage.spaces.helperText.outdatedSpace"),
|
|
226
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
227
|
+
material.Link,
|
|
228
|
+
{
|
|
229
|
+
href: ufo.joinURL(spaceOrigin, ".well-known/service/admin/components"),
|
|
230
|
+
target: "_blank",
|
|
231
|
+
sx: { pl: 0.5 },
|
|
232
|
+
children: t("storage.spaces.helperText.upgradeSpace")
|
|
233
|
+
}
|
|
234
|
+
)
|
|
235
|
+
] }),
|
|
236
|
+
placement: "top",
|
|
237
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
238
|
+
material.Chip,
|
|
239
|
+
{
|
|
240
|
+
label: t("common.upgrade"),
|
|
241
|
+
color: "error",
|
|
242
|
+
size: "small",
|
|
243
|
+
sx: { transform: "scale(0.8)", cursor: "pointer" }
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
) }),
|
|
248
|
+
/* @__PURE__ */ jsxRuntime.jsx(index$1.PreviewSpaceNft, { src: util.getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" })
|
|
249
|
+
] }),
|
|
215
250
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Stack, { ml: 2, flex: 1, spacing: 1, minWidth: 0, children: [
|
|
216
251
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", sx: { whiteSpace: "nowrap" }, children: [
|
|
217
252
|
spaceName && /* @__PURE__ */ jsxRuntime.jsx(material.Box, { className: "space-name", children: spaceName }),
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
type SpaceInfo = {
|
|
2
|
+
version: string;
|
|
3
|
+
name: string;
|
|
4
|
+
subscriptionId: string;
|
|
5
|
+
ownerDid: string;
|
|
6
|
+
isAvailable: boolean;
|
|
7
|
+
errorCode: number;
|
|
8
|
+
};
|
|
1
9
|
export default function useSpaceInfo({ endpoint, deps }: {
|
|
2
10
|
endpoint: string;
|
|
3
11
|
deps?: any[];
|
|
4
|
-
}): import("ahooks/lib/useRequest/src/types").Result<
|
|
5
|
-
|
|
6
|
-
subscriptionId: any;
|
|
7
|
-
ownerDid: any;
|
|
8
|
-
isAvailable: boolean;
|
|
9
|
-
errorMessage: string;
|
|
10
|
-
errorCode: number;
|
|
11
|
-
} | undefined, []>;
|
|
12
|
+
}): import("ahooks/lib/useRequest/src/types").Result<SpaceInfo | undefined, any[]>;
|
|
13
|
+
export {};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const isUrl = require('is-url');
|
|
4
4
|
const ahooks = require('ahooks');
|
|
5
|
+
const constants = require('../libs/constants.js');
|
|
5
6
|
const api = require('../libs/api.js');
|
|
6
7
|
|
|
7
8
|
function useSpaceInfo({ endpoint, deps = [] }) {
|
|
@@ -16,14 +17,47 @@ function useSpaceInfo({ endpoint, deps = [] }) {
|
|
|
16
17
|
withExtras: true
|
|
17
18
|
}
|
|
18
19
|
});
|
|
19
|
-
const
|
|
20
|
+
const [
|
|
21
|
+
rawName,
|
|
22
|
+
rawSubscriptionId,
|
|
23
|
+
isListable,
|
|
24
|
+
isReadable,
|
|
25
|
+
isWriteable,
|
|
26
|
+
rawVersion,
|
|
27
|
+
rawOwnerDid,
|
|
28
|
+
rawAvailable,
|
|
29
|
+
rawErrorCode
|
|
30
|
+
] = [
|
|
31
|
+
headers["x-space-name"],
|
|
32
|
+
headers["x-subscription-id"],
|
|
33
|
+
headers["x-listable"] === "true",
|
|
34
|
+
headers["x-readable"] === "true",
|
|
35
|
+
headers["x-writeable"] === "true",
|
|
36
|
+
// 新版 headers
|
|
37
|
+
headers["x-space-version"],
|
|
38
|
+
headers["x-space-owner-did"],
|
|
39
|
+
headers["x-space-is-available"],
|
|
40
|
+
headers["x-error-code"]
|
|
41
|
+
];
|
|
42
|
+
const name = rawName ? decodeURIComponent(rawName) : "";
|
|
43
|
+
if (rawAvailable === void 0) {
|
|
44
|
+
const isAvailable = isListable && isReadable && isWriteable;
|
|
45
|
+
return {
|
|
46
|
+
version: rawVersion || "",
|
|
47
|
+
name,
|
|
48
|
+
subscriptionId: rawSubscriptionId,
|
|
49
|
+
ownerDid: rawOwnerDid || "",
|
|
50
|
+
isAvailable,
|
|
51
|
+
errorCode: isAvailable ? 0 : constants.SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED
|
|
52
|
+
};
|
|
53
|
+
}
|
|
20
54
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
errorCode: parseInt(
|
|
55
|
+
version: rawVersion || "",
|
|
56
|
+
name,
|
|
57
|
+
subscriptionId: rawSubscriptionId,
|
|
58
|
+
ownerDid: rawOwnerDid,
|
|
59
|
+
isAvailable: rawAvailable === "true",
|
|
60
|
+
errorCode: parseInt(rawErrorCode, 10)
|
|
27
61
|
};
|
|
28
62
|
},
|
|
29
63
|
{
|
package/dist/cjs/index.js
CHANGED
|
@@ -41,12 +41,11 @@ exports.fixCorsErrorPageUrl = constants.fixCorsErrorPageUrl;
|
|
|
41
41
|
exports.classNames = util.classNames;
|
|
42
42
|
exports.decryptSpaceGateway = util.decryptSpaceGateway;
|
|
43
43
|
exports.extraDIDSpacesCoreUrl = util.extraDIDSpacesCoreUrl;
|
|
44
|
-
exports.getDIDSpaceDidFromEndpoint = util.getDIDSpaceDidFromEndpoint;
|
|
45
|
-
exports.getDIDSpaceUrlFromEndpoint = util.getDIDSpaceUrlFromEndpoint;
|
|
46
44
|
exports.getSpaceDidFromEndpoint = util.getSpaceDidFromEndpoint;
|
|
47
45
|
exports.getSpaceDidFromSpaceUrl = util.getSpaceDidFromSpaceUrl;
|
|
48
46
|
exports.getSpaceGatewayUrlFromEndpoint = util.getSpaceGatewayUrlFromEndpoint;
|
|
49
47
|
exports.getSpaceNftDisplayUrlFromEndpoint = util.getSpaceNftDisplayUrlFromEndpoint;
|
|
48
|
+
exports.getSpaceUrlFromEndpoint = util.getSpaceUrlFromEndpoint;
|
|
50
49
|
exports.isCorsBlockedError = util.isCorsBlockedError;
|
|
51
50
|
exports.t = util.t;
|
|
52
51
|
exports.getSpaceGatewayUrl = gateway.getSpaceGatewayUrl;
|
package/dist/cjs/libs/util.d.ts
CHANGED
|
@@ -11,10 +11,9 @@ type ClassStr = string | undefined | null;
|
|
|
11
11
|
* classNames(['foo', 'bar']); // => 'foo bar'
|
|
12
12
|
*/
|
|
13
13
|
export declare function classNames(...classes: (ClassStr | Record<string, boolean> | Array<ClassStr | Record<string, boolean>>)[]): string;
|
|
14
|
-
export declare function getDIDSpaceDidFromEndpoint(endpoint: string): string | undefined;
|
|
15
|
-
export declare function getDIDSpaceUrlFromEndpoint(endpoint: string): string;
|
|
16
|
-
export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
|
|
17
14
|
export declare function getSpaceDidFromEndpoint(endpoint: string): string | undefined;
|
|
15
|
+
export declare function getSpaceUrlFromEndpoint(endpoint: string): string;
|
|
16
|
+
export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
|
|
18
17
|
export declare function getSpaceGatewayUrlFromEndpoint(endpoint: string): string;
|
|
19
18
|
export declare function extraDIDSpacesCoreUrl(url: string): string;
|
|
20
19
|
export declare function getSpaceDidFromSpaceUrl(url: string): string | undefined;
|
package/dist/cjs/libs/util.js
CHANGED
|
@@ -24,12 +24,12 @@ function classNames(...classes) {
|
|
|
24
24
|
});
|
|
25
25
|
return result.join(" ");
|
|
26
26
|
}
|
|
27
|
-
function
|
|
27
|
+
function getSpaceDidFromEndpoint(endpoint) {
|
|
28
28
|
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
29
29
|
const spaceDid = strArray.at(-4);
|
|
30
30
|
return spaceDid;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function getSpaceUrlFromEndpoint(endpoint) {
|
|
33
33
|
const prefix = endpoint.replace(/\/api\/space\/.+/, "");
|
|
34
34
|
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
35
35
|
const spaceDid = strArray.at(-4);
|
|
@@ -41,13 +41,8 @@ function getSpaceNftDisplayUrlFromEndpoint(endpoint) {
|
|
|
41
41
|
const spaceDid = strArray.at(-4);
|
|
42
42
|
return ufo.joinURL(prefix, `/api/space/nft/display?spaceDid=${spaceDid}`);
|
|
43
43
|
}
|
|
44
|
-
function getSpaceDidFromEndpoint(endpoint) {
|
|
45
|
-
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
46
|
-
const spaceDid = strArray.at(-4);
|
|
47
|
-
return spaceDid;
|
|
48
|
-
}
|
|
49
44
|
function getSpaceGatewayUrlFromEndpoint(endpoint) {
|
|
50
|
-
const spaceUrl =
|
|
45
|
+
const spaceUrl = getSpaceUrlFromEndpoint(endpoint);
|
|
51
46
|
return spaceUrl.split("/space/")[0];
|
|
52
47
|
}
|
|
53
48
|
function extraDIDSpacesCoreUrl(url) {
|
|
@@ -87,11 +82,10 @@ function t(key, localeOrData, data = {}) {
|
|
|
87
82
|
exports.classNames = classNames;
|
|
88
83
|
exports.decryptSpaceGateway = decryptSpaceGateway;
|
|
89
84
|
exports.extraDIDSpacesCoreUrl = extraDIDSpacesCoreUrl;
|
|
90
|
-
exports.getDIDSpaceDidFromEndpoint = getDIDSpaceDidFromEndpoint;
|
|
91
|
-
exports.getDIDSpaceUrlFromEndpoint = getDIDSpaceUrlFromEndpoint;
|
|
92
85
|
exports.getSpaceDidFromEndpoint = getSpaceDidFromEndpoint;
|
|
93
86
|
exports.getSpaceDidFromSpaceUrl = getSpaceDidFromSpaceUrl;
|
|
94
87
|
exports.getSpaceGatewayUrlFromEndpoint = getSpaceGatewayUrlFromEndpoint;
|
|
95
88
|
exports.getSpaceNftDisplayUrlFromEndpoint = getSpaceNftDisplayUrlFromEndpoint;
|
|
89
|
+
exports.getSpaceUrlFromEndpoint = getSpaceUrlFromEndpoint;
|
|
96
90
|
exports.isCorsBlockedError = isCorsBlockedError;
|
|
97
91
|
exports.t = t;
|
package/dist/cjs/locales/en.js
CHANGED
|
@@ -10,7 +10,8 @@ const en = flat.flatten({
|
|
|
10
10
|
error: "Error",
|
|
11
11
|
open: "Open",
|
|
12
12
|
unknown: "Unknown",
|
|
13
|
-
invalidUrl: "Invalid url: {url}"
|
|
13
|
+
invalidUrl: "Invalid url: {url}",
|
|
14
|
+
upgrade: "Upgrade"
|
|
14
15
|
},
|
|
15
16
|
storage: {
|
|
16
17
|
spaces: {
|
|
@@ -55,7 +56,9 @@ const en = flat.flatten({
|
|
|
55
56
|
success: "Connected successfully"
|
|
56
57
|
},
|
|
57
58
|
helperText: {
|
|
58
|
-
fixCorsError: "Fixing CORS Errors When Connecting to Space"
|
|
59
|
+
fixCorsError: "Fixing CORS Errors When Connecting to Space",
|
|
60
|
+
outdatedSpace: "The current version of DID Spaces is too low, please contact your administrator to upgrade for the best experience! \n If you are an administrator, you can upgrade by clicking the following link",
|
|
61
|
+
upgradeSpace: "Upgrade DID Spaces"
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
}
|
package/dist/cjs/locales/zh.js
CHANGED
|
@@ -10,7 +10,8 @@ const zh = flat.flatten({
|
|
|
10
10
|
error: "\u9519\u8BEF",
|
|
11
11
|
open: "\u6253\u5F00",
|
|
12
12
|
unknown: "\u672A\u77E5",
|
|
13
|
-
invalidUrl: "\u65E0\u6548\u7684 url: {url}"
|
|
13
|
+
invalidUrl: "\u65E0\u6548\u7684 url: {url}",
|
|
14
|
+
upgrade: "\u5347\u7EA7"
|
|
14
15
|
},
|
|
15
16
|
storage: {
|
|
16
17
|
spaces: {
|
|
@@ -53,6 +54,11 @@ const zh = flat.flatten({
|
|
|
53
54
|
title: "\u8BF7\u4E3A {appName} \u51FA\u793A DID Spaces NFT",
|
|
54
55
|
scan: "\u4F7F\u7528\u4F60\u7684 DID Wallet \u626B\u63CF\u4E0B\u9762\u7684\u4E8C\u7EF4\u7801\u4E3A\u5E94\u7528 {appName} \u51FA\u793A DID Spaces NFT",
|
|
55
56
|
success: "\u8FDE\u63A5\u6210\u529F"
|
|
57
|
+
},
|
|
58
|
+
helperText: {
|
|
59
|
+
fixCorsError: "\u4FEE\u590D\u8FDE\u63A5 DID Spaces \u65F6\u7684 CORS \u9519\u8BEF",
|
|
60
|
+
outdatedSpace: "\u5F53\u524D DID Spaces \u7248\u672C\u8FC7\u4F4E\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u5347\u7EA7\u4EE5\u83B7\u5F97\u6700\u4F73\u4F53\u9A8C\uFF01\n\u5982\u679C\u60A8\u662F\u7BA1\u7406\u5458\uFF0C\u53EF\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u5347\u7EA7",
|
|
61
|
+
upgradeSpace: "\u5347\u7EA7 DID Spaces"
|
|
56
62
|
}
|
|
57
63
|
}
|
|
58
64
|
}
|
|
@@ -15,7 +15,7 @@ function PreviewSpaceNft({
|
|
|
15
15
|
const handleClose = () => setOpen(false);
|
|
16
16
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
17
|
/* @__PURE__ */ jsxs("div", { style: { position: "relative" }, onClick: handleOpen, children: [
|
|
18
|
-
/* @__PURE__ */ jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsx(SvgEmptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width
|
|
18
|
+
/* @__PURE__ */ jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsx(SvgEmptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width, height } }) }),
|
|
19
19
|
/* @__PURE__ */ jsx(
|
|
20
20
|
"div",
|
|
21
21
|
{
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import isUndefined from 'lodash/isUndefined';
|
|
3
|
-
import {
|
|
4
|
-
import { Box,
|
|
3
|
+
import { joinURL, withQuery } from 'ufo';
|
|
4
|
+
import { Box, Tooltip, Link, Chip, Stack, Skeleton } from '@mui/material';
|
|
5
5
|
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
|
6
6
|
import DidAddress from '@arcblock/ux/lib/DID';
|
|
7
7
|
import { styled } from '@arcblock/ux/lib/Theme';
|
|
8
8
|
import { useState, useRef, useEffect } from 'react';
|
|
9
9
|
import { AxiosError } from 'axios';
|
|
10
10
|
import { useCreation } from 'ahooks';
|
|
11
|
+
import { compareVersions } from 'compare-versions';
|
|
12
|
+
import { version } from '../../package.json.js';
|
|
11
13
|
import { SPACE_CONNECT_ERROR_CODE, fixCorsErrorPageUrl } from '../../libs/constants.js';
|
|
12
14
|
import useMobile from '../../hooks/use-mobile.js';
|
|
13
15
|
import useSpaceInfo from '../../hooks/use-space-info.js';
|
|
14
16
|
import useLocale from '../../hooks/use-locale.js';
|
|
15
|
-
import {
|
|
17
|
+
import { getSpaceDidFromEndpoint, getSpaceUrlFromEndpoint, getSpaceGatewayUrlFromEndpoint, isCorsBlockedError, classNames, getSpaceNftDisplayUrlFromEndpoint } from '../../libs/util.js';
|
|
16
18
|
import { SpaceStatus } from '../../types/index.js';
|
|
17
19
|
import '../../icons/index.js';
|
|
18
20
|
import { PreviewSpaceNft } from '../preview-space-nft/index.js';
|
|
@@ -138,8 +140,9 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
138
140
|
if (isUndefined(isCompact)) {
|
|
139
141
|
isCompact = isMobile;
|
|
140
142
|
}
|
|
141
|
-
const spaceDid =
|
|
142
|
-
const spaceUrl =
|
|
143
|
+
const spaceDid = getSpaceDidFromEndpoint(endpoint);
|
|
144
|
+
const spaceUrl = getSpaceUrlFromEndpoint(endpoint);
|
|
145
|
+
const spaceOrigin = new URL(endpoint).origin;
|
|
143
146
|
const gatewayUrl = getSpaceGatewayUrlFromEndpoint(endpoint);
|
|
144
147
|
const [refreshSpaceInfo, setRefreshSpaceInfo] = useState(false);
|
|
145
148
|
const refresh = () => setRefreshSpaceInfo((p) => !p);
|
|
@@ -159,7 +162,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
159
162
|
spaceStatus.current = SpaceStatus.LOADING;
|
|
160
163
|
spaceName = /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
|
|
161
164
|
} else if (spaceInfo) {
|
|
162
|
-
spaceName = spaceInfo.
|
|
165
|
+
spaceName = spaceInfo.name;
|
|
163
166
|
if (!isAvailable) {
|
|
164
167
|
spaceStatus.current = SpaceStatus.UNAVAILABLE;
|
|
165
168
|
errorCode = spaceInfo.errorCode;
|
|
@@ -178,6 +181,8 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
178
181
|
errorCode = SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR;
|
|
179
182
|
}
|
|
180
183
|
}
|
|
184
|
+
const spaceVersion = spaceInfo?.version;
|
|
185
|
+
const isLegacySpace = !!spaceInfo && (!spaceVersion || compareVersions(spaceVersion, version) < 0);
|
|
181
186
|
const renderAction = () => {
|
|
182
187
|
if (loading)
|
|
183
188
|
return null;
|
|
@@ -185,7 +190,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
185
190
|
return action({
|
|
186
191
|
spaceGateway: {
|
|
187
192
|
did: spaceDid,
|
|
188
|
-
name: spaceInfo?.
|
|
193
|
+
name: spaceInfo?.name ?? "",
|
|
189
194
|
url: gatewayUrl,
|
|
190
195
|
endpoint,
|
|
191
196
|
ownerDid: spaceInfo?.ownerDid ?? ""
|
|
@@ -194,6 +199,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
194
199
|
errorCode,
|
|
195
200
|
selected,
|
|
196
201
|
compat: isCompact,
|
|
202
|
+
isLegacySpace,
|
|
197
203
|
refresh
|
|
198
204
|
});
|
|
199
205
|
}
|
|
@@ -209,7 +215,36 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
209
215
|
...rest,
|
|
210
216
|
children: [
|
|
211
217
|
/* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", children: [
|
|
212
|
-
/* @__PURE__ */
|
|
218
|
+
/* @__PURE__ */ jsxs(Box, { sx: { position: "relative" }, children: [
|
|
219
|
+
isLegacySpace && /* @__PURE__ */ jsx(Box, { sx: { position: "absolute", top: 0, right: 0, zIndex: 2, transform: "translate(40%, -50%)" }, children: /* @__PURE__ */ jsx(
|
|
220
|
+
Tooltip,
|
|
221
|
+
{
|
|
222
|
+
title: /* @__PURE__ */ jsxs("span", { style: { whiteSpace: "pre-wrap" }, children: [
|
|
223
|
+
t("storage.spaces.helperText.outdatedSpace"),
|
|
224
|
+
/* @__PURE__ */ jsx(
|
|
225
|
+
Link,
|
|
226
|
+
{
|
|
227
|
+
href: joinURL(spaceOrigin, ".well-known/service/admin/components"),
|
|
228
|
+
target: "_blank",
|
|
229
|
+
sx: { pl: 0.5 },
|
|
230
|
+
children: t("storage.spaces.helperText.upgradeSpace")
|
|
231
|
+
}
|
|
232
|
+
)
|
|
233
|
+
] }),
|
|
234
|
+
placement: "top",
|
|
235
|
+
children: /* @__PURE__ */ jsx(
|
|
236
|
+
Chip,
|
|
237
|
+
{
|
|
238
|
+
label: t("common.upgrade"),
|
|
239
|
+
color: "error",
|
|
240
|
+
size: "small",
|
|
241
|
+
sx: { transform: "scale(0.8)", cursor: "pointer" }
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
) }),
|
|
246
|
+
/* @__PURE__ */ jsx(PreviewSpaceNft, { src: getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" })
|
|
247
|
+
] }),
|
|
213
248
|
/* @__PURE__ */ jsxs(Stack, { ml: 2, flex: 1, spacing: 1, minWidth: 0, children: [
|
|
214
249
|
/* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", sx: { whiteSpace: "nowrap" }, children: [
|
|
215
250
|
spaceName && /* @__PURE__ */ jsx(Box, { className: "space-name", children: spaceName }),
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
type SpaceInfo = {
|
|
2
|
+
version: string;
|
|
3
|
+
name: string;
|
|
4
|
+
subscriptionId: string;
|
|
5
|
+
ownerDid: string;
|
|
6
|
+
isAvailable: boolean;
|
|
7
|
+
errorCode: number;
|
|
8
|
+
};
|
|
1
9
|
export default function useSpaceInfo({ endpoint, deps }: {
|
|
2
10
|
endpoint: string;
|
|
3
11
|
deps?: any[];
|
|
4
|
-
}): import("ahooks/lib/useRequest/src/types").Result<
|
|
5
|
-
|
|
6
|
-
subscriptionId: any;
|
|
7
|
-
ownerDid: any;
|
|
8
|
-
isAvailable: boolean;
|
|
9
|
-
errorMessage: string;
|
|
10
|
-
errorCode: number;
|
|
11
|
-
} | undefined, []>;
|
|
12
|
+
}): import("ahooks/lib/useRequest/src/types").Result<SpaceInfo | undefined, any[]>;
|
|
13
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import isUrl from 'is-url';
|
|
2
2
|
import { useRequest } from 'ahooks';
|
|
3
|
+
import { SPACE_CONNECT_ERROR_CODE } from '../libs/constants.js';
|
|
3
4
|
import api from '../libs/api.js';
|
|
4
5
|
|
|
5
6
|
function useSpaceInfo({ endpoint, deps = [] }) {
|
|
@@ -14,14 +15,47 @@ function useSpaceInfo({ endpoint, deps = [] }) {
|
|
|
14
15
|
withExtras: true
|
|
15
16
|
}
|
|
16
17
|
});
|
|
17
|
-
const
|
|
18
|
+
const [
|
|
19
|
+
rawName,
|
|
20
|
+
rawSubscriptionId,
|
|
21
|
+
isListable,
|
|
22
|
+
isReadable,
|
|
23
|
+
isWriteable,
|
|
24
|
+
rawVersion,
|
|
25
|
+
rawOwnerDid,
|
|
26
|
+
rawAvailable,
|
|
27
|
+
rawErrorCode
|
|
28
|
+
] = [
|
|
29
|
+
headers["x-space-name"],
|
|
30
|
+
headers["x-subscription-id"],
|
|
31
|
+
headers["x-listable"] === "true",
|
|
32
|
+
headers["x-readable"] === "true",
|
|
33
|
+
headers["x-writeable"] === "true",
|
|
34
|
+
// 新版 headers
|
|
35
|
+
headers["x-space-version"],
|
|
36
|
+
headers["x-space-owner-did"],
|
|
37
|
+
headers["x-space-is-available"],
|
|
38
|
+
headers["x-error-code"]
|
|
39
|
+
];
|
|
40
|
+
const name = rawName ? decodeURIComponent(rawName) : "";
|
|
41
|
+
if (rawAvailable === void 0) {
|
|
42
|
+
const isAvailable = isListable && isReadable && isWriteable;
|
|
43
|
+
return {
|
|
44
|
+
version: rawVersion || "",
|
|
45
|
+
name,
|
|
46
|
+
subscriptionId: rawSubscriptionId,
|
|
47
|
+
ownerDid: rawOwnerDid || "",
|
|
48
|
+
isAvailable,
|
|
49
|
+
errorCode: isAvailable ? 0 : SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED
|
|
50
|
+
};
|
|
51
|
+
}
|
|
18
52
|
return {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
errorCode: parseInt(
|
|
53
|
+
version: rawVersion || "",
|
|
54
|
+
name,
|
|
55
|
+
subscriptionId: rawSubscriptionId,
|
|
56
|
+
ownerDid: rawOwnerDid,
|
|
57
|
+
isAvailable: rawAvailable === "true",
|
|
58
|
+
errorCode: parseInt(rawErrorCode, 10)
|
|
25
59
|
};
|
|
26
60
|
},
|
|
27
61
|
{
|
package/dist/es/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { BaseConnectTo } from './components/base-connect-to/index.js';
|
|
|
8
8
|
export { AuthConnectTo } from './components/auth-connect-to/index.js';
|
|
9
9
|
export { SessionConnectTo } from './components/session-connect-to/index.js';
|
|
10
10
|
export { AUTHORIZE, SPACE_CONNECT_ERROR_CODE, copyGatewayPageUrl, fixCorsErrorPageUrl } from './libs/constants.js';
|
|
11
|
-
export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl,
|
|
11
|
+
export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, getSpaceUrlFromEndpoint, isCorsBlockedError, t } from './libs/util.js';
|
|
12
12
|
export { getSpaceGatewayUrl, verifySpaceUrl } from './libs/gateway.js';
|
|
13
13
|
export { translations } from './locales/index.js';
|
|
14
14
|
export { SpaceStatus } from './types/index.js';
|
package/dist/es/libs/util.d.ts
CHANGED
|
@@ -11,10 +11,9 @@ type ClassStr = string | undefined | null;
|
|
|
11
11
|
* classNames(['foo', 'bar']); // => 'foo bar'
|
|
12
12
|
*/
|
|
13
13
|
export declare function classNames(...classes: (ClassStr | Record<string, boolean> | Array<ClassStr | Record<string, boolean>>)[]): string;
|
|
14
|
-
export declare function getDIDSpaceDidFromEndpoint(endpoint: string): string | undefined;
|
|
15
|
-
export declare function getDIDSpaceUrlFromEndpoint(endpoint: string): string;
|
|
16
|
-
export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
|
|
17
14
|
export declare function getSpaceDidFromEndpoint(endpoint: string): string | undefined;
|
|
15
|
+
export declare function getSpaceUrlFromEndpoint(endpoint: string): string;
|
|
16
|
+
export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
|
|
18
17
|
export declare function getSpaceGatewayUrlFromEndpoint(endpoint: string): string;
|
|
19
18
|
export declare function extraDIDSpacesCoreUrl(url: string): string;
|
|
20
19
|
export declare function getSpaceDidFromSpaceUrl(url: string): string | undefined;
|
package/dist/es/libs/util.js
CHANGED
|
@@ -22,12 +22,12 @@ function classNames(...classes) {
|
|
|
22
22
|
});
|
|
23
23
|
return result.join(" ");
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function getSpaceDidFromEndpoint(endpoint) {
|
|
26
26
|
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
27
27
|
const spaceDid = strArray.at(-4);
|
|
28
28
|
return spaceDid;
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function getSpaceUrlFromEndpoint(endpoint) {
|
|
31
31
|
const prefix = endpoint.replace(/\/api\/space\/.+/, "");
|
|
32
32
|
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
33
33
|
const spaceDid = strArray.at(-4);
|
|
@@ -39,13 +39,8 @@ function getSpaceNftDisplayUrlFromEndpoint(endpoint) {
|
|
|
39
39
|
const spaceDid = strArray.at(-4);
|
|
40
40
|
return joinURL(prefix, `/api/space/nft/display?spaceDid=${spaceDid}`);
|
|
41
41
|
}
|
|
42
|
-
function getSpaceDidFromEndpoint(endpoint) {
|
|
43
|
-
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
44
|
-
const spaceDid = strArray.at(-4);
|
|
45
|
-
return spaceDid;
|
|
46
|
-
}
|
|
47
42
|
function getSpaceGatewayUrlFromEndpoint(endpoint) {
|
|
48
|
-
const spaceUrl =
|
|
43
|
+
const spaceUrl = getSpaceUrlFromEndpoint(endpoint);
|
|
49
44
|
return spaceUrl.split("/space/")[0];
|
|
50
45
|
}
|
|
51
46
|
function extraDIDSpacesCoreUrl(url) {
|
|
@@ -82,4 +77,4 @@ function t(key, localeOrData, data = {}) {
|
|
|
82
77
|
return translate(translations, key, locale, "en", finalData);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
|
-
export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl,
|
|
80
|
+
export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, getSpaceUrlFromEndpoint, isCorsBlockedError, t };
|
package/dist/es/locales/en.js
CHANGED
|
@@ -8,7 +8,8 @@ const en = flatten({
|
|
|
8
8
|
error: "Error",
|
|
9
9
|
open: "Open",
|
|
10
10
|
unknown: "Unknown",
|
|
11
|
-
invalidUrl: "Invalid url: {url}"
|
|
11
|
+
invalidUrl: "Invalid url: {url}",
|
|
12
|
+
upgrade: "Upgrade"
|
|
12
13
|
},
|
|
13
14
|
storage: {
|
|
14
15
|
spaces: {
|
|
@@ -53,7 +54,9 @@ const en = flatten({
|
|
|
53
54
|
success: "Connected successfully"
|
|
54
55
|
},
|
|
55
56
|
helperText: {
|
|
56
|
-
fixCorsError: "Fixing CORS Errors When Connecting to Space"
|
|
57
|
+
fixCorsError: "Fixing CORS Errors When Connecting to Space",
|
|
58
|
+
outdatedSpace: "The current version of DID Spaces is too low, please contact your administrator to upgrade for the best experience! \n If you are an administrator, you can upgrade by clicking the following link",
|
|
59
|
+
upgradeSpace: "Upgrade DID Spaces"
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
}
|
package/dist/es/locales/zh.js
CHANGED
|
@@ -8,7 +8,8 @@ const zh = flatten({
|
|
|
8
8
|
error: "\u9519\u8BEF",
|
|
9
9
|
open: "\u6253\u5F00",
|
|
10
10
|
unknown: "\u672A\u77E5",
|
|
11
|
-
invalidUrl: "\u65E0\u6548\u7684 url: {url}"
|
|
11
|
+
invalidUrl: "\u65E0\u6548\u7684 url: {url}",
|
|
12
|
+
upgrade: "\u5347\u7EA7"
|
|
12
13
|
},
|
|
13
14
|
storage: {
|
|
14
15
|
spaces: {
|
|
@@ -51,6 +52,11 @@ const zh = flatten({
|
|
|
51
52
|
title: "\u8BF7\u4E3A {appName} \u51FA\u793A DID Spaces NFT",
|
|
52
53
|
scan: "\u4F7F\u7528\u4F60\u7684 DID Wallet \u626B\u63CF\u4E0B\u9762\u7684\u4E8C\u7EF4\u7801\u4E3A\u5E94\u7528 {appName} \u51FA\u793A DID Spaces NFT",
|
|
53
54
|
success: "\u8FDE\u63A5\u6210\u529F"
|
|
55
|
+
},
|
|
56
|
+
helperText: {
|
|
57
|
+
fixCorsError: "\u4FEE\u590D\u8FDE\u63A5 DID Spaces \u65F6\u7684 CORS \u9519\u8BEF",
|
|
58
|
+
outdatedSpace: "\u5F53\u524D DID Spaces \u7248\u672C\u8FC7\u4F4E\uFF0C\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u5347\u7EA7\u4EE5\u83B7\u5F97\u6700\u4F73\u4F53\u9A8C\uFF01\n\u5982\u679C\u60A8\u662F\u7BA1\u7406\u5458\uFF0C\u53EF\u70B9\u51FB\u4EE5\u4E0B\u94FE\u63A5\u5347\u7EA7",
|
|
59
|
+
upgradeSpace: "\u5347\u7EA7 DID Spaces"
|
|
54
60
|
}
|
|
55
61
|
}
|
|
56
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/did-space-react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.77",
|
|
4
4
|
"description": "Reusable react components for did space",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"@arcblock/did": "^1.18.152",
|
|
88
|
-
"@arcblock/did-connect": "^2.10.
|
|
89
|
-
"@arcblock/ux": "^2.10.
|
|
88
|
+
"@arcblock/did-connect": "^2.10.76",
|
|
89
|
+
"@arcblock/ux": "^2.10.76",
|
|
90
90
|
"@blocklet/js-sdk": "^1.16.34-beta-20241129-100152-679bd732",
|
|
91
91
|
"@blocklet/sdk": "^1.16.34-beta-20241129-100152-679bd732",
|
|
92
92
|
"@mui/icons-material": "^5.16.8",
|
|
@@ -95,6 +95,7 @@
|
|
|
95
95
|
"@mui/system": "^5.16.8",
|
|
96
96
|
"ahooks": "^3.8.1",
|
|
97
97
|
"axios": "^1.7.8",
|
|
98
|
+
"compare-versions": "^6.1.1",
|
|
98
99
|
"flat": "^5.0.2",
|
|
99
100
|
"is-url": "^1.2.4",
|
|
100
101
|
"lodash": "^4.17.21",
|
|
@@ -127,7 +128,7 @@
|
|
|
127
128
|
"@types/react": "^18.3.12",
|
|
128
129
|
"@types/react-dom": "^18.3.1",
|
|
129
130
|
"@vitejs/plugin-legacy": "^5.4.3",
|
|
130
|
-
"@vitest/coverage-v8": "^2.1.
|
|
131
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
131
132
|
"babel-plugin-inline-react-svg": "^2.0.2",
|
|
132
133
|
"copyfiles": "^2.4.1",
|
|
133
134
|
"eslint": "^8.57.1",
|
|
@@ -137,13 +138,13 @@
|
|
|
137
138
|
"react-dom": "^18.3.1",
|
|
138
139
|
"rollup-plugin-node-builtins": "^2.1.2",
|
|
139
140
|
"storybook": "^7.6.20",
|
|
140
|
-
"type-fest": "^4.
|
|
141
|
+
"type-fest": "^4.30.0",
|
|
141
142
|
"typescript": "~5.5.4",
|
|
142
143
|
"unbuild": "^2.0.0",
|
|
143
144
|
"vite": "^5.4.11",
|
|
144
145
|
"vite-plugin-babel": "^1.2.0",
|
|
145
146
|
"vite-plugin-node-polyfills": "^0.22.0",
|
|
146
|
-
"vitest": "^2.1.
|
|
147
|
+
"vitest": "^2.1.8"
|
|
147
148
|
},
|
|
148
|
-
"gitHead": "
|
|
149
|
+
"gitHead": "46a997767b63ac536c1c3811e42ba62d6b1ccdf8"
|
|
149
150
|
}
|