@blocklet/did-space-react 0.5.58 → 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.
- package/.turbo/turbo-build.log +36 -17
- package/.turbo/turbo-lint$colon$fix.log +2 -2
- package/README.md +85 -39
- package/es/components/auth-connect-to/base-auth.d.ts +5 -0
- package/es/components/auth-connect-to/base-auth.js +60 -0
- package/es/components/auth-connect-to/gateway-auth.d.ts +5 -0
- package/es/components/auth-connect-to/gateway-auth.js +49 -0
- package/es/components/auth-connect-to/index.d.ts +18 -0
- package/es/components/auth-connect-to/index.js +61 -0
- package/es/components/base-connect-to/index.d.ts +10 -0
- package/es/components/{ConnectTo → base-connect-to}/index.js +32 -26
- package/{lib/components/PreviewNFT → es/components/preview-space-nft}/index.d.ts +1 -2
- package/es/components/{PreviewNFT → preview-space-nft}/index.js +7 -2
- package/es/components/session-connect-to/index.d.ts +16 -0
- package/es/components/session-connect-to/index.js +26 -0
- package/es/components/session-connect-to/re-connect.d.ts +13 -0
- package/es/components/session-connect-to/re-connect.js +51 -0
- package/es/components/{SpaceCard → space-card}/index.d.ts +1 -2
- package/es/components/{SpaceCard → space-card}/index.js +82 -33
- package/es/hooks/use-space-info.js +1 -1
- package/es/icons/index.d.ts +5 -4
- package/es/icons/index.js +11 -0
- package/es/index.d.ts +8 -5
- package/es/index.js +15 -4
- package/es/libs/constants.d.ts +4 -0
- package/es/libs/constants.js +6 -0
- package/es/libs/util.d.ts +1 -0
- package/es/libs/util.js +15 -1
- package/es/locales/en.js +27 -9
- package/es/locales/zh.js +27 -9
- package/es/types/index.d.ts +22 -7
- package/es/types/index.js +3 -1
- package/lib/components/auth-connect-to/base-auth.d.ts +5 -0
- package/lib/components/auth-connect-to/base-auth.js +62 -0
- package/lib/components/auth-connect-to/gateway-auth.d.ts +5 -0
- package/lib/components/auth-connect-to/gateway-auth.js +51 -0
- package/lib/components/auth-connect-to/index.d.ts +18 -0
- package/lib/components/auth-connect-to/index.js +65 -0
- package/lib/components/base-connect-to/index.d.ts +10 -0
- package/lib/components/{ConnectTo → base-connect-to}/index.js +31 -25
- package/{es/components/PreviewNFT → lib/components/preview-space-nft}/index.d.ts +1 -2
- package/lib/components/{PreviewNFT → preview-space-nft}/index.js +7 -2
- package/lib/components/session-connect-to/index.d.ts +16 -0
- package/lib/components/session-connect-to/index.js +29 -0
- package/lib/components/session-connect-to/re-connect.d.ts +13 -0
- package/lib/components/session-connect-to/re-connect.js +53 -0
- package/lib/components/{SpaceCard → space-card}/index.d.ts +1 -2
- package/lib/components/{SpaceCard → space-card}/index.js +82 -33
- package/lib/hooks/use-space-info.js +1 -1
- package/lib/icons/index.d.ts +5 -4
- package/lib/icons/index.js +16 -0
- package/lib/index.d.ts +8 -5
- package/lib/index.js +33 -10
- package/lib/libs/constants.d.ts +4 -0
- package/lib/libs/constants.js +9 -0
- package/lib/libs/util.d.ts +1 -0
- package/lib/libs/util.js +15 -0
- package/lib/locales/en.js +27 -9
- package/lib/locales/zh.js +27 -9
- package/lib/types/index.d.ts +22 -7
- package/lib/types/index.js +3 -1
- package/package.json +25 -14
- package/src/components/auth-connect-to/base-auth.tsx +64 -0
- package/src/components/auth-connect-to/gateway-auth.tsx +53 -0
- package/src/components/auth-connect-to/index.tsx +71 -0
- package/src/components/{ConnectTo/connect-to.stories.tsx → base-connect-to/base-connect-to.stories.tsx} +1 -1
- package/src/components/{ConnectTo → base-connect-to}/index.tsx +35 -22
- package/src/components/{PreviewNFT → preview-space-nft}/index.tsx +12 -6
- package/src/components/session-connect-to/index.tsx +39 -0
- package/src/components/session-connect-to/re-connect.tsx +57 -0
- package/src/components/{SpaceCard → space-card}/index.tsx +88 -30
- package/src/hooks/use-space-info.ts +1 -1
- package/src/icons/index.tsx +12 -4
- package/src/index.ts +11 -6
- package/src/libs/constants.ts +4 -0
- package/src/libs/util.ts +17 -0
- package/src/locales/en.tsx +26 -7
- package/src/locales/zh.tsx +25 -7
- package/src/types/index.ts +23 -6
- package/src/types/shims.d.ts +4 -4
- package/es/components/ConnectTo/index.d.ts +0 -10
- package/es/libs/theme.d.ts +0 -1
- package/lib/components/ConnectTo/index.d.ts +0 -10
- package/lib/libs/theme.d.ts +0 -1
- package/src/libs/theme.ts +0 -18
- /package/es/components/{ConnectTo/connect-to.stories.d.ts → base-connect-to/base-connect-to.stories.d.ts} +0 -0
- /package/es/components/{SpaceCard → space-card}/space-card.stories.d.ts +0 -0
- /package/lib/components/{ConnectTo/connect-to.stories.d.ts → base-connect-to/base-connect-to.stories.d.ts} +0 -0
- /package/lib/components/{SpaceCard → space-card}/space-card.stories.d.ts +0 -0
- /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.
|
|
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/
|
|
46
|
-
"import": "./es/
|
|
47
|
-
"require": "./lib/
|
|
45
|
+
"./lib/libs/*": {
|
|
46
|
+
"import": "./es/libs/*.js",
|
|
47
|
+
"require": "./lib/libs/*.js"
|
|
48
48
|
},
|
|
49
|
-
"./lib/components/
|
|
50
|
-
"import": "./es/components/
|
|
51
|
-
"require": "./lib/components/
|
|
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/
|
|
54
|
-
"import": "./es/components/
|
|
55
|
-
"require": "./lib/components/
|
|
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,15 +80,15 @@
|
|
|
68
80
|
}
|
|
69
81
|
},
|
|
70
82
|
"dependencies": {
|
|
71
|
-
"@abtnode/util": "1.16.32",
|
|
72
83
|
"@arcblock/did": "^1.18.136",
|
|
84
|
+
"@arcblock/did-connect": "^2.10.48",
|
|
73
85
|
"@arcblock/ux": "^2.10.53",
|
|
74
86
|
"@blocklet/js-sdk": "1.16.32",
|
|
87
|
+
"@blocklet/sdk": "1.16.32",
|
|
75
88
|
"@mui/icons-material": "^5.16.7",
|
|
76
89
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
77
90
|
"@mui/material": "^5.16.7",
|
|
78
91
|
"@mui/system": "^5.16.7",
|
|
79
|
-
"@ocap/util": "^1.18.136",
|
|
80
92
|
"ahooks": "^3.8.1",
|
|
81
93
|
"axios": "^1.7.7",
|
|
82
94
|
"flat": "^5.0.2",
|
|
@@ -93,7 +105,6 @@
|
|
|
93
105
|
"access": "public"
|
|
94
106
|
},
|
|
95
107
|
"devDependencies": {
|
|
96
|
-
"@abtnode/client": "^1.16.32",
|
|
97
108
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
98
109
|
"@babel/cli": "^7.25.9",
|
|
99
110
|
"@babel/core": "^7.26.0",
|
|
@@ -130,5 +141,5 @@
|
|
|
130
141
|
"vite-plugin-node-polyfills": "^0.22.0",
|
|
131
142
|
"vitest": "^2.1.4"
|
|
132
143
|
},
|
|
133
|
-
"gitHead": "
|
|
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,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
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
{
|
|
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
|
|
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 {
|
|
4
|
+
import { EmptySpacesNFTIcon } from '../../icons';
|
|
5
5
|
|
|
6
|
-
function PreviewSpaceNft({
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
+
}
|