@blocklet/did-space-react 1.0.0 → 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 +2 -6
  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/dist/cjs/index.js CHANGED
@@ -6,14 +6,13 @@ const useSpaceInfo = require('./hooks/use-space-info.js');
6
6
  const useLocale = require('./hooks/use-locale.js');
7
7
  const index = require('./components/space-card/index.js');
8
8
  const index$1 = require('./components/preview-space-nft/index.js');
9
- const index$2 = require('./components/base-connect-to/index.js');
10
- const index$3 = require('./components/auth-connect-to/index.js');
11
- const index$4 = require('./components/session-connect-to/index.js');
9
+ const index$2 = require('./components/auth-connect-to/index.js');
10
+ const index$3 = require('./components/base-connect-to/index.js');
12
11
  const constants = require('./libs/constants.js');
13
12
  const util = require('./libs/util.js');
14
13
  const gateway = require('./libs/gateway.js');
15
- const index$5 = require('./locales/index.js');
16
- const index$6 = require('./types/index.js');
14
+ const index$4 = require('./locales/index.js');
15
+ const index$5 = require('./types/index.js');
17
16
  require('./icons/index.js');
18
17
  const emptySpaceNft = require('./icons/empty-space-nft.svg.js');
19
18
  const spaceConnected = require('./icons/space-connected.svg.js');
@@ -21,7 +20,6 @@ const spaceDisconnect = require('./icons/space-disconnect.svg.js');
21
20
  const spaceConnectError = require('./icons/space-connect-error.svg.js');
22
21
  const baseAuth = require('./components/auth-connect-to/base-auth.js');
23
22
  const gatewayAuth = require('./components/auth-connect-to/gateway-auth.js');
24
- const reConnect = require('./components/session-connect-to/re-connect.js');
25
23
 
26
24
 
27
25
 
@@ -29,11 +27,15 @@ exports.api = api;
29
27
  exports.useMobile = useMobile;
30
28
  exports.useSpaceInfo = useSpaceInfo;
31
29
  exports.useLocale = useLocale;
30
+ exports.DIDSpaceConnection = index.DIDSpaceConnection;
32
31
  exports.SpaceCard = index.SpaceCard;
32
+ exports.DIDSpaceNFTPreview = index$1.DIDSpaceNFTPreview;
33
33
  exports.PreviewSpaceNft = index$1.PreviewSpaceNft;
34
- exports.BaseConnectTo = index$2.BaseConnectTo;
35
- exports.AuthConnectTo = index$3.AuthConnectTo;
36
- exports.SessionConnectTo = index$4.SessionConnectTo;
34
+ exports.AuthConnectTo = index$2.AuthConnectTo;
35
+ exports.DIDSpaceConnect = index$2.DIDSpaceConnect;
36
+ exports.ReConnect = index$2.ReConnect;
37
+ exports.SessionConnectTo = index$2.SessionConnectTo;
38
+ exports.BaseConnectTo = index$3.BaseConnectTo;
37
39
  exports.AUTHORIZE = constants.AUTHORIZE;
38
40
  exports.SPACE_CONNECT_ERROR_CODE = constants.SPACE_CONNECT_ERROR_CODE;
39
41
  exports.copyGatewayPageUrl = constants.copyGatewayPageUrl;
@@ -50,12 +52,12 @@ exports.isCorsBlockedError = util.isCorsBlockedError;
50
52
  exports.t = util.t;
51
53
  exports.getSpaceGatewayUrl = gateway.getSpaceGatewayUrl;
52
54
  exports.verifySpaceUrl = gateway.verifySpaceUrl;
53
- exports.translations = index$5.translations;
54
- exports.SpaceStatus = index$6.SpaceStatus;
55
+ exports.translations = index$4.translations;
56
+ exports.DIDSpaceStatus = index$5.DIDSpaceStatus;
57
+ exports.SpaceStatus = index$5.SpaceStatus;
55
58
  exports.EmptySpacesNFTIcon = emptySpaceNft;
56
59
  exports.SpacesConnectedIcon = spaceConnected;
57
60
  exports.SpaceDisconnectedIcon = spaceDisconnect;
58
61
  exports.SpaceConnectErrorIcon = spaceConnectError;
59
62
  exports.WalletAuth = baseAuth.BaseAuth;
60
63
  exports.GatewayAuth = gatewayAuth.GatewayAuth;
61
- exports.ReConnect = reConnect.ReConnect;
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const version = "1.0.0";
3
+ const version = "1.0.1";
4
4
 
5
5
  exports.version = version;
@@ -16,14 +16,14 @@ export interface AuthorizeConnect {
16
16
  checkTimeout?: number;
17
17
  extraParams?: Record<string, any>;
18
18
  }
19
- export declare enum SpaceStatus {
19
+ export declare enum DIDSpaceStatus {
20
20
  LOADING = "loading",
21
21
  CONNECTED = "connected",
22
22
  DISCONNECTED = "disconnected",
23
23
  /** 不可用,跟订阅状态相关,比如过期、逾期、用量不足等 */
24
24
  UNAVAILABLE = "unavailable"
25
25
  }
26
- export interface SpaceGateway {
26
+ export interface DIDSpaceGateway {
27
27
  did: string;
28
28
  name: string;
29
29
  url: string;
@@ -44,3 +44,5 @@ export interface GatewayAuthOptions extends BaseAuthOptions {
44
44
  spaceDid?: string;
45
45
  spaceGatewayUrl?: string;
46
46
  }
47
+ export type SpaceGateway = DIDSpaceGateway;
48
+ export declare const SpaceStatus: typeof DIDSpaceStatus;
@@ -1,11 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var SpaceStatus = /* @__PURE__ */ ((SpaceStatus2) => {
4
- SpaceStatus2["LOADING"] = "loading";
5
- SpaceStatus2["CONNECTED"] = "connected";
6
- SpaceStatus2["DISCONNECTED"] = "disconnected";
7
- SpaceStatus2["UNAVAILABLE"] = "unavailable";
8
- return SpaceStatus2;
9
- })(SpaceStatus || {});
3
+ var DIDSpaceStatus = /* @__PURE__ */ ((DIDSpaceStatus2) => {
4
+ DIDSpaceStatus2["LOADING"] = "loading";
5
+ DIDSpaceStatus2["CONNECTED"] = "connected";
6
+ DIDSpaceStatus2["DISCONNECTED"] = "disconnected";
7
+ DIDSpaceStatus2["UNAVAILABLE"] = "unavailable";
8
+ return DIDSpaceStatus2;
9
+ })(DIDSpaceStatus || {});
10
+ const SpaceStatus = DIDSpaceStatus;
10
11
 
12
+ exports.DIDSpaceStatus = DIDSpaceStatus;
11
13
  exports.SpaceStatus = SpaceStatus;
@@ -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;
@@ -1,39 +1,97 @@
1
- import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { useState } from 'react';
3
+ import { BlockletSDK } from '@blocklet/js-sdk';
4
+ import { Button } from '@mui/material';
5
+ import { decryptSpaceGateway } from '../../libs/util.js';
3
6
  import { BaseConnectTo } from '../base-connect-to/index.js';
4
7
  import { GatewayAuth } from './gateway-auth.js';
5
8
  import { BaseAuth } from './base-auth.js';
6
9
  import { PopupAuth } from './popup-auth.js';
10
+ import useLocale from '../../hooks/use-locale.js';
7
11
 
8
- function AuthConnectTo({ options, onSuccess, ...rest }) {
12
+ function DIDSpaceConnect({
13
+ session,
14
+ reconnect = false,
15
+ spaceDid = "",
16
+ spaceGatewayUrl = "",
17
+ options = {},
18
+ onSuccess,
19
+ onError,
20
+ ...rest
21
+ }) {
22
+ const { t } = useLocale();
9
23
  const [walletOptions, setWalletOptions] = useState({
10
24
  open: false
11
25
  });
12
26
  const [gatewayOptions, setGatewayOptions] = useState({
13
27
  open: false,
14
- spaceDid: "",
15
- spaceGatewayUrl: ""
28
+ spaceDid,
29
+ spaceGatewayUrl
16
30
  });
17
31
  const onWalletClick = () => setWalletOptions((pre) => ({ ...pre, open: true }));
18
- const onGatewayConfirm = ({ spaceDid, spaceGatewayUrl }) => {
32
+ const onGatewayConfirm = (params) => {
19
33
  setGatewayOptions((pre) => ({
20
34
  ...pre,
21
35
  open: true,
22
- spaceDid,
23
- spaceGatewayUrl
36
+ ...params
24
37
  }));
25
38
  };
26
39
  const handleSuccess = async (response, decrypt) => {
27
- await onSuccess?.(response, decrypt);
28
- setWalletOptions((pre) => ({
29
- ...pre,
30
- open: false
31
- }));
32
- setGatewayOptions((pre) => ({
33
- ...pre,
34
- open: false
35
- }));
40
+ try {
41
+ const spaceGateway = decryptSpaceGateway(response, decrypt);
42
+ if (session) {
43
+ await new BlockletSDK().user.updateDidSpace({ spaceGateway });
44
+ session.refresh();
45
+ }
46
+ await onSuccess?.({
47
+ spaceGateway,
48
+ response,
49
+ decrypt
50
+ });
51
+ } catch (err) {
52
+ console.error(err);
53
+ onError?.(err);
54
+ } finally {
55
+ setWalletOptions((pre) => ({
56
+ ...pre,
57
+ open: false
58
+ }));
59
+ setGatewayOptions((pre) => ({
60
+ ...pre,
61
+ open: false
62
+ }));
63
+ }
36
64
  };
65
+ if (session) {
66
+ options.action = "connect-to-did-spaces-for-user";
67
+ }
68
+ if (reconnect) {
69
+ if (!spaceDid || !spaceGatewayUrl) {
70
+ console.error("spaceDid and spaceGatewayUrl are required for reconnect");
71
+ return null;
72
+ }
73
+ return /* @__PURE__ */ jsxs(
74
+ Button,
75
+ {
76
+ ...rest,
77
+ onClick: () => {
78
+ setGatewayOptions((pre) => ({ ...pre, open: true }));
79
+ },
80
+ children: [
81
+ t("storage.spaces.connect.reconnect"),
82
+ /* @__PURE__ */ jsx(
83
+ GatewayAuth,
84
+ {
85
+ ...options,
86
+ ...gatewayOptions,
87
+ onSuccess: handleSuccess,
88
+ onClose: () => setGatewayOptions((pre) => ({ ...pre, open: false }))
89
+ }
90
+ )
91
+ ]
92
+ }
93
+ );
94
+ }
37
95
  return /* @__PURE__ */ jsxs(Fragment, { children: [
38
96
  /* @__PURE__ */ jsx(BaseConnectTo, { ...rest, onWalletClick, onGatewayConfirm }),
39
97
  /* @__PURE__ */ jsx(
@@ -56,7 +114,40 @@ function AuthConnectTo({ options, onSuccess, ...rest }) {
56
114
  )
57
115
  ] });
58
116
  }
59
- AuthConnectTo.WalletAuth = BaseAuth;
60
- AuthConnectTo.GatewayAuth = GatewayAuth;
117
+ DIDSpaceConnect.WalletAuth = BaseAuth;
118
+ DIDSpaceConnect.GatewayAuth = GatewayAuth;
119
+ function AuthConnectTo(props) {
120
+ const { onSuccess, ...rest } = props;
121
+ return /* @__PURE__ */ jsx(DIDSpaceConnect, { ...rest, onSuccess: async ({ response, decrypt }) => await onSuccess?.(response, decrypt) });
122
+ }
123
+ function ReConnect(props) {
124
+ const { session, spaceDid, spaceGatewayUrl, onConnected, onError, ...rest } = props;
125
+ return (
126
+ // @ts-ignore
127
+ /* @__PURE__ */ jsx(
128
+ DIDSpaceConnect,
129
+ {
130
+ ...rest,
131
+ reconnect: true,
132
+ session,
133
+ spaceDid,
134
+ spaceGatewayUrl,
135
+ onSuccess: async ({ spaceGateway }) => await onConnected?.(spaceGateway),
136
+ onError
137
+ }
138
+ )
139
+ );
140
+ }
141
+ function SessionConnectTo({ session, onConnected, onError, ...rest }) {
142
+ return /* @__PURE__ */ jsx(
143
+ DIDSpaceConnect,
144
+ {
145
+ ...rest,
146
+ session,
147
+ onSuccess: async ({ spaceGateway }) => await onConnected?.(spaceGateway),
148
+ onError
149
+ }
150
+ );
151
+ }
61
152
 
62
- export { AuthConnectTo, GatewayAuth, BaseAuth as WalletAuth };
153
+ export { AuthConnectTo, DIDSpaceConnect, GatewayAuth, ReConnect, SessionConnectTo, BaseAuth as WalletAuth };
@@ -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;
@@ -5,7 +5,7 @@ import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined';
5
5
  import '../../icons/index.js';
6
6
  import SvgEmptySpaceNft from '../../icons/empty-space-nft.svg.js';
7
7
 
8
- function PreviewSpaceNft({
8
+ function DIDSpaceNFTPreview({
9
9
  src,
10
10
  width = "58px",
11
11
  height = "58px"
@@ -80,5 +80,6 @@ function PreviewSpaceNft({
80
80
  )
81
81
  ] });
82
82
  }
83
+ const PreviewSpaceNft = DIDSpaceNFTPreview;
83
84
 
84
- export { PreviewSpaceNft };
85
+ export { DIDSpaceNFTPreview, 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;
@@ -15,9 +15,9 @@ import useMobile from '../../hooks/use-mobile.js';
15
15
  import useSpaceInfo from '../../hooks/use-space-info.js';
16
16
  import useLocale from '../../hooks/use-locale.js';
17
17
  import { getSpaceDidFromEndpoint, getSpaceUrlFromEndpoint, getSpaceGatewayUrlFromEndpoint, isCorsBlockedError, classNames, getSpaceNftDisplayUrlFromEndpoint } from '../../libs/util.js';
18
- import { SpaceStatus } from '../../types/index.js';
18
+ import { DIDSpaceStatus } from '../../types/index.js';
19
19
  import '../../icons/index.js';
20
- import { PreviewSpaceNft } from '../preview-space-nft/index.js';
20
+ import { DIDSpaceNFTPreview } from '../preview-space-nft/index.js';
21
21
  import SvgSpaceConnected from '../../icons/space-connected.svg.js';
22
22
  import SvgSpaceDisconnect from '../../icons/space-disconnect.svg.js';
23
23
  import SvgSpaceConnectError from '../../icons/space-connect-error.svg.js';
@@ -38,17 +38,17 @@ function Status({
38
38
  const statusConfig = useCreation(
39
39
  () => ({
40
40
  // 加载中
41
- [SpaceStatus.LOADING]: {
41
+ [DIDSpaceStatus.LOADING]: {
42
42
  icon: null,
43
43
  text: null
44
44
  },
45
45
  // 已连接
46
- [SpaceStatus.CONNECTED]: {
46
+ [DIDSpaceStatus.CONNECTED]: {
47
47
  icon: /* @__PURE__ */ jsx(SvgSpaceConnected, { style: iconStyle }),
48
48
  text: /* @__PURE__ */ jsx("span", { style: { color: "#047857" }, children: t("storage.spaces.connected.tag") })
49
49
  },
50
50
  // 未连接(未授权)
51
- [SpaceStatus.DISCONNECTED]: {
51
+ [DIDSpaceStatus.DISCONNECTED]: {
52
52
  icon: /* @__PURE__ */ jsx(SvgSpaceDisconnect, { style: iconStyle }),
53
53
  text: /* @__PURE__ */ jsx("span", { style: { color: "#626a77" }, children: t("storage.spaces.disconnected.tag") })
54
54
  }
@@ -105,14 +105,14 @@ function Status({
105
105
  }),
106
106
  [locale, spaceVersion]
107
107
  );
108
- const { icon, text } = status === SpaceStatus.UNAVAILABLE ? errorStatusConfig[errorCode] : statusConfig[status];
108
+ const { icon, text } = status === DIDSpaceStatus.UNAVAILABLE ? errorStatusConfig[errorCode] : statusConfig[status];
109
109
  useEffect(() => {
110
110
  const handleVisibilityChange = () => {
111
111
  if (!document.hidden) {
112
112
  refresh();
113
113
  }
114
114
  };
115
- if (status !== SpaceStatus.CONNECTED) {
115
+ if (status !== DIDSpaceStatus.CONNECTED) {
116
116
  document.addEventListener("visibilitychange", handleVisibilityChange);
117
117
  } else {
118
118
  document.removeEventListener("visibilitychange", handleVisibilityChange);
@@ -150,7 +150,15 @@ function ErrorLink({ title, url }) {
150
150
  }
151
151
  ) });
152
152
  }
153
- function SpaceCard({ endpoint, selected = false, compat, action, className, deps, ...rest }) {
153
+ function DIDSpaceConnection({
154
+ endpoint,
155
+ selected = false,
156
+ compat,
157
+ action,
158
+ className,
159
+ deps,
160
+ ...rest
161
+ }) {
154
162
  const isMobile = useMobile();
155
163
  const { t } = useLocale();
156
164
  let isCompact = compat;
@@ -172,34 +180,34 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
172
180
  });
173
181
  let spaceName = "";
174
182
  const isAvailable = spaceInfo?.isAvailable ?? false;
175
- const spaceStatus = useRef(SpaceStatus.LOADING);
183
+ const spaceStatus = useRef(DIDSpaceStatus.LOADING);
176
184
  let errorCode = 0;
177
185
  if (loading) {
178
- spaceStatus.current = SpaceStatus.LOADING;
186
+ spaceStatus.current = DIDSpaceStatus.LOADING;
179
187
  spaceName = /* @__PURE__ */ jsx(Skeleton, { variant: "text", sx: { width: "180px", fontSize: "1rem" } });
188
+ } else if (error instanceof AxiosError) {
189
+ spaceName = t("common.unknown");
190
+ spaceStatus.current = DIDSpaceStatus.UNAVAILABLE;
191
+ if (isCorsBlockedError(error)) {
192
+ errorCode = SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED;
193
+ } else {
194
+ errorCode = SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR;
195
+ }
180
196
  } else if (spaceInfo) {
181
197
  spaceName = spaceInfo.name;
182
198
  const spaceVersion = spaceInfo.version;
183
199
  const isIncompatible = !spaceVersion || semver.major(expectVersion) !== semver.major(spaceVersion);
184
200
  if (isIncompatible) {
185
- spaceStatus.current = SpaceStatus.UNAVAILABLE;
201
+ spaceStatus.current = DIDSpaceStatus.UNAVAILABLE;
186
202
  errorCode = SPACE_CONNECT_ERROR_CODE.INCOMPATIBLE;
187
203
  } else if (!isAvailable) {
188
- spaceStatus.current = SpaceStatus.UNAVAILABLE;
204
+ spaceStatus.current = DIDSpaceStatus.UNAVAILABLE;
189
205
  errorCode = spaceInfo.errorCode;
190
206
  if (errorCode === SPACE_CONNECT_ERROR_CODE.UNAUTHORIZED) {
191
- spaceStatus.current = SpaceStatus.DISCONNECTED;
207
+ spaceStatus.current = DIDSpaceStatus.DISCONNECTED;
192
208
  }
193
209
  } else {
194
- spaceStatus.current = SpaceStatus.CONNECTED;
195
- }
196
- } else if (error instanceof AxiosError) {
197
- spaceName = t("common.unknown");
198
- spaceStatus.current = SpaceStatus.UNAVAILABLE;
199
- if (isCorsBlockedError(error)) {
200
- errorCode = SPACE_CONNECT_ERROR_CODE.CORS_BLOCKED;
201
- } else {
202
- errorCode = SPACE_CONNECT_ERROR_CODE.NETWORK_ERROR;
210
+ spaceStatus.current = DIDSpaceStatus.CONNECTED;
203
211
  }
204
212
  }
205
213
  const renderAction = () => {
@@ -233,7 +241,7 @@ function SpaceCard({ endpoint, selected = false, compat, action, className, deps
233
241
  ...rest,
234
242
  children: [
235
243
  /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", children: [
236
- /* @__PURE__ */ jsx(PreviewSpaceNft, { src: getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
244
+ /* @__PURE__ */ jsx(DIDSpaceNFTPreview, { src: getSpaceNftDisplayUrlFromEndpoint(endpoint), width: "72px", height: "72px" }),
237
245
  /* @__PURE__ */ jsxs(Stack, { ml: 2, flex: 1, spacing: 1, minWidth: 0, children: [
238
246
  /* @__PURE__ */ jsxs(Box, { display: "flex", alignItems: "center", sx: { whiteSpace: "nowrap" }, children: [
239
247
  spaceName && /* @__PURE__ */ jsx(Box, { className: "space-name", children: spaceName }),
@@ -309,5 +317,6 @@ const BoxContainer = styled(Box)`
309
317
  margin-right: 8px;
310
318
  }
311
319
  `;
320
+ const SpaceCard = DIDSpaceConnection;
312
321
 
313
- export { SpaceCard };
322
+ export { DIDSpaceConnection, SpaceCard };
@@ -21,7 +21,7 @@ function useSpaceInfo({ endpoint, deps = [] }) {
21
21
  isListable,
22
22
  isReadable,
23
23
  isWriteable,
24
- rawVersion,
24
+ rawVersion = "legacy",
25
25
  rawOwnerDid,
26
26
  rawAvailable,
27
27
  rawErrorCode
@@ -41,7 +41,7 @@ function useSpaceInfo({ endpoint, deps = [] }) {
41
41
  if (rawAvailable === void 0 || rawErrorCode === void 0) {
42
42
  const isAvailable = isListable && isReadable && isWriteable;
43
43
  return {
44
- version: rawVersion || "",
44
+ version: rawVersion,
45
45
  name,
46
46
  subscriptionId: rawSubscriptionId,
47
47
  ownerDid: rawOwnerDid || "",
@@ -50,7 +50,7 @@ function useSpaceInfo({ endpoint, deps = [] }) {
50
50
  };
51
51
  }
52
52
  return {
53
- version: rawVersion || "",
53
+ version: rawVersion,
54
54
  name,
55
55
  subscriptionId: rawSubscriptionId,
56
56
  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';
package/dist/es/index.js CHANGED
@@ -2,16 +2,15 @@ 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 { SpaceCard } from './components/space-card/index.js';
6
- export { PreviewSpaceNft } from './components/preview-space-nft/index.js';
5
+ export { DIDSpaceConnection, SpaceCard } from './components/space-card/index.js';
6
+ export { DIDSpaceNFTPreview, PreviewSpaceNft } from './components/preview-space-nft/index.js';
7
+ export { AuthConnectTo, DIDSpaceConnect, ReConnect, SessionConnectTo } from './components/auth-connect-to/index.js';
7
8
  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
9
  export { AUTHORIZE, SPACE_CONNECT_ERROR_CODE, copyGatewayPageUrl, fixCorsErrorPageUrl } from './libs/constants.js';
11
10
  export { classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getSpaceDidFromEndpoint, getSpaceDidFromSpaceUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, getSpaceUrlFromEndpoint, isCorsBlockedError, t } from './libs/util.js';
12
11
  export { getSpaceGatewayUrl, verifySpaceUrl } from './libs/gateway.js';
13
12
  export { translations } from './locales/index.js';
14
- export { SpaceStatus } from './types/index.js';
13
+ export { DIDSpaceStatus, SpaceStatus } from './types/index.js';
15
14
  import './icons/index.js';
16
15
  export { default as EmptySpacesNFTIcon } from './icons/empty-space-nft.svg.js';
17
16
  export { default as SpacesConnectedIcon } from './icons/space-connected.svg.js';
@@ -19,4 +18,3 @@ export { default as SpaceDisconnectedIcon } from './icons/space-disconnect.svg.j
19
18
  export { default as SpaceConnectErrorIcon } from './icons/space-connect-error.svg.js';
20
19
  export { BaseAuth as WalletAuth } from './components/auth-connect-to/base-auth.js';
21
20
  export { GatewayAuth } from './components/auth-connect-to/gateway-auth.js';
22
- export { ReConnect } from './components/session-connect-to/re-connect.js';
@@ -1,3 +1,3 @@
1
- const version = "1.0.0";
1
+ const version = "1.0.1";
2
2
 
3
3
  export { version };
@@ -16,14 +16,14 @@ export interface AuthorizeConnect {
16
16
  checkTimeout?: number;
17
17
  extraParams?: Record<string, any>;
18
18
  }
19
- export declare enum SpaceStatus {
19
+ export declare enum DIDSpaceStatus {
20
20
  LOADING = "loading",
21
21
  CONNECTED = "connected",
22
22
  DISCONNECTED = "disconnected",
23
23
  /** 不可用,跟订阅状态相关,比如过期、逾期、用量不足等 */
24
24
  UNAVAILABLE = "unavailable"
25
25
  }
26
- export interface SpaceGateway {
26
+ export interface DIDSpaceGateway {
27
27
  did: string;
28
28
  name: string;
29
29
  url: string;
@@ -44,3 +44,5 @@ export interface GatewayAuthOptions extends BaseAuthOptions {
44
44
  spaceDid?: string;
45
45
  spaceGatewayUrl?: string;
46
46
  }
47
+ export type SpaceGateway = DIDSpaceGateway;
48
+ export declare const SpaceStatus: typeof DIDSpaceStatus;
@@ -1,9 +1,10 @@
1
- var SpaceStatus = /* @__PURE__ */ ((SpaceStatus2) => {
2
- SpaceStatus2["LOADING"] = "loading";
3
- SpaceStatus2["CONNECTED"] = "connected";
4
- SpaceStatus2["DISCONNECTED"] = "disconnected";
5
- SpaceStatus2["UNAVAILABLE"] = "unavailable";
6
- return SpaceStatus2;
7
- })(SpaceStatus || {});
1
+ var DIDSpaceStatus = /* @__PURE__ */ ((DIDSpaceStatus2) => {
2
+ DIDSpaceStatus2["LOADING"] = "loading";
3
+ DIDSpaceStatus2["CONNECTED"] = "connected";
4
+ DIDSpaceStatus2["DISCONNECTED"] = "disconnected";
5
+ DIDSpaceStatus2["UNAVAILABLE"] = "unavailable";
6
+ return DIDSpaceStatus2;
7
+ })(DIDSpaceStatus || {});
8
+ const SpaceStatus = DIDSpaceStatus;
8
9
 
9
- export { SpaceStatus };
10
+ export { DIDSpaceStatus, SpaceStatus };