@blocklet/did-space-react 0.5.57
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 +50 -0
- package/.turbo/turbo-lint$colon$fix.log +8 -0
- package/LICENSE +13 -0
- package/README.md +52 -0
- package/build.config.ts +47 -0
- package/es/components/ConnectTo/connect-to.stories.d.ts +10 -0
- package/es/components/ConnectTo/index.d.ts +10 -0
- package/es/components/ConnectTo/index.js +138 -0
- package/es/components/PreviewNFT/index.d.ts +6 -0
- package/es/components/PreviewNFT/index.js +79 -0
- package/es/components/SpaceCard/index.d.ts +18 -0
- package/es/components/SpaceCard/index.js +198 -0
- package/es/components/SpaceCard/space-card.stories.d.ts +12 -0
- package/es/hooks/use-locale.d.ts +5 -0
- package/es/hooks/use-locale.js +14 -0
- package/es/hooks/use-mobile.d.ts +4 -0
- package/es/hooks/use-mobile.js +9 -0
- package/es/hooks/use-space-info.d.ts +8 -0
- package/es/hooks/use-space-info.js +30 -0
- package/es/icons/empty-space-nft.svg.js +200 -0
- package/es/icons/index.d.ts +4 -0
- package/es/icons/space-connect-error.svg.js +24 -0
- package/es/icons/space-connected.svg.js +24 -0
- package/es/icons/space-disconnect.svg.js +24 -0
- package/es/index.d.ts +12 -0
- package/es/index.js +10 -0
- package/es/libs/api.d.ts +2 -0
- package/es/libs/api.js +5 -0
- package/es/libs/gateway.d.ts +5 -0
- package/es/libs/gateway.js +44 -0
- package/es/libs/theme.d.ts +1 -0
- package/es/libs/util.d.ts +20 -0
- package/es/libs/util.js +58 -0
- package/es/locales/en.d.ts +2 -0
- package/es/locales/en.js +37 -0
- package/es/locales/index.d.ts +4 -0
- package/es/locales/index.js +9 -0
- package/es/locales/zh.d.ts +2 -0
- package/es/locales/zh.js +37 -0
- package/es/types/index.d.ts +31 -0
- package/es/types/index.js +9 -0
- package/lib/components/ConnectTo/connect-to.stories.d.ts +10 -0
- package/lib/components/ConnectTo/index.d.ts +10 -0
- package/lib/components/ConnectTo/index.js +140 -0
- package/lib/components/PreviewNFT/index.d.ts +6 -0
- package/lib/components/PreviewNFT/index.js +81 -0
- package/lib/components/SpaceCard/index.d.ts +18 -0
- package/lib/components/SpaceCard/index.js +200 -0
- package/lib/components/SpaceCard/space-card.stories.d.ts +12 -0
- package/lib/hooks/use-locale.d.ts +5 -0
- package/lib/hooks/use-locale.js +16 -0
- package/lib/hooks/use-mobile.d.ts +4 -0
- package/lib/hooks/use-mobile.js +11 -0
- package/lib/hooks/use-space-info.d.ts +8 -0
- package/lib/hooks/use-space-info.js +32 -0
- package/lib/icons/empty-space-nft.svg.js +215 -0
- package/lib/icons/index.d.ts +4 -0
- package/lib/icons/space-connect-error.svg.js +39 -0
- package/lib/icons/space-connected.svg.js +39 -0
- package/lib/icons/space-disconnect.svg.js +39 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +32 -0
- package/lib/libs/api.d.ts +2 -0
- package/lib/libs/api.js +7 -0
- package/lib/libs/gateway.d.ts +5 -0
- package/lib/libs/gateway.js +47 -0
- package/lib/libs/theme.d.ts +1 -0
- package/lib/libs/util.d.ts +20 -0
- package/lib/libs/util.js +67 -0
- package/lib/locales/en.d.ts +2 -0
- package/lib/locales/en.js +39 -0
- package/lib/locales/index.d.ts +4 -0
- package/lib/locales/index.js +11 -0
- package/lib/locales/zh.d.ts +2 -0
- package/lib/locales/zh.js +39 -0
- package/lib/types/index.d.ts +31 -0
- package/lib/types/index.js +11 -0
- package/package.json +134 -0
- package/src/components/ConnectTo/connect-to.stories.tsx +11 -0
- package/src/components/ConnectTo/index.tsx +147 -0
- package/src/components/PreviewNFT/index.tsx +72 -0
- package/src/components/SpaceCard/index.tsx +230 -0
- package/src/components/SpaceCard/space-card.stories.tsx +13 -0
- package/src/hooks/use-locale.ts +15 -0
- package/src/hooks/use-mobile.ts +8 -0
- package/src/hooks/use-space-info.ts +32 -0
- package/src/icons/empty-space-nft.svg +59 -0
- package/src/icons/index.tsx +4 -0
- package/src/icons/space-connect-error.svg +4 -0
- package/src/icons/space-connected.svg +4 -0
- package/src/icons/space-disconnect.svg +4 -0
- package/src/index.ts +16 -0
- package/src/libs/api.ts +5 -0
- package/src/libs/gateway.ts +55 -0
- package/src/libs/theme.ts +18 -0
- package/src/libs/util.ts +86 -0
- package/src/locales/en.tsx +35 -0
- package/src/locales/index.tsx +7 -0
- package/src/locales/zh.tsx +35 -0
- package/src/types/index.ts +34 -0
- package/src/types/shims.d.ts +15 -0
- package/vite.config.ts +32 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type $TSFixMe = any;
|
|
2
|
+
export interface AuthorizeConnect {
|
|
3
|
+
prefix?: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
open: boolean;
|
|
6
|
+
action: string;
|
|
7
|
+
checkTimeout: number;
|
|
8
|
+
messages: {
|
|
9
|
+
title: string;
|
|
10
|
+
scan: string;
|
|
11
|
+
confirm: string;
|
|
12
|
+
success: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
extraParams?: Record<string, any>;
|
|
15
|
+
checkFn?: Function;
|
|
16
|
+
onClose?: Function;
|
|
17
|
+
}
|
|
18
|
+
export declare enum SpaceStatus {
|
|
19
|
+
UNKNOWN = "unknown",
|
|
20
|
+
CONNECTED = "connected",
|
|
21
|
+
DISCONNECTED = "disconnected",
|
|
22
|
+
EXPIRED = "expired"
|
|
23
|
+
}
|
|
24
|
+
export interface SpaceGateway {
|
|
25
|
+
did: string;
|
|
26
|
+
name: string;
|
|
27
|
+
url: string;
|
|
28
|
+
endpoint: string;
|
|
29
|
+
protected?: boolean;
|
|
30
|
+
loading?: boolean;
|
|
31
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var SpaceStatus = /* @__PURE__ */ ((SpaceStatus2) => {
|
|
2
|
+
SpaceStatus2["UNKNOWN"] = "unknown";
|
|
3
|
+
SpaceStatus2["CONNECTED"] = "connected";
|
|
4
|
+
SpaceStatus2["DISCONNECTED"] = "disconnected";
|
|
5
|
+
SpaceStatus2["EXPIRED"] = "expired";
|
|
6
|
+
return SpaceStatus2;
|
|
7
|
+
})(SpaceStatus || {});
|
|
8
|
+
|
|
9
|
+
export { SpaceStatus };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SplitButtonProps } from '@arcblock/ux/lib/SplitButton';
|
|
2
|
+
export interface ConnectToProps extends Omit<SplitButtonProps, 'menu' | 'onClick'> {
|
|
3
|
+
onWalletConnect?: () => void;
|
|
4
|
+
onGatewayConnect?: (params: {
|
|
5
|
+
spaceDid: string;
|
|
6
|
+
spaceGatewayUrl: string;
|
|
7
|
+
}) => void;
|
|
8
|
+
}
|
|
9
|
+
declare function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: ConnectToProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default ConnectTo;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const did = require('@arcblock/did');
|
|
6
|
+
const material = require('@mui/material');
|
|
7
|
+
const Button = require('@arcblock/ux/lib/Button');
|
|
8
|
+
const SplitButton = require('@arcblock/ux/lib/SplitButton');
|
|
9
|
+
const Dialog = require('@arcblock/ux/lib/Dialog');
|
|
10
|
+
const util = require('../../libs/util.js');
|
|
11
|
+
const gateway = require('../../libs/gateway.js');
|
|
12
|
+
const useLocale = require('../../hooks/use-locale.js');
|
|
13
|
+
|
|
14
|
+
function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
15
|
+
const { t } = useLocale();
|
|
16
|
+
const [url, setUrl] = React.useState("");
|
|
17
|
+
const [loading, setLoading] = React.useState(false);
|
|
18
|
+
const [open, setOpen] = React.useState(false);
|
|
19
|
+
const [errorMessage, setErrorMessage] = React.useState("");
|
|
20
|
+
const handleUseSpaceGatewayConnect = async () => {
|
|
21
|
+
try {
|
|
22
|
+
setLoading(true);
|
|
23
|
+
const spaceGatewayUrl = await gateway.getSpaceGatewayUrl(url);
|
|
24
|
+
const didSpacesCoreUrl = util.extraDIDSpacesCoreUrl(spaceGatewayUrl);
|
|
25
|
+
const spaceDid = util.getSpaceDidFromGatewayUrl(url);
|
|
26
|
+
if (!did.isValid(spaceDid) || !await gateway.isValidSpaceGatewayUrl(didSpacesCoreUrl)) {
|
|
27
|
+
throw new Error(t("storage.spaces.gateway.add.invalidUrl"));
|
|
28
|
+
}
|
|
29
|
+
onGatewayConnect?.({
|
|
30
|
+
spaceDid,
|
|
31
|
+
spaceGatewayUrl: didSpacesCoreUrl
|
|
32
|
+
});
|
|
33
|
+
setOpen(false);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error(err);
|
|
36
|
+
setErrorMessage(err.message);
|
|
37
|
+
} finally {
|
|
38
|
+
setLoading(false);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const openGatewayInput = () => {
|
|
42
|
+
setErrorMessage("");
|
|
43
|
+
setUrl("");
|
|
44
|
+
setOpen(true);
|
|
45
|
+
};
|
|
46
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
47
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
48
|
+
SplitButton,
|
|
49
|
+
{
|
|
50
|
+
menu: [
|
|
51
|
+
// @ts-expect-error
|
|
52
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
53
|
+
SplitButton.Item,
|
|
54
|
+
{
|
|
55
|
+
sx: {
|
|
56
|
+
textTransform: "none"
|
|
57
|
+
},
|
|
58
|
+
onClick: openGatewayInput,
|
|
59
|
+
size: "small",
|
|
60
|
+
...rest,
|
|
61
|
+
children: t("storage.spaces.connect.useSpaceGateway")
|
|
62
|
+
},
|
|
63
|
+
"1"
|
|
64
|
+
)
|
|
65
|
+
],
|
|
66
|
+
onClick: onWalletConnect,
|
|
67
|
+
color: "primary",
|
|
68
|
+
style: { textTransform: "none !important", fontSize: "1rem", ...style },
|
|
69
|
+
size: "small",
|
|
70
|
+
...rest,
|
|
71
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { sx: { fontWeight: "bold", textTransform: "none" }, children: t("storage.spaces.connect.useWallet") })
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
75
|
+
Dialog,
|
|
76
|
+
{
|
|
77
|
+
title: t("storage.spaces.gateway.add.title"),
|
|
78
|
+
fullWidth: true,
|
|
79
|
+
maxWidth: "md",
|
|
80
|
+
open,
|
|
81
|
+
onClose: () => setOpen(false),
|
|
82
|
+
PaperProps: { style: { minHeight: "auto" } },
|
|
83
|
+
actions: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
84
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
85
|
+
Button,
|
|
86
|
+
{
|
|
87
|
+
variant: "outlined",
|
|
88
|
+
onClick: (e) => {
|
|
89
|
+
e.stopPropagation();
|
|
90
|
+
setOpen(false);
|
|
91
|
+
},
|
|
92
|
+
color: "inherit",
|
|
93
|
+
children: t("common.cancel")
|
|
94
|
+
}
|
|
95
|
+
),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
97
|
+
Button,
|
|
98
|
+
{
|
|
99
|
+
onClick: handleUseSpaceGatewayConnect,
|
|
100
|
+
color: "primary",
|
|
101
|
+
disabled: loading || !url,
|
|
102
|
+
variant: "contained",
|
|
103
|
+
autoFocus: true,
|
|
104
|
+
children: [
|
|
105
|
+
loading && /* @__PURE__ */ jsxRuntime.jsx(material.CircularProgress, { size: 16 }),
|
|
106
|
+
t("common.confirm")
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
] }),
|
|
111
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { paddingTop: 12, overflowY: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(material.DialogContentText, { component: "div", children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { component: "div", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
112
|
+
material.TextField,
|
|
113
|
+
{
|
|
114
|
+
label: t("storage.spaces.gateway.add.label"),
|
|
115
|
+
autoComplete: "off",
|
|
116
|
+
variant: "outlined",
|
|
117
|
+
name: "url",
|
|
118
|
+
fullWidth: true,
|
|
119
|
+
value: url,
|
|
120
|
+
onChange: (e) => {
|
|
121
|
+
setErrorMessage("");
|
|
122
|
+
setUrl(e.target.value);
|
|
123
|
+
},
|
|
124
|
+
disabled: loading,
|
|
125
|
+
error: Boolean(errorMessage),
|
|
126
|
+
helperText: errorMessage,
|
|
127
|
+
onKeyDown: async (e) => {
|
|
128
|
+
if (e.key === "Enter") {
|
|
129
|
+
await handleUseSpaceGatewayConnect();
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
autoFocus: true
|
|
133
|
+
}
|
|
134
|
+
) }) }) })
|
|
135
|
+
}
|
|
136
|
+
)
|
|
137
|
+
] });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
module.exports = ConnectTo;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const React = require('react');
|
|
5
|
+
const material = require('@mui/material');
|
|
6
|
+
const CloseOutlinedIcon = require('@mui/icons-material/CloseOutlined');
|
|
7
|
+
const emptySpaceNft = require('../../icons/empty-space-nft.svg.js');
|
|
8
|
+
|
|
9
|
+
function PreviewSpaceNft({ src, width = "58px", height = "58px" }) {
|
|
10
|
+
const [open, setOpen] = React.useState(false);
|
|
11
|
+
const handleOpen = () => setOpen(true);
|
|
12
|
+
const handleClose = () => setOpen(false);
|
|
13
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
14
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { position: "relative" }, onClick: handleOpen, children: [
|
|
15
|
+
/* @__PURE__ */ jsxRuntime.jsx("object", { data: src, width, height, children: /* @__PURE__ */ jsxRuntime.jsx(emptySpaceNft, { viewBox: "0 0 228 258", style: { cursor: "pointer", width: "64px", height: "64px" } }) }),
|
|
16
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
17
|
+
"div",
|
|
18
|
+
{
|
|
19
|
+
style: {
|
|
20
|
+
position: "absolute",
|
|
21
|
+
top: 0,
|
|
22
|
+
left: 0,
|
|
23
|
+
width: "100%",
|
|
24
|
+
height: "100%",
|
|
25
|
+
zIndex: "1",
|
|
26
|
+
cursor: "pointer"
|
|
27
|
+
},
|
|
28
|
+
onClick: handleOpen
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
] }),
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
33
|
+
material.Dialog,
|
|
34
|
+
{
|
|
35
|
+
open,
|
|
36
|
+
onClose: handleClose,
|
|
37
|
+
"aria-labelledby": "preview-space-nft-display",
|
|
38
|
+
"aria-describedby": "preview space nft display",
|
|
39
|
+
fullWidth: true,
|
|
40
|
+
maxWidth: "md",
|
|
41
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(material.DialogContent, { style: { padding: "8px 8px", backgroundColor: "rgba(0,0,0,0.8)" }, children: [
|
|
42
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
43
|
+
material.IconButton,
|
|
44
|
+
{
|
|
45
|
+
color: "inherit",
|
|
46
|
+
onClick: handleClose,
|
|
47
|
+
"aria-label": "close",
|
|
48
|
+
style: { position: "absolute", top: 8, right: 8, color: "white" },
|
|
49
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(CloseOutlinedIcon, {})
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
"(",
|
|
53
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
54
|
+
"object",
|
|
55
|
+
{
|
|
56
|
+
data: src,
|
|
57
|
+
style: {
|
|
58
|
+
width: "100%",
|
|
59
|
+
height: "75vh",
|
|
60
|
+
objectFit: "contain"
|
|
61
|
+
},
|
|
62
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
63
|
+
emptySpaceNft,
|
|
64
|
+
{
|
|
65
|
+
viewBox: "0 0 228 258",
|
|
66
|
+
style: {
|
|
67
|
+
width: "100%",
|
|
68
|
+
height: "75vh"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
),
|
|
74
|
+
")"
|
|
75
|
+
] })
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
] });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = PreviewSpaceNft;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BoxProps } from '@mui/material';
|
|
2
|
+
import { SpaceGateway, SpaceStatus } from '../../types';
|
|
3
|
+
export type Action = React.ReactNode | ((props: {
|
|
4
|
+
spaceGateway: SpaceGateway;
|
|
5
|
+
spaceStatus: SpaceStatus;
|
|
6
|
+
selected: boolean;
|
|
7
|
+
compat: boolean;
|
|
8
|
+
refresh: () => void;
|
|
9
|
+
}) => React.ReactNode);
|
|
10
|
+
export interface SpaceCardProps extends BoxProps {
|
|
11
|
+
endpoint: string;
|
|
12
|
+
selected?: boolean;
|
|
13
|
+
compat?: boolean;
|
|
14
|
+
action?: Action;
|
|
15
|
+
deps?: any[];
|
|
16
|
+
}
|
|
17
|
+
declare function SpaceCard({ endpoint, selected, compat, action, className, deps, ...rest }: SpaceCardProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export default SpaceCard;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const isUndefined = require('lodash/isUndefined');
|
|
5
|
+
const ufo = require('ufo');
|
|
6
|
+
const material = require('@mui/material');
|
|
7
|
+
const DidAddress = require('@arcblock/ux/lib/DID');
|
|
8
|
+
const Theme = require('@arcblock/ux/lib/Theme');
|
|
9
|
+
const React = require('react');
|
|
10
|
+
const useMobile = require('../../hooks/use-mobile.js');
|
|
11
|
+
const useSpaceInfo = require('../../hooks/use-space-info.js');
|
|
12
|
+
const useLocale = require('../../hooks/use-locale.js');
|
|
13
|
+
const util = require('../../libs/util.js');
|
|
14
|
+
const index = require('../../types/index.js');
|
|
15
|
+
const spaceConnected = require('../../icons/space-connected.svg.js');
|
|
16
|
+
const spaceDisconnect = require('../../icons/space-disconnect.svg.js');
|
|
17
|
+
const spaceConnectError = require('../../icons/space-connect-error.svg.js');
|
|
18
|
+
const index$1 = require('../PreviewNFT/index.js');
|
|
19
|
+
|
|
20
|
+
function Status({
|
|
21
|
+
spaceUrl,
|
|
22
|
+
status,
|
|
23
|
+
refresh,
|
|
24
|
+
sx,
|
|
25
|
+
...rest
|
|
26
|
+
}) {
|
|
27
|
+
const { t } = useLocale();
|
|
28
|
+
const iconStyle = { marginLeft: "8px", marginRight: "4px" };
|
|
29
|
+
let icon = null;
|
|
30
|
+
let text = null;
|
|
31
|
+
if (status === index.SpaceStatus.CONNECTED) {
|
|
32
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(spaceConnected, { style: iconStyle });
|
|
33
|
+
text = /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#047857" }, children: t("storage.spaces.connected.tag") });
|
|
34
|
+
}
|
|
35
|
+
if (status === index.SpaceStatus.DISCONNECTED) {
|
|
36
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(spaceDisconnect, { style: iconStyle });
|
|
37
|
+
text = /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#626a77" }, children: t("storage.spaces.disconnected.tag") });
|
|
38
|
+
}
|
|
39
|
+
if (status === index.SpaceStatus.EXPIRED) {
|
|
40
|
+
icon = /* @__PURE__ */ jsxRuntime.jsx(spaceConnectError, { style: iconStyle });
|
|
41
|
+
text = /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { component: "span", sx: { display: "flex", alignItems: "center", color: "error.main" }, children: [
|
|
42
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: t("storage.spaces.expired.guide") }),
|
|
43
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
44
|
+
material.Link,
|
|
45
|
+
{
|
|
46
|
+
href: ufo.withQuery(ufo.joinURL(spaceUrl, "overview"), { guide: 1 }),
|
|
47
|
+
target: "_blank",
|
|
48
|
+
underline: "always",
|
|
49
|
+
color: "error",
|
|
50
|
+
sx: { ml: 0.5 },
|
|
51
|
+
children: [
|
|
52
|
+
"[",
|
|
53
|
+
t("common.open"),
|
|
54
|
+
"]"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
React.useEffect(() => {
|
|
61
|
+
const handleVisibilityChange = () => {
|
|
62
|
+
if (!document.hidden) {
|
|
63
|
+
refresh();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
if (status === index.SpaceStatus.EXPIRED) {
|
|
67
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
68
|
+
} else {
|
|
69
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
70
|
+
}
|
|
71
|
+
return () => document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
72
|
+
}, [status, refresh]);
|
|
73
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
74
|
+
material.Box,
|
|
75
|
+
{
|
|
76
|
+
component: "span",
|
|
77
|
+
sx: { display: "flex", alignItems: "center", color: "primary.main", fontSize: 14, ...sx },
|
|
78
|
+
...rest,
|
|
79
|
+
children: [
|
|
80
|
+
icon,
|
|
81
|
+
" ",
|
|
82
|
+
text
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function SpaceCard({ endpoint, selected = false, compat, action, className, deps, ...rest }) {
|
|
88
|
+
const isMobile = useMobile();
|
|
89
|
+
let isCompact = compat;
|
|
90
|
+
if (isUndefined(isCompact)) {
|
|
91
|
+
isCompact = isMobile;
|
|
92
|
+
}
|
|
93
|
+
const spaceDid = util.getDIDSpaceDidFromEndpoint(endpoint);
|
|
94
|
+
const spaceUrl = util.getDIDSpaceUrlFromEndpoint(endpoint);
|
|
95
|
+
const gatewayUrl = util.getSpaceGatewayUrlFromEndpoint(endpoint);
|
|
96
|
+
const [refreshSpaceInfo, setRefreshSpaceInfo] = React.useState(false);
|
|
97
|
+
const refresh = () => setRefreshSpaceInfo((p) => !p);
|
|
98
|
+
const { data: spaceInfo, loading } = useSpaceInfo({
|
|
99
|
+
endpoint,
|
|
100
|
+
deps: [refreshSpaceInfo].concat(deps ?? [])
|
|
101
|
+
});
|
|
102
|
+
const spaceName = spaceInfo?.spaceName ?? "";
|
|
103
|
+
const hasPermission = spaceInfo?.hasPermission ?? false;
|
|
104
|
+
const isAvailable = spaceInfo?.isAvailable ?? false;
|
|
105
|
+
const spaceStatus = React.useRef(index.SpaceStatus.UNKNOWN);
|
|
106
|
+
if (spaceInfo && !loading) {
|
|
107
|
+
if (!isAvailable) {
|
|
108
|
+
spaceStatus.current = index.SpaceStatus.EXPIRED;
|
|
109
|
+
} else if (hasPermission) {
|
|
110
|
+
spaceStatus.current = index.SpaceStatus.CONNECTED;
|
|
111
|
+
} else {
|
|
112
|
+
spaceStatus.current = index.SpaceStatus.DISCONNECTED;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const renderAction = () => {
|
|
116
|
+
if (loading)
|
|
117
|
+
return null;
|
|
118
|
+
if (typeof action === "function") {
|
|
119
|
+
return action({
|
|
120
|
+
spaceGateway: {
|
|
121
|
+
did: spaceDid,
|
|
122
|
+
name: spaceName,
|
|
123
|
+
url: gatewayUrl,
|
|
124
|
+
endpoint
|
|
125
|
+
},
|
|
126
|
+
spaceStatus: spaceStatus.current,
|
|
127
|
+
selected,
|
|
128
|
+
compat: isCompact,
|
|
129
|
+
refresh
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return action;
|
|
133
|
+
};
|
|
134
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
135
|
+
BoxContainer,
|
|
136
|
+
{
|
|
137
|
+
className: util.classNames(className, {
|
|
138
|
+
selected,
|
|
139
|
+
error: spaceStatus.current === index.SpaceStatus.EXPIRED || spaceStatus.current === index.SpaceStatus.DISCONNECTED
|
|
140
|
+
}),
|
|
141
|
+
...rest,
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", children: [
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx(index$1, { src: util.getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
|
|
145
|
+
/* @__PURE__ */ jsxRuntime.jsxs(material.Stack, { ml: 2, flex: 1, spacing: 1, minWidth: 0, children: [
|
|
146
|
+
/* @__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(Status, { spaceUrl, status: spaceStatus.current, refresh, sx: { mr: 1 } })
|
|
149
|
+
] }),
|
|
150
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
151
|
+
DidAddress,
|
|
152
|
+
{
|
|
153
|
+
copyable: false,
|
|
154
|
+
size: 14,
|
|
155
|
+
compact: true,
|
|
156
|
+
responsive: false,
|
|
157
|
+
did: spaceDid,
|
|
158
|
+
sx: {
|
|
159
|
+
".did-address-text": {
|
|
160
|
+
color: "text.secondary"
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
] }),
|
|
166
|
+
!isCompact && renderAction()
|
|
167
|
+
] }),
|
|
168
|
+
isCompact && /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", marginTop: 0.5, children: [
|
|
169
|
+
selected && /* @__PURE__ */ jsxRuntime.jsx(Status, { spaceUrl, status: spaceStatus.current, refresh, flex: 1 }),
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { flex: 1 }),
|
|
171
|
+
renderAction()
|
|
172
|
+
] })
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
const BoxContainer = Theme.styled(material.Box)`
|
|
178
|
+
display: flex;
|
|
179
|
+
flex-direction: column;
|
|
180
|
+
padding: 16px;
|
|
181
|
+
box-sizing: border-box;
|
|
182
|
+
position: relative;
|
|
183
|
+
border: 1px solid ${({ theme }) => theme.palette.grey["200"] || "#f8f8f8"};
|
|
184
|
+
border-radius: 8px;
|
|
185
|
+
|
|
186
|
+
&.selected {
|
|
187
|
+
border-color: ${({ theme }) => theme.palette.primary.main || "#3b82f6"};
|
|
188
|
+
&.error {
|
|
189
|
+
border-color: ${({ theme }) => theme.palette.error.main || "#d32f2f"};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.space-name {
|
|
194
|
+
white-space: nowrap;
|
|
195
|
+
overflow: hidden;
|
|
196
|
+
text-overflow: ellipsis;
|
|
197
|
+
}
|
|
198
|
+
`;
|
|
199
|
+
|
|
200
|
+
module.exports = SpaceCard;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { StoryFn } from '@storybook/react';
|
|
2
|
+
import Basic from './stories/basic';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
title: string;
|
|
5
|
+
parameters: {
|
|
6
|
+
layout: string;
|
|
7
|
+
};
|
|
8
|
+
tags: string[];
|
|
9
|
+
decorators: ((Story: StoryFn) => import("react/jsx-runtime").JSX.Element)[];
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
12
|
+
export { Basic };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const context = require('@arcblock/ux/lib/Locale/context');
|
|
4
|
+
const util = require('@arcblock/ux/lib/Locale/util');
|
|
5
|
+
const ahooks = require('ahooks');
|
|
6
|
+
const index = require('../locales/index.js');
|
|
7
|
+
|
|
8
|
+
function useLocale() {
|
|
9
|
+
const { locale } = context.useLocaleContext();
|
|
10
|
+
const t = ahooks.useMemoizedFn((key, data = {}) => {
|
|
11
|
+
return util.translate(index.translations, key, locale, "en", data);
|
|
12
|
+
});
|
|
13
|
+
return { t, locale };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = useLocale;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const styles = require('@mui/material/styles');
|
|
4
|
+
const useMediaQuery = require('@mui/material/useMediaQuery');
|
|
5
|
+
|
|
6
|
+
function useMobile({ key } = { key: "md" }) {
|
|
7
|
+
const theme = styles.useTheme();
|
|
8
|
+
return useMediaQuery(theme.breakpoints.down(key));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = useMobile;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isUrl = require('is-url');
|
|
4
|
+
const ahooks = require('ahooks');
|
|
5
|
+
const api = require('../libs/api.js');
|
|
6
|
+
|
|
7
|
+
function useSpaceInfo({ endpoint, deps = [] }) {
|
|
8
|
+
return ahooks.useRequest(
|
|
9
|
+
async () => {
|
|
10
|
+
if (!isUrl(endpoint)) {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
const { headers } = await api.head(endpoint, {
|
|
14
|
+
timeout: 5e3
|
|
15
|
+
});
|
|
16
|
+
const spaceName = headers["x-space-name"];
|
|
17
|
+
return {
|
|
18
|
+
spaceName: spaceName ? decodeURIComponent(spaceName) : "",
|
|
19
|
+
hasPermission: headers["x-listable"] === "true" && headers["x-readable"] === "true" && headers["x-writeable"] === "true",
|
|
20
|
+
isAvailable: headers["x-space-is-available"] === "true"
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
refreshDeps: [endpoint].concat(deps),
|
|
25
|
+
onError(error) {
|
|
26
|
+
console.error(error);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = useSpaceInfo;
|