@blocklet/ui-react 2.9.51 → 2.9.53

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 (112) hide show
  1. package/es/@types/index.d.ts +3 -5
  2. package/es/Dashboard/index.d.ts +5 -6
  3. package/es/Dashboard/index.js +5 -5
  4. package/es/Footer/index.js +2 -2
  5. package/es/Header/index.js +5 -5
  6. package/es/UserCenter/components/notification.js +1 -1
  7. package/es/UserCenter/components/passport.js +1 -2
  8. package/es/UserCenter/components/privacy.js +1 -1
  9. package/es/UserCenter/components/settings.js +9 -1
  10. package/es/UserCenter/components/storage/connect-to.d.ts +1 -1
  11. package/es/UserCenter/components/storage/connect-to.js +9 -3
  12. package/es/UserCenter/components/storage/connected.d.ts +1 -1
  13. package/es/UserCenter/components/storage/connected.js +5 -2
  14. package/es/UserCenter/components/storage/delete.d.ts +1 -1
  15. package/es/UserCenter/components/storage/delete.js +4 -1
  16. package/es/UserCenter/components/storage/index.js +4 -2
  17. package/es/UserCenter/components/storage/item.js +7 -12
  18. package/es/UserCenter/components/user-center.d.ts +2 -2
  19. package/es/UserCenter/components/user-center.js +15 -6
  20. package/es/UserCenter/libs/locales.d.ts +54 -0
  21. package/es/UserCenter/libs/locales.js +56 -2
  22. package/es/UserSessions/components/user-session-info.d.ts +6 -0
  23. package/es/UserSessions/components/user-session-info.js +58 -0
  24. package/es/UserSessions/components/user-sessions.d.ts +9 -0
  25. package/es/UserSessions/components/user-sessions.js +255 -0
  26. package/es/UserSessions/index.d.ts +1 -0
  27. package/es/UserSessions/index.js +1 -0
  28. package/es/UserSessions/libs/locales.d.ts +52 -0
  29. package/es/UserSessions/libs/locales.js +52 -0
  30. package/es/UserSessions/libs/utils.d.ts +2 -0
  31. package/es/UserSessions/libs/utils.js +73 -0
  32. package/es/blocklets.js +6 -6
  33. package/es/common/header-addons.d.ts +3 -4
  34. package/es/common/header-addons.js +4 -4
  35. package/es/contexts/config-user-space.js +2 -2
  36. package/es/index.d.ts +1 -0
  37. package/es/index.js +1 -0
  38. package/es/types.d.ts +2 -2
  39. package/es/types.js +2 -2
  40. package/lib/@types/index.d.ts +3 -5
  41. package/lib/Dashboard/index.d.ts +5 -6
  42. package/lib/Dashboard/index.js +4 -4
  43. package/lib/Footer/index.js +1 -1
  44. package/lib/Header/index.js +4 -4
  45. package/lib/UserCenter/components/notification.js +1 -1
  46. package/lib/UserCenter/components/passport.js +1 -2
  47. package/lib/UserCenter/components/privacy.js +1 -1
  48. package/lib/UserCenter/components/settings.js +10 -1
  49. package/lib/UserCenter/components/storage/connect-to.d.ts +1 -1
  50. package/lib/UserCenter/components/storage/connect-to.js +3 -3
  51. package/lib/UserCenter/components/storage/connected.d.ts +1 -1
  52. package/lib/UserCenter/components/storage/connected.js +1 -1
  53. package/lib/UserCenter/components/storage/delete.d.ts +1 -1
  54. package/lib/UserCenter/components/storage/index.js +22 -17
  55. package/lib/UserCenter/components/storage/item.js +1 -13
  56. package/lib/UserCenter/components/user-center.d.ts +2 -2
  57. package/lib/UserCenter/components/user-center.js +20 -10
  58. package/lib/UserCenter/libs/locales.d.ts +54 -0
  59. package/lib/UserCenter/libs/locales.js +56 -2
  60. package/lib/UserSessions/components/user-session-info.d.ts +6 -0
  61. package/lib/UserSessions/components/user-session-info.js +68 -0
  62. package/lib/UserSessions/components/user-sessions.d.ts +9 -0
  63. package/lib/UserSessions/components/user-sessions.js +282 -0
  64. package/lib/UserSessions/index.d.ts +1 -0
  65. package/lib/UserSessions/index.js +13 -0
  66. package/lib/UserSessions/libs/locales.d.ts +52 -0
  67. package/lib/UserSessions/libs/locales.js +58 -0
  68. package/lib/UserSessions/libs/utils.d.ts +2 -0
  69. package/lib/UserSessions/libs/utils.js +80 -0
  70. package/lib/blocklets.js +6 -6
  71. package/lib/common/header-addons.d.ts +3 -4
  72. package/lib/common/header-addons.js +3 -3
  73. package/lib/contexts/config-user-space.js +1 -1
  74. package/lib/index.d.ts +1 -0
  75. package/lib/index.js +12 -0
  76. package/lib/types.d.ts +2 -2
  77. package/lib/types.js +3 -3
  78. package/package.json +14 -6
  79. package/src/@types/index.ts +3 -5
  80. package/src/Dashboard/index.jsx +7 -3
  81. package/src/Footer/index.jsx +2 -2
  82. package/src/Header/index.jsx +5 -3
  83. package/src/Icon/index.jsx +1 -0
  84. package/src/UserCenter/components/notification.tsx +2 -2
  85. package/src/UserCenter/components/passport.tsx +1 -2
  86. package/src/UserCenter/components/privacy.tsx +1 -1
  87. package/src/UserCenter/components/settings.tsx +15 -2
  88. package/src/UserCenter/components/storage/connect-to.tsx +17 -11
  89. package/src/UserCenter/components/storage/connected.tsx +9 -3
  90. package/src/UserCenter/components/storage/delete.tsx +8 -2
  91. package/src/UserCenter/components/storage/index.tsx +17 -13
  92. package/src/UserCenter/components/storage/item.tsx +8 -15
  93. package/src/UserCenter/components/storage/preview-nft.tsx +1 -1
  94. package/src/UserCenter/components/user-center.tsx +21 -14
  95. package/src/UserCenter/components/webhook-item.tsx +1 -1
  96. package/src/UserCenter/libs/locales.ts +54 -0
  97. package/src/UserSessions/components/user-session-info.tsx +52 -0
  98. package/src/UserSessions/components/user-sessions.tsx +276 -0
  99. package/src/UserSessions/index.tsx +1 -0
  100. package/src/UserSessions/libs/locales.ts +52 -0
  101. package/src/UserSessions/libs/utils.ts +82 -0
  102. package/src/blocklets.js +6 -6
  103. package/src/common/header-addons.jsx +2 -2
  104. package/src/contexts/config-user-space.tsx +12 -11
  105. package/src/index.ts +1 -0
  106. package/src/{UserCenter/libs → libs}/client.ts +1 -0
  107. package/src/libs/spaces.tsx +2 -2
  108. package/src/types.js +2 -2
  109. /package/es/{UserCenter/libs → libs}/client.d.ts +0 -0
  110. /package/es/{UserCenter/libs → libs}/client.js +0 -0
  111. /package/lib/{UserCenter/libs → libs}/client.d.ts +0 -0
  112. /package/lib/{UserCenter/libs → libs}/client.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/ui-react",
3
- "version": "2.9.51",
3
+ "version": "2.9.53",
4
4
  "description": "Some useful front-end web components that can be used in Blocklets.",
5
5
  "keywords": [
6
6
  "react",
@@ -18,9 +18,9 @@
18
18
  "url": "git+https://github.com/ArcBlock/ux.git"
19
19
  },
20
20
  "scripts": {
21
- "lint": "eslint src tests --ext js --ext jsx",
21
+ "lint": "eslint src tests --ext js --ext jsx --ext tsx --ext ts",
22
22
  "lint:fix": "npm run lint -- --fix",
23
- "build": "unbuild && node tools/auto-exports.js",
23
+ "build": "unbuild",
24
24
  "watch": "CONSOLA_LEVEL=1 nodemon -e .jsx,.js,.ts,.tsx -w src -x 'yalc publish --push'",
25
25
  "precommit": "CI=1 npm run lint",
26
26
  "prepush": "CI=1 npm run lint",
@@ -63,8 +63,9 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@abtnode/constant": "^1.16.24",
66
- "@arcblock/did-connect": "^2.9.51",
67
- "@arcblock/ux": "^2.9.51",
66
+ "@arcblock/did-connect": "^2.9.53",
67
+ "@arcblock/react-hooks": "^2.9.53",
68
+ "@arcblock/ux": "^2.9.53",
68
69
  "@blocklet/js-sdk": "^1.16.24",
69
70
  "@emotion/react": "^11.10.4",
70
71
  "@emotion/styled": "^11.10.4",
@@ -72,14 +73,20 @@
72
73
  "@iconify/react": "^4.1.1",
73
74
  "ahooks": "^3.7.10",
74
75
  "axios": "^0.27.2",
76
+ "clsx": "^2.1.0",
75
77
  "core-js": "^3.25.5",
78
+ "dsbridge": "^3.1.4",
76
79
  "iconify-icon": "^1.0.8",
77
80
  "iconify-icons-material-symbols-400": "^0.0.1",
78
81
  "is-url": "^1.2.4",
79
82
  "lodash": "^4.17.21",
83
+ "p-all": "^5.0.0",
80
84
  "p-wait-for": "^5.0.2",
85
+ "prop-types": "^15.8.1",
81
86
  "react-error-boundary": "^3.1.4",
82
87
  "react-placeholder": "^4.1.0",
88
+ "react-router-dom": "^6.22.3",
89
+ "ua-parser-js": "^1.0.37",
83
90
  "ufo": "^1.3.2",
84
91
  "url-join": "^4.0.1"
85
92
  },
@@ -96,10 +103,11 @@
96
103
  "@babel/core": "^7.19.3",
97
104
  "@babel/preset-env": "^7.19.3",
98
105
  "@babel/preset-react": "^7.18.6",
106
+ "@types/ua-parser-js": "^0.7.39",
99
107
  "eslint-plugin-react-hooks": "^4.6.0",
100
108
  "glob": "^10.3.3",
101
109
  "jest": "^28.1.3",
102
110
  "unbuild": "^2.0.0"
103
111
  },
104
- "gitHead": "e89e3c3f37f0891ef91d1f9f6f864f29806c22b7"
112
+ "gitHead": "bf54e5b6fe510e2340ae87d1561d38d04dc25363"
105
113
  }
@@ -1,15 +1,13 @@
1
1
  import type { Axios } from 'axios';
2
+ import type { UserPublicInfo } from '@blocklet/js-sdk';
2
3
 
3
4
  export type SessionContext = {
4
5
  session: Session;
5
6
  api: Axios;
6
7
  };
7
8
 
8
- export type User = {
9
- did: string;
10
- fullName: string;
9
+ export type User = UserPublicInfo & {
11
10
  role: string;
12
- avatar: string;
13
11
  email?: string;
14
12
  phone?: string;
15
13
  sourceProvider?: string;
@@ -17,7 +15,7 @@ export type User = {
17
15
  lastLoginIp?: string;
18
16
  createdAt?: string;
19
17
  passports?: any[];
20
- didSpace: Record<string, any>;
18
+ didSpace?: Record<string, any>;
21
19
  };
22
20
 
23
21
  export type UserCenterTab = {
@@ -6,7 +6,7 @@ import PropTypes from 'prop-types';
6
6
  import { SessionContext } from '@arcblock/did-connect/lib/Session';
7
7
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
8
8
  import UxDashboard from '@arcblock/ux/lib/Layout/dashboard';
9
- import { blockletMetaProps, sessionManagerProps } from '../types';
9
+ import { BlockletMetaProps, SessionManagerProps } from '../types';
10
10
  import { mapRecursive, flatRecursive, matchPaths } from '../utils';
11
11
  import { publicPath, formatBlockletInfo, getLocalizedNavigation, filterNavByRole } from '../blocklets';
12
12
  import HeaderAddons from '../common/header-addons';
@@ -32,6 +32,7 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
32
32
  }
33
33
  }, [meta]);
34
34
  const { localizedNav, flattened, matchedIndex } = useMemo(() => {
35
+ // eslint-disable-next-line @typescript-eslint/no-shadow
35
36
  let localizedNav = getLocalizedNavigation(formattedBlocklet?.navigation?.dashboard, locale) || [];
36
37
  // 根据 role 筛选 nav 数据
37
38
  localizedNav = filterNavByRole(localizedNav, userRole);
@@ -49,7 +50,9 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
49
50
  'items'
50
51
  );
51
52
  // 展平后使用 matchPaths 检测 link#active 状态
53
+ // eslint-disable-next-line @typescript-eslint/no-shadow
52
54
  const flattened = flatRecursive(localizedNav).filter((item) => !!item.url);
55
+ // eslint-disable-next-line @typescript-eslint/no-shadow
53
56
  const matchedIndex = matchPaths(flattened.map((item) => item.url));
54
57
  if (matchedIndex !== -1) {
55
58
  flattened[matchedIndex].active = true;
@@ -84,6 +87,7 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
84
87
  return null;
85
88
  }
86
89
  const { appLogo, appLogoRect, appName } = formattedBlocklet;
90
+ // eslint-disable-next-line @typescript-eslint/naming-convention
87
91
  const _headerAddons = (
88
92
  <HeaderAddons
89
93
  formattedBlocklet={formattedBlocklet}
@@ -111,13 +115,13 @@ function Dashboard({ meta, fallbackUrl, invalidPathFallback, headerAddons, sessi
111
115
  }
112
116
 
113
117
  Dashboard.propTypes = {
114
- meta: blockletMetaProps,
118
+ meta: BlockletMetaProps,
115
119
  // 如果当前用户没有权限访问任何导航菜单, 则自动跳转到 fallbackUrl, 默认值为 publicPath, 设置为 null 表示禁用自动跳转
116
120
  fallbackUrl: PropTypes.string,
117
121
  // 当前路径未匹配任何 nav links 时的 fallback, 默认行为跳转到首个可用的 nav link
118
122
  invalidPathFallback: PropTypes.func,
119
123
  headerAddons: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
120
- sessionManagerProps,
124
+ sessionManagerProps: SessionManagerProps,
121
125
  links: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
122
126
  };
123
127
 
@@ -11,7 +11,7 @@ import OverridableThemeProvider from '../common/overridable-theme-provider';
11
11
  import InternalFooter from './internal-footer';
12
12
  import { mapRecursive } from '../utils';
13
13
  import { formatBlockletInfo, getLocalizedNavigation } from '../blocklets';
14
- import { blockletMetaProps } from '../types';
14
+ import { BlockletMetaProps } from '../types';
15
15
 
16
16
  /**
17
17
  * 专门用于 (composable) blocklet 的 Footer 组件, 基于 blocklet meta 中的数据渲染
@@ -72,7 +72,7 @@ function Footer({ meta, theme: themeOverrides, ...rest }) {
72
72
  }
73
73
 
74
74
  Footer.propTypes = {
75
- meta: blockletMetaProps,
75
+ meta: BlockletMetaProps,
76
76
  // 允许覆盖 footer 内置的 theme
77
77
  theme: PropTypes.object,
78
78
  };
@@ -11,7 +11,7 @@ import omit from 'lodash/omit';
11
11
 
12
12
  import Icon from '../Icon';
13
13
  import OverridableThemeProvider from '../common/overridable-theme-provider';
14
- import { blockletMetaProps, sessionManagerProps } from '../types';
14
+ import { BlockletMetaProps, SessionManagerProps } from '../types';
15
15
  import { mapRecursive, flatRecursive, matchPaths } from '../utils';
16
16
  import { publicPath, formatBlockletInfo, getLocalizedNavigation } from '../blocklets';
17
17
  import HeaderAddons from '../common/header-addons';
@@ -61,6 +61,7 @@ const parseNavigation = (navigation) => {
61
61
  * 专门用于 (composable) blocklet 的 Header 组件, 解析 blocklet meta 中的数据, 通过组合 UX 中的 Header & NavMenu 组件来渲染
62
62
  */
63
63
  // eslint-disable-next-line no-shadow
64
+
64
65
  function Header({ meta, addons, sessionManagerProps, homeLink, theme: themeOverrides, hideNavMenu, ...rest }) {
65
66
  useWalletHiddenTopbar();
66
67
  const { locale } = useLocaleContext() || {};
@@ -82,6 +83,7 @@ function Header({ meta, addons, sessionManagerProps, homeLink, theme: themeOverr
82
83
  const parsedNavigation = parseNavigation(navigation);
83
84
  const { navItems, activeId } = parsedNavigation;
84
85
 
86
+ // eslint-disable-next-line @typescript-eslint/naming-convention
85
87
  const _addons =
86
88
  typeof addons === 'function' ? (builtInAddons) => addons(builtInAddons, { navigation: parsedNavigation }) : addons;
87
89
  const headerAddons = (
@@ -116,14 +118,14 @@ function Header({ meta, addons, sessionManagerProps, homeLink, theme: themeOverr
116
118
  }
117
119
 
118
120
  Header.propTypes = {
119
- meta: blockletMetaProps,
121
+ meta: BlockletMetaProps,
120
122
 
121
123
  // 需要考虑 定制的 addons 与内置的 连接钱包/选择语言 addons 共存的情况
122
124
  // - PropTypes.func: 可以把自定义 addons 插在 session-manager 或 locale-selector (如果存在的话) 前/中/后
123
125
  // - PropTypes.node: 将 addons 原样传给 UX Header 组件
124
126
  addons: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
125
127
 
126
- sessionManagerProps,
128
+ sessionManagerProps: SessionManagerProps,
127
129
  homeLink: PropTypes.string,
128
130
  // 允许覆盖 header 内置的 theme
129
131
  theme: PropTypes.object,
@@ -8,6 +8,7 @@ import { isUrl, isIconifyString } from '../utils';
8
8
  * Icon 组件, 基于 mui Avatar 组件扩展对 iconify 的支持
9
9
  */
10
10
  export default function Icon({ icon, size, sx, ...rest }) {
11
+ // eslint-disable-next-line @typescript-eslint/naming-convention
11
12
  const _sx = [...(Array.isArray(sx) ? sx : [sx])];
12
13
  if (size) {
13
14
  _sx.push({ width: size, height: size });
@@ -10,13 +10,13 @@ import Toast from '@arcblock/ux/lib/Toast';
10
10
  import { getWalletDid } from '@arcblock/ux/lib/SessionUser/libs/utils';
11
11
  import { translate } from '@arcblock/ux/lib/Locale/util';
12
12
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
13
+ import { AxiosError } from 'axios';
13
14
 
14
15
  import { translations } from '../libs/locales';
15
16
  import WebhookItem from './webhook-item';
16
17
  import { User, WebhookItemData } from '../../@types';
17
18
  import { formatAxiosError } from '../libs/utils';
18
- import { client } from '../libs/client';
19
- import { AxiosError } from 'axios';
19
+ import { client } from '../../libs/client';
20
20
 
21
21
  export default function Notification({ user }: { user: User }) {
22
22
  const { locale } = useLocaleContext();
@@ -31,9 +31,8 @@ export default function Passport({ user, ...rest }: { user: User } & BoxProps) {
31
31
  }
32
32
  if (a.revoked) {
33
33
  return 1;
34
- } else {
35
- return -1;
36
34
  }
35
+ return -1;
37
36
  });
38
37
 
39
38
  return uniqBy(passportList, 'role');
@@ -8,7 +8,7 @@ import Toast from '@arcblock/ux/lib/Toast';
8
8
  import type { AxiosError } from 'axios';
9
9
 
10
10
  import { translations } from '../libs/locales';
11
- import { client } from '../libs/client';
11
+ import { client } from '../../libs/client';
12
12
  import { formatAxiosError } from '../libs/utils';
13
13
 
14
14
  type PrivacyConfig = {
@@ -4,12 +4,14 @@ 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
8
  import { ConfigUserSpaceProvider } from '../../contexts/config-user-space';
8
9
  import { translations } from '../libs/locales';
9
10
  import Notification from './notification';
10
11
  import Privacy from './privacy';
11
12
  import { User, UserCenterTab } from '../../@types';
12
13
  import DidSpace from './storage';
14
+ import { UserSessions } from '../../UserSessions';
13
15
 
14
16
  export default function Settings({
15
17
  user,
@@ -52,7 +54,16 @@ export default function Settings({
52
54
  user?.didSpace?.endpoint && {
53
55
  label: t('storageManagement'),
54
56
  value: 'storage',
55
- content: <ConfigUserSpaceProvider><DidSpace /></ConfigUserSpaceProvider>,
57
+ content: (
58
+ <ConfigUserSpaceProvider>
59
+ <DidSpace />
60
+ </ConfigUserSpaceProvider>
61
+ ),
62
+ },
63
+ {
64
+ label: t('sessionManagement'),
65
+ value: 'session',
66
+ content: <UserSessions user={user} />,
56
67
  },
57
68
  ].filter(Boolean);
58
69
  }, [user, privacyConfigList]);
@@ -73,7 +84,9 @@ export default function Settings({
73
84
  {...rest}
74
85
  sx={{
75
86
  ...rest?.sx,
76
- width: 520,
87
+ minWidth: {
88
+ md: 500,
89
+ },
77
90
  maxWidth: '100%',
78
91
  }}>
79
92
  <Tabs variant="card" tabs={tabs} current={currentTab.value} onChange={handleChangeTab} />
@@ -5,12 +5,17 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
5
5
  import DidConnect from '@arcblock/did-connect/lib/Connect';
6
6
  import { joinURL } from 'ufo';
7
7
  import toast from '@arcblock/ux/lib/Toast';
8
- import { func, string } from 'prop-types';
9
8
  import isEmpty from 'lodash/isEmpty';
10
- import {axios} from '../../libs/api';
9
+ import { axios } from '../../libs/api';
11
10
  import { SpaceGateway } from '../../../contexts/config-user-space';
12
11
 
13
- function ConnectTo({ onConnect, storageEndpoint, ...rest }: { onConnect: (spaceGateway: SpaceGateway) => Promise<void>, storageEndpoint: string}) {
12
+ function ConnectTo({
13
+ onConnect,
14
+ storageEndpoint,
15
+ }: {
16
+ onConnect: (spaceGateway: SpaceGateway) => Promise<void>;
17
+ storageEndpoint: string;
18
+ }) {
14
19
  const { t, locale } = useLocaleContext();
15
20
 
16
21
  const [authorizeFromNftConnect, setAuthorizeFromNftConnect] = useState({
@@ -18,8 +23,11 @@ function ConnectTo({ onConnect, storageEndpoint, ...rest }: { onConnect: (spaceG
18
23
  action: 'connect-to-did-spaces-for-user',
19
24
  checkTimeout: 1000 * 300,
20
25
  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,
26
+ checkFn: axios.create({
27
+ // FIXME: @jianchao 检查 env 的使用是否正确
28
+ // @ts-ignore
29
+ baseURL: joinURL(window.location.origin, window.env && window.env.apiPrefix ? window.env.apiPrefix : '/'),
30
+ }).get,
23
31
  extraParams: {},
24
32
  messages: {
25
33
  title: t('storage.spaces.provideNFT.title', { appName: window.blocklet.appName }, locale),
@@ -36,7 +44,6 @@ function ConnectTo({ onConnect, storageEndpoint, ...rest }: { onConnect: (spaceG
36
44
  },
37
45
  });
38
46
 
39
-
40
47
  const updateSpaceGateway = async (spaceGateway: SpaceGateway) => {
41
48
  await onConnect(spaceGateway);
42
49
  toast.success(t('storage.spaces.connectedWithName', { name: spaceGateway.name }));
@@ -73,24 +80,24 @@ function ConnectTo({ onConnect, storageEndpoint, ...rest }: { onConnect: (spaceG
73
80
  open: true,
74
81
  extraParams: {
75
82
  appDid: window.blocklet.appId,
76
- appName: window.blocklet.appName,
83
+ appName: window.blocklet.appName,
77
84
  appDescription: window.blocklet.appDescription,
78
85
  scopes: 'list:object read:object write:object',
79
86
  appUrl: window.blocklet.appUrl,
80
- referrer: window.location.href
87
+ referrer: window.location.href,
81
88
  },
82
89
  }));
83
90
  };
84
91
 
85
92
  return (
86
93
  <Box>
87
- <Button
94
+ <Button
88
95
  color="primary"
89
96
  style={{ textTransform: 'none !important', fontSize: '1rem' }}
90
97
  size="small"
91
98
  onClick={handleUseWalletConnect}
92
99
  variant="outlined">
93
- {storageEndpoint ? t('storage.spaces.connect.useWalletReconnect') : t('storage.spaces.connect.useWallet')}
100
+ {storageEndpoint ? t('storage.spaces.connect.useWalletReconnect') : t('storage.spaces.connect.useWallet')}
94
101
  </Button>
95
102
 
96
103
  {/* 为了获取 DID Spaces Url */}
@@ -109,7 +116,6 @@ function ConnectTo({ onConnect, storageEndpoint, ...rest }: { onConnect: (spaceG
109
116
  messages={authorizeFromNftConnect.messages}
110
117
  locale={locale}
111
118
  />
112
-
113
119
  </Box>
114
120
  );
115
121
  }
@@ -1,9 +1,15 @@
1
- import { Box, Typography } from '@mui/material';
2
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
- import SpaceItem from './item';
2
+ import { Box, Typography } from '@mui/material';
4
3
  import { SettingStorageEndpoint, SpaceGateway } from '../../../contexts/config-user-space';
4
+ import SpaceItem from './item';
5
5
 
6
- function Connected({ spaceGateway, settingStorageEndpoint }: {spaceGateway: SpaceGateway | undefined, settingStorageEndpoint: SettingStorageEndpoint }) {
6
+ function Connected({
7
+ spaceGateway,
8
+ settingStorageEndpoint,
9
+ }: {
10
+ spaceGateway: SpaceGateway | undefined;
11
+ settingStorageEndpoint: SettingStorageEndpoint;
12
+ }) {
7
13
  const { t } = useLocaleContext();
8
14
 
9
15
  return (
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import { IconButton } from '@mui/material';
3
3
  import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
4
4
  import Confirm from '@arcblock/ux/lib/Dialog/confirm';
@@ -6,7 +6,13 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
6
6
  import toast from '@arcblock/ux/lib/Toast';
7
7
  import { SpaceGateway } from '../../../contexts/config-user-space';
8
8
 
9
- function SpaceDelete({ spaceGateway, onDeleteSpace }: {spaceGateway: SpaceGateway, onDeleteSpace: (spaceGateway: SpaceGateway) => Promise<void> }) {
9
+ function SpaceDelete({
10
+ spaceGateway,
11
+ onDeleteSpace,
12
+ }: {
13
+ spaceGateway: SpaceGateway;
14
+ onDeleteSpace: (spaceGateway: SpaceGateway) => Promise<void>;
15
+ }) {
10
16
  const { t } = useLocaleContext();
11
17
  const [open, setOpen] = useState(false);
12
18
  const [loading, setLoading] = useState(false);
@@ -1,4 +1,5 @@
1
1
  import Center from '@arcblock/ux/lib/Center';
2
+ import { LocaleProvider } from '@arcblock/ux/lib/Locale/context';
2
3
  import styled from '@emotion/styled';
3
4
  import { Box, CircularProgress } from '@mui/material';
4
5
  import { useConfigUserSpaceContext } from '../../../contexts/config-user-space';
@@ -6,6 +7,7 @@ import useMobile from '../../../hooks/use-mobile';
6
7
  import ConnectTo from './connect-to';
7
8
  import Connected from './connected';
8
9
  import Disconnect from './disconnect';
10
+ import { translations } from '../../libs/locales';
9
11
 
10
12
  function DidSpace() {
11
13
  const isMobile = useMobile({});
@@ -21,21 +23,23 @@ function DidSpace() {
21
23
  }
22
24
 
23
25
  return (
24
- <Container>
25
- {/* 标题区 */}
26
+ <LocaleProvider translations={translations}>
27
+ <Container>
28
+ {/* 标题区 */}
26
29
 
27
- <Box maxWidth={isMobile ? '360px' : '720px'}>
28
- {hasStorageEndpoint ? (
29
- <Connected spaceGateway={spaceGateway} settingStorageEndpoint={settingStorageEndpoint} />
30
- ) : (
31
- <Disconnect />
32
- )}
33
- </Box>
30
+ <Box maxWidth={isMobile ? '360px' : '720px'}>
31
+ {hasStorageEndpoint ? (
32
+ <Connected spaceGateway={spaceGateway} settingStorageEndpoint={settingStorageEndpoint} />
33
+ ) : (
34
+ <Disconnect />
35
+ )}
36
+ </Box>
34
37
 
35
- <Box display="flex" alignItems="center" justifyContent="center" paddingTop="24px">
36
- <ConnectTo onConnect={updateSpaceGateway} storageEndpoint={storageEndpoint} />
37
- </Box>
38
- </Container>
38
+ <Box display="flex" alignItems="center" justifyContent="center" paddingTop="24px">
39
+ <ConnectTo onConnect={updateSpaceGateway} storageEndpoint={storageEndpoint} />
40
+ </Box>
41
+ </Container>
42
+ </LocaleProvider>
39
43
  );
40
44
  }
41
45
 
@@ -1,32 +1,25 @@
1
1
  import { Box, BoxProps, Chip, Typography } from '@mui/material';
2
2
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
3
- import toast from '@arcblock/ux/lib/Toast';
4
3
  import CheckIcon from '@mui/icons-material/Check';
5
4
  import styled from '@emotion/styled';
5
+ import DidAddress from '@arcblock/ux/lib/DID';
6
+
6
7
  // @ts-expect-error
7
8
  import SpacesConnectedSvg from './icons/space-connected.svg?react';
8
- import DidAddress from '@arcblock/ux/lib/DID';
9
- import PropTypes, { bool, func } from 'prop-types';
10
9
  import PreviewSpaceNft from './preview-nft';
11
10
  import { SpaceGateway } from '../../../contexts/config-user-space';
12
11
  import useMobile from '../../../hooks/use-mobile';
13
12
  import { getSpaceNftDisplayUrlFromEndpoint } from '../../../libs/spaces';
14
13
 
15
-
16
- function SpaceItem({ spaceGateway, connected, onDisconnect, ...rest }: {spaceGateway: SpaceGateway, connected: boolean, onDisconnect: Function} & BoxProps) {
14
+ function SpaceItem({
15
+ spaceGateway,
16
+ connected,
17
+ onDisconnect,
18
+ ...rest
19
+ }: { spaceGateway: SpaceGateway; connected: boolean; onDisconnect: Function } & BoxProps) {
17
20
  const isMobile = useMobile({});
18
21
  const { t } = useLocaleContext();
19
22
 
20
- const handleOnDisconnect = async () => {
21
- try {
22
- await onDisconnect();
23
- toast.success(t('storage.spaces.gateway.delete.succeeded', { name: spaceGateway.name }));
24
- } catch (error: any) {
25
- console.error(error);
26
- toast.error(error.message);
27
- }
28
- };
29
-
30
23
  return (
31
24
  <BoxContainer
32
25
  style={{
@@ -5,7 +5,7 @@ import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined';
5
5
  // @ts-expect-error
6
6
  import EmptySpacesNFT from './icons/empty-spaces-nft.svg?react';
7
7
 
8
- function PreviewSpaceNft({ src, alt }: {src: string, alt: string}) {
8
+ function PreviewSpaceNft({ src, alt }: { src: string; alt: string }) {
9
9
  const [showEmptySpaceNFT, setShowEmptySpaceNFT] = useState(false);
10
10
  const [open, setOpen] = useState(false);
11
11
 
@@ -16,17 +16,19 @@ import { ErrorFallback } from '@arcblock/ux/lib/ErrorBoundary';
16
16
  import cloneDeep from 'lodash/cloneDeep';
17
17
  import { getQuery, withQuery } from 'ufo';
18
18
  import type { AxiosError } from 'axios';
19
+ import type { UserPublicInfo } from '@blocklet/js-sdk';
19
20
 
20
- import { Header, Footer } from '../../';
21
+ import Footer from '../../Footer';
22
+ import Header from '../../Header';
21
23
  import { translations } from '../libs/locales';
22
24
  import UserInfo from './user-info';
23
25
  import UserBasicInfo from './user-basic-info';
24
- import type { SessionContext as TSessionContext, UserCenterTab } from '../../@types';
26
+ import type { SessionContext as TSessionContext, User, UserCenterTab } from '../../@types';
25
27
  // @ts-ignore
26
28
  import { formatBlockletInfo, getLocalizedNavigation } from '../../blocklets';
27
29
  import Passport from './passport';
28
30
  import Settings from './settings';
29
- import { client } from '../libs/client';
31
+ import { client } from '../../libs/client';
30
32
 
31
33
  export default function UserCenter({
32
34
  children,
@@ -37,7 +39,7 @@ export default function UserCenter({
37
39
  hideFooter = false,
38
40
  headerProps = {},
39
41
  footerProps = {},
40
- userDid,
42
+ userDid = undefined,
41
43
  stickySidebar = false,
42
44
  }: {
43
45
  readonly children: any;
@@ -46,8 +48,9 @@ export default function UserCenter({
46
48
  readonly disableAutoRedirect?: boolean;
47
49
  readonly autoPopupSetting?: boolean;
48
50
  readonly hideFooter?: boolean;
49
- readonly headerProps?: object;
50
- readonly footerProps?: object;
51
+ // FIXME: @zhanghan 将 header 和 footer 改为 ts 后,去掉这个 any
52
+ readonly headerProps?: any;
53
+ readonly footerProps?: any;
51
54
  readonly userDid?: string;
52
55
  readonly stickySidebar?: boolean;
53
56
  }) {
@@ -81,14 +84,15 @@ export default function UserCenter({
81
84
  return false;
82
85
  }, [currentDid, session?.user?.did]);
83
86
 
84
- const userState = useRequest(
87
+ const userState = useRequest<UserPublicInfo | User | undefined, []>(
88
+ // eslint-disable-next-line consistent-return
85
89
  async () => {
86
90
  await pWaitFor(() => session?.initialized);
87
91
  if (isMyself) {
88
- return session.user;
92
+ return session.user as User;
89
93
  }
90
94
  if (currentDid) {
91
- return await client.user.getUserPublicInfo({ did: currentDid });
95
+ return client.user.getUserPublicInfo({ did: currentDid });
92
96
  }
93
97
  },
94
98
  {
@@ -114,6 +118,7 @@ export default function UserCenter({
114
118
  sx: {
115
119
  '.MuiDialog-paper': {
116
120
  borderRadius: 2,
121
+ maxWidth: 1200,
117
122
  },
118
123
  '.ux-dialog_title': {
119
124
  fontWeight: 600,
@@ -174,7 +179,7 @@ export default function UserCenter({
174
179
  title: t('settings'),
175
180
  content: (
176
181
  <Settings
177
- user={userState.data}
182
+ user={userState.data as User}
178
183
  settings={{
179
184
  userCenterTabs,
180
185
  }}
@@ -258,7 +263,7 @@ export default function UserCenter({
258
263
  switchPassport={session.switchPassport}
259
264
  switchProfile={session.switchProfile}
260
265
  openSettings={openSettings}
261
- user={userState.data}
266
+ user={userState.data as User}
262
267
  showFullDid={false}
263
268
  sx={{
264
269
  display: {
@@ -294,12 +299,14 @@ export default function UserCenter({
294
299
  <CircularProgress sx={{ color: colors.primary100 }} />
295
300
  </Box>
296
301
  ) : (
302
+ // eslint-disable-next-line react/jsx-no-useless-fragment
297
303
  <>
298
304
  {currentActiveTab?.protected && !isMyself ? (
299
305
  <Box>
300
306
  <Empty>{t('underProtected')}</Empty>
301
307
  </Box>
302
308
  ) : (
309
+ // eslint-disable-next-line react/jsx-no-useless-fragment
303
310
  <>{children && <Box {...contentProps}>{children}</Box>}</>
304
311
  )}
305
312
  </>
@@ -355,7 +362,7 @@ export default function UserCenter({
355
362
  switchPassport={session.switchPassport}
356
363
  switchProfile={session.switchProfile}
357
364
  openSettings={openSettings}
358
- user={userState.data}
365
+ user={userState.data as User}
359
366
  sx={{
360
367
  display: {
361
368
  xs: 'none',
@@ -368,11 +375,11 @@ export default function UserCenter({
368
375
  <>
369
376
  <Box>
370
377
  <Typography sx={{ fontWeight: 600, mb: 1.5 }}>{t('myInfo')}</Typography>
371
- <UserInfo user={userState.data} />
378
+ <UserInfo user={userState.data as User} />
372
379
  </Box>
373
380
  <Box>
374
381
  <Typography sx={{ fontWeight: 600, mb: 1.5 }}>{t('passport')}</Typography>
375
- <Passport user={userState.data} />
382
+ <Passport user={userState.data as User} />
376
383
  </Box>
377
384
  </>
378
385
  ) : null}
@@ -6,7 +6,6 @@ import {
6
6
  InputAdornment,
7
7
  MenuItem,
8
8
  Select,
9
- Stack,
10
9
  TextField,
11
10
  Typography,
12
11
  } from '@mui/material';
@@ -75,6 +74,7 @@ export default function WebhookItem({
75
74
  onCancel();
76
75
  });
77
76
 
77
+ // eslint-disable-next-line @typescript-eslint/naming-convention
78
78
  const _onTest = useMemoizedFn(async (data) => {
79
79
  currentState.loading = true;
80
80
  await onTest(data);