@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/did-space-react",
3
- "version": "0.5.57",
3
+ "version": "0.5.59",
4
4
  "description": "Reusable react components for did space",
5
5
  "keywords": [
6
6
  "react",
@@ -42,17 +42,29 @@
42
42
  "import": "./es/hooks/*.js",
43
43
  "require": "./lib/hooks/*.js"
44
44
  },
45
- "./lib/components/ConnectTo": {
46
- "import": "./es/components/ConnectTo/index.js",
47
- "require": "./lib/components/ConnectTo/index.js"
45
+ "./lib/libs/*": {
46
+ "import": "./es/libs/*.js",
47
+ "require": "./lib/libs/*.js"
48
48
  },
49
- "./lib/components/PreviewNFT": {
50
- "import": "./es/components/PreviewNFT/index.js",
51
- "require": "./lib/components/PreviewNFT/index.js"
49
+ "./lib/components/auth-connect-to": {
50
+ "import": "./es/components/auth-connect-to/index.js",
51
+ "require": "./lib/components/auth-connect-to/index.js"
52
52
  },
53
- "./lib/components/SpaceCard": {
54
- "import": "./es/components/SpaceCard/index.js",
55
- "require": "./lib/components/SpaceCard/index.js"
53
+ "./lib/components/base-connect-to": {
54
+ "import": "./es/components/base-connect-to/index.js",
55
+ "require": "./lib/components/base-connect-to/index.js"
56
+ },
57
+ "./lib/components/preview-space-nft": {
58
+ "import": "./es/components/preview-space-nft/index.js",
59
+ "require": "./lib/components/preview-space-nft/index.js"
60
+ },
61
+ "./lib/components/session-connect-to": {
62
+ "import": "./es/components/session-connect-to/index.js",
63
+ "require": "./lib/components/session-connect-to/index.js"
64
+ },
65
+ "./lib/components/space-card": {
66
+ "import": "./es/components/space-card/index.js",
67
+ "require": "./lib/components/space-card/index.js"
56
68
  },
57
69
  "./lib/icons": {
58
70
  "import": "./es/icons/index.js",
@@ -68,22 +80,22 @@
68
80
  }
69
81
  },
70
82
  "dependencies": {
71
- "@abtnode/util": "1.16.32",
72
- "@arcblock/did": "^1.18.135",
73
- "@arcblock/ux": "^2.10.33",
83
+ "@arcblock/did": "^1.18.136",
84
+ "@arcblock/did-connect": "^2.10.48",
85
+ "@arcblock/ux": "^2.10.53",
74
86
  "@blocklet/js-sdk": "1.16.32",
75
- "@mui/icons-material": "^5.16.6",
87
+ "@blocklet/sdk": "1.16.32",
88
+ "@mui/icons-material": "^5.16.7",
76
89
  "@mui/lab": "^5.0.0-alpha.173",
77
- "@mui/material": "^5.16.6",
78
- "@mui/system": "^5.16.6",
79
- "@ocap/util": "^1.18.135",
80
- "ahooks": "^3.8.0",
81
- "axios": "^1.7.5",
90
+ "@mui/material": "^5.16.7",
91
+ "@mui/system": "^5.16.7",
92
+ "ahooks": "^3.8.1",
93
+ "axios": "^1.7.7",
82
94
  "flat": "^5.0.2",
83
95
  "is-url": "^1.2.4",
84
96
  "lodash": "^4.17.21",
85
97
  "p-wait-for": "3",
86
- "react-error-boundary": "^4.0.13",
98
+ "react-error-boundary": "^4.1.2",
87
99
  "ufo": "^1.5.4"
88
100
  },
89
101
  "peerDependencies": {
@@ -93,13 +105,12 @@
93
105
  "access": "public"
94
106
  },
95
107
  "devDependencies": {
96
- "@abtnode/client": "^1.16.32",
97
- "@arcblock/eslint-config-ts": "^0.3.2",
98
- "@babel/cli": "^7.24.8",
99
- "@babel/core": "^7.25.2",
100
- "@babel/preset-env": "^7.25.8",
101
- "@babel/preset-react": "^7.25.7",
102
- "@babel/preset-typescript": "^7.25.7",
108
+ "@arcblock/eslint-config-ts": "^0.3.3",
109
+ "@babel/cli": "^7.25.9",
110
+ "@babel/core": "^7.26.0",
111
+ "@babel/preset-env": "^7.26.0",
112
+ "@babel/preset-react": "^7.25.9",
113
+ "@babel/preset-typescript": "^7.26.0",
103
114
  "@storybook/addon-essentials": "^7.6.20",
104
115
  "@storybook/addon-interactions": "^7.6.20",
105
116
  "@storybook/addon-links": "^7.6.20",
@@ -109,26 +120,26 @@
109
120
  "@storybook/react-vite": "^7.6.20",
110
121
  "@storybook/test": "^7.6.20",
111
122
  "@svgr/rollup": "^8.1.0",
112
- "@types/react": "^18.3.3",
113
- "@types/react-dom": "^18.3.0",
114
- "@vitejs/plugin-legacy": "^5.4.1",
115
- "@vitest/coverage-v8": "^2.1.2",
123
+ "@types/react": "^18.3.12",
124
+ "@types/react-dom": "^18.3.1",
125
+ "@vitejs/plugin-legacy": "^5.4.3",
126
+ "@vitest/coverage-v8": "^2.1.4",
116
127
  "babel-plugin-inline-react-svg": "^2.0.2",
117
128
  "copyfiles": "^2.4.1",
118
- "eslint": "^8.57.0",
129
+ "eslint": "^8.57.1",
119
130
  "glob": "^10.4.5",
120
131
  "prettier": "^2.8.8",
121
132
  "react": "^18.3.1",
122
133
  "react-dom": "^18.3.1",
123
134
  "rollup-plugin-node-builtins": "^2.1.2",
124
135
  "storybook": "^7.6.20",
125
- "type-fest": "^4.23.0",
136
+ "type-fest": "^4.26.1",
126
137
  "typescript": "~5.5.4",
127
138
  "unbuild": "^2.0.0",
128
- "vite": "^5.4.8",
139
+ "vite": "^5.4.10",
129
140
  "vite-plugin-babel": "^1.2.0",
130
141
  "vite-plugin-node-polyfills": "^0.22.0",
131
- "vitest": "^2.1.2"
142
+ "vitest": "^2.1.4"
132
143
  },
133
- "gitHead": "4ead6cc11feaff06936aba21cf3919e01cd12e97"
144
+ "gitHead": "b78b535df2c165c673fbd8d62db6509abc8ea5d8"
134
145
  }
@@ -0,0 +1,64 @@
1
+ import { Typography } from '@mui/material';
2
+ import DidConnect from '@arcblock/did-connect/lib/Connect';
3
+ import { RELAY_SOCKET_PREFIX } from '@arcblock/ux/lib/Util/constant';
4
+ import { joinURL } from 'ufo';
5
+ import { createAxios } from '@blocklet/js-sdk';
6
+ import useLocale from '../../hooks/use-locale';
7
+ import { AUTHORIZE } from '../../libs/constants';
8
+ import type { BaseAuthOptions } from '../../types';
9
+
10
+ export interface BaseAuthProps extends BaseAuthOptions, Record<string, any> {
11
+ open: boolean;
12
+ }
13
+
14
+ export function BaseAuth({ open, extraParams, onSuccess, onClose, ...rest }: BaseAuthProps) {
15
+ const { t, locale } = useLocale();
16
+
17
+ const finalExtraParams = {
18
+ appPid: window.blocklet?.appPid,
19
+ appDid: window.blocklet?.appId,
20
+ appName: window.blocklet?.appName,
21
+ appDescription: window.blocklet?.appDescription,
22
+ appUrl: window.blocklet?.appUrl,
23
+ referrer: window.location.href,
24
+ scopes: AUTHORIZE.DEFAULT_SCOPE,
25
+ ...extraParams,
26
+ };
27
+
28
+ const {
29
+ action = 'connect-to-did-spaces',
30
+ prefix = '/api/did',
31
+ baseUrl = joinURL(window.location.origin, RELAY_SOCKET_PREFIX),
32
+ checkFn = createAxios({ baseURL: joinURL(window.location.origin, RELAY_SOCKET_PREFIX) }).get,
33
+ webWalletUrl = window.blocklet?.webWalletUrl,
34
+ checkTimeout = 1e3 * 300,
35
+ messages = {
36
+ title: t('storage.spaces.provideNFT.title', { appName: finalExtraParams.appName }),
37
+ scan: t('storage.spaces.provideNFT.scan', { appName: finalExtraParams.appName }),
38
+ confirm: '',
39
+ success: <Typography gutterBottom>{t('storage.spaces.provideNFT.success')}</Typography>,
40
+ },
41
+ ...restOptions
42
+ } = rest;
43
+
44
+ return (
45
+ <DidConnect
46
+ {...restOptions}
47
+ open={open}
48
+ action={action}
49
+ prefix={prefix}
50
+ baseUrl={baseUrl}
51
+ checkFn={checkFn}
52
+ webWalletUrl={webWalletUrl}
53
+ messages={messages}
54
+ checkTimeout={checkTimeout}
55
+ extraParams={finalExtraParams}
56
+ forceConnected={false}
57
+ saveConnect={false}
58
+ popup
59
+ locale={locale}
60
+ onSuccess={onSuccess}
61
+ onClose={onClose}
62
+ />
63
+ );
64
+ }
@@ -0,0 +1,53 @@
1
+ import { joinURL } from 'ufo';
2
+ import { createAxios } from '@blocklet/js-sdk';
3
+ import { Typography } from '@mui/material';
4
+ import useLocale from '../../hooks/use-locale';
5
+ import type { GatewayAuthOptions } from '../../types';
6
+ import { BaseAuth } from './base-auth';
7
+
8
+ export interface GatewayAuthProps extends GatewayAuthOptions {
9
+ open: boolean;
10
+ }
11
+
12
+ export function GatewayAuth({
13
+ open,
14
+ spaceDid,
15
+ spaceGatewayUrl,
16
+ extraParams = {},
17
+ onSuccess,
18
+ onClose,
19
+ }: GatewayAuthProps) {
20
+ const { t } = useLocale();
21
+
22
+ if (!spaceGatewayUrl || !spaceDid) {
23
+ return null;
24
+ }
25
+
26
+ const { appName = window.blocklet?.appName } = extraParams;
27
+ const prefix = joinURL(spaceGatewayUrl, 'space/api/did');
28
+ const baseUrl = new URL(spaceGatewayUrl).origin;
29
+ const checkFn = createAxios({ baseURL: joinURL(spaceGatewayUrl, 'space') }).get;
30
+ const messages = {
31
+ title: t('storage.spaces.authorize.title', { appName }),
32
+ scan: t('storage.spaces.authorize.scan', { appName }),
33
+ confirm: '',
34
+ success: <Typography gutterBottom>{t('storage.spaces.authorize.success')}</Typography>,
35
+ };
36
+
37
+ return (
38
+ <BaseAuth
39
+ open={open}
40
+ action="one-click-authorization"
41
+ prefix={prefix}
42
+ baseUrl={baseUrl}
43
+ checkFn={checkFn}
44
+ messages={messages}
45
+ extraParams={{
46
+ ...extraParams,
47
+ spaceDid,
48
+ }}
49
+ onSuccess={onSuccess}
50
+ onClose={onClose}
51
+ />
52
+ );
53
+ }
@@ -0,0 +1,71 @@
1
+ import { useState } from 'react';
2
+ import { BaseConnectTo, type BaseConnectToProps } from '../base-connect-to';
3
+ import { GatewayAuth, type GatewayAuthProps } from './gateway-auth';
4
+ import { BaseAuth, type BaseAuthProps } from './base-auth';
5
+ import { BaseAuthOptions } from '../../types';
6
+
7
+ export interface Options extends BaseAuthOptions, Record<string, any> {}
8
+
9
+ export interface AuthConnectToProps extends BaseConnectToProps {
10
+ options?: Options;
11
+ onSuccess?: (response: Record<string, string>, decrypt: Function) => Promise<void>;
12
+ }
13
+
14
+ /** Space 连接组件, 内置 Auth 验证流程 */
15
+ export function AuthConnectTo({ options, onSuccess, ...rest }: AuthConnectToProps) {
16
+ const [walletOptions, setWalletOptions] = useState({
17
+ open: false,
18
+ });
19
+ const [gatewayOptions, setGatewayOptions] = useState({
20
+ open: false,
21
+ spaceDid: '',
22
+ spaceGatewayUrl: '',
23
+ });
24
+
25
+ const onWalletClick = () => setWalletOptions((pre) => ({ ...pre, open: true }));
26
+
27
+ const onGatewayConfirm = ({ spaceDid, spaceGatewayUrl }: { spaceDid: string; spaceGatewayUrl: string }) => {
28
+ setGatewayOptions((pre) => ({
29
+ ...pre,
30
+ open: true,
31
+ spaceDid,
32
+ spaceGatewayUrl,
33
+ }));
34
+ };
35
+
36
+ const handleSuccess = async (response: Record<string, string>, decrypt: Function) => {
37
+ await onSuccess?.(response, decrypt);
38
+ setWalletOptions((pre) => ({
39
+ ...pre,
40
+ open: false,
41
+ }));
42
+ setGatewayOptions((pre) => ({
43
+ ...pre,
44
+ open: false,
45
+ }));
46
+ };
47
+
48
+ return (
49
+ <>
50
+ <BaseConnectTo {...rest} onWalletClick={onWalletClick} onGatewayConfirm={onGatewayConfirm} />
51
+ <BaseAuth
52
+ {...options}
53
+ {...walletOptions}
54
+ onSuccess={handleSuccess}
55
+ onClose={() => setWalletOptions((pre) => ({ ...pre, open: false }))}
56
+ />
57
+ <GatewayAuth
58
+ {...options}
59
+ {...gatewayOptions}
60
+ onSuccess={handleSuccess}
61
+ onClose={() => setGatewayOptions((pre) => ({ ...pre, open: false }))}
62
+ />
63
+ </>
64
+ );
65
+ }
66
+
67
+ AuthConnectTo.WalletAuth = BaseAuth;
68
+ AuthConnectTo.GatewayAuth = GatewayAuth;
69
+
70
+ export { BaseAuth as WalletAuth, type BaseAuthProps as WalletAuthProps };
71
+ export { GatewayAuth, type GatewayAuthProps };
@@ -1,7 +1,7 @@
1
1
  import Basic from './stories/basic';
2
2
 
3
3
  export default {
4
- title: 'Connect/ConnectTo',
4
+ title: 'Connect/BaseConnectTo',
5
5
  parameters: {
6
6
  layout: 'padded',
7
7
  },
@@ -1,27 +1,31 @@
1
1
  import { useState } from 'react';
2
2
  import { isValid as isValidDid } from '@arcblock/did';
3
- import { CircularProgress, DialogContentText, TextField, Typography } from '@mui/material';
3
+ import { CircularProgress, DialogContentText, Link, TextField, Tooltip, Typography } from '@mui/material';
4
+ import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
4
5
  import Button from '@arcblock/ux/lib/Button';
5
6
  import SplitButton, { SplitButtonProps } from '@arcblock/ux/lib/SplitButton';
6
7
  import Dialog from '@arcblock/ux/lib/Dialog';
7
8
 
9
+ import { withQuery } from 'ufo';
10
+ import { copyGatewayPageUrl } from '../../libs/constants';
8
11
  import { extraDIDSpacesCoreUrl, getSpaceDidFromGatewayUrl } from '../../libs/util';
9
12
  import { getSpaceGatewayUrl, isValidSpaceGatewayUrl } from '../../libs/gateway';
10
13
  import useLocale from '../../hooks/use-locale';
11
14
 
12
- export interface ConnectToProps extends Omit<SplitButtonProps, 'menu' | 'onClick'> {
13
- onWalletConnect?: () => void;
14
- onGatewayConnect?: (params: { spaceDid: string; spaceGatewayUrl: string }) => void;
15
+ export interface BaseConnectToProps extends Omit<SplitButtonProps, 'menu' | 'onClick'> {
16
+ onWalletClick?: () => void;
17
+ onGatewayConfirm?: (params: { spaceDid: string; spaceGatewayUrl: string }) => void;
15
18
  }
16
19
 
17
- function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: ConnectToProps) {
18
- const { t } = useLocale();
20
+ /** 基础连接按钮组件,只负责前端 ux */
21
+ export function BaseConnectTo({ style, onWalletClick, onGatewayConfirm, ...rest }: BaseConnectToProps) {
22
+ const { t, locale } = useLocale();
19
23
  const [url, setUrl] = useState('');
20
24
  const [loading, setLoading] = useState(false);
21
25
  const [open, setOpen] = useState(false);
22
26
  const [errorMessage, setErrorMessage] = useState('');
23
27
 
24
- const handleUseSpaceGatewayConnect = async () => {
28
+ const onGatewayChange = async () => {
25
29
  try {
26
30
  setLoading(true);
27
31
 
@@ -33,7 +37,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: Connec
33
37
  throw new Error(t('storage.spaces.gateway.add.invalidUrl'));
34
38
  }
35
39
 
36
- onGatewayConnect?.({
40
+ onGatewayConfirm?.({
37
41
  spaceDid: spaceDid!,
38
42
  spaceGatewayUrl: didSpacesCoreUrl,
39
43
  });
@@ -46,7 +50,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: Connec
46
50
  }
47
51
  };
48
52
 
49
- const openGatewayInput = () => {
53
+ const onGatewayClick = () => {
50
54
  setErrorMessage('');
51
55
  setUrl('');
52
56
  setOpen(true);
@@ -62,19 +66,18 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: Connec
62
66
  textTransform: 'none',
63
67
  }}
64
68
  key="1"
65
- onClick={openGatewayInput}
66
69
  size="small"
67
- {...rest}
70
+ onClick={onGatewayClick}
68
71
  >
69
72
  {t('storage.spaces.connect.useSpaceGateway')}
70
73
  </SplitButton.Item>,
71
74
  ]}
72
- onClick={onWalletConnect}
73
75
  color="primary"
74
76
  // @ts-expect-error
75
77
  style={{ textTransform: 'none !important', fontSize: '1rem', ...style }}
76
78
  size="small"
77
79
  {...rest}
80
+ onClick={onWalletClick}
78
81
  >
79
82
  <Typography sx={{ fontWeight: 'bold', textTransform: 'none' }}>
80
83
  {t('storage.spaces.connect.useWallet')}
@@ -99,13 +102,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: Connec
99
102
  >
100
103
  {t('common.cancel')}
101
104
  </Button>
102
- <Button
103
- onClick={handleUseSpaceGatewayConnect}
104
- color="primary"
105
- disabled={loading || !url}
106
- variant="contained"
107
- autoFocus
108
- >
105
+ <Button onClick={onGatewayChange} color="primary" disabled={loading || !url} variant="contained" autoFocus>
109
106
  {loading && <CircularProgress size={16} />}
110
107
  {t('common.confirm')}
111
108
  </Button>
@@ -131,10 +128,28 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: Connec
131
128
  helperText={errorMessage}
132
129
  onKeyDown={async (e) => {
133
130
  if (e.key === 'Enter') {
134
- await handleUseSpaceGatewayConnect();
131
+ await onGatewayChange();
135
132
  }
136
133
  }}
137
134
  autoFocus
135
+ InputProps={{
136
+ endAdornment: (
137
+ <Tooltip title={t('storage.spaces.connect.howToGetGatewayUrl')} placement="top">
138
+ {/* 打开如何复制网关地址 */}
139
+ <Link href={withQuery(copyGatewayPageUrl, { locale })} target="_blank">
140
+ <HelpOutlineIcon
141
+ sx={{
142
+ ml: 0.5,
143
+ color: 'text.secondary',
144
+ cursor: 'pointer',
145
+ fontSize: '18px',
146
+ verticalAlign: '-2px',
147
+ }}
148
+ />
149
+ </Link>
150
+ </Tooltip>
151
+ ),
152
+ }}
138
153
  />
139
154
  </Typography>
140
155
  </DialogContentText>
@@ -143,5 +158,3 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }: Connec
143
158
  </>
144
159
  );
145
160
  }
146
-
147
- export default ConnectTo;
@@ -1,9 +1,17 @@
1
1
  import { useState } from 'react';
2
2
  import { Dialog, DialogContent, IconButton } from '@mui/material';
3
3
  import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined';
4
- import { EmptySpacesNFT } from '../../icons';
4
+ import { EmptySpacesNFTIcon } from '../../icons';
5
5
 
6
- function PreviewSpaceNft({ src, width = '58px', height = '58px' }: { src: string; width?: string; height?: string }) {
6
+ export function PreviewSpaceNft({
7
+ src,
8
+ width = '58px',
9
+ height = '58px',
10
+ }: {
11
+ src: string;
12
+ width?: string;
13
+ height?: string;
14
+ }) {
7
15
  const [open, setOpen] = useState(false);
8
16
 
9
17
  const handleOpen = () => setOpen(true);
@@ -13,7 +21,7 @@ function PreviewSpaceNft({ src, width = '58px', height = '58px' }: { src: string
13
21
  <>
14
22
  <div style={{ position: 'relative' }} onClick={handleOpen}>
15
23
  <object data={src} width={width} height={height}>
16
- <EmptySpacesNFT viewBox="0 0 228 258" style={{ cursor: 'pointer', width: '64px', height: '64px' }} />
24
+ <EmptySpacesNFTIcon viewBox="0 0 228 258" style={{ cursor: 'pointer', width: '64px', height: '64px' }} />
17
25
  </object>
18
26
  <div
19
27
  style={{
@@ -54,7 +62,7 @@ function PreviewSpaceNft({ src, width = '58px', height = '58px' }: { src: string
54
62
  objectFit: 'contain',
55
63
  }}
56
64
  >
57
- <EmptySpacesNFT
65
+ <EmptySpacesNFTIcon
58
66
  viewBox="0 0 228 258"
59
67
  style={{
60
68
  width: '100%',
@@ -68,5 +76,3 @@ function PreviewSpaceNft({ src, width = '58px', height = '58px' }: { src: string
68
76
  </>
69
77
  );
70
78
  }
71
-
72
- export default PreviewSpaceNft;
@@ -0,0 +1,39 @@
1
+ import { BlockletSDK } from '@blocklet/js-sdk';
2
+ import { decryptSpaceGateway } from '../../libs/util';
3
+ import { SpaceGateway } from '../../types';
4
+ import { AuthConnectTo, type Options } from '../auth-connect-to';
5
+ import { BaseConnectToProps } from '../base-connect-to';
6
+ import { ReConnect, type ReConnectProps } from './re-connect';
7
+
8
+ export interface SessionConnectToProps extends Omit<BaseConnectToProps, 'onError'> {
9
+ session: {
10
+ refresh: Function;
11
+ };
12
+ onConnected?: (spaceGateway: SpaceGateway) => Promise<void>;
13
+ onError?: (error: Error) => void;
14
+ }
15
+
16
+ /** 会话连接组件,会将 spaceGateway 信息存储于 users 表 */
17
+ export function SessionConnectTo({ session, onConnected, onError, ...rest }: SessionConnectToProps) {
18
+ const options: Partial<Options> = {
19
+ action: 'connect-to-did-spaces-for-user',
20
+ };
21
+
22
+ const onSuccess = async (response: Record<string, string>, decrypt: Function) => {
23
+ try {
24
+ const spaceGateway = decryptSpaceGateway(response, decrypt);
25
+ await new BlockletSDK().user.updateDidSpace({ spaceGateway });
26
+ session.refresh();
27
+ await onConnected?.(spaceGateway);
28
+ } catch (err) {
29
+ console.error(err);
30
+ onError?.(err as Error);
31
+ }
32
+ };
33
+
34
+ return <AuthConnectTo {...rest} options={options} onSuccess={onSuccess} />;
35
+ }
36
+
37
+ SessionConnectTo.ReConnect = ReConnect;
38
+
39
+ export { ReConnect, type ReConnectProps };
@@ -0,0 +1,57 @@
1
+ import { Button, ButtonProps } from '@mui/material';
2
+ import { useState } from 'react';
3
+ import { BlockletSDK } from '@blocklet/js-sdk';
4
+ import useLocale from '../../hooks/use-locale';
5
+ import { decryptSpaceGateway } from '../../libs/util';
6
+ import { GatewayAuth } from '../auth-connect-to/gateway-auth';
7
+ import { SpaceGateway } from '../../types';
8
+
9
+ export interface ReConnectProps extends Omit<ButtonProps, 'onClick' | 'onError'> {
10
+ session: {
11
+ refresh: Function;
12
+ };
13
+ spaceDid: string;
14
+ spaceGatewayUrl: string;
15
+ onConnected?: (spaceGateway: SpaceGateway) => Promise<void>;
16
+ onError?: (error: Error) => void;
17
+ }
18
+
19
+ /** 用于 DApp 重新连接 Space */
20
+ export function ReConnect({ session, spaceDid, spaceGatewayUrl, onConnected, onError, ...rest }: ReConnectProps) {
21
+ const { t } = useLocale();
22
+ const [authOptions, setAuthOptions] = useState({
23
+ open: false,
24
+ spaceDid,
25
+ spaceGatewayUrl,
26
+ });
27
+
28
+ const onSuccess = async (response: Record<string, string>, decrypt: Function) => {
29
+ try {
30
+ const spaceGateway = decryptSpaceGateway(response, decrypt);
31
+ await new BlockletSDK().user.updateDidSpace({ spaceGateway });
32
+ session.refresh();
33
+ await onConnected?.(spaceGateway);
34
+ } catch (err) {
35
+ console.error(err);
36
+ onError?.(err as Error);
37
+ } finally {
38
+ setAuthOptions((pre) => ({ ...pre, open: false }));
39
+ }
40
+ };
41
+
42
+ return (
43
+ <Button
44
+ {...rest}
45
+ onClick={() => {
46
+ setAuthOptions((pre) => ({ ...pre, open: true }));
47
+ }}
48
+ >
49
+ {t('storage.spaces.connect.reconnect')}
50
+ <GatewayAuth
51
+ {...authOptions}
52
+ onSuccess={onSuccess}
53
+ onClose={() => setAuthOptions((pre) => ({ ...pre, open: false }))}
54
+ />
55
+ </Button>
56
+ );
57
+ }