@blocklet/ui-react 2.9.18 → 2.9.19
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/build.config.ts +1 -1
- package/es/@types/index.d.ts +2 -0
- package/es/UserCenter/components/settings.d.ts +1 -2
- package/es/UserCenter/components/settings.js +8 -1
- package/es/UserCenter/components/storage/connect-to.d.ts +7 -0
- package/es/UserCenter/components/storage/connect-to.js +104 -0
- package/es/UserCenter/components/storage/connected.d.ts +7 -0
- package/es/UserCenter/components/storage/connected.js +21 -0
- package/es/UserCenter/components/storage/delete.d.ts +7 -0
- package/es/UserCenter/components/storage/delete.js +59 -0
- package/es/UserCenter/components/storage/disconnect.d.ts +3 -0
- package/es/UserCenter/components/storage/disconnect.js +23 -0
- package/es/UserCenter/components/storage/icons/empty-spaces-nft.svg +58 -0
- package/es/UserCenter/components/storage/icons/long-arrow.svg +5 -0
- package/es/UserCenter/components/storage/icons/space-connected.svg +3 -0
- package/es/UserCenter/components/storage/icons/space-disconnect.svg +3 -0
- package/es/UserCenter/components/storage/index.d.ts +3 -0
- package/es/UserCenter/components/storage/index.js +25 -0
- package/es/UserCenter/components/storage/item.d.ts +9 -0
- package/es/UserCenter/components/storage/item.js +147 -0
- package/es/UserCenter/components/storage/preview-nft.d.ts +6 -0
- package/es/UserCenter/components/storage/preview-nft.js +80 -0
- package/es/UserCenter/libs/api.d.ts +3 -0
- package/es/UserCenter/libs/api.js +4 -0
- package/es/UserCenter/libs/locales.d.ts +2 -0
- package/es/UserCenter/libs/locales.js +2 -0
- package/es/contexts/config-user-space.d.ts +26 -0
- package/es/contexts/config-user-space.js +53 -0
- package/es/hooks/use-mobile.d.ts +4 -0
- package/es/hooks/use-mobile.js +5 -0
- package/es/libs/spaces.d.ts +1 -0
- package/es/libs/spaces.js +7 -0
- package/lib/@types/index.d.ts +2 -0
- package/lib/UserCenter/components/settings.d.ts +1 -2
- package/lib/UserCenter/components/settings.js +9 -1
- package/lib/UserCenter/components/storage/connect-to.d.ts +7 -0
- package/lib/UserCenter/components/storage/connect-to.js +127 -0
- package/lib/UserCenter/components/storage/connected.d.ts +7 -0
- package/lib/UserCenter/components/storage/connected.js +45 -0
- package/lib/UserCenter/components/storage/delete.d.ts +7 -0
- package/lib/UserCenter/components/storage/delete.js +71 -0
- package/lib/UserCenter/components/storage/disconnect.d.ts +3 -0
- package/lib/UserCenter/components/storage/disconnect.js +37 -0
- package/lib/UserCenter/components/storage/icons/empty-spaces-nft.svg +58 -0
- package/lib/UserCenter/components/storage/icons/long-arrow.svg +5 -0
- package/lib/UserCenter/components/storage/icons/space-connected.svg +3 -0
- package/lib/UserCenter/components/storage/icons/space-disconnect.svg +3 -0
- package/lib/UserCenter/components/storage/index.d.ts +3 -0
- package/lib/UserCenter/components/storage/index.js +56 -0
- package/lib/UserCenter/components/storage/item.d.ts +9 -0
- package/lib/UserCenter/components/storage/item.js +179 -0
- package/lib/UserCenter/components/storage/preview-nft.d.ts +6 -0
- package/lib/UserCenter/components/storage/preview-nft.js +88 -0
- package/lib/UserCenter/libs/api.d.ts +3 -0
- package/lib/UserCenter/libs/api.js +16 -0
- package/lib/UserCenter/libs/locales.d.ts +2 -0
- package/lib/UserCenter/libs/locales.js +2 -0
- package/lib/contexts/config-user-space.d.ts +26 -0
- package/lib/contexts/config-user-space.js +61 -0
- package/lib/hooks/use-mobile.d.ts +4 -0
- package/lib/hooks/use-mobile.js +13 -0
- package/lib/libs/spaces.d.ts +1 -0
- package/lib/libs/spaces.js +13 -0
- package/package.json +6 -4
- package/src/@types/index.ts +3 -0
- package/src/UserCenter/components/settings.tsx +8 -2
- package/src/UserCenter/components/storage/connect-to.tsx +117 -0
- package/src/UserCenter/components/storage/connected.tsx +29 -0
- package/src/UserCenter/components/storage/delete.tsx +66 -0
- package/src/UserCenter/components/storage/disconnect.tsx +27 -0
- package/src/UserCenter/components/storage/icons/empty-spaces-nft.svg +58 -0
- package/src/UserCenter/components/storage/icons/long-arrow.svg +5 -0
- package/src/UserCenter/components/storage/icons/space-connected.svg +3 -0
- package/src/UserCenter/components/storage/icons/space-disconnect.svg +3 -0
- package/src/UserCenter/components/storage/index.tsx +47 -0
- package/src/UserCenter/components/storage/item.tsx +150 -0
- package/src/UserCenter/components/storage/preview-nft.tsx +72 -0
- package/src/UserCenter/components/user-center.tsx +1 -1
- package/src/UserCenter/libs/api.ts +7 -0
- package/src/UserCenter/libs/locales.ts +2 -0
- package/src/contexts/config-user-space.tsx +86 -0
- package/src/hooks/use-mobile.tsx +6 -0
- package/src/libs/spaces.tsx +10 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _reactPlaceholder = _interopRequireDefault(require("react-placeholder"));
|
|
10
|
+
var _material = require("@mui/material");
|
|
11
|
+
var _CloseOutlined = _interopRequireDefault(require("@mui/icons-material/CloseOutlined"));
|
|
12
|
+
var _emptySpacesNft = _interopRequireDefault(require("./icons/empty-spaces-nft.svg?react"));
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function PreviewSpaceNft({
|
|
15
|
+
src,
|
|
16
|
+
alt
|
|
17
|
+
}) {
|
|
18
|
+
const [showEmptySpaceNFT, setShowEmptySpaceNFT] = (0, _react.useState)(false);
|
|
19
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
20
|
+
const handleOpen = () => setOpen(true);
|
|
21
|
+
const handleClose = () => setOpen(false);
|
|
22
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
23
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_reactPlaceholder.default, {
|
|
24
|
+
ready: showEmptySpaceNFT,
|
|
25
|
+
customPlaceholder:
|
|
26
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
27
|
+
/* @__PURE__ */
|
|
28
|
+
(0, _jsxRuntime.jsx)("img", {
|
|
29
|
+
style: {
|
|
30
|
+
cursor: "pointer"
|
|
31
|
+
},
|
|
32
|
+
alt,
|
|
33
|
+
src,
|
|
34
|
+
width: "58px",
|
|
35
|
+
height: "58px",
|
|
36
|
+
onError: () => setShowEmptySpaceNFT(true),
|
|
37
|
+
onClick: handleOpen
|
|
38
|
+
}),
|
|
39
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_emptySpacesNft.default, {
|
|
40
|
+
style: {
|
|
41
|
+
cursor: "pointer",
|
|
42
|
+
width: "58px",
|
|
43
|
+
height: "58px"
|
|
44
|
+
},
|
|
45
|
+
onClick: handleOpen
|
|
46
|
+
})
|
|
47
|
+
}), /* @__PURE__ */(0, _jsxRuntime.jsx)(_material.Dialog, {
|
|
48
|
+
open,
|
|
49
|
+
onClose: handleClose,
|
|
50
|
+
"aria-labelledby": "preview-space-nft-display",
|
|
51
|
+
"aria-describedby": "preview space nft display",
|
|
52
|
+
fullWidth: true,
|
|
53
|
+
maxWidth: "md",
|
|
54
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.DialogContent, {
|
|
55
|
+
style: {
|
|
56
|
+
padding: "8px 8px",
|
|
57
|
+
backgroundColor: "rgba(0,0,0,0.8)"
|
|
58
|
+
},
|
|
59
|
+
children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
60
|
+
color: "inherit",
|
|
61
|
+
onClick: handleClose,
|
|
62
|
+
"aria-label": "close",
|
|
63
|
+
style: {
|
|
64
|
+
position: "absolute",
|
|
65
|
+
top: 8,
|
|
66
|
+
right: 8,
|
|
67
|
+
color: "white"
|
|
68
|
+
},
|
|
69
|
+
children: /* @__PURE__ */(0, _jsxRuntime.jsx)(_CloseOutlined.default, {})
|
|
70
|
+
}), showEmptySpaceNFT ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_emptySpacesNft.default, {
|
|
71
|
+
style: {
|
|
72
|
+
width: "100%",
|
|
73
|
+
height: "75vh"
|
|
74
|
+
}
|
|
75
|
+
}) : /* @__PURE__ */(0, _jsxRuntime.jsx)("img", {
|
|
76
|
+
src,
|
|
77
|
+
alt: "",
|
|
78
|
+
style: {
|
|
79
|
+
width: "100%",
|
|
80
|
+
height: "75vh",
|
|
81
|
+
objectFit: "contain"
|
|
82
|
+
}
|
|
83
|
+
})]
|
|
84
|
+
})
|
|
85
|
+
})]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
module.exports = PreviewSpaceNft;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.api = void 0;
|
|
7
|
+
Object.defineProperty(exports, "axios", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _axios.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
_axios.default.defaults.timeout = 10 * 1e3;
|
|
16
|
+
const api = exports.api = _axios.default.create();
|
|
@@ -23,6 +23,7 @@ export declare const translations: {
|
|
|
23
23
|
noUserFound: string;
|
|
24
24
|
notificationManagement: string;
|
|
25
25
|
privacyManagement: string;
|
|
26
|
+
storageManagement: string;
|
|
26
27
|
webhook: {
|
|
27
28
|
url: string;
|
|
28
29
|
slack: string;
|
|
@@ -57,6 +58,7 @@ export declare const translations: {
|
|
|
57
58
|
emptyField: string;
|
|
58
59
|
notificationManagement: string;
|
|
59
60
|
privacyManagement: string;
|
|
61
|
+
storageManagement: string;
|
|
60
62
|
emptyContent: string;
|
|
61
63
|
underProtected: string;
|
|
62
64
|
noUserFound: string;
|
|
@@ -29,6 +29,7 @@ const translations = exports.translations = {
|
|
|
29
29
|
noUserFound: "\u672A\u627E\u5230\u6307\u5B9A\u7684\u7528\u6237",
|
|
30
30
|
notificationManagement: "\u901A\u77E5\u7BA1\u7406",
|
|
31
31
|
privacyManagement: "\u9690\u79C1\u7BA1\u7406",
|
|
32
|
+
storageManagement: "\u5B58\u50A8\u7BA1\u7406",
|
|
32
33
|
webhook: {
|
|
33
34
|
url: "\u81EA\u5B9A\u4E49URL",
|
|
34
35
|
slack: "Slack"
|
|
@@ -63,6 +64,7 @@ const translations = exports.translations = {
|
|
|
63
64
|
emptyField: "Empty field",
|
|
64
65
|
notificationManagement: "Notification",
|
|
65
66
|
privacyManagement: "Privacy",
|
|
67
|
+
storageManagement: "Storage",
|
|
66
68
|
emptyContent: "Empty",
|
|
67
69
|
underProtected: "This page has protected privacy",
|
|
68
70
|
noUserFound: "No user found",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface SpaceGateway {
|
|
3
|
+
did: string;
|
|
4
|
+
name: string;
|
|
5
|
+
url: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SettingStorageEndpoint {
|
|
9
|
+
(endpoint: string | undefined): void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
interface ConfigUserSpaceContextType {
|
|
12
|
+
loading: boolean;
|
|
13
|
+
spaceGateway: SpaceGateway | undefined;
|
|
14
|
+
deleteSpaceGateway: (spaceGateway: SpaceGateway) => Promise<void>;
|
|
15
|
+
updateSpaceGateway: (updateSpaceGateway: SpaceGateway) => Promise<void>;
|
|
16
|
+
storageEndpoint: string;
|
|
17
|
+
settingStorageEndpoint: SettingStorageEndpoint;
|
|
18
|
+
hasStorageEndpoint: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare const ConfigUserSpaceContext: import("react").Context<ConfigUserSpaceContextType>;
|
|
21
|
+
declare const Consumer: import("react").Consumer<ConfigUserSpaceContextType>;
|
|
22
|
+
declare function ConfigUserSpaceProvider({ children }: {
|
|
23
|
+
children: React.ReactNode;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
25
|
+
declare function useConfigUserSpaceContext(): ConfigUserSpaceContextType;
|
|
26
|
+
export { ConfigUserSpaceContext, ConfigUserSpaceProvider, Consumer as ConfigUserSpaceConsumer, useConfigUserSpaceContext, };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ConfigUserSpaceContext = exports.ConfigUserSpaceConsumer = void 0;
|
|
7
|
+
exports.ConfigUserSpaceProvider = ConfigUserSpaceProvider;
|
|
8
|
+
exports.useConfigUserSpaceContext = useConfigUserSpaceContext;
|
|
9
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _Session = require("@arcblock/did-connect/lib/Session");
|
|
12
|
+
const ConfigUserSpaceContext = exports.ConfigUserSpaceContext = (0, _react.createContext)({});
|
|
13
|
+
const {
|
|
14
|
+
Provider,
|
|
15
|
+
Consumer
|
|
16
|
+
} = ConfigUserSpaceContext;
|
|
17
|
+
exports.ConfigUserSpaceConsumer = Consumer;
|
|
18
|
+
function ConfigUserSpaceProvider({
|
|
19
|
+
children
|
|
20
|
+
}) {
|
|
21
|
+
const [loading] = (0, _react.useState)(false);
|
|
22
|
+
const {
|
|
23
|
+
session
|
|
24
|
+
} = (0, _react.useContext)(_Session.SessionContext);
|
|
25
|
+
const {
|
|
26
|
+
user
|
|
27
|
+
} = session;
|
|
28
|
+
const [spaceGateway, setSpaceGateway] = (0, _react.useState)();
|
|
29
|
+
const storageEndpoint = (0, _react.useMemo)(() => {
|
|
30
|
+
return user?.didSpace?.endpoint;
|
|
31
|
+
}, [user?.didSpace]);
|
|
32
|
+
(0, _react.useEffect)(() => {
|
|
33
|
+
setSpaceGateway(user?.didSpace);
|
|
34
|
+
}, [user?.didSpace]);
|
|
35
|
+
const deleteSpaceGateway = async () => {
|
|
36
|
+
setSpaceGateway(void 0);
|
|
37
|
+
};
|
|
38
|
+
const updateSpaceGateway = async x => {
|
|
39
|
+
setSpaceGateway(x);
|
|
40
|
+
session.refresh();
|
|
41
|
+
await settingStorageEndpoint(x.endpoint);
|
|
42
|
+
};
|
|
43
|
+
const settingStorageEndpoint = endpoint => {};
|
|
44
|
+
const hasStorageEndpoint = Boolean(storageEndpoint && spaceGateway);
|
|
45
|
+
return /* @__PURE__ */(0, _jsxRuntime.jsx)(Provider, {
|
|
46
|
+
value: {
|
|
47
|
+
loading,
|
|
48
|
+
spaceGateway,
|
|
49
|
+
deleteSpaceGateway,
|
|
50
|
+
updateSpaceGateway,
|
|
51
|
+
storageEndpoint,
|
|
52
|
+
settingStorageEndpoint,
|
|
53
|
+
hasStorageEndpoint
|
|
54
|
+
},
|
|
55
|
+
children
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function useConfigUserSpaceContext() {
|
|
59
|
+
const res = (0, _react.useContext)(ConfigUserSpaceContext);
|
|
60
|
+
return res;
|
|
61
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
module.exports = useMobile;
|
|
7
|
+
var _material = require("@mui/material");
|
|
8
|
+
function useMobile({
|
|
9
|
+
key = "sm"
|
|
10
|
+
}) {
|
|
11
|
+
const theme = (0, _material.useTheme)();
|
|
12
|
+
return (0, _material.useMediaQuery)(theme.breakpoints.down(key));
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSpaceNftDisplayUrlFromEndpoint(endpoint: string): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSpaceNftDisplayUrlFromEndpoint = getSpaceNftDisplayUrlFromEndpoint;
|
|
7
|
+
var _ufo = require("ufo");
|
|
8
|
+
function getSpaceNftDisplayUrlFromEndpoint(endpoint) {
|
|
9
|
+
const prefix = endpoint.replace(/\/api\/space\/.+/, "");
|
|
10
|
+
const strArray = endpoint.replace(/\/$/, "").split("/");
|
|
11
|
+
const spaceDid = strArray.at(-4);
|
|
12
|
+
return (0, _ufo.joinURL)(prefix, `/api/space/nft/display?spaceDid=${spaceDid}`);
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/ui-react",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.19",
|
|
4
4
|
"description": "Some useful front-end web components that can be used in Blocklets.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@abtnode/constant": "1.16.23-beta-aeb9f5bd",
|
|
66
|
-
"@arcblock/did-connect": "^2.9.
|
|
67
|
-
"@arcblock/ux": "^2.9.
|
|
66
|
+
"@arcblock/did-connect": "^2.9.19",
|
|
67
|
+
"@arcblock/ux": "^2.9.19",
|
|
68
68
|
"@blocklet/js-sdk": "1.16.23-beta-aeb9f5bd",
|
|
69
69
|
"@emotion/react": "^11.10.4",
|
|
70
70
|
"@emotion/styled": "^11.10.4",
|
|
@@ -77,7 +77,9 @@
|
|
|
77
77
|
"iconify-icon": "^1.0.8",
|
|
78
78
|
"iconify-icons-material-symbols-400": "^0.0.1",
|
|
79
79
|
"is-url": "^1.2.4",
|
|
80
|
+
"lodash": "^4.17.21",
|
|
80
81
|
"react-error-boundary": "^3.1.4",
|
|
82
|
+
"react-placeholder": "^4.1.0",
|
|
81
83
|
"ufo": "^1.3.2"
|
|
82
84
|
},
|
|
83
85
|
"peerDependencies": {
|
|
@@ -96,5 +98,5 @@
|
|
|
96
98
|
"jest": "^28.1.3",
|
|
97
99
|
"unbuild": "^2.0.0"
|
|
98
100
|
},
|
|
99
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "409ab4e9bc7a641c7d3f64dfebe05d8ea3cfe2da"
|
|
100
102
|
}
|
package/src/@types/index.ts
CHANGED
|
@@ -17,6 +17,7 @@ export type User = {
|
|
|
17
17
|
lastLoginIp?: string;
|
|
18
18
|
createdAt?: string;
|
|
19
19
|
passports?: any[];
|
|
20
|
+
didSpace: Record<string, any>;
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
export type UserCenterTab = {
|
|
@@ -36,6 +37,8 @@ export type Session = {
|
|
|
36
37
|
switchDid: any;
|
|
37
38
|
switchProfile: any;
|
|
38
39
|
switchPassport: any;
|
|
40
|
+
|
|
41
|
+
refresh: Function;
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
export type WebhookType = 'slack' | 'api';
|
|
@@ -4,11 +4,12 @@ import type { BoxProps } from '@mui/material';
|
|
|
4
4
|
import { useCreation, useMemoizedFn, useReactive } from 'ahooks';
|
|
5
5
|
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
6
6
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
7
|
-
|
|
7
|
+
import { ConfigUserSpaceProvider } from '../../contexts/config-user-space';
|
|
8
8
|
import { translations } from '../libs/locales';
|
|
9
9
|
import Notification from './notification';
|
|
10
10
|
import Privacy from './privacy';
|
|
11
11
|
import { User, UserCenterTab } from '../../@types';
|
|
12
|
+
import DidSpace from './storage';
|
|
12
13
|
|
|
13
14
|
export default function Settings({
|
|
14
15
|
user,
|
|
@@ -48,7 +49,12 @@ export default function Settings({
|
|
|
48
49
|
value: 'privacy',
|
|
49
50
|
content: <Privacy configList={privacyConfigList} onSave={onSave} />,
|
|
50
51
|
},
|
|
51
|
-
|
|
52
|
+
user?.didSpace?.endpoint && {
|
|
53
|
+
label: t('storageManagement'),
|
|
54
|
+
value: 'storage',
|
|
55
|
+
content: <ConfigUserSpaceProvider><DidSpace /></ConfigUserSpaceProvider>,
|
|
56
|
+
},
|
|
57
|
+
].filter(Boolean);
|
|
52
58
|
}, [user, privacyConfigList]);
|
|
53
59
|
const currentState = useReactive({
|
|
54
60
|
tab: tabs[0].value,
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import Button from '@arcblock/ux/lib/Button';
|
|
4
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
5
|
+
import DidConnect from '@arcblock/did-connect/lib/Connect';
|
|
6
|
+
import { joinURL } from 'ufo';
|
|
7
|
+
import toast from '@arcblock/ux/lib/Toast';
|
|
8
|
+
import { func, string } from 'prop-types';
|
|
9
|
+
import isEmpty from 'lodash/isEmpty';
|
|
10
|
+
import {axios} from '../../libs/api';
|
|
11
|
+
import { SpaceGateway } from '../../../contexts/config-user-space';
|
|
12
|
+
|
|
13
|
+
function ConnectTo({ onConnect, storageEndpoint, ...rest }: { onConnect: (spaceGateway: SpaceGateway) => Promise<void>, storageEndpoint: string}) {
|
|
14
|
+
const { t, locale } = useLocaleContext();
|
|
15
|
+
|
|
16
|
+
const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = useState({
|
|
17
|
+
open: false,
|
|
18
|
+
action: 'connect-to-did-spaces-for-user',
|
|
19
|
+
checkTimeout: 1000 * 300,
|
|
20
|
+
prefix: '/api/did',
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
checkFn: axios.create({ baseURL: joinURL(window.location.origin, window.env && window.env.apiPrefix ? window.env.apiPrefix : '/') }).get,
|
|
23
|
+
extraParams: {},
|
|
24
|
+
messages: {
|
|
25
|
+
title: t('storage.spaces.provideNFT.title', { appName: window.blocklet.appName }, locale),
|
|
26
|
+
scan: t('storage.spaces.provideNFT.scan', { appName: window.blocklet.appName }, locale),
|
|
27
|
+
confirm: '',
|
|
28
|
+
success: <Typography gutterBottom>{t('storage.spaces.provideNFT.success')}</Typography>,
|
|
29
|
+
},
|
|
30
|
+
onClose: () => {
|
|
31
|
+
// eslint-disable-next-line no-shadow
|
|
32
|
+
setAuthorizeFromNftConnect((preValue) => ({
|
|
33
|
+
...preValue,
|
|
34
|
+
open: false,
|
|
35
|
+
}));
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const updateSpaceGateway = async (spaceGateway: SpaceGateway) => {
|
|
41
|
+
await onConnect(spaceGateway);
|
|
42
|
+
toast.success(t('storage.spaces.connectedWithName', { name: spaceGateway.name }));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const onAuthorizeConnectSuccess = (response: Record<string, string>, decrypt: Function) => {
|
|
46
|
+
setTimeout(async () => {
|
|
47
|
+
setAuthorizeFromNftConnect((preValue) => ({
|
|
48
|
+
...preValue,
|
|
49
|
+
open: false,
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
if (!isEmpty(response.spaceGateway)) {
|
|
53
|
+
await updateSpaceGateway(decrypt(response.spaceGateway));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const endpoint = decrypt(response.endpoint);
|
|
58
|
+
const space = response.space ? decrypt(response.space) : {};
|
|
59
|
+
|
|
60
|
+
// eslint-disable-next-line no-use-before-define
|
|
61
|
+
await updateSpaceGateway({
|
|
62
|
+
endpoint,
|
|
63
|
+
// name 默认为 DID Space,兼容旧版本的 DID Spaces
|
|
64
|
+
...{ name: 'DID Space' },
|
|
65
|
+
...space,
|
|
66
|
+
});
|
|
67
|
+
}, 0);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleUseWalletConnect = () => {
|
|
71
|
+
setAuthorizeFromNftConnect((preValue) => ({
|
|
72
|
+
...preValue,
|
|
73
|
+
open: true,
|
|
74
|
+
extraParams: {
|
|
75
|
+
appDid: window.blocklet.appId,
|
|
76
|
+
appName: window.blocklet.appName,
|
|
77
|
+
appDescription: window.blocklet.appDescription,
|
|
78
|
+
scopes: 'list:object read:object write:object',
|
|
79
|
+
appUrl: window.blocklet.appUrl,
|
|
80
|
+
referrer: window.location.href
|
|
81
|
+
},
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Box>
|
|
87
|
+
<Button
|
|
88
|
+
color="primary"
|
|
89
|
+
style={{ textTransform: 'none !important', fontSize: '1rem' }}
|
|
90
|
+
size="small"
|
|
91
|
+
onClick={handleUseWalletConnect}
|
|
92
|
+
variant="outlined">
|
|
93
|
+
{storageEndpoint ? t('storage.spaces.connect.useWalletReconnect') : t('storage.spaces.connect.useWallet')}
|
|
94
|
+
</Button>
|
|
95
|
+
|
|
96
|
+
{/* 为了获取 DID Spaces Url */}
|
|
97
|
+
<DidConnect
|
|
98
|
+
forceConnected={false}
|
|
99
|
+
saveConnect={false}
|
|
100
|
+
prefix={authorizeFromNftConnect.prefix}
|
|
101
|
+
open={authorizeFromNftConnect.open}
|
|
102
|
+
popup
|
|
103
|
+
action={authorizeFromNftConnect.action}
|
|
104
|
+
checkFn={authorizeFromNftConnect.checkFn}
|
|
105
|
+
onSuccess={onAuthorizeConnectSuccess}
|
|
106
|
+
onClose={authorizeFromNftConnect.onClose}
|
|
107
|
+
checkTimeout={authorizeFromNftConnect.checkTimeout}
|
|
108
|
+
extraParams={authorizeFromNftConnect.extraParams}
|
|
109
|
+
messages={authorizeFromNftConnect.messages}
|
|
110
|
+
locale={locale}
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
</Box>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default ConnectTo;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material';
|
|
2
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
|
+
import SpaceItem from './item';
|
|
4
|
+
import { SettingStorageEndpoint, SpaceGateway } from '../../../contexts/config-user-space';
|
|
5
|
+
|
|
6
|
+
function Connected({ spaceGateway, settingStorageEndpoint }: {spaceGateway: SpaceGateway | undefined, settingStorageEndpoint: SettingStorageEndpoint }) {
|
|
7
|
+
const { t } = useLocaleContext();
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Box display="flex" flexDirection="column">
|
|
11
|
+
<Box display="flex" flexDirection="row" alignItems="center" justifyContent="space-between" marginBottom="12px">
|
|
12
|
+
<Typography fontSize="1.2rem" fontWeight="bold">
|
|
13
|
+
{t('storage.spaces.connected.title')}
|
|
14
|
+
</Typography>
|
|
15
|
+
</Box>
|
|
16
|
+
<Box>
|
|
17
|
+
<SpaceItem
|
|
18
|
+
style={{ marginTop: '12px' }}
|
|
19
|
+
key={spaceGateway?.endpoint}
|
|
20
|
+
spaceGateway={spaceGateway as SpaceGateway}
|
|
21
|
+
connected
|
|
22
|
+
onDisconnect={() => settingStorageEndpoint(undefined)}
|
|
23
|
+
/>
|
|
24
|
+
</Box>
|
|
25
|
+
</Box>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default Connected;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { IconButton } from '@mui/material';
|
|
3
|
+
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
|
|
4
|
+
import Confirm from '@arcblock/ux/lib/Dialog/confirm';
|
|
5
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
6
|
+
import toast from '@arcblock/ux/lib/Toast';
|
|
7
|
+
import { SpaceGateway } from '../../../contexts/config-user-space';
|
|
8
|
+
|
|
9
|
+
function SpaceDelete({ spaceGateway, onDeleteSpace }: {spaceGateway: SpaceGateway, onDeleteSpace: (spaceGateway: SpaceGateway) => Promise<void> }) {
|
|
10
|
+
const { t } = useLocaleContext();
|
|
11
|
+
const [open, setOpen] = useState(false);
|
|
12
|
+
const [loading, setLoading] = useState(false);
|
|
13
|
+
|
|
14
|
+
const handleOpen = (e: React.MouseEvent, bool: boolean) => {
|
|
15
|
+
e?.stopPropagation();
|
|
16
|
+
setOpen(bool);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const handleOnDelete = async (e: React.MouseEvent) => {
|
|
20
|
+
try {
|
|
21
|
+
e?.stopPropagation();
|
|
22
|
+
setLoading(true);
|
|
23
|
+
await onDeleteSpace(spaceGateway);
|
|
24
|
+
setOpen(false);
|
|
25
|
+
} catch (error: any) {
|
|
26
|
+
console.error(error);
|
|
27
|
+
toast.error(`${t('storage.spaces.gateway.delete.failed')}: ${error.message}`);
|
|
28
|
+
} finally {
|
|
29
|
+
setLoading(false);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<>
|
|
35
|
+
<IconButton size="small" onClick={(e) => handleOpen(e, true)}>
|
|
36
|
+
<DeleteOutlineIcon />
|
|
37
|
+
</IconButton>
|
|
38
|
+
|
|
39
|
+
<Confirm
|
|
40
|
+
title={t('common.delConfirmDescription', {
|
|
41
|
+
data: `${spaceGateway?.name}`,
|
|
42
|
+
})}
|
|
43
|
+
open={open}
|
|
44
|
+
confirmButton={{
|
|
45
|
+
text: t('common.confirm'),
|
|
46
|
+
props: {
|
|
47
|
+
variant: 'contained',
|
|
48
|
+
color: 'error',
|
|
49
|
+
loading,
|
|
50
|
+
},
|
|
51
|
+
}}
|
|
52
|
+
cancelButton={{
|
|
53
|
+
text: t('common.cancel'),
|
|
54
|
+
props: {
|
|
55
|
+
variant: 'contained',
|
|
56
|
+
color: 'primary',
|
|
57
|
+
},
|
|
58
|
+
}}
|
|
59
|
+
onConfirm={handleOnDelete}
|
|
60
|
+
onCancel={(e: React.MouseEvent) => handleOpen(e, false)}
|
|
61
|
+
/>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default SpaceDelete;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Box, Typography } from '@mui/material';
|
|
2
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
3
|
+
// @ts-expect-error
|
|
4
|
+
import EmptySpacesNFT from './icons/empty-spaces-nft.svg?react';
|
|
5
|
+
|
|
6
|
+
function Disconnect() {
|
|
7
|
+
const { t } = useLocaleContext();
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Box>
|
|
11
|
+
<Box
|
|
12
|
+
minHeight="40vh"
|
|
13
|
+
display="flex"
|
|
14
|
+
flexDirection="column"
|
|
15
|
+
justifyContent="center"
|
|
16
|
+
alignItems="center"
|
|
17
|
+
alignContent="center">
|
|
18
|
+
<EmptySpacesNFT style={{ width: 200, height: 250 }} />
|
|
19
|
+
<Typography marginTop="24px" marginBottom="24px">
|
|
20
|
+
{t('storage.spaces.connect.providerForStorage')}
|
|
21
|
+
</Typography>
|
|
22
|
+
</Box>
|
|
23
|
+
</Box>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default Disconnect;
|