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