@blocklet/did-space-react 0.6.1 → 1.0.1

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.
Files changed (36) hide show
  1. package/README.md +113 -66
  2. package/dist/cjs/components/auth-connect-to/index.d.ts +43 -8
  3. package/dist/cjs/components/auth-connect-to/index.js +111 -17
  4. package/dist/cjs/components/base-connect-to/index.d.ts +1 -1
  5. package/dist/cjs/components/preview-space-nft/index.d.ts +2 -1
  6. package/dist/cjs/components/preview-space-nft/index.js +3 -1
  7. package/dist/cjs/components/space-card/index.d.ts +10 -7
  8. package/dist/cjs/components/space-card/index.js +31 -21
  9. package/dist/cjs/hooks/use-space-info.js +3 -3
  10. package/dist/cjs/index.d.ts +1 -2
  11. package/dist/cjs/index.js +14 -12
  12. package/dist/cjs/package.json.js +1 -1
  13. package/dist/cjs/types/index.d.ts +4 -2
  14. package/dist/cjs/types/index.js +9 -7
  15. package/dist/es/components/auth-connect-to/index.d.ts +43 -8
  16. package/dist/es/components/auth-connect-to/index.js +110 -19
  17. package/dist/es/components/base-connect-to/index.d.ts +1 -1
  18. package/dist/es/components/preview-space-nft/index.d.ts +2 -1
  19. package/dist/es/components/preview-space-nft/index.js +3 -2
  20. package/dist/es/components/space-card/index.d.ts +10 -7
  21. package/dist/es/components/space-card/index.js +33 -24
  22. package/dist/es/hooks/use-space-info.js +3 -3
  23. package/dist/es/index.d.ts +1 -2
  24. package/dist/es/index.js +4 -6
  25. package/dist/es/package.json.js +1 -1
  26. package/dist/es/types/index.d.ts +4 -2
  27. package/dist/es/types/index.js +9 -8
  28. package/package.json +9 -13
  29. package/dist/cjs/components/session-connect-to/index.d.ts +0 -16
  30. package/dist/cjs/components/session-connect-to/index.js +0 -29
  31. package/dist/cjs/components/session-connect-to/re-connect.d.ts +0 -13
  32. package/dist/cjs/components/session-connect-to/re-connect.js +0 -53
  33. package/dist/es/components/session-connect-to/index.d.ts +0 -16
  34. package/dist/es/components/session-connect-to/index.js +0 -26
  35. package/dist/es/components/session-connect-to/re-connect.d.ts +0 -13
  36. package/dist/es/components/session-connect-to/re-connect.js +0 -51
package/README.md CHANGED
@@ -1,98 +1,145 @@
1
- # DID Space Components
1
+ # Getting Started
2
2
 
3
- ## SpaceCard
3
+ This package provides React components designed to help you seamlessly integrate and interact with DID Space. With these components, you can easily enable users to connect to and display information about their DID Space.
4
4
 
5
- ```tsx
6
- import { SpaceCard } from '@blocklet/did-space-react';
5
+ ```bash
6
+ # install
7
+ npm install @blocklet/did-space-react
8
+ ```
7
9
 
8
- function Demo() {
9
- const endpoint = 'https://${spaceDomain}/app/api/space/${spaceDid}/app/${appDid}/object/';
10
+ ## Core Components
10
11
 
11
- return (
12
- <>
13
- {/* Basic use*/}
14
- <SpaceCard endpoint={endpoint} selected />
15
- {/* Compat Layout */}
16
- <SpaceCard endpoint={endpoint} selected compat />
17
- {/* With Action */}
18
- <SpaceCard
19
- endpoint={endpoint}
20
- selected
21
- action={
22
- <IconButton size="small" LinkComponent={Link} href={getSpaceHomeUrl(spaceGateway.endpoint)} target="_blank">
23
- <OpenInNewIcon />
24
- </IconButton>
25
- }
26
- />
27
- {/* With Render Action */}
28
- <SpaceCard
29
- endpoint={x.endpoint}
30
- selected
31
- action={({ spaceGateway, selected, refresh }) => (
32
- <MoreAction spaceGateway={spaceGateway} onBackedUp={() => refresh()} />
33
- )}
34
- />
35
- </>
36
- );
37
- }
38
- ```
12
+ This package includes two key components:
39
13
 
40
- ## BaseConnectTo
14
+ 1. DIDSpaceConnect: A button for connecting or reconnecting to DID Space.
15
+ 2. DIDSpaceConnection: A display card showcasing details of the connected DID Space.
41
16
 
42
- ```tsx
43
- import { BaseConnectTo } from '@blocklet/did-space-react';
17
+ # How to use
44
18
 
45
- function Demo() {
46
- return (
47
- <BaseConnectTo
48
- onWalletClick={() => {
49
- // eslint-disable-next-line no-console
50
- console.log('on Wallet Click');
51
- }}
52
- onGatewayConfirm={({ spaceDid, spaceGatewayUrl }) => {
53
- // eslint-disable-next-line no-console
54
- console.log(`on Gateway Confirm\n spaceDid: ${spaceDid}\n spaceGatewayUrl: ${spaceGatewayUrl}`);
55
- }}
56
- />
57
- );
58
- }
59
- ```
19
+ ## DIDSpaceConnect
60
20
 
61
- ## AuthConnectTo
21
+ The DIDSpaceConnect component enables users to establish a connection with DID Space. Here are the main usage scenarios:
62
22
 
63
- Auto connect to DID Space and save space gateway:
23
+ ### Connecting to a Specific DID Space
24
+
25
+ This component allows you to easily create a button on the page to connect to a DID Space. After clicking the button and successfully connecting to the DID Space, the system will return a `spaceGateway` object, which contains information such as the DID Space's name, DID, and site URL. You can choose how to store this object based on your needs.
26
+
27
+ Example:
64
28
 
65
29
  ```tsx
66
30
  import Toast from '@arcblock/ux/lib/Toast';
67
- import { decryptSpaceGateway, AuthConnectTo, type AuthConnectToProps } from '@blocklet/did-space-react';
31
+ import { DIDSpaceConnect, type DIDSpaceGateway } from '@blocklet/did-space-react';
68
32
 
69
- function ConnectTo({ ...rest }: AuthConnectToProps) {
70
- const onSuccess = async (response: Record<string, string>, decrypt: Function) => {
33
+ export default function Demo() {
34
+ const onSuccess = async ({ spaceGateway }: { spaceGateway: DIDSpaceGateway }) => {
71
35
  try {
72
- const spaceGateway = decryptSpaceGateway(response, decrypt);
73
- // do sth to save space gateway
36
+ // do something with spaceGateway
74
37
  } catch (error) {
75
38
  console.error(error);
76
39
  Toast.error(formatError(error));
77
40
  }
78
41
  };
79
42
 
80
- return <AuthConnectTo {...rest} onSuccess={onSuccess} />;
43
+ return <DIDSpaceConnect {...rest} onSuccess={onSuccess} />;
81
44
  }
45
+ ```
46
+
47
+ ### Connecting DID Space for Users
48
+
49
+ When users connect to DID Space for the first time, the DIDSpaceConnect component will automatically save the `spaceGateway` to their account. This data can later be retrieved through `session.user.didSpace`.
50
+
51
+ Example:
52
+
53
+ ```tsx
54
+ import { DIDSpaceConnect } from '@blocklet/did-space-react';
55
+
56
+ export default function Demo() {
57
+ const session = useSessionContext();
82
58
 
83
- export default ConnectTo;
59
+ return <DIDSpaceConnect session={session} />;
60
+ }
84
61
  ```
85
62
 
86
- ## SessionConnectTo
63
+ ### Reconnecting to a Specific DID Space
87
64
 
88
- Auto connect to DID Space and save space gateway to the users table:
65
+ If the user needs to reconnect to a previously linked DID Space, you need to set `reconnect` to true and provide `spaceDid` and `spaceGatewayUrl` props. This turns the component into a reconnect button that triggers a reconnection request.
66
+
67
+ Example:
89
68
 
90
69
  ```tsx
91
- import { SessionConnectTo } from '@blocklet/did-space-react';
70
+ import { DIDSpaceConnect } from '@blocklet/did-space-react';
92
71
 
93
- function ConnectTo() {
72
+ export default function Demo() {
94
73
  const session = useSessionContext();
74
+ const { did, url } = session.user?.didSpace ?? {};
75
+
76
+ if (did && url) {
77
+ return <DIDSpaceConnect reconnect spaceDid={did} spaceGatewayUrl={url} />;
78
+ }
95
79
 
96
- return <SessionConnectTo session={session} />;
80
+ return null;
81
+ }
82
+ ```
83
+
84
+ ## DIDSpaceConnection
85
+
86
+ The DIDSpaceConnection component is a versatile UI element designed to display key information about the connected DID Space. It enhances the user experience by providing context and interactivity.
87
+
88
+ Key Features:
89
+
90
+ 1. Display Information: Shows details like the DID Space name, DID, and URL.
91
+ 1. Connection Status: If the selected attribute is provided, it also displays the connection status and action buttons.
92
+ 1. Responsive Design: Adapts to various screen sizes, ensuring usability on mobile and desktop devices.
93
+ 1. Compact Mode: Use the compat attribute to enforce a compact layout.
94
+
95
+ Example:
96
+
97
+ ```tsx
98
+ import { DIDSpaceConnection } from '@blocklet/did-space-react';
99
+
100
+ export default function Demo() {
101
+ // This is just a sample template, the actual endpoint address can be obtained from `spaceGateway.endpoint`
102
+ const endpoint = 'https://${spaceDomain}/app/api/space/${spaceDid}/app/${appDid}/object/';
103
+
104
+ return (
105
+ <>
106
+ {/* basic use */}
107
+ <DIDSpaceConnection endpoint={endpoint} selected />
108
+ {/* enforce compat layout */}
109
+ <DIDSpaceConnection endpoint={endpoint} selected compat />
110
+ </>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ### Custom Actions
116
+
117
+ You can enhance the DIDSpaceConnection by customizing the action buttons through the action attribute. This allows you to tailor the functionality to your specific application needs.
118
+
119
+ Example:
120
+
121
+ ```tsx
122
+ import { DIDSpaceConnection } from '@blocklet/did-space-react';
123
+
124
+ export default function Demo() {
125
+ const endpoint = 'https://${spaceDomain}/app/api/space/${spaceDid}/app/${appDid}/object/';
126
+
127
+ return (
128
+ <DIDSpaceConnection
129
+ endpoint={x.endpoint}
130
+ selected
131
+ action={({ spaceGateway, selected, refresh }) => (
132
+ // open DID Space site
133
+ <IconButton
134
+ size="small"
135
+ LinkComponent={Link}
136
+ href={`${spaceGateway.url}/space/${spaceGateway.did}`}
137
+ target="_blank"
138
+ >
139
+ <OpenInNewIcon />
140
+ </IconButton>
141
+ )}
142
+ />
143
+ );
97
144
  }
98
145
  ```
@@ -1,18 +1,53 @@
1
+ import { ButtonProps } from '@mui/material';
1
2
  import { type BaseConnectToProps } from '../base-connect-to';
2
3
  import { GatewayAuth, type GatewayAuthProps } from './gateway-auth';
3
4
  import { BaseAuth, type BaseAuthProps } from './base-auth';
4
- import { BaseAuthOptions } from '../../types';
5
- export interface Options extends BaseAuthOptions, Record<string, any> {
5
+ import { BaseAuthOptions, DIDSpaceGateway } from '../../types';
6
+ export interface DIDSpaceConnectOptions extends BaseAuthOptions, Record<string, any> {
6
7
  }
7
- export interface AuthConnectToProps extends BaseConnectToProps {
8
- options?: Options;
9
- onSuccess?: (response: Record<string, string>, decrypt: Function) => Promise<void>;
8
+ export interface DIDSpaceConnectProps extends BaseConnectToProps {
9
+ session?: {
10
+ refresh: Function;
11
+ };
12
+ reconnect?: false | true;
13
+ spaceDid?: string;
14
+ spaceGatewayUrl?: string;
15
+ options?: DIDSpaceConnectOptions;
16
+ onSuccess?: ({ spaceGateway, response, decrypt, }: {
17
+ spaceGateway: DIDSpaceGateway;
18
+ response: Record<string, string>;
19
+ decrypt: Function;
20
+ }) => Promise<void>;
21
+ onError?: (error: Error) => void;
10
22
  }
11
- /** Space 连接组件, 内置 Auth 验证流程 */
12
- export declare function AuthConnectTo({ options, onSuccess, ...rest }: AuthConnectToProps): import("react/jsx-runtime").JSX.Element;
13
- export declare namespace AuthConnectTo {
23
+ /** DID Space 连接组件, 内置 Auth 验证流程 */
24
+ export declare function DIDSpaceConnect({ session, reconnect, spaceDid, spaceGatewayUrl, options, onSuccess, onError, ...rest }: DIDSpaceConnectProps): import("react/jsx-runtime").JSX.Element | null;
25
+ export declare namespace DIDSpaceConnect {
14
26
  var WalletAuth: typeof BaseAuth;
15
27
  var GatewayAuth: typeof import("./gateway-auth").GatewayAuth;
16
28
  }
17
29
  export { BaseAuth as WalletAuth, type BaseAuthProps as WalletAuthProps };
18
30
  export { GatewayAuth, type GatewayAuthProps };
31
+ export type Options = DIDSpaceConnectOptions;
32
+ export type AuthConnectToProps = DIDSpaceConnectProps;
33
+ export declare function AuthConnectTo(props: Omit<AuthConnectToProps, 'onSuccess'> & {
34
+ onSuccess?: (response: Record<string, string>, decrypt: Function) => Promise<void>;
35
+ }): import("react/jsx-runtime").JSX.Element;
36
+ export interface ReConnectProps extends Omit<ButtonProps, 'onClick' | 'onError'> {
37
+ session: {
38
+ refresh: Function;
39
+ };
40
+ spaceDid: string;
41
+ spaceGatewayUrl: string;
42
+ onConnected?: (spaceGateway: DIDSpaceGateway) => Promise<void>;
43
+ onError?: (error: Error) => void;
44
+ }
45
+ export declare function ReConnect(props: ReConnectProps): import("react/jsx-runtime").JSX.Element;
46
+ export interface SessionConnectToProps extends Omit<BaseConnectToProps, 'onError'> {
47
+ session: {
48
+ refresh: Function;
49
+ };
50
+ onConnected?: (spaceGateway: DIDSpaceGateway) => Promise<void>;
51
+ onError?: (error: Error) => void;
52
+ }
53
+ export declare function SessionConnectTo({ session, onConnected, onError, ...rest }: SessionConnectToProps): import("react/jsx-runtime").JSX.Element;
@@ -2,40 +2,98 @@
2
2
 
3
3
  const jsxRuntime = require('react/jsx-runtime');
4
4
  const React = require('react');
5
+ const jsSdk = require('@blocklet/js-sdk');
6
+ const material = require('@mui/material');
7
+ const util = require('../../libs/util.js');
5
8
  const index = require('../base-connect-to/index.js');
6
9
  const gatewayAuth = require('./gateway-auth.js');
7
10
  const baseAuth = require('./base-auth.js');
8
11
  const popupAuth = require('./popup-auth.js');
12
+ const useLocale = require('../../hooks/use-locale.js');
9
13
 
10
- function AuthConnectTo({ options, onSuccess, ...rest }) {
14
+ function DIDSpaceConnect({
15
+ session,
16
+ reconnect = false,
17
+ spaceDid = "",
18
+ spaceGatewayUrl = "",
19
+ options = {},
20
+ onSuccess,
21
+ onError,
22
+ ...rest
23
+ }) {
24
+ const { t } = useLocale();
11
25
  const [walletOptions, setWalletOptions] = React.useState({
12
26
  open: false
13
27
  });
14
28
  const [gatewayOptions, setGatewayOptions] = React.useState({
15
29
  open: false,
16
- spaceDid: "",
17
- spaceGatewayUrl: ""
30
+ spaceDid,
31
+ spaceGatewayUrl
18
32
  });
19
33
  const onWalletClick = () => setWalletOptions((pre) => ({ ...pre, open: true }));
20
- const onGatewayConfirm = ({ spaceDid, spaceGatewayUrl }) => {
34
+ const onGatewayConfirm = (params) => {
21
35
  setGatewayOptions((pre) => ({
22
36
  ...pre,
23
37
  open: true,
24
- spaceDid,
25
- spaceGatewayUrl
38
+ ...params
26
39
  }));
27
40
  };
28
41
  const handleSuccess = async (response, decrypt) => {
29
- await onSuccess?.(response, decrypt);
30
- setWalletOptions((pre) => ({
31
- ...pre,
32
- open: false
33
- }));
34
- setGatewayOptions((pre) => ({
35
- ...pre,
36
- open: false
37
- }));
42
+ try {
43
+ const spaceGateway = util.decryptSpaceGateway(response, decrypt);
44
+ if (session) {
45
+ await new jsSdk.BlockletSDK().user.updateDidSpace({ spaceGateway });
46
+ session.refresh();
47
+ }
48
+ await onSuccess?.({
49
+ spaceGateway,
50
+ response,
51
+ decrypt
52
+ });
53
+ } catch (err) {
54
+ console.error(err);
55
+ onError?.(err);
56
+ } finally {
57
+ setWalletOptions((pre) => ({
58
+ ...pre,
59
+ open: false
60
+ }));
61
+ setGatewayOptions((pre) => ({
62
+ ...pre,
63
+ open: false
64
+ }));
65
+ }
38
66
  };
67
+ if (session) {
68
+ options.action = "connect-to-did-spaces-for-user";
69
+ }
70
+ if (reconnect) {
71
+ if (!spaceDid || !spaceGatewayUrl) {
72
+ console.error("spaceDid and spaceGatewayUrl are required for reconnect");
73
+ return null;
74
+ }
75
+ return /* @__PURE__ */ jsxRuntime.jsxs(
76
+ material.Button,
77
+ {
78
+ ...rest,
79
+ onClick: () => {
80
+ setGatewayOptions((pre) => ({ ...pre, open: true }));
81
+ },
82
+ children: [
83
+ t("storage.spaces.connect.reconnect"),
84
+ /* @__PURE__ */ jsxRuntime.jsx(
85
+ gatewayAuth.GatewayAuth,
86
+ {
87
+ ...options,
88
+ ...gatewayOptions,
89
+ onSuccess: handleSuccess,
90
+ onClose: () => setGatewayOptions((pre) => ({ ...pre, open: false }))
91
+ }
92
+ )
93
+ ]
94
+ }
95
+ );
96
+ }
39
97
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
40
98
  /* @__PURE__ */ jsxRuntime.jsx(index.BaseConnectTo, { ...rest, onWalletClick, onGatewayConfirm }),
41
99
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -58,9 +116,45 @@ function AuthConnectTo({ options, onSuccess, ...rest }) {
58
116
  )
59
117
  ] });
60
118
  }
61
- AuthConnectTo.WalletAuth = baseAuth.BaseAuth;
62
- AuthConnectTo.GatewayAuth = gatewayAuth.GatewayAuth;
119
+ DIDSpaceConnect.WalletAuth = baseAuth.BaseAuth;
120
+ DIDSpaceConnect.GatewayAuth = gatewayAuth.GatewayAuth;
121
+ function AuthConnectTo(props) {
122
+ const { onSuccess, ...rest } = props;
123
+ return /* @__PURE__ */ jsxRuntime.jsx(DIDSpaceConnect, { ...rest, onSuccess: async ({ response, decrypt }) => await onSuccess?.(response, decrypt) });
124
+ }
125
+ function ReConnect(props) {
126
+ const { session, spaceDid, spaceGatewayUrl, onConnected, onError, ...rest } = props;
127
+ return (
128
+ // @ts-ignore
129
+ /* @__PURE__ */ jsxRuntime.jsx(
130
+ DIDSpaceConnect,
131
+ {
132
+ ...rest,
133
+ reconnect: true,
134
+ session,
135
+ spaceDid,
136
+ spaceGatewayUrl,
137
+ onSuccess: async ({ spaceGateway }) => await onConnected?.(spaceGateway),
138
+ onError
139
+ }
140
+ )
141
+ );
142
+ }
143
+ function SessionConnectTo({ session, onConnected, onError, ...rest }) {
144
+ return /* @__PURE__ */ jsxRuntime.jsx(
145
+ DIDSpaceConnect,
146
+ {
147
+ ...rest,
148
+ session,
149
+ onSuccess: async ({ spaceGateway }) => await onConnected?.(spaceGateway),
150
+ onError
151
+ }
152
+ );
153
+ }
63
154
 
64
155
  exports.GatewayAuth = gatewayAuth.GatewayAuth;
65
156
  exports.WalletAuth = baseAuth.BaseAuth;
66
157
  exports.AuthConnectTo = AuthConnectTo;
158
+ exports.DIDSpaceConnect = DIDSpaceConnect;
159
+ exports.ReConnect = ReConnect;
160
+ exports.SessionConnectTo = SessionConnectTo;
@@ -1,5 +1,5 @@
1
1
  import { SplitButtonProps } from '@arcblock/ux/lib/SplitButton';
2
- export interface BaseConnectToProps extends Omit<SplitButtonProps, 'menu' | 'onClick'> {
2
+ export interface BaseConnectToProps extends Omit<SplitButtonProps, 'menu' | 'onClick' | 'onError'> {
3
3
  onWalletClick?: () => void;
4
4
  onGatewayConfirm?: (params: {
5
5
  spaceDid: string;
@@ -1,5 +1,6 @@
1
- export declare function PreviewSpaceNft({ src, width, height, }: {
1
+ export declare function DIDSpaceNFTPreview({ src, width, height, }: {
2
2
  src: string;
3
3
  width?: string;
4
4
  height?: string;
5
5
  }): import("react/jsx-runtime").JSX.Element;
6
+ export declare const PreviewSpaceNft: typeof DIDSpaceNFTPreview;
@@ -7,7 +7,7 @@ const CloseOutlinedIcon = require('@mui/icons-material/CloseOutlined');
7
7
  require('../../icons/index.js');
8
8
  const emptySpaceNft = require('../../icons/empty-space-nft.svg.js');
9
9
 
10
- function PreviewSpaceNft({
10
+ function DIDSpaceNFTPreview({
11
11
  src,
12
12
  width = "58px",
13
13
  height = "58px"
@@ -82,5 +82,7 @@ function PreviewSpaceNft({
82
82
  )
83
83
  ] });
84
84
  }
85
+ const PreviewSpaceNft = DIDSpaceNFTPreview;
85
86
 
87
+ exports.DIDSpaceNFTPreview = DIDSpaceNFTPreview;
86
88
  exports.PreviewSpaceNft = PreviewSpaceNft;
@@ -1,18 +1,21 @@
1
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;
2
+ import { DIDSpaceGateway, DIDSpaceStatus } from '../../types';
3
+ export type DIDSpaceConnectionAction = React.ReactNode | ((props: {
4
+ spaceGateway: DIDSpaceGateway;
5
+ spaceStatus: DIDSpaceStatus;
6
6
  errorCode: number;
7
7
  selected: boolean;
8
8
  compat: boolean;
9
9
  refresh: () => void;
10
10
  }) => React.ReactNode);
11
- export interface SpaceCardProps extends BoxProps {
11
+ export interface DIDSpaceConnectionProps extends BoxProps {
12
12
  endpoint: string;
13
13
  selected?: boolean;
14
14
  compat?: boolean;
15
- action?: Action;
15
+ action?: DIDSpaceConnectionAction;
16
16
  deps?: any[];
17
17
  }
18
- export declare function SpaceCard({ endpoint, selected, compat, action, className, deps, ...rest }: SpaceCardProps): import("react/jsx-runtime").JSX.Element;
18
+ export declare function DIDSpaceConnection({ endpoint, selected, compat, action, className, deps, ...rest }: DIDSpaceConnectionProps): import("react/jsx-runtime").JSX.Element;
19
+ export type SpaceCardProps = DIDSpaceConnectionProps;
20
+ export declare const SpaceCard: typeof DIDSpaceConnection;
21
+ export type Action = DIDSpaceConnectionAction;
@@ -40,17 +40,17 @@ function Status({
40
40
  const statusConfig = ahooks.useCreation(
41
41
  () => ({
42
42
  // 加载中
43
- [index.SpaceStatus.LOADING]: {
43
+ [index.DIDSpaceStatus.LOADING]: {
44
44
  icon: null,
45
45
  text: null
46
46
  },
47
47
  // 已连接
48
- [index.SpaceStatus.CONNECTED]: {
48
+ [index.DIDSpaceStatus.CONNECTED]: {
49
49
  icon: /* @__PURE__ */ jsxRuntime.jsx(spaceConnected, { style: iconStyle }),
50
50
  text: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#047857" }, children: t("storage.spaces.connected.tag") })
51
51
  },
52
52
  // 未连接(未授权)
53
- [index.SpaceStatus.DISCONNECTED]: {
53
+ [index.DIDSpaceStatus.DISCONNECTED]: {
54
54
  icon: /* @__PURE__ */ jsxRuntime.jsx(spaceDisconnect, { style: iconStyle }),
55
55
  text: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { color: "#626a77" }, children: t("storage.spaces.disconnected.tag") })
56
56
  }
@@ -107,14 +107,14 @@ function Status({
107
107
  }),
108
108
  [locale, spaceVersion]
109
109
  );
110
- const { icon, text } = status === index.SpaceStatus.UNAVAILABLE ? errorStatusConfig[errorCode] : statusConfig[status];
110
+ const { icon, text } = status === index.DIDSpaceStatus.UNAVAILABLE ? errorStatusConfig[errorCode] : statusConfig[status];
111
111
  React.useEffect(() => {
112
112
  const handleVisibilityChange = () => {
113
113
  if (!document.hidden) {
114
114
  refresh();
115
115
  }
116
116
  };
117
- if (status !== index.SpaceStatus.CONNECTED) {
117
+ if (status !== index.DIDSpaceStatus.CONNECTED) {
118
118
  document.addEventListener("visibilitychange", handleVisibilityChange);
119
119
  } else {
120
120
  document.removeEventListener("visibilitychange", handleVisibilityChange);
@@ -152,7 +152,15 @@ function ErrorLink({ title, url }) {
152
152
  }
153
153
  ) });
154
154
  }
155
- function SpaceCard({ endpoint, selected = false, compat, action, className, deps, ...rest }) {
155
+ function DIDSpaceConnection({
156
+ endpoint,
157
+ selected = false,
158
+ compat,
159
+ action,
160
+ className,
161
+ deps,
162
+ ...rest
163
+ }) {
156
164
  const isMobile = useMobile();
157
165
  const { t } = useLocale();
158
166
  let isCompact = compat;
@@ -174,34 +182,34 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
174
182
  });
175
183
  let spaceName = "";
176
184
  const isAvailable = spaceInfo?.isAvailable ?? false;
177
- const spaceStatus = React.useRef(index.SpaceStatus.LOADING);
185
+ const spaceStatus = React.useRef(index.DIDSpaceStatus.LOADING);
178
186
  let errorCode = 0;
179
187
  if (loading) {
180
- spaceStatus.current = index.SpaceStatus.LOADING;
188
+ spaceStatus.current = index.DIDSpaceStatus.LOADING;
181
189
  spaceName = /* @__PURE__ */ jsxRuntime.jsx(material.Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
190
+ } else if (error instanceof axios.AxiosError) {
191
+ spaceName = t("common.unknown");
192
+ spaceStatus.current = index.DIDSpaceStatus.UNAVAILABLE;
193
+ if (util.isCorsBlockedError(error)) {
194
+ errorCode = constants.SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED;
195
+ } else {
196
+ errorCode = constants.SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR;
197
+ }
182
198
  } else if (spaceInfo) {
183
199
  spaceName = spaceInfo.name;
184
200
  const spaceVersion = spaceInfo.version;
185
201
  const isIncompatible = !spaceVersion || semver.major(expectVersion) !== semver.major(spaceVersion);
186
202
  if (isIncompatible) {
187
- spaceStatus.current = index.SpaceStatus.UNAVAILABLE;
203
+ spaceStatus.current = index.DIDSpaceStatus.UNAVAILABLE;
188
204
  errorCode = constants.SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE;
189
205
  } else if (!isAvailable) {
190
- spaceStatus.current = index.SpaceStatus.UNAVAILABLE;
206
+ spaceStatus.current = index.DIDSpaceStatus.UNAVAILABLE;
191
207
  errorCode = spaceInfo.errorCode;
192
208
  if (errorCode === constants.SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED) {
193
- spaceStatus.current = index.SpaceStatus.DISCONNECTED;
209
+ spaceStatus.current = index.DIDSpaceStatus.DISCONNECTED;
194
210
  }
195
211
  } else {
196
- spaceStatus.current = index.SpaceStatus.CONNECTED;
197
- }
198
- } else if (error instanceof axios.AxiosError) {
199
- spaceName = t("common.unknown");
200
- spaceStatus.current = index.SpaceStatus.UNAVAILABLE;
201
- if (util.isCorsBlockedError(error)) {
202
- errorCode = constants.SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED;
203
- } else {
204
- errorCode = constants.SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR;
212
+ spaceStatus.current = index.DIDSpaceStatus.CONNECTED;
205
213
  }
206
214
  }
207
215
  const renderAction = () => {
@@ -235,7 +243,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
235
243
  ...rest,
236
244
  children: [
237
245
  /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", children: [
238
- /* @__PURE__ */ jsxRuntime.jsx(index$1.PreviewSpaceNft, { src: util.getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
246
+ /* @__PURE__ */ jsxRuntime.jsx(index$1.DIDSpaceNFTPreview, { src: util.getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
239
247
  /* @__PURE__ */ jsxRuntime.jsxs(material.Stack, { ml: 2, flex: 1, spacing: 1, minWidth: 0, children: [
240
248
  /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { display: "flex", alignItems: "center", sx: { whiteSpace: "nowrap" }, children: [
241
249
  spaceName && /* @__PURE__ */ jsxRuntime.jsx(material.Box, { className: "space-name", children: spaceName }),
@@ -311,5 +319,7 @@ const BoxContainer = Theme.styled(material.Box)`
311
319
  margin-right: 8px;
312
320
  }
313
321
  `;
322
+ const SpaceCard = DIDSpaceConnection;
314
323
 
324
+ exports.DIDSpaceConnection = DIDSpaceConnection;
315
325
  exports.SpaceCard = SpaceCard;
@@ -23,7 +23,7 @@ function useSpaceInfo({ endpoint, deps = [] }) {
23
23
  isListable,
24
24
  isReadable,
25
25
  isWriteable,
26
- rawVersion,
26
+ rawVersion = "legacy",
27
27
  rawOwnerDid,
28
28
  rawAvailable,
29
29
  rawErrorCode
@@ -43,7 +43,7 @@ function useSpaceInfo({ endpoint, deps = [] }) {
43
43
  if (rawAvailable === void 0 || rawErrorCode === void 0) {
44
44
  const isAvailable = isListable && isReadable && isWriteable;
45
45
  return {
46
- version: rawVersion || "",
46
+ version: rawVersion,
47
47
  name,
48
48
  subscriptionId: rawSubscriptionId,
49
49
  ownerDid: rawOwnerDid || "",
@@ -52,7 +52,7 @@ function useSpaceInfo({ endpoint, deps = [] }) {
52
52
  };
53
53
  }
54
54
  return {
55
- version: rawVersion || "",
55
+ version: rawVersion,
56
56
  name,
57
57
  subscriptionId: rawSubscriptionId,
58
58
  ownerDid: rawOwnerDid,
@@ -4,9 +4,8 @@ import useSpaceInfo from './hooks/use-space-info';
4
4
  import useLocale from './hooks/use-locale';
5
5
  export * from './components/space-card';
6
6
  export * from './components/preview-space-nft';
7
- export * from './components/base-connect-to';
8
7
  export * from './components/auth-connect-to';
9
- export * from './components/session-connect-to';
8
+ export * from './components/base-connect-to';
10
9
  export * from './libs/constants';
11
10
  export * from './libs/util';
12
11
  export * from './libs/gateway';