@blocklet/did-space-react 0.5.57 → 0.5.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.turbo/turbo-build.log +37 -18
  2. package/.turbo/turbo-lint$colon$fix.log +2 -2
  3. package/README.md +85 -39
  4. package/es/components/auth-connect-to/base-auth.d.ts +5 -0
  5. package/es/components/auth-connect-to/base-auth.js +60 -0
  6. package/es/components/auth-connect-to/gateway-auth.d.ts +5 -0
  7. package/es/components/auth-connect-to/gateway-auth.js +49 -0
  8. package/es/components/auth-connect-to/index.d.ts +18 -0
  9. package/es/components/auth-connect-to/index.js +61 -0
  10. package/es/components/base-connect-to/index.d.ts +10 -0
  11. package/es/components/{ConnectTo → base-connect-to}/index.js +32 -26
  12. package/{lib/components/PreviewNFT → es/components/preview-space-nft}/index.d.ts +1 -2
  13. package/es/components/{PreviewNFT → preview-space-nft}/index.js +7 -2
  14. package/es/components/session-connect-to/index.d.ts +16 -0
  15. package/es/components/session-connect-to/index.js +26 -0
  16. package/es/components/session-connect-to/re-connect.d.ts +13 -0
  17. package/es/components/session-connect-to/re-connect.js +51 -0
  18. package/es/components/{SpaceCard → space-card}/index.d.ts +1 -2
  19. package/es/components/{SpaceCard → space-card}/index.js +82 -33
  20. package/es/hooks/use-space-info.js +1 -1
  21. package/es/icons/index.d.ts +5 -4
  22. package/es/icons/index.js +11 -0
  23. package/es/index.d.ts +8 -5
  24. package/es/index.js +15 -4
  25. package/es/libs/constants.d.ts +4 -0
  26. package/es/libs/constants.js +6 -0
  27. package/es/libs/util.d.ts +1 -0
  28. package/es/libs/util.js +15 -1
  29. package/es/locales/en.js +27 -9
  30. package/es/locales/zh.js +27 -9
  31. package/es/types/index.d.ts +22 -7
  32. package/es/types/index.js +3 -1
  33. package/lib/components/auth-connect-to/base-auth.d.ts +5 -0
  34. package/lib/components/auth-connect-to/base-auth.js +62 -0
  35. package/lib/components/auth-connect-to/gateway-auth.d.ts +5 -0
  36. package/lib/components/auth-connect-to/gateway-auth.js +51 -0
  37. package/lib/components/auth-connect-to/index.d.ts +18 -0
  38. package/lib/components/auth-connect-to/index.js +65 -0
  39. package/lib/components/base-connect-to/index.d.ts +10 -0
  40. package/lib/components/{ConnectTo → base-connect-to}/index.js +31 -25
  41. package/{es/components/PreviewNFT → lib/components/preview-space-nft}/index.d.ts +1 -2
  42. package/lib/components/{PreviewNFT → preview-space-nft}/index.js +7 -2
  43. package/lib/components/session-connect-to/index.d.ts +16 -0
  44. package/lib/components/session-connect-to/index.js +29 -0
  45. package/lib/components/session-connect-to/re-connect.d.ts +13 -0
  46. package/lib/components/session-connect-to/re-connect.js +53 -0
  47. package/lib/components/{SpaceCard → space-card}/index.d.ts +1 -2
  48. package/lib/components/{SpaceCard → space-card}/index.js +82 -33
  49. package/lib/hooks/use-space-info.js +1 -1
  50. package/lib/icons/index.d.ts +5 -4
  51. package/lib/icons/index.js +16 -0
  52. package/lib/index.d.ts +8 -5
  53. package/lib/index.js +33 -10
  54. package/lib/libs/constants.d.ts +4 -0
  55. package/lib/libs/constants.js +9 -0
  56. package/lib/libs/util.d.ts +1 -0
  57. package/lib/libs/util.js +15 -0
  58. package/lib/locales/en.js +27 -9
  59. package/lib/locales/zh.js +27 -9
  60. package/lib/types/index.d.ts +22 -7
  61. package/lib/types/index.js +3 -1
  62. package/package.json +47 -36
  63. package/src/components/auth-connect-to/base-auth.tsx +64 -0
  64. package/src/components/auth-connect-to/gateway-auth.tsx +53 -0
  65. package/src/components/auth-connect-to/index.tsx +71 -0
  66. package/src/components/{ConnectTo/connect-to.stories.tsx → base-connect-to/base-connect-to.stories.tsx} +1 -1
  67. package/src/components/{ConnectTo → base-connect-to}/index.tsx +35 -22
  68. package/src/components/{PreviewNFT → preview-space-nft}/index.tsx +12 -6
  69. package/src/components/session-connect-to/index.tsx +39 -0
  70. package/src/components/session-connect-to/re-connect.tsx +57 -0
  71. package/src/components/{SpaceCard → space-card}/index.tsx +88 -30
  72. package/src/hooks/use-space-info.ts +1 -1
  73. package/src/icons/index.tsx +12 -4
  74. package/src/index.ts +11 -6
  75. package/src/libs/constants.ts +4 -0
  76. package/src/libs/util.ts +17 -0
  77. package/src/locales/en.tsx +26 -7
  78. package/src/locales/zh.tsx +25 -7
  79. package/src/types/index.ts +23 -6
  80. package/src/types/shims.d.ts +4 -4
  81. package/es/components/ConnectTo/index.d.ts +0 -10
  82. package/es/libs/theme.d.ts +0 -1
  83. package/lib/components/ConnectTo/index.d.ts +0 -10
  84. package/lib/libs/theme.d.ts +0 -1
  85. package/src/libs/theme.ts +0 -18
  86. /package/es/components/{ConnectTo/connect-to.stories.d.ts → base-connect-to/base-connect-to.stories.d.ts} +0 -0
  87. /package/es/components/{SpaceCard → space-card}/space-card.stories.d.ts +0 -0
  88. /package/lib/components/{ConnectTo/connect-to.stories.d.ts → base-connect-to/base-connect-to.stories.d.ts} +0 -0
  89. /package/lib/components/{SpaceCard → space-card}/space-card.stories.d.ts +0 -0
  90. /package/src/components/{SpaceCard → space-card}/space-card.stories.tsx +0 -0
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const material = require('@mui/material');
5
+ const DidConnect = require('@arcblock/did-connect/lib/Connect');
6
+ const constant = require('@arcblock/ux/lib/Util/constant');
7
+ const ufo = require('ufo');
8
+ const jsSdk = require('@blocklet/js-sdk');
9
+ const useLocale = require('../../hooks/use-locale.js');
10
+ const constants = require('../../libs/constants.js');
11
+
12
+ function BaseAuth({ open, extraParams, onSuccess, onClose, ...rest }) {
13
+ const { t, locale } = useLocale();
14
+ const finalExtraParams = {
15
+ appPid: window.blocklet?.appPid,
16
+ appDid: window.blocklet?.appId,
17
+ appName: window.blocklet?.appName,
18
+ appDescription: window.blocklet?.appDescription,
19
+ appUrl: window.blocklet?.appUrl,
20
+ referrer: window.location.href,
21
+ scopes: constants.AUTHORIZE.DEFAULT_SCOPE,
22
+ ...extraParams
23
+ };
24
+ const {
25
+ action = "connect-to-did-spaces",
26
+ prefix = "/api/did",
27
+ baseUrl = ufo.joinURL(window.location.origin, constant.RELAY_SOCKET_PREFIX),
28
+ checkFn = jsSdk.createAxios({ baseURL: ufo.joinURL(window.location.origin, constant.RELAY_SOCKET_PREFIX) }).get,
29
+ webWalletUrl = window.blocklet?.webWalletUrl,
30
+ checkTimeout = 1e3 * 300,
31
+ messages = {
32
+ title: t("storage.spaces.provideNFT.title", { appName: finalExtraParams.appName }),
33
+ scan: t("storage.spaces.provideNFT.scan", { appName: finalExtraParams.appName }),
34
+ confirm: "",
35
+ success: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { gutterBottom: true, children: t("storage.spaces.provideNFT.success") })
36
+ },
37
+ ...restOptions
38
+ } = rest;
39
+ return /* @__PURE__ */ jsxRuntime.jsx(
40
+ DidConnect,
41
+ {
42
+ ...restOptions,
43
+ open,
44
+ action,
45
+ prefix,
46
+ baseUrl,
47
+ checkFn,
48
+ webWalletUrl,
49
+ messages,
50
+ checkTimeout,
51
+ extraParams: finalExtraParams,
52
+ forceConnected: false,
53
+ saveConnect: false,
54
+ popup: true,
55
+ locale,
56
+ onSuccess,
57
+ onClose
58
+ }
59
+ );
60
+ }
61
+
62
+ exports.BaseAuth = BaseAuth;
@@ -0,0 +1,5 @@
1
+ import type { GatewayAuthOptions } from '../../types';
2
+ export interface GatewayAuthProps extends GatewayAuthOptions {
3
+ open: boolean;
4
+ }
5
+ export declare function GatewayAuth({ open, spaceDid, spaceGatewayUrl, extraParams, onSuccess, onClose, }: GatewayAuthProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const ufo = require('ufo');
5
+ const jsSdk = require('@blocklet/js-sdk');
6
+ const material = require('@mui/material');
7
+ const useLocale = require('../../hooks/use-locale.js');
8
+ const baseAuth = require('./base-auth.js');
9
+
10
+ function GatewayAuth({
11
+ open,
12
+ spaceDid,
13
+ spaceGatewayUrl,
14
+ extraParams = {},
15
+ onSuccess,
16
+ onClose
17
+ }) {
18
+ const { t } = useLocale();
19
+ if (!spaceGatewayUrl || !spaceDid) {
20
+ return null;
21
+ }
22
+ const { appName = window.blocklet?.appName } = extraParams;
23
+ const prefix = ufo.joinURL(spaceGatewayUrl, "space/api/did");
24
+ const baseUrl = new URL(spaceGatewayUrl).origin;
25
+ const checkFn = jsSdk.createAxios({ baseURL: ufo.joinURL(spaceGatewayUrl, "space") }).get;
26
+ const messages = {
27
+ title: t("storage.spaces.authorize.title", { appName }),
28
+ scan: t("storage.spaces.authorize.scan", { appName }),
29
+ confirm: "",
30
+ success: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { gutterBottom: true, children: t("storage.spaces.authorize.success") })
31
+ };
32
+ return /* @__PURE__ */ jsxRuntime.jsx(
33
+ baseAuth.BaseAuth,
34
+ {
35
+ open,
36
+ action: "one-click-authorization",
37
+ prefix,
38
+ baseUrl,
39
+ checkFn,
40
+ messages,
41
+ extraParams: {
42
+ ...extraParams,
43
+ spaceDid
44
+ },
45
+ onSuccess,
46
+ onClose
47
+ }
48
+ );
49
+ }
50
+
51
+ exports.GatewayAuth = GatewayAuth;
@@ -0,0 +1,18 @@
1
+ import { type BaseConnectToProps } from '../base-connect-to';
2
+ import { GatewayAuth, type GatewayAuthProps } from './gateway-auth';
3
+ import { BaseAuth, type BaseAuthProps } from './base-auth';
4
+ import { BaseAuthOptions } from '../../types';
5
+ export interface Options extends BaseAuthOptions, Record<string, any> {
6
+ }
7
+ export interface AuthConnectToProps extends BaseConnectToProps {
8
+ options?: Options;
9
+ onSuccess?: (response: Record<string, string>, decrypt: Function) => Promise<void>;
10
+ }
11
+ /** Space 连接组件, 内置 Auth 验证流程 */
12
+ export declare function AuthConnectTo({ options, onSuccess, ...rest }: AuthConnectToProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare namespace AuthConnectTo {
14
+ var WalletAuth: typeof BaseAuth;
15
+ var GatewayAuth: typeof import("./gateway-auth").GatewayAuth;
16
+ }
17
+ export { BaseAuth as WalletAuth, type BaseAuthProps as WalletAuthProps };
18
+ export { GatewayAuth, type GatewayAuthProps };
@@ -0,0 +1,65 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const React = require('react');
5
+ const index = require('../base-connect-to/index.js');
6
+ const gatewayAuth = require('./gateway-auth.js');
7
+ const baseAuth = require('./base-auth.js');
8
+
9
+ function AuthConnectTo({ options, onSuccess, ...rest }) {
10
+ const [walletOptions, setWalletOptions] = React.useState({
11
+ open: false
12
+ });
13
+ const [gatewayOptions, setGatewayOptions] = React.useState({
14
+ open: false,
15
+ spaceDid: "",
16
+ spaceGatewayUrl: ""
17
+ });
18
+ const onWalletClick = () => setWalletOptions((pre) => ({ ...pre, open: true }));
19
+ const onGatewayConfirm = ({ spaceDid, spaceGatewayUrl }) => {
20
+ setGatewayOptions((pre) => ({
21
+ ...pre,
22
+ open: true,
23
+ spaceDid,
24
+ spaceGatewayUrl
25
+ }));
26
+ };
27
+ const handleSuccess = async (response, decrypt) => {
28
+ await onSuccess?.(response, decrypt);
29
+ setWalletOptions((pre) => ({
30
+ ...pre,
31
+ open: false
32
+ }));
33
+ setGatewayOptions((pre) => ({
34
+ ...pre,
35
+ open: false
36
+ }));
37
+ };
38
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
39
+ /* @__PURE__ */ jsxRuntime.jsx(index.BaseConnectTo, { ...rest, onWalletClick, onGatewayConfirm }),
40
+ /* @__PURE__ */ jsxRuntime.jsx(
41
+ baseAuth.BaseAuth,
42
+ {
43
+ ...options,
44
+ ...walletOptions,
45
+ onSuccess: handleSuccess,
46
+ onClose: () => setWalletOptions((pre) => ({ ...pre, open: false }))
47
+ }
48
+ ),
49
+ /* @__PURE__ */ jsxRuntime.jsx(
50
+ gatewayAuth.GatewayAuth,
51
+ {
52
+ ...options,
53
+ ...gatewayOptions,
54
+ onSuccess: handleSuccess,
55
+ onClose: () => setGatewayOptions((pre) => ({ ...pre, open: false }))
56
+ }
57
+ )
58
+ ] });
59
+ }
60
+ AuthConnectTo.WalletAuth = baseAuth.BaseAuth;
61
+ AuthConnectTo.GatewayAuth = gatewayAuth.GatewayAuth;
62
+
63
+ exports.GatewayAuth = gatewayAuth.GatewayAuth;
64
+ exports.WalletAuth = baseAuth.BaseAuth;
65
+ exports.AuthConnectTo = AuthConnectTo;
@@ -0,0 +1,10 @@
1
+ import { SplitButtonProps } from '@arcblock/ux/lib/SplitButton';
2
+ export interface BaseConnectToProps extends Omit<SplitButtonProps, 'menu' | 'onClick'> {
3
+ onWalletClick?: () => void;
4
+ onGatewayConfirm?: (params: {
5
+ spaceDid: string;
6
+ spaceGatewayUrl: string;
7
+ }) => void;
8
+ }
9
+ /** 基础连接按钮组件,只负责前端 ux */
10
+ export declare function BaseConnectTo({ style, onWalletClick, onGatewayConfirm, ...rest }: BaseConnectToProps): import("react/jsx-runtime").JSX.Element;
@@ -4,20 +4,23 @@ const jsxRuntime = require('react/jsx-runtime');
4
4
  const React = require('react');
5
5
  const did = require('@arcblock/did');
6
6
  const material = require('@mui/material');
7
+ const HelpOutlineIcon = require('@mui/icons-material/HelpOutline');
7
8
  const Button = require('@arcblock/ux/lib/Button');
8
9
  const SplitButton = require('@arcblock/ux/lib/SplitButton');
9
10
  const Dialog = require('@arcblock/ux/lib/Dialog');
11
+ const ufo = require('ufo');
12
+ const constants = require('../../libs/constants.js');
10
13
  const util = require('../../libs/util.js');
11
14
  const gateway = require('../../libs/gateway.js');
12
15
  const useLocale = require('../../hooks/use-locale.js');
13
16
 
14
- function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
15
- const { t } = useLocale();
17
+ function BaseConnectTo({ style, onWalletClick, onGatewayConfirm, ...rest }) {
18
+ const { t, locale } = useLocale();
16
19
  const [url, setUrl] = React.useState("");
17
20
  const [loading, setLoading] = React.useState(false);
18
21
  const [open, setOpen] = React.useState(false);
19
22
  const [errorMessage, setErrorMessage] = React.useState("");
20
- const handleUseSpaceGatewayConnect = async () => {
23
+ const onGatewayChange = async () => {
21
24
  try {
22
25
  setLoading(true);
23
26
  const spaceGatewayUrl = await gateway.getSpaceGatewayUrl(url);
@@ -26,7 +29,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
26
29
  if (!did.isValid(spaceDid) || !await gateway.isValidSpaceGatewayUrl(didSpacesCoreUrl)) {
27
30
  throw new Error(t("storage.spaces.gateway.add.invalidUrl"));
28
31
  }
29
- onGatewayConnect?.({
32
+ onGatewayConfirm?.({
30
33
  spaceDid,
31
34
  spaceGatewayUrl: didSpacesCoreUrl
32
35
  });
@@ -38,7 +41,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
38
41
  setLoading(false);
39
42
  }
40
43
  };
41
- const openGatewayInput = () => {
44
+ const onGatewayClick = () => {
42
45
  setErrorMessage("");
43
46
  setUrl("");
44
47
  setOpen(true);
@@ -55,19 +58,18 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
55
58
  sx: {
56
59
  textTransform: "none"
57
60
  },
58
- onClick: openGatewayInput,
59
61
  size: "small",
60
- ...rest,
62
+ onClick: onGatewayClick,
61
63
  children: t("storage.spaces.connect.useSpaceGateway")
62
64
  },
63
65
  "1"
64
66
  )
65
67
  ],
66
- onClick: onWalletConnect,
67
68
  color: "primary",
68
69
  style: { textTransform: "none !important", fontSize: "1rem", ...style },
69
70
  size: "small",
70
71
  ...rest,
72
+ onClick: onWalletClick,
71
73
  children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { sx: { fontWeight: "bold", textTransform: "none" }, children: t("storage.spaces.connect.useWallet") })
72
74
  }
73
75
  ),
@@ -93,20 +95,10 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
93
95
  children: t("common.cancel")
94
96
  }
95
97
  ),
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
- )
98
+ /* @__PURE__ */ jsxRuntime.jsxs(Button, { onClick: onGatewayChange, color: "primary", disabled: loading || !url, variant: "contained", autoFocus: true, children: [
99
+ loading && /* @__PURE__ */ jsxRuntime.jsx(material.CircularProgress, { size: 16 }),
100
+ t("common.confirm")
101
+ ] })
110
102
  ] }),
111
103
  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
104
  material.TextField,
@@ -126,10 +118,24 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
126
118
  helperText: errorMessage,
127
119
  onKeyDown: async (e) => {
128
120
  if (e.key === "Enter") {
129
- await handleUseSpaceGatewayConnect();
121
+ await onGatewayChange();
130
122
  }
131
123
  },
132
- autoFocus: true
124
+ autoFocus: true,
125
+ InputProps: {
126
+ endAdornment: /* @__PURE__ */ jsxRuntime.jsx(material.Tooltip, { title: t("storage.spaces.connect.howToGetGatewayUrl"), placement: "top", children: /* @__PURE__ */ jsxRuntime.jsx(material.Link, { href: ufo.withQuery(constants.copyGatewayPageUrl, { locale }), target: "_blank", children: /* @__PURE__ */ jsxRuntime.jsx(
127
+ HelpOutlineIcon,
128
+ {
129
+ sx: {
130
+ ml: 0.5,
131
+ color: "text.secondary",
132
+ cursor: "pointer",
133
+ fontSize: "18px",
134
+ verticalAlign: "-2px"
135
+ }
136
+ }
137
+ ) }) })
138
+ }
133
139
  }
134
140
  ) }) }) })
135
141
  }
@@ -137,4 +143,4 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
137
143
  ] });
138
144
  }
139
145
 
140
- module.exports = ConnectTo;
146
+ exports.BaseConnectTo = BaseConnectTo;
@@ -1,6 +1,5 @@
1
- declare function PreviewSpaceNft({ src, width, height }: {
1
+ export declare function PreviewSpaceNft({ 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 default PreviewSpaceNft;
@@ -4,9 +4,14 @@ const jsxRuntime = require('react/jsx-runtime');
4
4
  const React = require('react');
5
5
  const material = require('@mui/material');
6
6
  const CloseOutlinedIcon = require('@mui/icons-material/CloseOutlined');
7
+ require('../../icons/index.js');
7
8
  const emptySpaceNft = require('../../icons/empty-space-nft.svg.js');
8
9
 
9
- function PreviewSpaceNft({ src, width = "58px", height = "58px" }) {
10
+ function PreviewSpaceNft({
11
+ src,
12
+ width = "58px",
13
+ height = "58px"
14
+ }) {
10
15
  const [open, setOpen] = React.useState(false);
11
16
  const handleOpen = () => setOpen(true);
12
17
  const handleClose = () => setOpen(false);
@@ -78,4 +83,4 @@ function PreviewSpaceNft({ src, width = "58px", height = "58px" }) {
78
83
  ] });
79
84
  }
80
85
 
81
- module.exports = PreviewSpaceNft;
86
+ exports.PreviewSpaceNft = PreviewSpaceNft;
@@ -0,0 +1,16 @@
1
+ import { SpaceGateway } from '../../types';
2
+ import { BaseConnectToProps } from '../base-connect-to';
3
+ import { ReConnect, type ReConnectProps } from './re-connect';
4
+ export interface SessionConnectToProps extends Omit<BaseConnectToProps, 'onError'> {
5
+ session: {
6
+ refresh: Function;
7
+ };
8
+ onConnected?: (spaceGateway: SpaceGateway) => Promise<void>;
9
+ onError?: (error: Error) => void;
10
+ }
11
+ /** 会话连接组件,会将 spaceGateway 信息存储于 users 表 */
12
+ export declare function SessionConnectTo({ session, onConnected, onError, ...rest }: SessionConnectToProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare namespace SessionConnectTo {
14
+ var ReConnect: typeof import("./re-connect").ReConnect;
15
+ }
16
+ export { ReConnect, type ReConnectProps };
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const jsSdk = require('@blocklet/js-sdk');
5
+ const util = require('../../libs/util.js');
6
+ const index = require('../auth-connect-to/index.js');
7
+ const reConnect = require('./re-connect.js');
8
+
9
+ function SessionConnectTo({ session, onConnected, onError, ...rest }) {
10
+ const options = {
11
+ action: "connect-to-did-spaces-for-user"
12
+ };
13
+ const onSuccess = async (response, decrypt) => {
14
+ try {
15
+ const spaceGateway = util.decryptSpaceGateway(response, decrypt);
16
+ await new jsSdk.BlockletSDK().user.updateDidSpace({ spaceGateway });
17
+ session.refresh();
18
+ await onConnected?.(spaceGateway);
19
+ } catch (err) {
20
+ console.error(err);
21
+ onError?.(err);
22
+ }
23
+ };
24
+ return /* @__PURE__ */ jsxRuntime.jsx(index.AuthConnectTo, { ...rest, options, onSuccess });
25
+ }
26
+ SessionConnectTo.ReConnect = reConnect.ReConnect;
27
+
28
+ exports.ReConnect = reConnect.ReConnect;
29
+ exports.SessionConnectTo = SessionConnectTo;
@@ -0,0 +1,13 @@
1
+ import { ButtonProps } from '@mui/material';
2
+ import { SpaceGateway } from '../../types';
3
+ export interface ReConnectProps extends Omit<ButtonProps, 'onClick' | 'onError'> {
4
+ session: {
5
+ refresh: Function;
6
+ };
7
+ spaceDid: string;
8
+ spaceGatewayUrl: string;
9
+ onConnected?: (spaceGateway: SpaceGateway) => Promise<void>;
10
+ onError?: (error: Error) => void;
11
+ }
12
+ /** 用于 DApp 重新连接 Space */
13
+ export declare function ReConnect({ session, spaceDid, spaceGatewayUrl, onConnected, onError, ...rest }: ReConnectProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('react/jsx-runtime');
4
+ const material = require('@mui/material');
5
+ const React = require('react');
6
+ const jsSdk = require('@blocklet/js-sdk');
7
+ const useLocale = require('../../hooks/use-locale.js');
8
+ const util = require('../../libs/util.js');
9
+ const gatewayAuth = require('../auth-connect-to/gateway-auth.js');
10
+
11
+ function ReConnect({ session, spaceDid, spaceGatewayUrl, onConnected, onError, ...rest }) {
12
+ const { t } = useLocale();
13
+ const [authOptions, setAuthOptions] = React.useState({
14
+ open: false,
15
+ spaceDid,
16
+ spaceGatewayUrl
17
+ });
18
+ const onSuccess = async (response, decrypt) => {
19
+ try {
20
+ const spaceGateway = util.decryptSpaceGateway(response, decrypt);
21
+ await new jsSdk.BlockletSDK().user.updateDidSpace({ spaceGateway });
22
+ session.refresh();
23
+ await onConnected?.(spaceGateway);
24
+ } catch (err) {
25
+ console.error(err);
26
+ onError?.(err);
27
+ } finally {
28
+ setAuthOptions((pre) => ({ ...pre, open: false }));
29
+ }
30
+ };
31
+ return /* @__PURE__ */ jsxRuntime.jsxs(
32
+ material.Button,
33
+ {
34
+ ...rest,
35
+ onClick: () => {
36
+ setAuthOptions((pre) => ({ ...pre, open: true }));
37
+ },
38
+ children: [
39
+ t("storage.spaces.connect.reconnect"),
40
+ /* @__PURE__ */ jsxRuntime.jsx(
41
+ gatewayAuth.GatewayAuth,
42
+ {
43
+ ...authOptions,
44
+ onSuccess,
45
+ onClose: () => setAuthOptions((pre) => ({ ...pre, open: false }))
46
+ }
47
+ )
48
+ ]
49
+ }
50
+ );
51
+ }
52
+
53
+ exports.ReConnect = ReConnect;
@@ -14,5 +14,4 @@ export interface SpaceCardProps extends BoxProps {
14
14
  action?: Action;
15
15
  deps?: any[];
16
16
  }
17
- declare function SpaceCard({ endpoint, selected, compat, action, className, deps, ...rest }: SpaceCardProps): import("react/jsx-runtime").JSX.Element;
18
- export default SpaceCard;
17
+ export declare function SpaceCard({ endpoint, selected, compat, action, className, deps, ...rest }: SpaceCardProps): import("react/jsx-runtime").JSX.Element;