@arcblock/ux 2.7.16 → 2.7.17
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/es/SessionManager/account-item.js +5 -4
- package/es/SessionManager/add-account-item.js +13 -31
- package/es/SessionManager/federated-login-detecter.js +32 -26
- package/es/SessionManager/index.js +44 -57
- package/es/SessionManager/manage-accounts.js +30 -17
- package/es/SessionManager/manage-blocklet.js +12 -4
- package/es/SessionManager/menu-accordion.js +14 -5
- package/es/SessionManager/translation.js +10 -10
- package/es/SessionManager/use-config.js +34 -0
- package/es/SessionManager/user-info.js +51 -43
- package/es/SessionManager/user-popper.js +1 -18
- package/es/Typography/index.js +89 -0
- package/es/Util/federated.js +65 -0
- package/lib/SessionManager/account-item.js +5 -4
- package/lib/SessionManager/add-account-item.js +14 -32
- package/lib/SessionManager/federated-login-detecter.js +33 -26
- package/lib/SessionManager/index.js +45 -58
- package/lib/SessionManager/manage-accounts.js +29 -16
- package/lib/SessionManager/manage-blocklet.js +12 -4
- package/lib/SessionManager/menu-accordion.js +14 -5
- package/lib/SessionManager/translation.js +10 -10
- package/lib/SessionManager/use-config.js +41 -0
- package/lib/SessionManager/user-info.js +50 -42
- package/lib/SessionManager/user-popper.js +1 -6
- package/lib/Typography/index.js +100 -0
- package/lib/Util/federated.js +85 -0
- package/package.json +8 -4
- package/src/SessionManager/account-item.jsx +6 -8
- package/src/SessionManager/add-account-item.jsx +12 -30
- package/src/SessionManager/federated-login-detecter.jsx +39 -26
- package/src/SessionManager/index.jsx +48 -68
- package/src/SessionManager/manage-accounts.jsx +27 -13
- package/src/SessionManager/manage-blocklet.jsx +8 -2
- package/src/SessionManager/menu-accordion.jsx +10 -3
- package/src/SessionManager/translation.js +10 -10
- package/src/SessionManager/use-config.js +33 -0
- package/src/SessionManager/user-info.jsx +34 -34
- package/src/SessionManager/user-popper.jsx +1 -16
- package/src/Typography/index.jsx +79 -0
- package/src/Util/federated.js +73 -0
- package/es/SessionManager/use-accounts.js +0 -19
- package/lib/SessionManager/use-accounts.js +0 -25
- package/src/SessionManager/use-accounts.js +0 -18
@@ -60,7 +60,8 @@ export default function AccountItem({
|
|
60
60
|
},
|
61
61
|
className: "session-manager-menu-item",
|
62
62
|
children: [/*#__PURE__*/_jsx(Avatar, {
|
63
|
-
did: account.did
|
63
|
+
did: account.did,
|
64
|
+
size: 42
|
64
65
|
}), /*#__PURE__*/_jsxs(Box, {
|
65
66
|
sx: {
|
66
67
|
flex: 1,
|
@@ -79,14 +80,14 @@ export default function AccountItem({
|
|
79
80
|
sx: {
|
80
81
|
lineHeight: 1
|
81
82
|
}
|
82
|
-
}), /*#__PURE__*/_jsxs(Typography, {
|
83
|
+
}), account.sourceAppPid && /*#__PURE__*/_jsxs(Typography, {
|
83
84
|
variant: "caption",
|
84
|
-
children: [t('from'), ' ',
|
85
|
+
children: [t('from'), ' ', /*#__PURE__*/_jsx(Link, {
|
85
86
|
href: account.appUrl,
|
86
87
|
target: "_blank",
|
87
88
|
underline: "none",
|
88
89
|
children: account.appName
|
89
|
-
})
|
90
|
+
})]
|
90
91
|
})]
|
91
92
|
}), /*#__PURE__*/_jsx(Box, {
|
92
93
|
className: "account-item-actions",
|
@@ -2,11 +2,11 @@ import { Icon } from '@iconify/react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
3
3
|
import { Menu, MenuItem, Typography } from '@mui/material';
|
4
4
|
import AddIcon from '@iconify-icons/ion/ios-add-circle-outline';
|
5
|
-
import isEmpty from 'lodash/isEmpty';
|
6
5
|
import { useCreation, useMemoizedFn, useReactive } from 'ahooks';
|
7
6
|
import { useRef } from 'react';
|
8
7
|
import { translate } from '../Locale/util';
|
9
8
|
import { translations } from './translation';
|
9
|
+
import { getCurrentApp, getFederatedApp } from '../Util/federated';
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
11
11
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
12
12
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
@@ -27,36 +27,16 @@ export default function AddAccountItem({
|
|
27
27
|
return appList;
|
28
28
|
}
|
29
29
|
const blocklet = window?.blocklet;
|
30
|
-
|
31
|
-
|
30
|
+
const masterApp = getFederatedApp(blocklet);
|
31
|
+
const currentApp = getCurrentApp(blocklet);
|
32
|
+
if (currentApp) {
|
33
|
+
appList.push(currentApp);
|
32
34
|
}
|
33
|
-
|
34
|
-
|
35
|
-
appName: blocklet.appName,
|
36
|
-
appDescription: blocklet.appDescription,
|
37
|
-
appLogo: blocklet.appLogo,
|
38
|
-
appPid: blocklet.appPid,
|
39
|
-
appUrl: blocklet.appUrl,
|
40
|
-
version: blocklet.version,
|
41
|
-
provider: 'wallet'
|
42
|
-
};
|
43
|
-
appList.push(currentApp);
|
44
|
-
const isFederatedMember = !isEmpty(blocklet.settings?.federated?.master);
|
45
|
-
if (isFederatedMember) {
|
46
|
-
const federatedMaster = blocklet.settings.federated.master;
|
47
|
-
const masterApp = {
|
48
|
-
appId: federatedMaster.appId,
|
49
|
-
appName: federatedMaster.appName,
|
50
|
-
appDescription: federatedMaster.appDescription,
|
51
|
-
appLogo: federatedMaster.appLogo,
|
52
|
-
appPid: federatedMaster.appPid,
|
53
|
-
appUrl: federatedMaster.appUrl,
|
54
|
-
version: federatedMaster.version,
|
55
|
-
provider: 'federated'
|
56
|
-
};
|
57
|
-
return [masterApp, currentApp];
|
35
|
+
if (masterApp && masterApp?.appId !== currentApp?.appId) {
|
36
|
+
appList.push(masterApp);
|
58
37
|
}
|
59
|
-
|
38
|
+
// NOTICE: masterApp 应该排在前面
|
39
|
+
return appList.reverse();
|
60
40
|
}, [window.blocklet]);
|
61
41
|
const _onAdd = useMemoizedFn(() => {
|
62
42
|
if (apps.length <= 1) {
|
@@ -101,9 +81,11 @@ export default function AddAccountItem({
|
|
101
81
|
vertical: 'top',
|
102
82
|
horizontal: 'left'
|
103
83
|
},
|
104
|
-
children: apps.map(app => /*#__PURE__*/
|
84
|
+
children: apps.map(app => /*#__PURE__*/_jsx(MenuItem, {
|
105
85
|
onClick: () => onAdd(app),
|
106
|
-
children:
|
86
|
+
children: t('connectWithAccount', {
|
87
|
+
name: app.appName
|
88
|
+
})
|
107
89
|
}, app.appId))
|
108
90
|
}) : null]
|
109
91
|
});
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import PropTypes from 'prop-types';
|
2
|
-
import { useCallback
|
2
|
+
import { useCallback } from 'react';
|
3
3
|
import Box from '@mui/material/Box';
|
4
4
|
import Chip from '@mui/material/Chip';
|
5
5
|
import Divider from '@mui/material/Divider';
|
6
6
|
import ShieldCheckIcon from '@iconify-icons/mdi/shield-check';
|
7
7
|
import { Icon } from '@iconify/react';
|
8
|
+
import { useCreation, useReactive } from 'ahooks';
|
8
9
|
import UserPopper from './user-popper';
|
9
10
|
import DidAvatar from '../Avatar';
|
10
11
|
import DidAddress from '../Address';
|
@@ -46,9 +47,12 @@ export default function FederatedLoginDetecter({
|
|
46
47
|
dark,
|
47
48
|
locale: _locale
|
48
49
|
}) {
|
49
|
-
const
|
50
|
-
|
51
|
-
|
50
|
+
const state = useReactive({
|
51
|
+
open: true
|
52
|
+
});
|
53
|
+
const federatedMaster = useCreation(() => {
|
54
|
+
return session.federatedMaster;
|
55
|
+
}, [session?.federatedMaster]);
|
52
56
|
const localeList = Object.keys(translations);
|
53
57
|
const locale = localeList.includes(_locale) ? _locale : localeList[0];
|
54
58
|
const onLoginFederated = useCallback(() => {
|
@@ -56,37 +60,39 @@ export default function FederatedLoginDetecter({
|
|
56
60
|
if (err) {
|
57
61
|
Toast.error(err || translations[_locale].loginFederatedFailed);
|
58
62
|
} else {
|
59
|
-
|
63
|
+
state.open = false;
|
60
64
|
}
|
61
65
|
}, {
|
62
|
-
|
63
|
-
mode:
|
66
|
+
sourceAppPid: federatedMaster?.site?.appPid,
|
67
|
+
mode: federatedMaster?.user ? 'auto' : 'manual'
|
64
68
|
});
|
65
|
-
}, [session,
|
69
|
+
}, [session, federatedMaster?.site?.appPid, federatedMaster?.user, _locale, state]);
|
66
70
|
let appLogoUrl;
|
67
|
-
if (
|
68
|
-
appLogoUrl = new URL(
|
71
|
+
if (federatedMaster?.site) {
|
72
|
+
appLogoUrl = new URL(federatedMaster.site.appLogo, federatedMaster.site.appUrl);
|
69
73
|
appLogoUrl.searchParams.set('imageFilter', 'resize');
|
70
74
|
// HACK: 保持跟其他地方使用的尺寸一致,可以复用同一资源的缓存,减少网络请求
|
71
75
|
appLogoUrl.searchParams.set('w', '80');
|
72
76
|
appLogoUrl.searchParams.set('h', '80');
|
73
77
|
}
|
74
|
-
return
|
75
|
-
open:
|
78
|
+
return federatedMaster?.site && /*#__PURE__*/_jsx(UserPopper, {
|
79
|
+
open: state.open,
|
76
80
|
anchorEl: anchorEl,
|
77
81
|
dark: dark,
|
78
82
|
autoClose: false,
|
79
|
-
onClose: () =>
|
83
|
+
onClose: () => {
|
84
|
+
state.open = false;
|
85
|
+
},
|
80
86
|
children: /*#__PURE__*/_jsxs(Box, {
|
81
87
|
p: 2,
|
82
|
-
children: [
|
88
|
+
children: [federatedMaster.site && /*#__PURE__*/_jsxs(Box, {
|
83
89
|
display: "flex",
|
84
90
|
alignItems: "center",
|
85
91
|
children: [/*#__PURE__*/_jsx(Box, {
|
86
92
|
component: "img",
|
87
93
|
mr: 2,
|
88
94
|
src: appLogoUrl.href,
|
89
|
-
alt:
|
95
|
+
alt: federatedMaster.site.appName,
|
90
96
|
width: "30px",
|
91
97
|
height: "30px"
|
92
98
|
}), /*#__PURE__*/_jsx(Box, {
|
@@ -96,7 +102,7 @@ export default function FederatedLoginDetecter({
|
|
96
102
|
children: translations[locale].useToConnect({
|
97
103
|
master: /*#__PURE__*/_jsx(Box, {
|
98
104
|
component: "a",
|
99
|
-
href:
|
105
|
+
href: federatedMaster.site.appUrl,
|
100
106
|
target: "_blank",
|
101
107
|
sx: {
|
102
108
|
textDecoration: 'none',
|
@@ -104,22 +110,22 @@ export default function FederatedLoginDetecter({
|
|
104
110
|
color: 'primary.main',
|
105
111
|
fontSize: '1.2em'
|
106
112
|
},
|
107
|
-
children:
|
113
|
+
children: federatedMaster.site.appName
|
108
114
|
}),
|
109
115
|
member: window.blocklet.appName
|
110
116
|
})
|
111
117
|
})]
|
112
|
-
}),
|
118
|
+
}), federatedMaster?.site && federatedMaster?.user && /*#__PURE__*/_jsx(Divider, {
|
113
119
|
style: {
|
114
120
|
margin: '15px 0 10px 0'
|
115
121
|
}
|
116
|
-
}),
|
122
|
+
}), federatedMaster?.user && /*#__PURE__*/_jsxs(Box, {
|
117
123
|
display: "flex",
|
118
124
|
alignItems: "center",
|
119
125
|
children: [/*#__PURE__*/_jsx(DidAvatar, {
|
120
126
|
variant: "circle",
|
121
|
-
did:
|
122
|
-
src: getUserAvatar(
|
127
|
+
did: federatedMaster.user.did,
|
128
|
+
src: getUserAvatar(federatedMaster.user.avatar),
|
123
129
|
size: 28,
|
124
130
|
shape: "circle"
|
125
131
|
}), /*#__PURE__*/_jsxs(Box, {
|
@@ -130,9 +136,9 @@ export default function FederatedLoginDetecter({
|
|
130
136
|
alignItems: "center",
|
131
137
|
children: [/*#__PURE__*/_jsx(Box, {
|
132
138
|
fontSize: 18,
|
133
|
-
children:
|
134
|
-
}),
|
135
|
-
label:
|
139
|
+
children: federatedMaster.user.fullName
|
140
|
+
}), federatedMaster.user.role?.toUpperCase() && /*#__PURE__*/_jsx(Chip, {
|
141
|
+
label: federatedMaster.user.role?.toUpperCase(),
|
136
142
|
size: "small",
|
137
143
|
variant: "outlined",
|
138
144
|
sx: {
|
@@ -147,10 +153,10 @@ export default function FederatedLoginDetecter({
|
|
147
153
|
})]
|
148
154
|
}), /*#__PURE__*/_jsx(DidAddress, {
|
149
155
|
responsive: false,
|
150
|
-
children:
|
156
|
+
children: federatedMaster.user.did
|
151
157
|
})]
|
152
158
|
})]
|
153
|
-
}),
|
159
|
+
}), federatedMaster?.site && /*#__PURE__*/_jsx(Box, {
|
154
160
|
display: "flex",
|
155
161
|
justifyContent: "center",
|
156
162
|
mt: 2,
|
@@ -2,11 +2,10 @@
|
|
2
2
|
/* eslint-disable react/jsx-no-bind */
|
3
3
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
4
4
|
import PropTypes from 'prop-types';
|
5
|
-
import { Box, IconButton, MenuList,
|
5
|
+
import { Box, IconButton, MenuList, Button, CircularProgress, Divider } from '@mui/material';
|
6
6
|
import AccountIcon from '@arcblock/icons/lib/Account';
|
7
|
-
import DisconnectIcon from '@arcblock/icons/lib/Disconnect';
|
8
7
|
import noop from 'lodash/noop';
|
9
|
-
import
|
8
|
+
import cloneDeep from 'lodash/cloneDeep';
|
10
9
|
import { useLatest, useMemoizedFn } from 'ahooks';
|
11
10
|
import DidAvatar from '../Avatar';
|
12
11
|
import { getUserAvatar, sleep } from '../Util';
|
@@ -18,7 +17,8 @@ import ManageAccounts from './manage-accounts';
|
|
18
17
|
import ManageBlocklet from './manage-blocklet';
|
19
18
|
import { translations } from './translation';
|
20
19
|
import { getConnectedAccounts, getSourceProvider } from './utils';
|
21
|
-
import
|
20
|
+
import useConfig from './use-config';
|
21
|
+
import { getCurrentApp, getFederatedApp } from '../Util/federated';
|
22
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
23
23
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
24
24
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
@@ -41,12 +41,15 @@ function SessionManager({
|
|
41
41
|
menuRender,
|
42
42
|
dark,
|
43
43
|
size,
|
44
|
+
showManageBlocklet,
|
44
45
|
...rest
|
45
46
|
}) {
|
46
47
|
const latestSession = useLatest(session);
|
47
48
|
const {
|
48
|
-
connectAccount
|
49
|
-
|
49
|
+
connectAccount,
|
50
|
+
config,
|
51
|
+
setConfig
|
52
|
+
} = useConfig();
|
50
53
|
const t = useMemoizedFn((key, data = {}) => {
|
51
54
|
return translate(translations, key, locale, 'en', data);
|
52
55
|
});
|
@@ -64,8 +67,6 @@ function SessionManager({
|
|
64
67
|
const isFirstLoading = useMemo(() => {
|
65
68
|
return session?.initialized === false && session?.loading === true;
|
66
69
|
}, [session?.initialized, session?.loading]);
|
67
|
-
|
68
|
-
// const federatedAccount = connectedAccounts.find((item) => item.provider === 'federated');
|
69
70
|
let hasBindWallet = false;
|
70
71
|
let hasBindAccount = false;
|
71
72
|
if (isRawWalletAccount) {
|
@@ -87,37 +88,18 @@ function SessionManager({
|
|
87
88
|
return;
|
88
89
|
}
|
89
90
|
const blocklet = window?.blocklet;
|
90
|
-
|
91
|
-
|
91
|
+
const currentApp = getCurrentApp(blocklet);
|
92
|
+
const masterApp = getFederatedApp(blocklet);
|
93
|
+
const targetApp = latestSession.current.user.sourceAppPid ? masterApp : currentApp;
|
94
|
+
if (targetApp) {
|
95
|
+
const loginAccount = {
|
96
|
+
did: latestSession.current.user.did,
|
97
|
+
avatar: latestSession.current.user.avatar,
|
98
|
+
provider: latestSession.current.provider,
|
99
|
+
...targetApp
|
100
|
+
};
|
101
|
+
connectAccount(loginAccount);
|
92
102
|
}
|
93
|
-
const currentApp = {
|
94
|
-
appId: blocklet.appId,
|
95
|
-
appPid: blocklet.appPid,
|
96
|
-
appName: blocklet.appName,
|
97
|
-
appDescription: blocklet.appDescription,
|
98
|
-
appLogo: blocklet.appLogo,
|
99
|
-
appUrl: blocklet.appUrl,
|
100
|
-
version: blocklet.version,
|
101
|
-
provider: 'wallet'
|
102
|
-
};
|
103
|
-
const federatedMaster = blocklet.settings?.federated?.master;
|
104
|
-
const masterApp = isEmpty(federatedMaster) ? null : {
|
105
|
-
appId: federatedMaster.appId,
|
106
|
-
appName: federatedMaster.appName,
|
107
|
-
appDescription: federatedMaster.appDescription,
|
108
|
-
appLogo: federatedMaster.appLogo,
|
109
|
-
appPid: federatedMaster.appPid,
|
110
|
-
appUrl: federatedMaster.appUrl,
|
111
|
-
version: federatedMaster.version,
|
112
|
-
provider: 'federated'
|
113
|
-
};
|
114
|
-
const loginAccount = {
|
115
|
-
did: latestSession.current.user.did,
|
116
|
-
avatar: latestSession.current.user.avatar,
|
117
|
-
provider: latestSession.current.provider,
|
118
|
-
...(latestSession.current.provider === 'federated' ? masterApp : currentApp)
|
119
|
-
};
|
120
|
-
connectAccount(loginAccount);
|
121
103
|
});
|
122
104
|
|
123
105
|
// HACK: 用于处理 统一登录 的自动登录情况,添加一个已连接的账号
|
@@ -236,7 +218,7 @@ function SessionManager({
|
|
236
218
|
user,
|
237
219
|
provider
|
238
220
|
} = session;
|
239
|
-
if (
|
221
|
+
if (['auth0'].includes(provider)) {
|
240
222
|
switchOAuthPassport(user);
|
241
223
|
} else {
|
242
224
|
close();
|
@@ -278,7 +260,7 @@ function SessionManager({
|
|
278
260
|
session: session,
|
279
261
|
size: size,
|
280
262
|
locale: locale,
|
281
|
-
|
263
|
+
onSwitchProfile: () => {
|
282
264
|
close();
|
283
265
|
_onSwitchProfile();
|
284
266
|
},
|
@@ -296,22 +278,25 @@ function SessionManager({
|
|
296
278
|
onSwitchDid: onSwitchDid,
|
297
279
|
connectAccount: _connectAccount,
|
298
280
|
close: close,
|
299
|
-
hasBindAccount: hasBindAccount
|
300
|
-
|
281
|
+
hasBindAccount: hasBindAccount,
|
282
|
+
onLogout: _onLogout,
|
283
|
+
expanded: config.expandAccount,
|
284
|
+
onExpand: value => {
|
285
|
+
const cloneConfig = cloneDeep(config);
|
286
|
+
cloneConfig.expandAccount = value;
|
287
|
+
setConfig(cloneConfig);
|
288
|
+
}
|
289
|
+
}), showManageBlocklet ? [/*#__PURE__*/_jsx(Divider, {}, "divider"), /*#__PURE__*/_jsx(ManageBlocklet, {
|
301
290
|
menu: menu,
|
302
291
|
menuRender: menuRender,
|
303
|
-
locale: locale
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
component: DisconnectIcon,
|
312
|
-
className: "session-manager-menu-icon"
|
313
|
-
}), t('disconnect')]
|
314
|
-
})]
|
292
|
+
locale: locale,
|
293
|
+
expanded: config.expandBlocklet,
|
294
|
+
onExpand: value => {
|
295
|
+
const cloneConfig = cloneDeep(config);
|
296
|
+
cloneConfig.expandBlocklet = value;
|
297
|
+
setConfig(cloneConfig);
|
298
|
+
}
|
299
|
+
}, "manageBlocklet")] : null]
|
315
300
|
})
|
316
301
|
})]
|
317
302
|
});
|
@@ -319,7 +304,7 @@ function SessionManager({
|
|
319
304
|
SessionManager.propTypes = {
|
320
305
|
session: PropTypes.shape({
|
321
306
|
federatedMaster: PropTypes.object,
|
322
|
-
provider: PropTypes.oneOf(['wallet', '
|
307
|
+
provider: PropTypes.oneOf(['wallet', 'auth0', '']),
|
323
308
|
user: PropTypes.shape({
|
324
309
|
did: PropTypes.string.isRequired,
|
325
310
|
role: PropTypes.string.isRequired,
|
@@ -363,7 +348,8 @@ SessionManager.propTypes = {
|
|
363
348
|
menu: PropTypes.array,
|
364
349
|
menuRender: PropTypes.func,
|
365
350
|
dark: PropTypes.bool,
|
366
|
-
size: PropTypes.number
|
351
|
+
size: PropTypes.number,
|
352
|
+
showManageBlocklet: PropTypes.bool
|
367
353
|
};
|
368
354
|
SessionManager.defaultProps = {
|
369
355
|
locale: 'en',
|
@@ -382,6 +368,7 @@ SessionManager.defaultProps = {
|
|
382
368
|
onSwitchPassport: noop,
|
383
369
|
onBindWallet: noop,
|
384
370
|
dark: false,
|
385
|
-
size: 24
|
371
|
+
size: 24,
|
372
|
+
showManageBlocklet: true
|
386
373
|
};
|
387
374
|
export default SessionManager;
|
@@ -1,10 +1,11 @@
|
|
1
1
|
/* eslint-disable react/prop-types */
|
2
2
|
/* eslint-disable react/jsx-no-bind */
|
3
3
|
import { useMemoizedFn, useUpdate } from 'ahooks';
|
4
|
-
import { MenuItem } from '@mui/material';
|
4
|
+
import { MenuItem, SvgIcon } from '@mui/material';
|
5
5
|
import { Icon } from '@iconify/react';
|
6
6
|
import AccountIcon from '@arcblock/icons/lib/Account';
|
7
7
|
import LinkIcon from '@iconify-icons/mdi/link';
|
8
|
+
import DisconnectIcon from '@arcblock/icons/lib/Disconnect';
|
8
9
|
import AccountItem from './account-item';
|
9
10
|
import MenuAccordion from './menu-accordion';
|
10
11
|
import { translations } from './translation';
|
@@ -12,7 +13,7 @@ import { translate } from '../Locale/util';
|
|
12
13
|
import { useConfirm } from '../Dialog/confirm';
|
13
14
|
import { getSourceProvider } from './utils';
|
14
15
|
import AddAccountItem from './add-account-item';
|
15
|
-
import
|
16
|
+
import useConfig from './use-config';
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
17
18
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
18
19
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
@@ -23,7 +24,11 @@ export default function ManageAccounts({
|
|
23
24
|
onSwitchDid,
|
24
25
|
connectAccount,
|
25
26
|
close,
|
26
|
-
hasBindAccount
|
27
|
+
hasBindAccount,
|
28
|
+
disableLogout,
|
29
|
+
onLogout,
|
30
|
+
expanded,
|
31
|
+
onExpand
|
27
32
|
}) {
|
28
33
|
const {
|
29
34
|
bindOAuth,
|
@@ -37,9 +42,9 @@ export default function ManageAccounts({
|
|
37
42
|
confirmHolder
|
38
43
|
} = useConfirm();
|
39
44
|
const {
|
40
|
-
|
41
|
-
|
42
|
-
} =
|
45
|
+
deleteAccount,
|
46
|
+
config
|
47
|
+
} = useConfig();
|
43
48
|
const update = useUpdate();
|
44
49
|
const onChoose = useMemoizedFn((account, {
|
45
50
|
active
|
@@ -53,7 +58,7 @@ export default function ManageAccounts({
|
|
53
58
|
onSwitchDid(...args);
|
54
59
|
}, {
|
55
60
|
provider: account.provider,
|
56
|
-
|
61
|
+
sourceAppPid: account.sourceAppPid
|
57
62
|
});
|
58
63
|
});
|
59
64
|
const oauthConfigList = Object.entries(oauthConfigs).map(([key, value]) => {
|
@@ -75,11 +80,7 @@ export default function ManageAccounts({
|
|
75
80
|
confirmButtonText: t('confirm'),
|
76
81
|
cancelButtonText: t('cancel'),
|
77
82
|
onConfirm(done) {
|
78
|
-
|
79
|
-
if (findIndex >= 0) {
|
80
|
-
accounts.splice(findIndex, 1);
|
81
|
-
}
|
82
|
-
setAccounts(accounts);
|
83
|
+
deleteAccount(account);
|
83
84
|
update();
|
84
85
|
done();
|
85
86
|
}
|
@@ -92,8 +93,8 @@ export default function ManageAccounts({
|
|
92
93
|
update();
|
93
94
|
onSwitchDid(...args);
|
94
95
|
}, {
|
95
|
-
|
96
|
-
|
96
|
+
sourceAppPid: app.sourceAppPid,
|
97
|
+
provider: app.provider
|
97
98
|
});
|
98
99
|
});
|
99
100
|
function _onBindWallet() {
|
@@ -107,6 +108,8 @@ export default function ManageAccounts({
|
|
107
108
|
}
|
108
109
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
109
110
|
children: [/*#__PURE__*/_jsxs(MenuAccordion, {
|
111
|
+
expanded: expanded,
|
112
|
+
onChange: onExpand,
|
110
113
|
locale: locale,
|
111
114
|
title: /*#__PURE__*/_jsxs(_Fragment, {
|
112
115
|
children: [/*#__PURE__*/_jsx(AccountIcon, {
|
@@ -115,9 +118,9 @@ export default function ManageAccounts({
|
|
115
118
|
width: 24,
|
116
119
|
height: 24
|
117
120
|
}
|
118
|
-
}), t('
|
121
|
+
}), t('accounts')]
|
119
122
|
}),
|
120
|
-
children: [accounts.map(item => /*#__PURE__*/_jsx(AccountItem, {
|
123
|
+
children: [config.accounts.map(item => /*#__PURE__*/_jsx(AccountItem, {
|
121
124
|
account: item,
|
122
125
|
locale: locale,
|
123
126
|
active: session.user.did === item.did,
|
@@ -126,7 +129,7 @@ export default function ManageAccounts({
|
|
126
129
|
}, item.did)), /*#__PURE__*/_jsx(AddAccountItem, {
|
127
130
|
locale: locale,
|
128
131
|
onAdd: onAdd
|
129
|
-
}), oauthConfigList.length > 0 && !hasBindAccount &&
|
132
|
+
}), oauthConfigList.length > 0 && !hasBindAccount && /*#__PURE__*/_jsxs(MenuItem, {
|
130
133
|
className: "session-manager-menu-item",
|
131
134
|
onClick: _onBindWallet,
|
132
135
|
"aria-label": !isRawWalletAccount ? `${t('bind')}DID Wallet` : `${t('bind')}${t('thirdParty')}`,
|
@@ -137,6 +140,16 @@ export default function ManageAccounts({
|
|
137
140
|
height: 24,
|
138
141
|
className: "session-manager-menu-icon"
|
139
142
|
}), !isRawWalletAccount ? `${t('bind')}DID Wallet` : `${t('bind')}${t('thirdParty')}`]
|
143
|
+
}), /*#__PURE__*/_jsxs(MenuItem, {
|
144
|
+
className: "session-manager-menu-item",
|
145
|
+
onClick: onLogout,
|
146
|
+
disabled: disableLogout,
|
147
|
+
"aria-label": "Logout account",
|
148
|
+
"data-cy": "sessionManager-logout-trigger",
|
149
|
+
children: [/*#__PURE__*/_jsx(SvgIcon, {
|
150
|
+
component: DisconnectIcon,
|
151
|
+
className: "session-manager-menu-icon"
|
152
|
+
}), t('disconnect')]
|
140
153
|
})]
|
141
154
|
}), confirmHolder]
|
142
155
|
});
|
@@ -13,20 +13,24 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
export default function ManageBlocklet({
|
14
14
|
menu,
|
15
15
|
menuRender,
|
16
|
-
locale
|
16
|
+
locale,
|
17
|
+
expanded,
|
18
|
+
onExpand
|
17
19
|
}) {
|
18
20
|
const t = useMemoizedFn((key, data = {}) => {
|
19
21
|
return translate(translations, key, locale, 'en', data);
|
20
22
|
});
|
21
23
|
return /*#__PURE__*/_jsxs(MenuAccordion, {
|
24
|
+
expanded: expanded,
|
22
25
|
locale: locale,
|
26
|
+
onChange: onExpand,
|
23
27
|
title: /*#__PURE__*/_jsxs(_Fragment, {
|
24
28
|
children: [/*#__PURE__*/_jsx(Icon, {
|
25
29
|
icon: AppsIcon,
|
26
30
|
width: 24,
|
27
31
|
height: 24,
|
28
32
|
className: "session-manager-menu-icon"
|
29
|
-
}), t('
|
33
|
+
}), t('blocklet')]
|
30
34
|
}),
|
31
35
|
children: [Array.isArray(menu) && menu.map((menuItem, index) => {
|
32
36
|
const {
|
@@ -54,9 +58,13 @@ export default function ManageBlocklet({
|
|
54
58
|
ManageBlocklet.propTypes = {
|
55
59
|
menu: PropTypes.array,
|
56
60
|
menuRender: PropTypes.func,
|
57
|
-
locale: PropTypes.string.isRequired
|
61
|
+
locale: PropTypes.string.isRequired,
|
62
|
+
expanded: PropTypes.bool,
|
63
|
+
onExpand: PropTypes.func
|
58
64
|
};
|
59
65
|
ManageBlocklet.defaultProps = {
|
60
66
|
menu: [],
|
61
|
-
menuRender: () => {}
|
67
|
+
menuRender: () => {},
|
68
|
+
expanded: true,
|
69
|
+
onExpand: () => {}
|
62
70
|
};
|
@@ -24,16 +24,21 @@ function isEmptyNode(node) {
|
|
24
24
|
export default function MenuAccordion({
|
25
25
|
title,
|
26
26
|
children,
|
27
|
-
locale
|
27
|
+
locale,
|
28
|
+
expanded,
|
29
|
+
onChange
|
28
30
|
}) {
|
29
31
|
const isEmptyChildren = useCreation(() => isEmptyNode(children), [children]);
|
30
32
|
const t = useMemoizedFn((key, data = {}) => {
|
31
33
|
return translate(translations, key, locale, 'en', data);
|
32
34
|
});
|
33
35
|
return /*#__PURE__*/_jsxs(Accordion, {
|
34
|
-
|
36
|
+
expanded: expanded,
|
35
37
|
disableGutters: true,
|
36
38
|
elevation: 0,
|
39
|
+
onChange: (e, value) => {
|
40
|
+
onChange(value);
|
41
|
+
},
|
37
42
|
sx: {
|
38
43
|
'&.MuiAccordion-root:before': {
|
39
44
|
content: 'unset'
|
@@ -50,7 +55,7 @@ export default function MenuAccordion({
|
|
50
55
|
paddingLeft: '30px',
|
51
56
|
'.session-manager-menu-item': {
|
52
57
|
fontSize: '15px',
|
53
|
-
padding: '12px
|
58
|
+
padding: '12px 15px',
|
54
59
|
whiteSpace: 'normal'
|
55
60
|
},
|
56
61
|
'.session-manager-menu-icon': {
|
@@ -88,8 +93,12 @@ export default function MenuAccordion({
|
|
88
93
|
MenuAccordion.propTypes = {
|
89
94
|
title: PropTypes.any.isRequired,
|
90
95
|
children: PropTypes.any.isRequired,
|
91
|
-
locale: PropTypes.string
|
96
|
+
locale: PropTypes.string,
|
97
|
+
expanded: PropTypes.bool,
|
98
|
+
onChange: PropTypes.func
|
92
99
|
};
|
93
100
|
MenuAccordion.defaultProps = {
|
94
|
-
locale: 'en'
|
101
|
+
locale: 'en',
|
102
|
+
expanded: true,
|
103
|
+
onChange: () => {}
|
95
104
|
};
|