@blocklet/ui-react 2.10.58 → 2.10.60
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/lib/UserCenter/components/storage/action.d.ts +9 -0
- package/lib/UserCenter/components/storage/action.js +34 -0
- package/lib/UserCenter/components/storage/connected.js +10 -15
- package/lib/UserCenter/components/storage/disconnect.js +8 -15
- package/lib/UserCenter/components/storage/index.js +3 -7
- package/lib/contexts/config-user-space.d.ts +2 -0
- package/lib/contexts/config-user-space.js +1 -1
- package/package.json +5 -5
- package/src/UserCenter/components/storage/action.tsx +47 -0
- package/src/UserCenter/components/storage/connected.tsx +8 -14
- package/src/UserCenter/components/storage/disconnect.tsx +8 -12
- package/src/UserCenter/components/storage/index.tsx +1 -6
- package/src/contexts/config-user-space.tsx +3 -1
- package/lib/UserCenter/components/storage/connect-to.d.ts +0 -6
- package/lib/UserCenter/components/storage/connect-to.js +0 -108
- package/src/UserCenter/components/storage/connect-to.tsx +0 -121
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SpaceGateway, SpaceStatus } from '@blocklet/did-space-react';
|
|
2
|
+
import { Session } from '../../../@types';
|
|
3
|
+
declare function Action({ session, spaceGateway, spaceStatus, refresh, }: {
|
|
4
|
+
session: Session;
|
|
5
|
+
spaceGateway: SpaceGateway;
|
|
6
|
+
spaceStatus: SpaceStatus;
|
|
7
|
+
refresh: Function;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
9
|
+
export default Action;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ReConnect, SpaceStatus } from "@blocklet/did-space-react";
|
|
3
|
+
import { IconButton, Link, Stack } from "@mui/material";
|
|
4
|
+
import Toast from "@arcblock/ux/lib/Toast";
|
|
5
|
+
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
|
|
6
|
+
import { getSpaceHomeUrl } from "../../../libs/spaces.js";
|
|
7
|
+
import { formatAxiosError } from "../../libs/utils.js";
|
|
8
|
+
function Action({
|
|
9
|
+
session,
|
|
10
|
+
spaceGateway,
|
|
11
|
+
spaceStatus,
|
|
12
|
+
refresh
|
|
13
|
+
}) {
|
|
14
|
+
return /* @__PURE__ */ jsxs(Stack, { direction: "row", spacing: 1, children: [
|
|
15
|
+
spaceStatus === SpaceStatus.DISCONNECTED && /* @__PURE__ */ jsx(
|
|
16
|
+
ReConnect,
|
|
17
|
+
{
|
|
18
|
+
variant: "outlined",
|
|
19
|
+
session,
|
|
20
|
+
spaceDid: session.user?.didSpace?.did,
|
|
21
|
+
spaceGatewayUrl: session.user?.didSpace?.url,
|
|
22
|
+
onConnected: async () => {
|
|
23
|
+
await refresh();
|
|
24
|
+
},
|
|
25
|
+
onError: (error) => {
|
|
26
|
+
console.error(error);
|
|
27
|
+
Toast.error(formatAxiosError(error));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
/* @__PURE__ */ jsx(IconButton, { size: "small", LinkComponent: Link, href: getSpaceHomeUrl(spaceGateway.endpoint), target: "_blank", children: /* @__PURE__ */ jsx(OpenInNewIcon, {}) })
|
|
32
|
+
] });
|
|
33
|
+
}
|
|
34
|
+
export default Action;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
3
|
-
import { Box,
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import { Box, Typography } from "@mui/material";
|
|
4
|
+
import { SpaceCard, SessionConnectTo } from "@blocklet/did-space-react";
|
|
5
|
+
import { useConfigUserSpaceContext } from "../../../contexts/config-user-space.js";
|
|
6
|
+
import Action from "./action.js";
|
|
7
7
|
function Connected({ spaceGateway }) {
|
|
8
8
|
const { t } = useLocaleContext();
|
|
9
|
+
const { updateSpaceGateway, session } = useConfigUserSpaceContext();
|
|
9
10
|
return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", children: [
|
|
10
|
-
/* @__PURE__ */
|
|
11
|
+
/* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "row", alignItems: "center", justifyContent: "space-between", marginBottom: "12px", children: [
|
|
12
|
+
/* @__PURE__ */ jsx(Typography, { fontSize: "16px", fontWeight: "bold", children: t("storage.spaces.connected.title") }),
|
|
13
|
+
/* @__PURE__ */ jsx(SessionConnectTo, { session, onConnected: updateSpaceGateway })
|
|
14
|
+
] }),
|
|
11
15
|
/* @__PURE__ */ jsx(Box, { children: spaceGateway && /* @__PURE__ */ jsx(
|
|
12
16
|
SpaceCard,
|
|
13
17
|
{
|
|
@@ -15,16 +19,7 @@ function Connected({ spaceGateway }) {
|
|
|
15
19
|
endpoint: spaceGateway.endpoint,
|
|
16
20
|
deps: [spaceGateway],
|
|
17
21
|
selected: true,
|
|
18
|
-
action: /* @__PURE__ */ jsx(
|
|
19
|
-
IconButton,
|
|
20
|
-
{
|
|
21
|
-
size: "small",
|
|
22
|
-
LinkComponent: Link,
|
|
23
|
-
href: getSpaceHomeUrl(spaceGateway.endpoint),
|
|
24
|
-
target: "_blank",
|
|
25
|
-
children: /* @__PURE__ */ jsx(OpenInNewIcon, {})
|
|
26
|
-
}
|
|
27
|
-
)
|
|
22
|
+
action: (props) => /* @__PURE__ */ jsx(Action, { session, ...props })
|
|
28
23
|
},
|
|
29
24
|
spaceGateway.endpoint
|
|
30
25
|
) })
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Typography } from "@mui/material";
|
|
3
3
|
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
4
|
+
import { SessionConnectTo } from "@blocklet/did-space-react";
|
|
4
5
|
import EmptySpacesNFT from "./icons/empty-spaces-nft.svg?react";
|
|
6
|
+
import { useConfigUserSpaceContext } from "../../../contexts/config-user-space.js";
|
|
5
7
|
function Disconnect() {
|
|
6
8
|
const { t } = useLocaleContext();
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
{
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
justifyContent: "center",
|
|
14
|
-
alignItems: "center",
|
|
15
|
-
alignContent: "center",
|
|
16
|
-
children: [
|
|
17
|
-
/* @__PURE__ */ jsx(EmptySpacesNFT, { style: { width: 200, height: 250 } }),
|
|
18
|
-
/* @__PURE__ */ jsx(Typography, { marginTop: "24px", marginBottom: "24px", children: t("storage.spaces.connect.providerForStorage") })
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
) });
|
|
9
|
+
const { updateSpaceGateway, session } = useConfigUserSpaceContext();
|
|
10
|
+
return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", alignContent: "center", children: [
|
|
11
|
+
/* @__PURE__ */ jsx(EmptySpacesNFT, { style: { width: 200, height: 250 } }),
|
|
12
|
+
/* @__PURE__ */ jsx(Typography, { sx: { mt: 1, mb: 2 }, children: t("storage.spaces.connect.providerForStorage") }),
|
|
13
|
+
/* @__PURE__ */ jsx(Box, { display: "flex", alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsx(SessionConnectTo, { session, onConnected: updateSpaceGateway }) })
|
|
14
|
+
] });
|
|
22
15
|
}
|
|
23
16
|
export default Disconnect;
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import Center from "@arcblock/ux/lib/Center";
|
|
3
3
|
import { LocaleProvider } from "@arcblock/ux/lib/Locale/context";
|
|
4
4
|
import styled from "@emotion/styled";
|
|
5
5
|
import { Box, CircularProgress } from "@mui/material";
|
|
6
6
|
import { useConfigUserSpaceContext } from "../../../contexts/config-user-space.js";
|
|
7
|
-
import ConnectTo from "./connect-to.js";
|
|
8
7
|
import Connected from "./connected.js";
|
|
9
8
|
import Disconnect from "./disconnect.js";
|
|
10
9
|
import { translations } from "../../libs/locales.js";
|
|
11
10
|
function DidSpace() {
|
|
12
|
-
const { spaceGateway,
|
|
11
|
+
const { spaceGateway, hasStorageEndpoint, loading } = useConfigUserSpaceContext();
|
|
13
12
|
if (loading) {
|
|
14
13
|
return /* @__PURE__ */ jsx(Center, { relative: "parent", children: /* @__PURE__ */ jsx(CircularProgress, {}) });
|
|
15
14
|
}
|
|
16
|
-
return /* @__PURE__ */ jsx(LocaleProvider, { translations, children: /* @__PURE__ */
|
|
17
|
-
/* @__PURE__ */ jsx(Box, { maxWidth: "720px", children: hasStorageEndpoint ? /* @__PURE__ */ jsx(Connected, { spaceGateway }) : /* @__PURE__ */ jsx(Disconnect, {}) }),
|
|
18
|
-
/* @__PURE__ */ jsx(Box, { display: "flex", alignItems: "center", justifyContent: "center", paddingTop: "24px", children: /* @__PURE__ */ jsx(ConnectTo, { onConnect: updateSpaceGateway, storageEndpoint }) })
|
|
19
|
-
] }) });
|
|
15
|
+
return /* @__PURE__ */ jsx(LocaleProvider, { translations, children: /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(Box, { maxWidth: "720px", children: hasStorageEndpoint ? /* @__PURE__ */ jsx(Connected, { spaceGateway }) : /* @__PURE__ */ jsx(Disconnect, {}) }) }) });
|
|
20
16
|
}
|
|
21
17
|
const Container = styled(Box)`
|
|
22
18
|
height: 100%;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Session } from '../../lib/@types';
|
|
1
2
|
export interface SpaceGateway {
|
|
2
3
|
did: string;
|
|
3
4
|
name: string;
|
|
@@ -10,6 +11,7 @@ export interface SettingStorageEndpoint {
|
|
|
10
11
|
interface ConfigUserSpaceContextType {
|
|
11
12
|
loading: boolean;
|
|
12
13
|
spaceGateway: SpaceGateway | undefined;
|
|
14
|
+
session: Session;
|
|
13
15
|
deleteSpaceGateway: (spaceGateway: SpaceGateway) => Promise<void>;
|
|
14
16
|
updateSpaceGateway: (updateSpaceGateway: SpaceGateway) => Promise<void>;
|
|
15
17
|
storageEndpoint: string;
|
|
@@ -21,7 +21,6 @@ function ConfigUserSpaceProvider({ children }) {
|
|
|
21
21
|
};
|
|
22
22
|
const updateSpaceGateway = async (x) => {
|
|
23
23
|
setSpaceGateway(x);
|
|
24
|
-
session.refresh();
|
|
25
24
|
await settingStorageEndpoint(x.endpoint);
|
|
26
25
|
};
|
|
27
26
|
const hasStorageEndpoint = Boolean(storageEndpoint && spaceGateway);
|
|
@@ -31,6 +30,7 @@ function ConfigUserSpaceProvider({ children }) {
|
|
|
31
30
|
value: {
|
|
32
31
|
loading,
|
|
33
32
|
spaceGateway,
|
|
33
|
+
session,
|
|
34
34
|
deleteSpaceGateway,
|
|
35
35
|
updateSpaceGateway,
|
|
36
36
|
storageEndpoint,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.60",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"url": "https://github.com/ArcBlock/ux/issues"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@arcblock/bridge": "^2.10.
|
|
36
|
-
"@arcblock/react-hooks": "^2.10.
|
|
37
|
-
"@blocklet/did-space-react": "^0.5.
|
|
35
|
+
"@arcblock/bridge": "^2.10.60",
|
|
36
|
+
"@arcblock/react-hooks": "^2.10.60",
|
|
37
|
+
"@blocklet/did-space-react": "^0.5.59",
|
|
38
38
|
"@iconify-icons/logos": "^1.2.36",
|
|
39
39
|
"@iconify-icons/material-symbols": "^1.2.58",
|
|
40
40
|
"@iconify/react": "^4.1.1",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"jest": "^29.7.0",
|
|
81
81
|
"unbuild": "^2.0.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "fb4ccbae5428593bc9d7555e832f7743fbd9c71b"
|
|
84
84
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ReConnect, SpaceGateway, SpaceStatus } from '@blocklet/did-space-react';
|
|
2
|
+
import { IconButton, Link, Stack } from '@mui/material';
|
|
3
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
4
|
+
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
|
5
|
+
import { AxiosError } from 'axios';
|
|
6
|
+
import { getSpaceHomeUrl } from '../../../libs/spaces';
|
|
7
|
+
import { Session } from '../../../@types';
|
|
8
|
+
import { formatAxiosError } from '../../libs/utils';
|
|
9
|
+
|
|
10
|
+
function Action({
|
|
11
|
+
session,
|
|
12
|
+
spaceGateway,
|
|
13
|
+
spaceStatus,
|
|
14
|
+
refresh,
|
|
15
|
+
}: {
|
|
16
|
+
session: Session;
|
|
17
|
+
spaceGateway: SpaceGateway;
|
|
18
|
+
spaceStatus: SpaceStatus;
|
|
19
|
+
refresh: Function;
|
|
20
|
+
}) {
|
|
21
|
+
return (
|
|
22
|
+
<Stack direction="row" spacing={1}>
|
|
23
|
+
{/* 重新连接 */}
|
|
24
|
+
{spaceStatus === SpaceStatus.DISCONNECTED && (
|
|
25
|
+
<ReConnect
|
|
26
|
+
variant="outlined"
|
|
27
|
+
session={session}
|
|
28
|
+
spaceDid={session.user?.didSpace?.did}
|
|
29
|
+
spaceGatewayUrl={session.user?.didSpace?.url}
|
|
30
|
+
onConnected={async () => {
|
|
31
|
+
await refresh();
|
|
32
|
+
}}
|
|
33
|
+
onError={(error) => {
|
|
34
|
+
console.error(error);
|
|
35
|
+
Toast.error(formatAxiosError(error as AxiosError));
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
{/* 打开空间 */}
|
|
40
|
+
<IconButton size="small" LinkComponent={Link} href={getSpaceHomeUrl(spaceGateway.endpoint)} target="_blank">
|
|
41
|
+
<OpenInNewIcon />
|
|
42
|
+
</IconButton>
|
|
43
|
+
</Stack>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default Action;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
|
-
import { Box,
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { getSpaceHomeUrl } from '../../../libs/spaces';
|
|
2
|
+
import { Box, Typography } from '@mui/material';
|
|
3
|
+
import { SpaceCard, SessionConnectTo } from '@blocklet/did-space-react';
|
|
4
|
+
import { SpaceGateway, useConfigUserSpaceContext } from '../../../contexts/config-user-space';
|
|
5
|
+
import Action from './action';
|
|
7
6
|
|
|
8
7
|
function Connected({ spaceGateway }: { spaceGateway: SpaceGateway | undefined }) {
|
|
9
8
|
const { t } = useLocaleContext();
|
|
9
|
+
const { updateSpaceGateway, session } = useConfigUserSpaceContext();
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
12
|
<Box display="flex" flexDirection="column">
|
|
@@ -14,6 +14,7 @@ function Connected({ spaceGateway }: { spaceGateway: SpaceGateway | undefined })
|
|
|
14
14
|
<Typography fontSize="16px" fontWeight="bold">
|
|
15
15
|
{t('storage.spaces.connected.title')}
|
|
16
16
|
</Typography>
|
|
17
|
+
<SessionConnectTo session={session} onConnected={updateSpaceGateway} />
|
|
17
18
|
</Box>
|
|
18
19
|
<Box>
|
|
19
20
|
{spaceGateway && (
|
|
@@ -23,15 +24,8 @@ function Connected({ spaceGateway }: { spaceGateway: SpaceGateway | undefined })
|
|
|
23
24
|
endpoint={spaceGateway.endpoint}
|
|
24
25
|
deps={[spaceGateway]}
|
|
25
26
|
selected
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
size="small"
|
|
29
|
-
LinkComponent={Link}
|
|
30
|
-
href={getSpaceHomeUrl(spaceGateway.endpoint)}
|
|
31
|
-
target="_blank">
|
|
32
|
-
<OpenInNewIcon />
|
|
33
|
-
</IconButton>
|
|
34
|
-
}
|
|
27
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
28
|
+
action={(props) => <Action session={session} {...props} />}
|
|
35
29
|
/>
|
|
36
30
|
)}
|
|
37
31
|
</Box>
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { Box, Typography } from '@mui/material';
|
|
2
2
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
|
+
import { SessionConnectTo } from '@blocklet/did-space-react';
|
|
3
4
|
// @ts-expect-error
|
|
4
5
|
import EmptySpacesNFT from './icons/empty-spaces-nft.svg?react';
|
|
6
|
+
import { useConfigUserSpaceContext } from '../../../contexts/config-user-space';
|
|
5
7
|
|
|
6
8
|
function Disconnect() {
|
|
7
9
|
const { t } = useLocaleContext();
|
|
10
|
+
const { updateSpaceGateway, session } = useConfigUserSpaceContext();
|
|
8
11
|
|
|
9
12
|
return (
|
|
10
|
-
<Box>
|
|
11
|
-
<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
justifyContent="center"
|
|
16
|
-
alignItems="center"
|
|
17
|
-
alignContent="center">
|
|
18
|
-
<EmptySpacesNFT style={{ width: 200, height: 250 }} />
|
|
19
|
-
<Typography marginTop="24px" marginBottom="24px">
|
|
20
|
-
{t('storage.spaces.connect.providerForStorage')}
|
|
21
|
-
</Typography>
|
|
13
|
+
<Box display="flex" flexDirection="column" justifyContent="center" alignItems="center" alignContent="center">
|
|
14
|
+
<EmptySpacesNFT style={{ width: 200, height: 250 }} />
|
|
15
|
+
<Typography sx={{ mt: 1, mb: 2 }}>{t('storage.spaces.connect.providerForStorage')}</Typography>
|
|
16
|
+
<Box display="flex" alignItems="center" justifyContent="center">
|
|
17
|
+
<SessionConnectTo session={session} onConnected={updateSpaceGateway} />
|
|
22
18
|
</Box>
|
|
23
19
|
</Box>
|
|
24
20
|
);
|
|
@@ -3,14 +3,12 @@ import { LocaleProvider } from '@arcblock/ux/lib/Locale/context';
|
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
4
|
import { Box, CircularProgress } from '@mui/material';
|
|
5
5
|
import { useConfigUserSpaceContext } from '../../../contexts/config-user-space';
|
|
6
|
-
import ConnectTo from './connect-to';
|
|
7
6
|
import Connected from './connected';
|
|
8
7
|
import Disconnect from './disconnect';
|
|
9
8
|
import { translations } from '../../libs/locales';
|
|
10
9
|
|
|
11
10
|
function DidSpace() {
|
|
12
|
-
const { spaceGateway,
|
|
13
|
-
useConfigUserSpaceContext();
|
|
11
|
+
const { spaceGateway, hasStorageEndpoint, loading } = useConfigUserSpaceContext();
|
|
14
12
|
|
|
15
13
|
if (loading) {
|
|
16
14
|
return (
|
|
@@ -24,9 +22,6 @@ function DidSpace() {
|
|
|
24
22
|
<LocaleProvider translations={translations}>
|
|
25
23
|
<Container>
|
|
26
24
|
<Box maxWidth="720px">{hasStorageEndpoint ? <Connected spaceGateway={spaceGateway} /> : <Disconnect />}</Box>
|
|
27
|
-
<Box display="flex" alignItems="center" justifyContent="center" paddingTop="24px">
|
|
28
|
-
<ConnectTo onConnect={updateSpaceGateway} storageEndpoint={storageEndpoint} />
|
|
29
|
-
</Box>
|
|
30
25
|
</Container>
|
|
31
26
|
</LocaleProvider>
|
|
32
27
|
);
|
|
@@ -2,6 +2,7 @@ import { createContext, useContext, useMemo, useState, useEffect } from 'react';
|
|
|
2
2
|
import { SessionContext } from '@arcblock/did-connect/lib/Session';
|
|
3
3
|
|
|
4
4
|
import { SessionContext as TSessionContext } from '../@types';
|
|
5
|
+
import { Session } from '../../lib/@types';
|
|
5
6
|
|
|
6
7
|
export interface SpaceGateway {
|
|
7
8
|
did: string;
|
|
@@ -17,6 +18,7 @@ export interface SettingStorageEndpoint {
|
|
|
17
18
|
interface ConfigUserSpaceContextType {
|
|
18
19
|
loading: boolean;
|
|
19
20
|
spaceGateway: SpaceGateway | undefined;
|
|
21
|
+
session: Session;
|
|
20
22
|
deleteSpaceGateway: (spaceGateway: SpaceGateway) => Promise<void>;
|
|
21
23
|
updateSpaceGateway: (updateSpaceGateway: SpaceGateway) => Promise<void>;
|
|
22
24
|
storageEndpoint: string;
|
|
@@ -51,7 +53,6 @@ function ConfigUserSpaceProvider({ children }: { children: React.ReactNode }) {
|
|
|
51
53
|
|
|
52
54
|
const updateSpaceGateway = async (x: SpaceGateway) => {
|
|
53
55
|
setSpaceGateway(x);
|
|
54
|
-
session.refresh();
|
|
55
56
|
// eslint-disable-next-line no-use-before-define
|
|
56
57
|
await settingStorageEndpoint(x.endpoint);
|
|
57
58
|
};
|
|
@@ -63,6 +64,7 @@ function ConfigUserSpaceProvider({ children }: { children: React.ReactNode }) {
|
|
|
63
64
|
value={{
|
|
64
65
|
loading,
|
|
65
66
|
spaceGateway,
|
|
67
|
+
session,
|
|
66
68
|
deleteSpaceGateway,
|
|
67
69
|
updateSpaceGateway,
|
|
68
70
|
storageEndpoint,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { SpaceGateway } from '../../../contexts/config-user-space';
|
|
2
|
-
declare function ConnectTo({ onConnect, storageEndpoint, }: {
|
|
3
|
-
onConnect: (spaceGateway: SpaceGateway) => Promise<void>;
|
|
4
|
-
storageEndpoint: string;
|
|
5
|
-
}): import("react").JSX.Element;
|
|
6
|
-
export default ConnectTo;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Box, Button, Typography } from "@mui/material";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
5
|
-
import DidConnect from "@arcblock/did-connect/lib/Connect";
|
|
6
|
-
import { joinURL } from "ufo";
|
|
7
|
-
import toast from "@arcblock/ux/lib/Toast";
|
|
8
|
-
import isEmpty from "lodash/isEmpty";
|
|
9
|
-
import { RELAY_SOCKET_PREFIX } from "@arcblock/ux/lib/Util/constant";
|
|
10
|
-
import { axios } from "../../libs/api.js";
|
|
11
|
-
function ConnectTo({
|
|
12
|
-
onConnect,
|
|
13
|
-
storageEndpoint
|
|
14
|
-
}) {
|
|
15
|
-
const { t, locale } = useLocaleContext();
|
|
16
|
-
const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = useState({
|
|
17
|
-
open: false,
|
|
18
|
-
action: "connect-to-did-spaces-for-user",
|
|
19
|
-
checkTimeout: 1e3 * 300,
|
|
20
|
-
prefix: "/api/did",
|
|
21
|
-
checkFn: axios.create({
|
|
22
|
-
baseURL: joinURL(window.location.origin, RELAY_SOCKET_PREFIX)
|
|
23
|
-
}).get,
|
|
24
|
-
extraParams: {},
|
|
25
|
-
messages: {
|
|
26
|
-
title: t("storage.spaces.provideNFT.title", { appName: window.blocklet.appName }, locale),
|
|
27
|
-
scan: t("storage.spaces.provideNFT.scan", { appName: window.blocklet.appName }, locale),
|
|
28
|
-
confirm: "",
|
|
29
|
-
success: /* @__PURE__ */ jsx(Typography, { gutterBottom: true, children: t("storage.spaces.provideNFT.success") })
|
|
30
|
-
},
|
|
31
|
-
onClose: () => {
|
|
32
|
-
setAuthorizeFromNftConnect((preValue) => ({
|
|
33
|
-
...preValue,
|
|
34
|
-
open: false
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const updateSpaceGateway = async (spaceGateway) => {
|
|
39
|
-
await onConnect(spaceGateway);
|
|
40
|
-
toast.success(t("storage.spaces.connectedWithName", { name: spaceGateway.name }));
|
|
41
|
-
};
|
|
42
|
-
const onAuthorizeConnectSuccess = (response, decrypt) => {
|
|
43
|
-
setTimeout(async () => {
|
|
44
|
-
setAuthorizeFromNftConnect((preValue) => ({
|
|
45
|
-
...preValue,
|
|
46
|
-
open: false
|
|
47
|
-
}));
|
|
48
|
-
if (!isEmpty(response.spaceGateway)) {
|
|
49
|
-
await updateSpaceGateway(decrypt(response.spaceGateway));
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const endpoint = decrypt(response.endpoint);
|
|
53
|
-
const space = response.space ? decrypt(response.space) : {};
|
|
54
|
-
await updateSpaceGateway({
|
|
55
|
-
endpoint,
|
|
56
|
-
// name 默认为 DID Space,兼容旧版本的 DID Spaces
|
|
57
|
-
...{ name: "DID Space" },
|
|
58
|
-
...space
|
|
59
|
-
});
|
|
60
|
-
}, 0);
|
|
61
|
-
};
|
|
62
|
-
const handleUseWalletConnect = () => {
|
|
63
|
-
setAuthorizeFromNftConnect((preValue) => ({
|
|
64
|
-
...preValue,
|
|
65
|
-
open: true,
|
|
66
|
-
extraParams: {
|
|
67
|
-
appDid: window.blocklet.appId,
|
|
68
|
-
appName: window.blocklet.appName,
|
|
69
|
-
appDescription: window.blocklet.appDescription,
|
|
70
|
-
scopes: "list:object read:object write:object",
|
|
71
|
-
appUrl: window.blocklet.appUrl,
|
|
72
|
-
referrer: window.location.href
|
|
73
|
-
}
|
|
74
|
-
}));
|
|
75
|
-
};
|
|
76
|
-
return /* @__PURE__ */ jsxs(Box, { children: [
|
|
77
|
-
/* @__PURE__ */ jsx(
|
|
78
|
-
Button,
|
|
79
|
-
{
|
|
80
|
-
color: "primary",
|
|
81
|
-
sx: { textTransform: "none !important", fontSize: "13px", paddingLeft: 0.75, paddingRight: 0.75 },
|
|
82
|
-
size: "small",
|
|
83
|
-
onClick: handleUseWalletConnect,
|
|
84
|
-
variant: "outlined",
|
|
85
|
-
children: storageEndpoint ? t("storage.spaces.connect.useWalletReconnect") : t("storage.spaces.connect.useWallet")
|
|
86
|
-
}
|
|
87
|
-
),
|
|
88
|
-
/* @__PURE__ */ jsx(
|
|
89
|
-
DidConnect,
|
|
90
|
-
{
|
|
91
|
-
forceConnected: false,
|
|
92
|
-
saveConnect: false,
|
|
93
|
-
prefix: authorizeFromNftConnect.prefix,
|
|
94
|
-
open: authorizeFromNftConnect.open,
|
|
95
|
-
popup: true,
|
|
96
|
-
action: authorizeFromNftConnect.action,
|
|
97
|
-
checkFn: authorizeFromNftConnect.checkFn,
|
|
98
|
-
onSuccess: onAuthorizeConnectSuccess,
|
|
99
|
-
onClose: authorizeFromNftConnect.onClose,
|
|
100
|
-
checkTimeout: authorizeFromNftConnect.checkTimeout,
|
|
101
|
-
extraParams: authorizeFromNftConnect.extraParams,
|
|
102
|
-
messages: authorizeFromNftConnect.messages,
|
|
103
|
-
locale
|
|
104
|
-
}
|
|
105
|
-
)
|
|
106
|
-
] });
|
|
107
|
-
}
|
|
108
|
-
export default ConnectTo;
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { Box, Button, Typography } from '@mui/material';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
4
|
-
import DidConnect from '@arcblock/did-connect/lib/Connect';
|
|
5
|
-
import { joinURL } from 'ufo';
|
|
6
|
-
import toast from '@arcblock/ux/lib/Toast';
|
|
7
|
-
import isEmpty from 'lodash/isEmpty';
|
|
8
|
-
import { RELAY_SOCKET_PREFIX } from '@arcblock/ux/lib/Util/constant';
|
|
9
|
-
import { axios } from '../../libs/api';
|
|
10
|
-
import { SpaceGateway } from '../../../contexts/config-user-space';
|
|
11
|
-
|
|
12
|
-
function ConnectTo({
|
|
13
|
-
onConnect,
|
|
14
|
-
storageEndpoint,
|
|
15
|
-
}: {
|
|
16
|
-
onConnect: (spaceGateway: SpaceGateway) => Promise<void>;
|
|
17
|
-
storageEndpoint: string;
|
|
18
|
-
}) {
|
|
19
|
-
const { t, locale } = useLocaleContext();
|
|
20
|
-
|
|
21
|
-
const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = useState({
|
|
22
|
-
open: false,
|
|
23
|
-
action: 'connect-to-did-spaces-for-user',
|
|
24
|
-
checkTimeout: 1000 * 300,
|
|
25
|
-
prefix: '/api/did',
|
|
26
|
-
checkFn: axios.create({
|
|
27
|
-
baseURL: joinURL(window.location.origin, RELAY_SOCKET_PREFIX),
|
|
28
|
-
}).get,
|
|
29
|
-
extraParams: {},
|
|
30
|
-
messages: {
|
|
31
|
-
title: t('storage.spaces.provideNFT.title', { appName: window.blocklet.appName }, locale),
|
|
32
|
-
scan: t('storage.spaces.provideNFT.scan', { appName: window.blocklet.appName }, locale),
|
|
33
|
-
confirm: '',
|
|
34
|
-
success: <Typography gutterBottom>{t('storage.spaces.provideNFT.success')}</Typography>,
|
|
35
|
-
},
|
|
36
|
-
onClose: () => {
|
|
37
|
-
// eslint-disable-next-line no-shadow
|
|
38
|
-
setAuthorizeFromNftConnect((preValue) => ({
|
|
39
|
-
...preValue,
|
|
40
|
-
open: false,
|
|
41
|
-
}));
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const updateSpaceGateway = async (spaceGateway: SpaceGateway) => {
|
|
46
|
-
await onConnect(spaceGateway);
|
|
47
|
-
toast.success(t('storage.spaces.connectedWithName', { name: spaceGateway.name }));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const onAuthorizeConnectSuccess = (response: Record<string, string>, decrypt: Function) => {
|
|
51
|
-
setTimeout(async () => {
|
|
52
|
-
setAuthorizeFromNftConnect((preValue) => ({
|
|
53
|
-
...preValue,
|
|
54
|
-
open: false,
|
|
55
|
-
}));
|
|
56
|
-
|
|
57
|
-
if (!isEmpty(response.spaceGateway)) {
|
|
58
|
-
await updateSpaceGateway(decrypt(response.spaceGateway));
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const endpoint = decrypt(response.endpoint);
|
|
63
|
-
const space = response.space ? decrypt(response.space) : {};
|
|
64
|
-
|
|
65
|
-
// eslint-disable-next-line no-use-before-define
|
|
66
|
-
await updateSpaceGateway({
|
|
67
|
-
endpoint,
|
|
68
|
-
// name 默认为 DID Space,兼容旧版本的 DID Spaces
|
|
69
|
-
...{ name: 'DID Space' },
|
|
70
|
-
...space,
|
|
71
|
-
});
|
|
72
|
-
}, 0);
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const handleUseWalletConnect = () => {
|
|
76
|
-
setAuthorizeFromNftConnect((preValue) => ({
|
|
77
|
-
...preValue,
|
|
78
|
-
open: true,
|
|
79
|
-
extraParams: {
|
|
80
|
-
appDid: window.blocklet.appId,
|
|
81
|
-
appName: window.blocklet.appName,
|
|
82
|
-
appDescription: window.blocklet.appDescription,
|
|
83
|
-
scopes: 'list:object read:object write:object',
|
|
84
|
-
appUrl: window.blocklet.appUrl,
|
|
85
|
-
referrer: window.location.href,
|
|
86
|
-
},
|
|
87
|
-
}));
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<Box>
|
|
92
|
-
<Button
|
|
93
|
-
color="primary"
|
|
94
|
-
sx={{ textTransform: 'none !important', fontSize: '13px', paddingLeft: 0.75, paddingRight: 0.75 }}
|
|
95
|
-
size="small"
|
|
96
|
-
onClick={handleUseWalletConnect}
|
|
97
|
-
variant="outlined">
|
|
98
|
-
{storageEndpoint ? t('storage.spaces.connect.useWalletReconnect') : t('storage.spaces.connect.useWallet')}
|
|
99
|
-
</Button>
|
|
100
|
-
|
|
101
|
-
{/* 为了获取 DID Spaces Url */}
|
|
102
|
-
<DidConnect
|
|
103
|
-
forceConnected={false}
|
|
104
|
-
saveConnect={false}
|
|
105
|
-
prefix={authorizeFromNftConnect.prefix}
|
|
106
|
-
open={authorizeFromNftConnect.open}
|
|
107
|
-
popup
|
|
108
|
-
action={authorizeFromNftConnect.action}
|
|
109
|
-
checkFn={authorizeFromNftConnect.checkFn}
|
|
110
|
-
onSuccess={onAuthorizeConnectSuccess}
|
|
111
|
-
onClose={authorizeFromNftConnect.onClose}
|
|
112
|
-
checkTimeout={authorizeFromNftConnect.checkTimeout}
|
|
113
|
-
extraParams={authorizeFromNftConnect.extraParams}
|
|
114
|
-
messages={authorizeFromNftConnect.messages}
|
|
115
|
-
locale={locale}
|
|
116
|
-
/>
|
|
117
|
-
</Box>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export default ConnectTo;
|