@blocklet/did-space-react 0.5.58 → 0.5.60
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 +27 -16
- 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/.turbo/turbo-build.log
CHANGED
|
@@ -1,49 +1,68 @@
|
|
|
1
1
|
|
|
2
|
-
> @blocklet/did-space-react@0.5.
|
|
2
|
+
> @blocklet/did-space-react@0.5.59 build /home/runner/work/did-spaces/did-spaces/packages/react
|
|
3
3
|
> unbuild && node tools/auto-exports.js && npm run cpfiles && node tools/build-types.js
|
|
4
4
|
|
|
5
5
|
[info] Building did-space-react
|
|
6
6
|
[info] Cleaning dist directory: `./lib`
|
|
7
7
|
[success] Build succeeded for did-space-react
|
|
8
|
-
[log] dist/index.js (total size:
|
|
8
|
+
[log] dist/index.js (total size: 2.72 kB, chunk size: 2.72 kB, exports: AuthConnectTo, BaseConnectTo, EmptySpacesNFTIcon, GatewayAuth, PreviewSpaceNft, ReConnect, SessionConnectTo, SpaceCard, SpaceConnectErrorIcon, SpaceDisconnectedIcon, SpaceStatus, SpacesConnectedIcon, WalletAuth, api, classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getDIDSpaceDidFromEndpoint, getDIDSpaceUrlFromEndpoint, getSpaceDidFromEndpoint, getSpaceDidFromGatewayUrl, getSpaceGatewayUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, isValidSpaceGatewayUrl, translations, useLocale, useMobile, useSpaceInfo)
|
|
9
9
|
└─ dist/libs/api.js
|
|
10
10
|
└─ dist/hooks/use-mobile.js
|
|
11
11
|
└─ dist/hooks/use-space-info.js
|
|
12
12
|
└─ dist/hooks/use-locale.js
|
|
13
|
-
└─ dist/components/
|
|
14
|
-
└─ dist/components/
|
|
15
|
-
└─ dist/components/
|
|
13
|
+
└─ dist/components/space-card/index.js
|
|
14
|
+
└─ dist/components/preview-space-nft/index.js
|
|
15
|
+
└─ dist/components/base-connect-to/index.js
|
|
16
|
+
└─ dist/components/auth-connect-to/index.js
|
|
17
|
+
└─ dist/components/session-connect-to/index.js
|
|
16
18
|
└─ dist/libs/util.js
|
|
19
|
+
└─ dist/libs/gateway.js
|
|
17
20
|
└─ dist/locales/index.js
|
|
18
21
|
└─ dist/types/index.js
|
|
22
|
+
└─ dist/icons/index.js
|
|
23
|
+
└─ dist/icons/empty-space-nft.svg.js
|
|
24
|
+
└─ dist/icons/space-connected.svg.js
|
|
25
|
+
└─ dist/icons/space-disconnect.svg.js
|
|
26
|
+
└─ dist/icons/space-connect-error.svg.js
|
|
27
|
+
└─ dist/components/auth-connect-to/base-auth.js
|
|
28
|
+
└─ dist/components/auth-connect-to/gateway-auth.js
|
|
29
|
+
└─ dist/components/session-connect-to/re-connect.js
|
|
19
30
|
|
|
20
|
-
Σ Total dist size (byte size):
|
|
31
|
+
Σ Total dist size (byte size): 2.72 kB
|
|
21
32
|
[log]
|
|
22
33
|
[warn] Build is done with some warnings:
|
|
34
|
+
|
|
35
|
+
- Potential missing package.json files: es/index.js, es/hooks, es/libs, es/components/auth-connect-to/index.js, es/components/base-connect-to/index.js, es/components/preview-space-nft/index.js, es/components/session-connect-to/index.js, es/components/space-card/index.js, es/icons/index.js, es/locales/index.js, es/types/index.js
|
|
23
36
|
[info] Building did-space-react
|
|
24
37
|
[info] Cleaning dist directory: `./es`
|
|
25
|
-
|
|
26
|
-
- Potential missing package.json files: es/index.js, es/hooks, es/components/ConnectTo/index.js, es/components/PreviewNFT/index.js, es/components/SpaceCard/index.js, es/icons/index.js, lib/icons/index.js, es/locales/index.js, es/types/index.js
|
|
27
38
|
[success] Build succeeded for did-space-react
|
|
28
|
-
[log] dist/index.js (total size:
|
|
39
|
+
[log] dist/index.js (total size: 1.63 kB, chunk size: 1.63 kB, exports: AuthConnectTo, BaseConnectTo, EmptySpacesNFTIcon, GatewayAuth, PreviewSpaceNft, ReConnect, SessionConnectTo, SpaceCard, SpaceConnectErrorIcon, SpaceDisconnectedIcon, SpaceStatus, SpacesConnectedIcon, WalletAuth, api, classNames, decryptSpaceGateway, extraDIDSpacesCoreUrl, getDIDSpaceDidFromEndpoint, getDIDSpaceUrlFromEndpoint, getSpaceDidFromEndpoint, getSpaceDidFromGatewayUrl, getSpaceGatewayUrl, getSpaceGatewayUrlFromEndpoint, getSpaceNftDisplayUrlFromEndpoint, isValidSpaceGatewayUrl, translations, useLocale, useMobile, useSpaceInfo)
|
|
29
40
|
└─ dist/libs/api.js
|
|
30
41
|
└─ dist/hooks/use-mobile.js
|
|
31
42
|
└─ dist/hooks/use-space-info.js
|
|
32
43
|
└─ dist/hooks/use-locale.js
|
|
33
|
-
└─ dist/components/
|
|
34
|
-
└─ dist/components/
|
|
35
|
-
└─ dist/components/
|
|
44
|
+
└─ dist/components/space-card/index.js
|
|
45
|
+
└─ dist/components/preview-space-nft/index.js
|
|
46
|
+
└─ dist/components/base-connect-to/index.js
|
|
47
|
+
└─ dist/components/auth-connect-to/index.js
|
|
48
|
+
└─ dist/components/session-connect-to/index.js
|
|
36
49
|
└─ dist/libs/util.js
|
|
50
|
+
└─ dist/libs/gateway.js
|
|
37
51
|
└─ dist/locales/index.js
|
|
38
52
|
└─ dist/types/index.js
|
|
53
|
+
└─ dist/icons/index.js
|
|
54
|
+
└─ dist/icons/empty-space-nft.svg.js
|
|
55
|
+
└─ dist/icons/space-connected.svg.js
|
|
56
|
+
└─ dist/icons/space-disconnect.svg.js
|
|
57
|
+
└─ dist/icons/space-connect-error.svg.js
|
|
58
|
+
└─ dist/components/auth-connect-to/base-auth.js
|
|
59
|
+
└─ dist/components/auth-connect-to/gateway-auth.js
|
|
60
|
+
└─ dist/components/session-connect-to/re-connect.js
|
|
39
61
|
|
|
40
|
-
Σ Total dist size (byte size):
|
|
62
|
+
Σ Total dist size (byte size): 1.63 kB
|
|
41
63
|
[log]
|
|
42
|
-
[warn] Build is done with some warnings:
|
|
43
|
-
|
|
44
|
-
- Potential missing package.json files: es/icons/index.js, lib/icons/index.js
|
|
45
64
|
|
|
46
|
-
> @blocklet/did-space-react@0.5.
|
|
65
|
+
> @blocklet/did-space-react@0.5.59 cpfiles
|
|
47
66
|
> copyfiles -u 1 './src/**/*.css' lib/ && copyfiles -u 1 './src/**/*.css' es/
|
|
48
67
|
|
|
49
68
|
tsc --declaration --emitDeclarationOnly --outDir lib --rootDir /home/runner/work/did-spaces/did-spaces/packages/react/src
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
> @blocklet/did-space-react@0.5.
|
|
2
|
+
> @blocklet/did-space-react@0.5.60 lint:fix /home/runner/work/did-spaces/did-spaces/packages/react
|
|
3
3
|
> npm run lint -- --fix
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @blocklet/did-space-react@0.5.
|
|
6
|
+
> @blocklet/did-space-react@0.5.60 lint
|
|
7
7
|
> tsc --noEmit && eslint src tests --ext js --ext jsx --ext ts --ext tsx --fix
|
|
8
8
|
|
package/README.md
CHANGED
|
@@ -3,50 +3,96 @@
|
|
|
3
3
|
## SpaceCard
|
|
4
4
|
|
|
5
5
|
```tsx
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
6
|
+
import { SpaceCard } from '@blocklet/did-space-react';
|
|
7
|
+
|
|
8
|
+
function Demo() {
|
|
9
|
+
const endpoint = 'https://${spaceDomain}/app/api/space/${spaceDid}/app/${appDid}/object/';
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<>
|
|
13
|
+
{/* Basic use*/}
|
|
14
|
+
<SpaceCard endpoint={endpoint} selected />
|
|
15
|
+
{/* Compat layout */}
|
|
16
|
+
<SpaceCard endpoint={endpoint} selected compat />
|
|
17
|
+
{/* With Action */}
|
|
18
|
+
<SpaceCard
|
|
19
|
+
endpoint={endpoint}
|
|
20
|
+
selected
|
|
21
|
+
action={
|
|
22
|
+
<IconButton size="small" LinkComponent={Link} href={getSpaceHomeUrl(spaceGateway.endpoint)} target="_blank">
|
|
23
|
+
<OpenInNewIcon />
|
|
24
|
+
</IconButton>
|
|
25
|
+
}
|
|
26
|
+
/>
|
|
27
|
+
{/* With Render Action */}
|
|
28
|
+
<SpaceCard
|
|
29
|
+
endpoint={x.endpoint}
|
|
30
|
+
selected
|
|
31
|
+
action={({ spaceGateway, selected, refresh }) => (
|
|
32
|
+
<MoreAction spaceGateway={spaceGateway} onBackedUp={() => refresh()} />
|
|
33
|
+
)}
|
|
34
|
+
/>
|
|
35
|
+
</>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## BaseConnectTo
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import { BaseConnectTo } from '@blocklet/did-space-react';
|
|
44
|
+
|
|
45
|
+
function Demo() {
|
|
46
|
+
return (
|
|
47
|
+
<BaseConnectTo
|
|
48
|
+
onWalletClick={() => {
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.log('on Wallet Click');
|
|
51
|
+
}}
|
|
52
|
+
onGatewayConfirm={({ spaceDid, spaceGatewayUrl }) => {
|
|
53
|
+
// eslint-disable-next-line no-console
|
|
54
|
+
console.log(`on Gateway Confirm\n spaceDid: ${spaceDid}\n spaceGatewayUrl: ${spaceGatewayUrl}`);
|
|
55
|
+
}}
|
|
33
56
|
/>
|
|
34
|
-
)
|
|
35
|
-
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## AuthConnectTo
|
|
62
|
+
|
|
63
|
+
Auto connect to DID Space and save space gateway:
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
import Toast from '@arcblock/ux/lib/Toast';
|
|
67
|
+
import { decryptSpaceGateway, AuthConnectTo, type AuthConnectToProps } from '@blocklet/did-space-react';
|
|
68
|
+
|
|
69
|
+
function ConnectTo({ ...rest }: AuthConnectToProps) {
|
|
70
|
+
const onSuccess = async (response: Record<string, string>, decrypt: Function) => {
|
|
71
|
+
try {
|
|
72
|
+
const spaceGateway = decryptSpaceGateway(response, decrypt);
|
|
73
|
+
// do sth to save space gateway
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(error);
|
|
76
|
+
Toast.error(formatError(error));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return <AuthConnectTo {...rest} onSuccess={onSuccess} />;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default ConnectTo;
|
|
36
84
|
```
|
|
37
85
|
|
|
38
|
-
##
|
|
86
|
+
## SessionConnectTo
|
|
87
|
+
|
|
88
|
+
Auto connect to DID Space and save space gateway to the users table:
|
|
39
89
|
|
|
40
90
|
```tsx
|
|
41
|
-
|
|
42
|
-
const onWalletConnect = () => {
|
|
43
|
-
// ...rest
|
|
44
|
-
};
|
|
91
|
+
import { SessionConnectTo } from '@blocklet/did-space-react';
|
|
45
92
|
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
// ...rest
|
|
49
|
-
};
|
|
93
|
+
function ConnectTo() {
|
|
94
|
+
const session = useSessionContext();
|
|
50
95
|
|
|
51
|
-
<
|
|
96
|
+
return <SessionConnectTo session={session} />;
|
|
97
|
+
}
|
|
52
98
|
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BaseAuthOptions } from '../../types';
|
|
2
|
+
export interface BaseAuthProps extends BaseAuthOptions, Record<string, any> {
|
|
3
|
+
open: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function BaseAuth({ open, extraParams, onSuccess, onClose, ...rest }: BaseAuthProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Typography } from '@mui/material';
|
|
3
|
+
import DidConnect from '@arcblock/did-connect/lib/Connect';
|
|
4
|
+
import { RELAY_SOCKET_PREFIX } from '@arcblock/ux/lib/Util/constant';
|
|
5
|
+
import { joinURL } from 'ufo';
|
|
6
|
+
import { createAxios } from '@blocklet/js-sdk';
|
|
7
|
+
import useLocale from '../../hooks/use-locale.js';
|
|
8
|
+
import { AUTHORIZE } from '../../libs/constants.js';
|
|
9
|
+
|
|
10
|
+
function BaseAuth({ open, extraParams, onSuccess, onClose, ...rest }) {
|
|
11
|
+
const { t, locale } = useLocale();
|
|
12
|
+
const finalExtraParams = {
|
|
13
|
+
appPid: window.blocklet?.appPid,
|
|
14
|
+
appDid: window.blocklet?.appId,
|
|
15
|
+
appName: window.blocklet?.appName,
|
|
16
|
+
appDescription: window.blocklet?.appDescription,
|
|
17
|
+
appUrl: window.blocklet?.appUrl,
|
|
18
|
+
referrer: window.location.href,
|
|
19
|
+
scopes: AUTHORIZE.DEFAULT_SCOPE,
|
|
20
|
+
...extraParams
|
|
21
|
+
};
|
|
22
|
+
const {
|
|
23
|
+
action = "connect-to-did-spaces",
|
|
24
|
+
prefix = "/api/did",
|
|
25
|
+
baseUrl = joinURL(window.location.origin, RELAY_SOCKET_PREFIX),
|
|
26
|
+
checkFn = createAxios({ baseURL: joinURL(window.location.origin, RELAY_SOCKET_PREFIX) }).get,
|
|
27
|
+
webWalletUrl = window.blocklet?.webWalletUrl,
|
|
28
|
+
checkTimeout = 1e3 * 300,
|
|
29
|
+
messages = {
|
|
30
|
+
title: t("storage.spaces.provideNFT.title", { appName: finalExtraParams.appName }),
|
|
31
|
+
scan: t("storage.spaces.provideNFT.scan", { appName: finalExtraParams.appName }),
|
|
32
|
+
confirm: "",
|
|
33
|
+
success: /* @__PURE__ */ jsx(Typography, { gutterBottom: true, children: t("storage.spaces.provideNFT.success") })
|
|
34
|
+
},
|
|
35
|
+
...restOptions
|
|
36
|
+
} = rest;
|
|
37
|
+
return /* @__PURE__ */ jsx(
|
|
38
|
+
DidConnect,
|
|
39
|
+
{
|
|
40
|
+
...restOptions,
|
|
41
|
+
open,
|
|
42
|
+
action,
|
|
43
|
+
prefix,
|
|
44
|
+
baseUrl,
|
|
45
|
+
checkFn,
|
|
46
|
+
webWalletUrl,
|
|
47
|
+
messages,
|
|
48
|
+
checkTimeout,
|
|
49
|
+
extraParams: finalExtraParams,
|
|
50
|
+
forceConnected: false,
|
|
51
|
+
saveConnect: false,
|
|
52
|
+
popup: true,
|
|
53
|
+
locale,
|
|
54
|
+
onSuccess,
|
|
55
|
+
onClose
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { 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,49 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { joinURL } from 'ufo';
|
|
3
|
+
import { createAxios } from '@blocklet/js-sdk';
|
|
4
|
+
import { Typography } from '@mui/material';
|
|
5
|
+
import useLocale from '../../hooks/use-locale.js';
|
|
6
|
+
import { BaseAuth } from './base-auth.js';
|
|
7
|
+
|
|
8
|
+
function GatewayAuth({
|
|
9
|
+
open,
|
|
10
|
+
spaceDid,
|
|
11
|
+
spaceGatewayUrl,
|
|
12
|
+
extraParams = {},
|
|
13
|
+
onSuccess,
|
|
14
|
+
onClose
|
|
15
|
+
}) {
|
|
16
|
+
const { t } = useLocale();
|
|
17
|
+
if (!spaceGatewayUrl || !spaceDid) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const { appName = window.blocklet?.appName } = extraParams;
|
|
21
|
+
const prefix = joinURL(spaceGatewayUrl, "space/api/did");
|
|
22
|
+
const baseUrl = new URL(spaceGatewayUrl).origin;
|
|
23
|
+
const checkFn = createAxios({ baseURL: joinURL(spaceGatewayUrl, "space") }).get;
|
|
24
|
+
const messages = {
|
|
25
|
+
title: t("storage.spaces.authorize.title", { appName }),
|
|
26
|
+
scan: t("storage.spaces.authorize.scan", { appName }),
|
|
27
|
+
confirm: "",
|
|
28
|
+
success: /* @__PURE__ */ jsx(Typography, { gutterBottom: true, children: t("storage.spaces.authorize.success") })
|
|
29
|
+
};
|
|
30
|
+
return /* @__PURE__ */ jsx(
|
|
31
|
+
BaseAuth,
|
|
32
|
+
{
|
|
33
|
+
open,
|
|
34
|
+
action: "one-click-authorization",
|
|
35
|
+
prefix,
|
|
36
|
+
baseUrl,
|
|
37
|
+
checkFn,
|
|
38
|
+
messages,
|
|
39
|
+
extraParams: {
|
|
40
|
+
...extraParams,
|
|
41
|
+
spaceDid
|
|
42
|
+
},
|
|
43
|
+
onSuccess,
|
|
44
|
+
onClose
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { 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,61 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { BaseConnectTo } from '../base-connect-to/index.js';
|
|
4
|
+
import { GatewayAuth } from './gateway-auth.js';
|
|
5
|
+
import { BaseAuth } from './base-auth.js';
|
|
6
|
+
|
|
7
|
+
function AuthConnectTo({ options, onSuccess, ...rest }) {
|
|
8
|
+
const [walletOptions, setWalletOptions] = useState({
|
|
9
|
+
open: false
|
|
10
|
+
});
|
|
11
|
+
const [gatewayOptions, setGatewayOptions] = useState({
|
|
12
|
+
open: false,
|
|
13
|
+
spaceDid: "",
|
|
14
|
+
spaceGatewayUrl: ""
|
|
15
|
+
});
|
|
16
|
+
const onWalletClick = () => setWalletOptions((pre) => ({ ...pre, open: true }));
|
|
17
|
+
const onGatewayConfirm = ({ spaceDid, spaceGatewayUrl }) => {
|
|
18
|
+
setGatewayOptions((pre) => ({
|
|
19
|
+
...pre,
|
|
20
|
+
open: true,
|
|
21
|
+
spaceDid,
|
|
22
|
+
spaceGatewayUrl
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
const handleSuccess = async (response, decrypt) => {
|
|
26
|
+
await onSuccess?.(response, decrypt);
|
|
27
|
+
setWalletOptions((pre) => ({
|
|
28
|
+
...pre,
|
|
29
|
+
open: false
|
|
30
|
+
}));
|
|
31
|
+
setGatewayOptions((pre) => ({
|
|
32
|
+
...pre,
|
|
33
|
+
open: false
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
37
|
+
/* @__PURE__ */ jsx(BaseConnectTo, { ...rest, onWalletClick, onGatewayConfirm }),
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
BaseAuth,
|
|
40
|
+
{
|
|
41
|
+
...options,
|
|
42
|
+
...walletOptions,
|
|
43
|
+
onSuccess: handleSuccess,
|
|
44
|
+
onClose: () => setWalletOptions((pre) => ({ ...pre, open: false }))
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
/* @__PURE__ */ jsx(
|
|
48
|
+
GatewayAuth,
|
|
49
|
+
{
|
|
50
|
+
...options,
|
|
51
|
+
...gatewayOptions,
|
|
52
|
+
onSuccess: handleSuccess,
|
|
53
|
+
onClose: () => setGatewayOptions((pre) => ({ ...pre, open: false }))
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
] });
|
|
57
|
+
}
|
|
58
|
+
AuthConnectTo.WalletAuth = BaseAuth;
|
|
59
|
+
AuthConnectTo.GatewayAuth = GatewayAuth;
|
|
60
|
+
|
|
61
|
+
export { AuthConnectTo, GatewayAuth, BaseAuth as WalletAuth };
|
|
@@ -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;
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { isValid } from '@arcblock/did';
|
|
4
|
-
import { Typography, CircularProgress, DialogContentText, TextField } from '@mui/material';
|
|
4
|
+
import { Typography, CircularProgress, DialogContentText, TextField, Tooltip, Link } from '@mui/material';
|
|
5
|
+
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
|
|
5
6
|
import Button from '@arcblock/ux/lib/Button';
|
|
6
7
|
import SplitButton from '@arcblock/ux/lib/SplitButton';
|
|
7
8
|
import Dialog from '@arcblock/ux/lib/Dialog';
|
|
9
|
+
import { withQuery } from 'ufo';
|
|
10
|
+
import { copyGatewayPageUrl } from '../../libs/constants.js';
|
|
8
11
|
import { extraDIDSpacesCoreUrl, getSpaceDidFromGatewayUrl } from '../../libs/util.js';
|
|
9
12
|
import { getSpaceGatewayUrl, isValidSpaceGatewayUrl } from '../../libs/gateway.js';
|
|
10
13
|
import useLocale from '../../hooks/use-locale.js';
|
|
11
14
|
|
|
12
|
-
function
|
|
13
|
-
const { t } = useLocale();
|
|
15
|
+
function BaseConnectTo({ style, onWalletClick, onGatewayConfirm, ...rest }) {
|
|
16
|
+
const { t, locale } = useLocale();
|
|
14
17
|
const [url, setUrl] = useState("");
|
|
15
18
|
const [loading, setLoading] = useState(false);
|
|
16
19
|
const [open, setOpen] = useState(false);
|
|
17
20
|
const [errorMessage, setErrorMessage] = useState("");
|
|
18
|
-
const
|
|
21
|
+
const onGatewayChange = async () => {
|
|
19
22
|
try {
|
|
20
23
|
setLoading(true);
|
|
21
24
|
const spaceGatewayUrl = await getSpaceGatewayUrl(url);
|
|
@@ -24,7 +27,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
|
24
27
|
if (!isValid(spaceDid) || !await isValidSpaceGatewayUrl(didSpacesCoreUrl)) {
|
|
25
28
|
throw new Error(t("storage.spaces.gateway.add.invalidUrl"));
|
|
26
29
|
}
|
|
27
|
-
|
|
30
|
+
onGatewayConfirm?.({
|
|
28
31
|
spaceDid,
|
|
29
32
|
spaceGatewayUrl: didSpacesCoreUrl
|
|
30
33
|
});
|
|
@@ -36,7 +39,7 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
|
36
39
|
setLoading(false);
|
|
37
40
|
}
|
|
38
41
|
};
|
|
39
|
-
const
|
|
42
|
+
const onGatewayClick = () => {
|
|
40
43
|
setErrorMessage("");
|
|
41
44
|
setUrl("");
|
|
42
45
|
setOpen(true);
|
|
@@ -53,19 +56,18 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
|
53
56
|
sx: {
|
|
54
57
|
textTransform: "none"
|
|
55
58
|
},
|
|
56
|
-
onClick: openGatewayInput,
|
|
57
59
|
size: "small",
|
|
58
|
-
|
|
60
|
+
onClick: onGatewayClick,
|
|
59
61
|
children: t("storage.spaces.connect.useSpaceGateway")
|
|
60
62
|
},
|
|
61
63
|
"1"
|
|
62
64
|
)
|
|
63
65
|
],
|
|
64
|
-
onClick: onWalletConnect,
|
|
65
66
|
color: "primary",
|
|
66
67
|
style: { textTransform: "none !important", fontSize: "1rem", ...style },
|
|
67
68
|
size: "small",
|
|
68
69
|
...rest,
|
|
70
|
+
onClick: onWalletClick,
|
|
69
71
|
children: /* @__PURE__ */ jsx(Typography, { sx: { fontWeight: "bold", textTransform: "none" }, children: t("storage.spaces.connect.useWallet") })
|
|
70
72
|
}
|
|
71
73
|
),
|
|
@@ -91,20 +93,10 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
|
91
93
|
children: t("common.cancel")
|
|
92
94
|
}
|
|
93
95
|
),
|
|
94
|
-
/* @__PURE__ */ jsxs(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
color: "primary",
|
|
99
|
-
disabled: loading || !url,
|
|
100
|
-
variant: "contained",
|
|
101
|
-
autoFocus: true,
|
|
102
|
-
children: [
|
|
103
|
-
loading && /* @__PURE__ */ jsx(CircularProgress, { size: 16 }),
|
|
104
|
-
t("common.confirm")
|
|
105
|
-
]
|
|
106
|
-
}
|
|
107
|
-
)
|
|
96
|
+
/* @__PURE__ */ jsxs(Button, { onClick: onGatewayChange, color: "primary", disabled: loading || !url, variant: "contained", autoFocus: true, children: [
|
|
97
|
+
loading && /* @__PURE__ */ jsx(CircularProgress, { size: 16 }),
|
|
98
|
+
t("common.confirm")
|
|
99
|
+
] })
|
|
108
100
|
] }),
|
|
109
101
|
children: /* @__PURE__ */ jsx("div", { style: { paddingTop: 12, overflowY: "hidden" }, children: /* @__PURE__ */ jsx(DialogContentText, { component: "div", children: /* @__PURE__ */ jsx(Typography, { component: "div", children: /* @__PURE__ */ jsx(
|
|
110
102
|
TextField,
|
|
@@ -124,10 +116,24 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
|
124
116
|
helperText: errorMessage,
|
|
125
117
|
onKeyDown: async (e) => {
|
|
126
118
|
if (e.key === "Enter") {
|
|
127
|
-
await
|
|
119
|
+
await onGatewayChange();
|
|
128
120
|
}
|
|
129
121
|
},
|
|
130
|
-
autoFocus: true
|
|
122
|
+
autoFocus: true,
|
|
123
|
+
InputProps: {
|
|
124
|
+
endAdornment: /* @__PURE__ */ jsx(Tooltip, { title: t("storage.spaces.connect.howToGetGatewayUrl"), placement: "top", children: /* @__PURE__ */ jsx(Link, { href: withQuery(copyGatewayPageUrl, { locale }), target: "_blank", children: /* @__PURE__ */ jsx(
|
|
125
|
+
HelpOutlineIcon,
|
|
126
|
+
{
|
|
127
|
+
sx: {
|
|
128
|
+
ml: 0.5,
|
|
129
|
+
color: "text.secondary",
|
|
130
|
+
cursor: "pointer",
|
|
131
|
+
fontSize: "18px",
|
|
132
|
+
verticalAlign: "-2px"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
) }) })
|
|
136
|
+
}
|
|
131
137
|
}
|
|
132
138
|
) }) }) })
|
|
133
139
|
}
|
|
@@ -135,4 +141,4 @@ function ConnectTo({ style, onWalletConnect, onGatewayConnect, ...rest }) {
|
|
|
135
141
|
] });
|
|
136
142
|
}
|
|
137
143
|
|
|
138
|
-
export {
|
|
144
|
+
export { BaseConnectTo };
|
|
@@ -2,9 +2,14 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
|
2
2
|
import { useState } from 'react';
|
|
3
3
|
import { Dialog, DialogContent, IconButton } from '@mui/material';
|
|
4
4
|
import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined';
|
|
5
|
+
import '../../icons/index.js';
|
|
5
6
|
import SvgEmptySpaceNft from '../../icons/empty-space-nft.svg.js';
|
|
6
7
|
|
|
7
|
-
function PreviewSpaceNft({
|
|
8
|
+
function PreviewSpaceNft({
|
|
9
|
+
src,
|
|
10
|
+
width = "58px",
|
|
11
|
+
height = "58px"
|
|
12
|
+
}) {
|
|
8
13
|
const [open, setOpen] = useState(false);
|
|
9
14
|
const handleOpen = () => setOpen(true);
|
|
10
15
|
const handleClose = () => setOpen(false);
|
|
@@ -76,4 +81,4 @@ function PreviewSpaceNft({ src, width = "58px", height = "58px" }) {
|
|
|
76
81
|
] });
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
export { PreviewSpaceNft
|
|
84
|
+
export { 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,26 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { BlockletSDK } from '@blocklet/js-sdk';
|
|
3
|
+
import { decryptSpaceGateway } from '../../libs/util.js';
|
|
4
|
+
import { AuthConnectTo } from '../auth-connect-to/index.js';
|
|
5
|
+
import { ReConnect } from './re-connect.js';
|
|
6
|
+
|
|
7
|
+
function SessionConnectTo({ session, onConnected, onError, ...rest }) {
|
|
8
|
+
const options = {
|
|
9
|
+
action: "connect-to-did-spaces-for-user"
|
|
10
|
+
};
|
|
11
|
+
const onSuccess = async (response, decrypt) => {
|
|
12
|
+
try {
|
|
13
|
+
const spaceGateway = decryptSpaceGateway(response, decrypt);
|
|
14
|
+
await new BlockletSDK().user.updateDidSpace({ spaceGateway });
|
|
15
|
+
session.refresh();
|
|
16
|
+
await onConnected?.(spaceGateway);
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error(err);
|
|
19
|
+
onError?.(err);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ jsx(AuthConnectTo, { ...rest, options, onSuccess });
|
|
23
|
+
}
|
|
24
|
+
SessionConnectTo.ReConnect = ReConnect;
|
|
25
|
+
|
|
26
|
+
export { ReConnect, SessionConnectTo };
|