@blocklet/did-space-react 0.5.57 → 0.5.59
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/.turbo/turbo-build.log +37 -18
- package/.turbo/turbo-lint$colon$fix.log +2 -2
- package/README.md +85 -39
- package/es/components/auth-connect-to/base-auth.d.ts +5 -0
- package/es/components/auth-connect-to/base-auth.js +60 -0
- package/es/components/auth-connect-to/gateway-auth.d.ts +5 -0
- package/es/components/auth-connect-to/gateway-auth.js +49 -0
- package/es/components/auth-connect-to/index.d.ts +18 -0
- package/es/components/auth-connect-to/index.js +61 -0
- package/es/components/base-connect-to/index.d.ts +10 -0
- package/es/components/{ConnectTo → base-connect-to}/index.js +32 -26
- package/{lib/components/PreviewNFT → es/components/preview-space-nft}/index.d.ts +1 -2
- package/es/components/{PreviewNFT → preview-space-nft}/index.js +7 -2
- package/es/components/session-connect-to/index.d.ts +16 -0
- package/es/components/session-connect-to/index.js +26 -0
- package/es/components/session-connect-to/re-connect.d.ts +13 -0
- package/es/components/session-connect-to/re-connect.js +51 -0
- package/es/components/{SpaceCard → space-card}/index.d.ts +1 -2
- package/es/components/{SpaceCard → space-card}/index.js +82 -33
- package/es/hooks/use-space-info.js +1 -1
- package/es/icons/index.d.ts +5 -4
- package/es/icons/index.js +11 -0
- package/es/index.d.ts +8 -5
- package/es/index.js +15 -4
- package/es/libs/constants.d.ts +4 -0
- package/es/libs/constants.js +6 -0
- package/es/libs/util.d.ts +1 -0
- package/es/libs/util.js +15 -1
- package/es/locales/en.js +27 -9
- package/es/locales/zh.js +27 -9
- package/es/types/index.d.ts +22 -7
- package/es/types/index.js +3 -1
- package/lib/components/auth-connect-to/base-auth.d.ts +5 -0
- package/lib/components/auth-connect-to/base-auth.js +62 -0
- package/lib/components/auth-connect-to/gateway-auth.d.ts +5 -0
- package/lib/components/auth-connect-to/gateway-auth.js +51 -0
- package/lib/components/auth-connect-to/index.d.ts +18 -0
- package/lib/components/auth-connect-to/index.js +65 -0
- package/lib/components/base-connect-to/index.d.ts +10 -0
- package/lib/components/{ConnectTo → base-connect-to}/index.js +31 -25
- package/{es/components/PreviewNFT → lib/components/preview-space-nft}/index.d.ts +1 -2
- package/lib/components/{PreviewNFT → preview-space-nft}/index.js +7 -2
- package/lib/components/session-connect-to/index.d.ts +16 -0
- package/lib/components/session-connect-to/index.js +29 -0
- package/lib/components/session-connect-to/re-connect.d.ts +13 -0
- package/lib/components/session-connect-to/re-connect.js +53 -0
- package/lib/components/{SpaceCard → space-card}/index.d.ts +1 -2
- package/lib/components/{SpaceCard → space-card}/index.js +82 -33
- package/lib/hooks/use-space-info.js +1 -1
- package/lib/icons/index.d.ts +5 -4
- package/lib/icons/index.js +16 -0
- package/lib/index.d.ts +8 -5
- package/lib/index.js +33 -10
- package/lib/libs/constants.d.ts +4 -0
- package/lib/libs/constants.js +9 -0
- package/lib/libs/util.d.ts +1 -0
- package/lib/libs/util.js +15 -0
- package/lib/locales/en.js +27 -9
- package/lib/locales/zh.js +27 -9
- package/lib/types/index.d.ts +22 -7
- package/lib/types/index.js +3 -1
- package/package.json +47 -36
- package/src/components/auth-connect-to/base-auth.tsx +64 -0
- package/src/components/auth-connect-to/gateway-auth.tsx +53 -0
- package/src/components/auth-connect-to/index.tsx +71 -0
- package/src/components/{ConnectTo/connect-to.stories.tsx → base-connect-to/base-connect-to.stories.tsx} +1 -1
- package/src/components/{ConnectTo → base-connect-to}/index.tsx +35 -22
- package/src/components/{PreviewNFT → preview-space-nft}/index.tsx +12 -6
- package/src/components/session-connect-to/index.tsx +39 -0
- package/src/components/session-connect-to/re-connect.tsx +57 -0
- package/src/components/{SpaceCard → space-card}/index.tsx +88 -30
- package/src/hooks/use-space-info.ts +1 -1
- package/src/icons/index.tsx +12 -4
- package/src/index.ts +11 -6
- package/src/libs/constants.ts +4 -0
- package/src/libs/util.ts +17 -0
- package/src/locales/en.tsx +26 -7
- package/src/locales/zh.tsx +25 -7
- package/src/types/index.ts +23 -6
- package/src/types/shims.d.ts +4 -4
- package/es/components/ConnectTo/index.d.ts +0 -10
- package/es/libs/theme.d.ts +0 -1
- package/lib/components/ConnectTo/index.d.ts +0 -10
- package/lib/libs/theme.d.ts +0 -1
- package/src/libs/theme.ts +0 -18
- /package/es/components/{ConnectTo/connect-to.stories.d.ts → base-connect-to/base-connect-to.stories.d.ts} +0 -0
- /package/es/components/{SpaceCard → space-card}/space-card.stories.d.ts +0 -0
- /package/lib/components/{ConnectTo/connect-to.stories.d.ts → base-connect-to/base-connect-to.stories.d.ts} +0 -0
- /package/lib/components/{SpaceCard → space-card}/space-card.stories.d.ts +0 -0
- /package/src/components/{SpaceCard → space-card}/space-card.stories.tsx +0 -0
|
@@ -4,28 +4,32 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
const isUndefined = require('lodash/isUndefined');
|
|
5
5
|
const ufo = require('ufo');
|
|
6
6
|
const material = require('@mui/material');
|
|
7
|
+
const OpenInNewIcon = require('@mui/icons-material/OpenInNew');
|
|
7
8
|
const DidAddress = require('@arcblock/ux/lib/DID');
|
|
8
9
|
const Theme = require('@arcblock/ux/lib/Theme');
|
|
9
10
|
const React = require('react');
|
|
11
|
+
const axios = require('axios');
|
|
10
12
|
const useMobile = require('../../hooks/use-mobile.js');
|
|
11
13
|
const useSpaceInfo = require('../../hooks/use-space-info.js');
|
|
12
14
|
const useLocale = require('../../hooks/use-locale.js');
|
|
13
15
|
const util = require('../../libs/util.js');
|
|
14
16
|
const index = require('../../types/index.js');
|
|
17
|
+
require('../../icons/index.js');
|
|
18
|
+
const index$1 = require('../preview-space-nft/index.js');
|
|
15
19
|
const spaceConnected = require('../../icons/space-connected.svg.js');
|
|
16
20
|
const spaceDisconnect = require('../../icons/space-disconnect.svg.js');
|
|
17
21
|
const spaceConnectError = require('../../icons/space-connect-error.svg.js');
|
|
18
|
-
const index$1 = require('../PreviewNFT/index.js');
|
|
19
22
|
|
|
20
23
|
function Status({
|
|
21
24
|
spaceUrl,
|
|
22
25
|
status,
|
|
26
|
+
isError,
|
|
23
27
|
refresh,
|
|
24
28
|
sx,
|
|
25
29
|
...rest
|
|
26
30
|
}) {
|
|
27
31
|
const { t } = useLocale();
|
|
28
|
-
const iconStyle = {
|
|
32
|
+
const iconStyle = { marginRight: "4px" };
|
|
29
33
|
let icon = null;
|
|
30
34
|
let text = null;
|
|
31
35
|
if (status === index.SpaceStatus.CONNECTED) {
|
|
@@ -38,24 +42,28 @@ function Status({
|
|
|
38
42
|
}
|
|
39
43
|
if (status === index.SpaceStatus.EXPIRED) {
|
|
40
44
|
icon = /* @__PURE__ */ jsxRuntime.jsx(spaceConnectError, { style: iconStyle });
|
|
41
|
-
text = /* @__PURE__ */ jsxRuntime.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
text = /* @__PURE__ */ jsxRuntime.jsx(material.Tooltip, { title: t("storage.spaces.error.expired"), placement: "top", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
46
|
+
material.Link,
|
|
47
|
+
{
|
|
48
|
+
href: ufo.withQuery(ufo.joinURL(spaceUrl, "overview"), { guide: 1 }),
|
|
49
|
+
target: "_blank",
|
|
50
|
+
underline: "hover",
|
|
51
|
+
color: "error",
|
|
52
|
+
sx: { display: "flex", alignItems: "center", color: "error.main" },
|
|
53
|
+
children: [
|
|
54
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: t("storage.spaces.error.tag") }),
|
|
55
|
+
/* @__PURE__ */ jsxRuntime.jsx(OpenInNewIcon, { sx: { fontSize: "14px", marginLeft: "4px" } })
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
) });
|
|
59
|
+
}
|
|
60
|
+
if (status === index.SpaceStatus.CORS_BLOCKED) {
|
|
61
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(spaceConnectError, { style: iconStyle });
|
|
62
|
+
text = /* @__PURE__ */ jsxRuntime.jsx(material.Tooltip, { title: t("storage.spaces.error.corsBlocked"), placement: "top", children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", alignItems: "center", color: "error.main" }, children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: t("storage.spaces.error.tag") }) }) });
|
|
63
|
+
}
|
|
64
|
+
if (status === index.SpaceStatus.UNKNOWN) {
|
|
65
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(spaceConnectError, { style: iconStyle });
|
|
66
|
+
text = /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { color: "error.main" }, children: t("storage.spaces.error.networkError") });
|
|
59
67
|
}
|
|
60
68
|
React.useEffect(() => {
|
|
61
69
|
const handleVisibilityChange = () => {
|
|
@@ -63,13 +71,13 @@ function Status({
|
|
|
63
71
|
refresh();
|
|
64
72
|
}
|
|
65
73
|
};
|
|
66
|
-
if (
|
|
74
|
+
if (isError) {
|
|
67
75
|
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
68
76
|
} else {
|
|
69
77
|
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
70
78
|
}
|
|
71
79
|
return () => document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
72
|
-
}, [
|
|
80
|
+
}, [isError, refresh]);
|
|
73
81
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
74
82
|
material.Box,
|
|
75
83
|
{
|
|
@@ -86,6 +94,7 @@ function Status({
|
|
|
86
94
|
}
|
|
87
95
|
function SpaceCard({ endpoint, selected = false, compat, action, className, deps, ...rest }) {
|
|
88
96
|
const isMobile = useMobile();
|
|
97
|
+
const { t } = useLocale();
|
|
89
98
|
let isCompact = compat;
|
|
90
99
|
if (isUndefined(isCompact)) {
|
|
91
100
|
isCompact = isMobile;
|
|
@@ -95,22 +104,43 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
95
104
|
const gatewayUrl = util.getSpaceGatewayUrlFromEndpoint(endpoint);
|
|
96
105
|
const [refreshSpaceInfo, setRefreshSpaceInfo] = React.useState(false);
|
|
97
106
|
const refresh = () => setRefreshSpaceInfo((p) => !p);
|
|
98
|
-
const {
|
|
107
|
+
const {
|
|
108
|
+
data: spaceInfo,
|
|
109
|
+
error,
|
|
110
|
+
loading
|
|
111
|
+
} = useSpaceInfo({
|
|
99
112
|
endpoint,
|
|
100
113
|
deps: [refreshSpaceInfo].concat(deps ?? [])
|
|
101
114
|
});
|
|
102
|
-
|
|
115
|
+
let spaceName = "";
|
|
103
116
|
const hasPermission = spaceInfo?.hasPermission ?? false;
|
|
104
117
|
const isAvailable = spaceInfo?.isAvailable ?? false;
|
|
105
|
-
|
|
106
|
-
|
|
118
|
+
let isError = false;
|
|
119
|
+
const spaceStatus = React.useRef(index.SpaceStatus.LOADING);
|
|
120
|
+
if (loading) {
|
|
121
|
+
spaceStatus.current = index.SpaceStatus.LOADING;
|
|
122
|
+
spaceName = /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
|
|
123
|
+
} else if (spaceInfo) {
|
|
124
|
+
spaceName = spaceInfo.spaceName;
|
|
107
125
|
if (!isAvailable) {
|
|
108
126
|
spaceStatus.current = index.SpaceStatus.EXPIRED;
|
|
127
|
+
isError = true;
|
|
109
128
|
} else if (hasPermission) {
|
|
110
129
|
spaceStatus.current = index.SpaceStatus.CONNECTED;
|
|
111
130
|
} else {
|
|
112
131
|
spaceStatus.current = index.SpaceStatus.DISCONNECTED;
|
|
113
132
|
}
|
|
133
|
+
} else if (error instanceof axios.AxiosError) {
|
|
134
|
+
spaceName = t("common.unknown");
|
|
135
|
+
isError = true;
|
|
136
|
+
if (!error.response && // 无响应
|
|
137
|
+
error.message === "Network Error" && // 网络错误
|
|
138
|
+
error.code !== "ECONNABORTED" && // 非超时引起
|
|
139
|
+
new URL(error.config.url).origin !== window.location.origin) {
|
|
140
|
+
spaceStatus.current = index.SpaceStatus.CORS_BLOCKED;
|
|
141
|
+
} else {
|
|
142
|
+
spaceStatus.current = index.SpaceStatus.UNKNOWN;
|
|
143
|
+
}
|
|
114
144
|
}
|
|
115
145
|
const renderAction = () => {
|
|
116
146
|
if (loading)
|
|
@@ -119,7 +149,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
119
149
|
return action({
|
|
120
150
|
spaceGateway: {
|
|
121
151
|
did: spaceDid,
|
|
122
|
-
name: spaceName,
|
|
152
|
+
name: spaceInfo?.spaceName ?? "",
|
|
123
153
|
url: gatewayUrl,
|
|
124
154
|
endpoint
|
|
125
155
|
},
|
|
@@ -136,16 +166,25 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
136
166
|
{
|
|
137
167
|
className: util.classNames(className, {
|
|
138
168
|
selected,
|
|
139
|
-
error:
|
|
169
|
+
error: isError
|
|
140
170
|
}),
|
|
141
171
|
...rest,
|
|
142
172
|
children: [
|
|
143
173
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", children: [
|
|
144
|
-
/* @__PURE__ */ jsxRuntime.jsx(index$1, { src: util.getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
|
|
174
|
+
/* @__PURE__ */ jsxRuntime.jsx(index$1.PreviewSpaceNft, { src: util.getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
|
|
145
175
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Stack, { ml: 2, flex: 1, spacing: 1, minWidth: 0, children: [
|
|
146
176
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", sx: { whiteSpace: "nowrap" }, children: [
|
|
147
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { className: "space-name", children: spaceName }),
|
|
148
|
-
!isCompact && selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
177
|
+
spaceName && /* @__PURE__ */ jsxRuntime.jsx(material.Box, { className: "space-name", children: spaceName }),
|
|
178
|
+
!isCompact && selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
179
|
+
Status,
|
|
180
|
+
{
|
|
181
|
+
spaceUrl,
|
|
182
|
+
status: spaceStatus.current,
|
|
183
|
+
refresh,
|
|
184
|
+
isError,
|
|
185
|
+
sx: { mr: 1 }
|
|
186
|
+
}
|
|
187
|
+
)
|
|
149
188
|
] }),
|
|
150
189
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
151
190
|
DidAddress,
|
|
@@ -166,7 +205,16 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
|
|
|
166
205
|
!isCompact && renderAction()
|
|
167
206
|
] }),
|
|
168
207
|
isCompact && /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", marginTop: 0.5, children: [
|
|
169
|
-
selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
208
|
+
selected && /* @__PURE__ */ jsxRuntime.jsx(
|
|
209
|
+
Status,
|
|
210
|
+
{
|
|
211
|
+
spaceUrl,
|
|
212
|
+
status: spaceStatus.current,
|
|
213
|
+
refresh,
|
|
214
|
+
isError,
|
|
215
|
+
flexShrink: 0
|
|
216
|
+
}
|
|
217
|
+
),
|
|
170
218
|
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { flex: 1 }),
|
|
171
219
|
renderAction()
|
|
172
220
|
] })
|
|
@@ -194,7 +242,8 @@ const BoxContainer = Theme.styled(material.Box)`
|
|
|
194
242
|
white-space: nowrap;
|
|
195
243
|
overflow: hidden;
|
|
196
244
|
text-overflow: ellipsis;
|
|
245
|
+
margin-right: 8px;
|
|
197
246
|
}
|
|
198
247
|
`;
|
|
199
248
|
|
|
200
|
-
|
|
249
|
+
exports.SpaceCard = SpaceCard;
|
package/lib/icons/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import EmptySpacesNFTIcon from './empty-space-nft.svg';
|
|
2
|
+
import SpacesConnectedIcon from './space-connected.svg';
|
|
3
|
+
import SpaceDisconnectedIcon from './space-disconnect.svg';
|
|
4
|
+
import SpaceConnectErrorIcon from './space-connect-error.svg';
|
|
5
|
+
export { EmptySpacesNFTIcon, SpacesConnectedIcon, SpaceDisconnectedIcon, SpaceConnectErrorIcon };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const emptySpaceNft = require('./empty-space-nft.svg.js');
|
|
4
|
+
const spaceConnected = require('./space-connected.svg.js');
|
|
5
|
+
const spaceDisconnect = require('./space-disconnect.svg.js');
|
|
6
|
+
const spaceConnectError = require('./space-connect-error.svg.js');
|
|
7
|
+
|
|
8
|
+
emptySpaceNft.displayName = "EmptySpacesNFTIcon";
|
|
9
|
+
spaceConnected.displayName = "SpacesConnectedIcon";
|
|
10
|
+
spaceDisconnect.displayName = "SpaceDisconnectedIcon";
|
|
11
|
+
spaceConnectError.displayName = "SpaceConnectErrorIcon";
|
|
12
|
+
|
|
13
|
+
exports.EmptySpacesNFTIcon = emptySpaceNft;
|
|
14
|
+
exports.SpacesConnectedIcon = spaceConnected;
|
|
15
|
+
exports.SpaceDisconnectedIcon = spaceDisconnect;
|
|
16
|
+
exports.SpaceConnectErrorIcon = spaceConnectError;
|
package/lib/index.d.ts
CHANGED
|
@@ -2,11 +2,14 @@ import api from './libs/api';
|
|
|
2
2
|
import useMobile from './hooks/use-mobile';
|
|
3
3
|
import useSpaceInfo from './hooks/use-space-info';
|
|
4
4
|
import useLocale from './hooks/use-locale';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
5
|
+
export * from './components/space-card';
|
|
6
|
+
export * from './components/preview-space-nft';
|
|
7
|
+
export * from './components/base-connect-to';
|
|
8
|
+
export * from './components/auth-connect-to';
|
|
9
|
+
export * from './components/session-connect-to';
|
|
9
10
|
export * from './libs/util';
|
|
11
|
+
export * from './libs/gateway';
|
|
10
12
|
export * from './locales';
|
|
11
13
|
export * from './types';
|
|
12
|
-
export { api,
|
|
14
|
+
export { api, useMobile, useSpaceInfo, useLocale };
|
|
15
|
+
export * from './icons';
|
package/lib/index.js
CHANGED
|
@@ -4,12 +4,23 @@ const api = require('./libs/api.js');
|
|
|
4
4
|
const useMobile = require('./hooks/use-mobile.js');
|
|
5
5
|
const useSpaceInfo = require('./hooks/use-space-info.js');
|
|
6
6
|
const useLocale = require('./hooks/use-locale.js');
|
|
7
|
-
const index = require('./components/
|
|
8
|
-
const index$1 = require('./components/
|
|
9
|
-
const index$2 = require('./components/
|
|
7
|
+
const index = require('./components/space-card/index.js');
|
|
8
|
+
const index$1 = require('./components/preview-space-nft/index.js');
|
|
9
|
+
const index$2 = require('./components/base-connect-to/index.js');
|
|
10
|
+
const index$3 = require('./components/auth-connect-to/index.js');
|
|
11
|
+
const index$4 = require('./components/session-connect-to/index.js');
|
|
10
12
|
const util = require('./libs/util.js');
|
|
11
|
-
const
|
|
12
|
-
const index$
|
|
13
|
+
const gateway = require('./libs/gateway.js');
|
|
14
|
+
const index$5 = require('./locales/index.js');
|
|
15
|
+
const index$6 = require('./types/index.js');
|
|
16
|
+
require('./icons/index.js');
|
|
17
|
+
const emptySpaceNft = require('./icons/empty-space-nft.svg.js');
|
|
18
|
+
const spaceConnected = require('./icons/space-connected.svg.js');
|
|
19
|
+
const spaceDisconnect = require('./icons/space-disconnect.svg.js');
|
|
20
|
+
const spaceConnectError = require('./icons/space-connect-error.svg.js');
|
|
21
|
+
const baseAuth = require('./components/auth-connect-to/base-auth.js');
|
|
22
|
+
const gatewayAuth = require('./components/auth-connect-to/gateway-auth.js');
|
|
23
|
+
const reConnect = require('./components/session-connect-to/re-connect.js');
|
|
13
24
|
|
|
14
25
|
|
|
15
26
|
|
|
@@ -17,10 +28,13 @@ exports.api = api;
|
|
|
17
28
|
exports.useMobile = useMobile;
|
|
18
29
|
exports.useSpaceInfo = useSpaceInfo;
|
|
19
30
|
exports.useLocale = useLocale;
|
|
20
|
-
exports.SpaceCard = index;
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
31
|
+
exports.SpaceCard = index.SpaceCard;
|
|
32
|
+
exports.PreviewSpaceNft = index$1.PreviewSpaceNft;
|
|
33
|
+
exports.BaseConnectTo = index$2.BaseConnectTo;
|
|
34
|
+
exports.AuthConnectTo = index$3.AuthConnectTo;
|
|
35
|
+
exports.SessionConnectTo = index$4.SessionConnectTo;
|
|
23
36
|
exports.classNames = util.classNames;
|
|
37
|
+
exports.decryptSpaceGateway = util.decryptSpaceGateway;
|
|
24
38
|
exports.extraDIDSpacesCoreUrl = util.extraDIDSpacesCoreUrl;
|
|
25
39
|
exports.getDIDSpaceDidFromEndpoint = util.getDIDSpaceDidFromEndpoint;
|
|
26
40
|
exports.getDIDSpaceUrlFromEndpoint = util.getDIDSpaceUrlFromEndpoint;
|
|
@@ -28,5 +42,14 @@ exports.getSpaceDidFromEndpoint = util.getSpaceDidFromEndpoint;
|
|
|
28
42
|
exports.getSpaceDidFromGatewayUrl = util.getSpaceDidFromGatewayUrl;
|
|
29
43
|
exports.getSpaceGatewayUrlFromEndpoint = util.getSpaceGatewayUrlFromEndpoint;
|
|
30
44
|
exports.getSpaceNftDisplayUrlFromEndpoint = util.getSpaceNftDisplayUrlFromEndpoint;
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
45
|
+
exports.getSpaceGatewayUrl = gateway.getSpaceGatewayUrl;
|
|
46
|
+
exports.isValidSpaceGatewayUrl = gateway.isValidSpaceGatewayUrl;
|
|
47
|
+
exports.translations = index$5.translations;
|
|
48
|
+
exports.SpaceStatus = index$6.SpaceStatus;
|
|
49
|
+
exports.EmptySpacesNFTIcon = emptySpaceNft;
|
|
50
|
+
exports.SpacesConnectedIcon = spaceConnected;
|
|
51
|
+
exports.SpaceDisconnectedIcon = spaceDisconnect;
|
|
52
|
+
exports.SpaceConnectErrorIcon = spaceConnectError;
|
|
53
|
+
exports.WalletAuth = baseAuth.BaseAuth;
|
|
54
|
+
exports.GatewayAuth = gatewayAuth.GatewayAuth;
|
|
55
|
+
exports.ReConnect = reConnect.ReConnect;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const AUTHORIZE = {
|
|
4
|
+
DEFAULT_SCOPE: "list:object read:object write:object"
|
|
5
|
+
};
|
|
6
|
+
const copyGatewayPageUrl = "https://www.arcblock.io/content/docs/did-spaces/how-to-obtain-space-gateway-url";
|
|
7
|
+
|
|
8
|
+
exports.AUTHORIZE = AUTHORIZE;
|
|
9
|
+
exports.copyGatewayPageUrl = copyGatewayPageUrl;
|
package/lib/libs/util.d.ts
CHANGED
|
@@ -17,4 +17,5 @@ export declare function getSpaceDidFromEndpoint(endpoint: string): string | unde
|
|
|
17
17
|
export declare function getSpaceGatewayUrlFromEndpoint(endpoint: string): string;
|
|
18
18
|
export declare function extraDIDSpacesCoreUrl(url: string): string;
|
|
19
19
|
export declare function getSpaceDidFromGatewayUrl(url: string): string | undefined;
|
|
20
|
+
export declare function decryptSpaceGateway(response: Record<string, string>, decrypt: Function): any;
|
|
20
21
|
export {};
|
package/lib/libs/util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const ufo = require('ufo');
|
|
4
|
+
const isEmpty = require('lodash/isEmpty');
|
|
4
5
|
|
|
5
6
|
function classNames(...classes) {
|
|
6
7
|
const result = [];
|
|
@@ -56,8 +57,22 @@ const spaceDidRegex = /\/space\/([^/]+)/;
|
|
|
56
57
|
function getSpaceDidFromGatewayUrl(url) {
|
|
57
58
|
return new URL(url).pathname.match(spaceDidRegex)?.[1];
|
|
58
59
|
}
|
|
60
|
+
function decryptSpaceGateway(response, decrypt) {
|
|
61
|
+
if (!isEmpty(response.spaceGateway)) {
|
|
62
|
+
return decrypt(response.spaceGateway);
|
|
63
|
+
}
|
|
64
|
+
const endpoint = decrypt(response.endpoint);
|
|
65
|
+
const space = response.space ? decrypt(response.space) : {};
|
|
66
|
+
return {
|
|
67
|
+
endpoint,
|
|
68
|
+
// name 默认为 DID Space,兼容旧版本的 DID Spaces
|
|
69
|
+
...{ name: "DID Space" },
|
|
70
|
+
...space
|
|
71
|
+
};
|
|
72
|
+
}
|
|
59
73
|
|
|
60
74
|
exports.classNames = classNames;
|
|
75
|
+
exports.decryptSpaceGateway = decryptSpaceGateway;
|
|
61
76
|
exports.extraDIDSpacesCoreUrl = extraDIDSpacesCoreUrl;
|
|
62
77
|
exports.getDIDSpaceDidFromEndpoint = getDIDSpaceDidFromEndpoint;
|
|
63
78
|
exports.getDIDSpaceUrlFromEndpoint = getDIDSpaceUrlFromEndpoint;
|
package/lib/locales/en.js
CHANGED
|
@@ -4,33 +4,51 @@ const flat = require('flat');
|
|
|
4
4
|
|
|
5
5
|
const en = flat.flatten({
|
|
6
6
|
common: {
|
|
7
|
-
open: "Open",
|
|
8
|
-
delete: "Delete",
|
|
9
|
-
confirm: "Confirm",
|
|
10
7
|
cancel: "Cancel",
|
|
11
|
-
|
|
8
|
+
confirm: "Confirm",
|
|
9
|
+
delete: "Delete",
|
|
10
|
+
error: "Error",
|
|
11
|
+
open: "Open",
|
|
12
|
+
unknown: "Unknown"
|
|
12
13
|
},
|
|
13
14
|
storage: {
|
|
14
15
|
spaces: {
|
|
16
|
+
authorize: {
|
|
17
|
+
title: "Connect {appName} to DID Spaces",
|
|
18
|
+
scan: "Use your DID Wallet to scan the QR code below to allow the app {appName} to connect to DID Spaces",
|
|
19
|
+
success: "Connected successfully"
|
|
20
|
+
},
|
|
15
21
|
connect: {
|
|
22
|
+
reconnect: "Reconnect Now",
|
|
16
23
|
useSpaceGateway: "Connect using the DID Spaces gateway",
|
|
17
|
-
useWallet: "Connect with DID Wallet"
|
|
24
|
+
useWallet: "Connect with DID Wallet",
|
|
25
|
+
howToGetGatewayUrl: "How to get the url of did spaces",
|
|
26
|
+
providerForStorage: "Please connect your DID Spaces"
|
|
18
27
|
},
|
|
19
28
|
connected: {
|
|
29
|
+
title: "Connected DID Spaces",
|
|
20
30
|
tag: "Connected"
|
|
21
31
|
},
|
|
22
32
|
disconnected: {
|
|
23
33
|
tag: "Disconnected"
|
|
24
34
|
},
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
error: {
|
|
36
|
+
tag: "Need Attention",
|
|
37
|
+
expired: "This DID spaces has expired, you can re-subscribe by opening this link",
|
|
38
|
+
corsBlocked: "Connection requests may be blocked by CORS. Please check security settings in the DID Space dashboard.",
|
|
39
|
+
networkError: "Network error"
|
|
27
40
|
},
|
|
28
41
|
gateway: {
|
|
29
42
|
add: {
|
|
30
|
-
|
|
43
|
+
invalidUrl: "Invalid DID Spaces gateway url",
|
|
31
44
|
label: "Enter the url of the DID Spaces",
|
|
32
|
-
|
|
45
|
+
title: "Add DID Spaces"
|
|
33
46
|
}
|
|
47
|
+
},
|
|
48
|
+
provideNFT: {
|
|
49
|
+
title: "Please show the DID Spaces NFT for {appName}",
|
|
50
|
+
scan: "Use your DID Wallet to scan the QR code below to allow the app {appName} show DID space NFT",
|
|
51
|
+
success: "Connected successfully"
|
|
34
52
|
}
|
|
35
53
|
}
|
|
36
54
|
}
|
package/lib/locales/zh.js
CHANGED
|
@@ -4,33 +4,51 @@ const flat = require('flat');
|
|
|
4
4
|
|
|
5
5
|
const zh = flat.flatten({
|
|
6
6
|
common: {
|
|
7
|
-
open: "\u6253\u5F00",
|
|
8
|
-
delete: "\u5220\u9664",
|
|
9
|
-
confirm: "\u786E\u8BA4",
|
|
10
7
|
cancel: "\u53D6\u6D88",
|
|
11
|
-
|
|
8
|
+
confirm: "\u786E\u8BA4",
|
|
9
|
+
delete: "\u5220\u9664",
|
|
10
|
+
error: "\u9519\u8BEF",
|
|
11
|
+
open: "\u6253\u5F00",
|
|
12
|
+
unknown: "\u672A\u77E5"
|
|
12
13
|
},
|
|
13
14
|
storage: {
|
|
14
15
|
spaces: {
|
|
16
|
+
authorize: {
|
|
17
|
+
title: "\u8FDE\u63A5 {appName} \u81F3 DID Spaces",
|
|
18
|
+
scan: "\u4F7F\u7528\u4F60\u7684 DID Wallet \u626B\u63CF\u4E0B\u9762\u7684\u4E8C\u7EF4\u7801\u4EE5\u5141\u8BB8\u5E94\u7528 {appName} \u8FDE\u63A5\u81F3 DID Spaces",
|
|
19
|
+
success: "\u8FDE\u63A5\u6210\u529F"
|
|
20
|
+
},
|
|
15
21
|
connect: {
|
|
22
|
+
reconnect: "\u7ACB\u5373\u91CD\u8FDE",
|
|
16
23
|
useSpaceGateway: "\u4F7F\u7528 DID Spaces \u7F51\u5173\u8FDE\u63A5",
|
|
17
|
-
useWallet: "\u4F7F\u7528 DID Wallet \u8FDE\u63A5"
|
|
24
|
+
useWallet: "\u4F7F\u7528 DID Wallet \u8FDE\u63A5",
|
|
25
|
+
howToGetGatewayUrl: "\u5982\u4F55\u83B7\u53D6 DID Spaces \u7684\u7F51\u5173\u5730\u5740",
|
|
26
|
+
providerForStorage: "\u8BF7\u8FDE\u63A5\u60A8\u7684 DID Spaces"
|
|
18
27
|
},
|
|
19
28
|
connected: {
|
|
29
|
+
title: "\u5DF2\u8FDE\u63A5\u7684 DID Spaces",
|
|
20
30
|
tag: "\u5DF2\u8FDE\u63A5"
|
|
21
31
|
},
|
|
22
32
|
disconnected: {
|
|
23
33
|
tag: "\u8FDE\u63A5\u5DF2\u65AD\u5F00"
|
|
24
34
|
},
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
error: {
|
|
36
|
+
tag: "\u9700\u8981\u5173\u6CE8",
|
|
37
|
+
expired: "\u6B64 DID Spaces \u5DF2\u8FC7\u671F\uFF0C\u60A8\u53EF\u4EE5\u6253\u5F00\u6B64\u94FE\u63A5\u91CD\u65B0\u8BA2\u9605",
|
|
38
|
+
corsBlocked: "\u8FDE\u63A5\u8BF7\u6C42\u53EF\u80FD\u88AB CORS \u963B\u6B62\u3002\u8BF7\u68C0\u67E5 DID Space \u63A7\u5236\u9762\u677F\u4E2D\u7684\u5B89\u5168\u8BBE\u7F6E\u3002",
|
|
39
|
+
networkError: "\u7F51\u7EDC\u9519\u8BEF"
|
|
27
40
|
},
|
|
28
41
|
gateway: {
|
|
29
42
|
add: {
|
|
30
|
-
|
|
43
|
+
invalidUrl: "\u65E0\u6548\u7684 DID Spaces \u7F51\u5173\u5730\u5740",
|
|
31
44
|
label: "\u8F93\u5165 DID Spaces \u7684\u5730\u5740",
|
|
32
|
-
|
|
45
|
+
title: "\u6DFB\u52A0 DID Spaces"
|
|
33
46
|
}
|
|
47
|
+
},
|
|
48
|
+
provideNFT: {
|
|
49
|
+
title: "\u8BF7\u4E3A {appName} \u51FA\u793A DID Spaces NFT",
|
|
50
|
+
scan: "\u4F7F\u7528\u4F60\u7684 DID Wallet \u626B\u63CF\u4E0B\u9762\u7684\u4E8C\u7EF4\u7801\u4E3A\u5E94\u7528 {appName} \u51FA\u793A DID Spaces NFT",
|
|
51
|
+
success: "\u8FDE\u63A5\u6210\u529F"
|
|
34
52
|
}
|
|
35
53
|
}
|
|
36
54
|
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
export type $TSFixMe = any;
|
|
2
2
|
export interface AuthorizeConnect {
|
|
3
|
-
prefix?: string;
|
|
4
|
-
baseUrl?: string;
|
|
5
3
|
open: boolean;
|
|
6
4
|
action: string;
|
|
7
|
-
|
|
5
|
+
checkFn: Function;
|
|
8
6
|
messages: {
|
|
9
7
|
title: string;
|
|
10
8
|
scan: string;
|
|
11
9
|
confirm: string;
|
|
12
10
|
success: React.ReactNode;
|
|
13
11
|
};
|
|
12
|
+
prefix?: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
webWalletUrl?: string;
|
|
15
|
+
maxIdleTime?: number;
|
|
16
|
+
checkTimeout?: number;
|
|
14
17
|
extraParams?: Record<string, any>;
|
|
15
|
-
checkFn?: Function;
|
|
16
|
-
onClose?: Function;
|
|
17
18
|
}
|
|
18
19
|
export declare enum SpaceStatus {
|
|
19
|
-
|
|
20
|
+
LOADING = "loading",
|
|
20
21
|
CONNECTED = "connected",
|
|
21
22
|
DISCONNECTED = "disconnected",
|
|
22
|
-
EXPIRED = "expired"
|
|
23
|
+
EXPIRED = "expired",
|
|
24
|
+
CORS_BLOCKED = "corsBlocked",
|
|
25
|
+
UNKNOWN = "unknown"
|
|
23
26
|
}
|
|
24
27
|
export interface SpaceGateway {
|
|
25
28
|
did: string;
|
|
@@ -29,3 +32,15 @@ export interface SpaceGateway {
|
|
|
29
32
|
protected?: boolean;
|
|
30
33
|
loading?: boolean;
|
|
31
34
|
}
|
|
35
|
+
export interface BaseAuthOptions {
|
|
36
|
+
action?: string;
|
|
37
|
+
checkFn?: Function;
|
|
38
|
+
extraParams?: Record<string, string>;
|
|
39
|
+
checkTimeout?: number;
|
|
40
|
+
onSuccess?: (response: Record<string, string>, decrypt: Function) => Promise<void>;
|
|
41
|
+
onClose?: () => void;
|
|
42
|
+
}
|
|
43
|
+
export interface GatewayAuthOptions extends BaseAuthOptions {
|
|
44
|
+
spaceDid?: string;
|
|
45
|
+
spaceGatewayUrl?: string;
|
|
46
|
+
}
|
package/lib/types/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var SpaceStatus = /* @__PURE__ */ ((SpaceStatus2) => {
|
|
4
|
-
SpaceStatus2["
|
|
4
|
+
SpaceStatus2["LOADING"] = "loading";
|
|
5
5
|
SpaceStatus2["CONNECTED"] = "connected";
|
|
6
6
|
SpaceStatus2["DISCONNECTED"] = "disconnected";
|
|
7
7
|
SpaceStatus2["EXPIRED"] = "expired";
|
|
8
|
+
SpaceStatus2["CORS_BLOCKED"] = "corsBlocked";
|
|
9
|
+
SpaceStatus2["UNKNOWN"] = "unknown";
|
|
8
10
|
return SpaceStatus2;
|
|
9
11
|
})(SpaceStatus || {});
|
|
10
12
|
|