@arcblock/ux 2.8.26 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/es/Address/did-address.js +33 -21
  2. package/es/AnimationWaiter/index.js +2 -1
  3. package/es/Avatar/index.js +1 -1
  4. package/es/BlockletContext/index.js +1 -1
  5. package/es/CardSelector/index.js +2 -1
  6. package/es/Colors/index.js +2 -1
  7. package/es/Colors/themes/temp.js +17 -0
  8. package/es/Datatable/TableSearch.js +2 -1
  9. package/es/Img/index.js +7 -6
  10. package/es/Locale/selector.js +15 -13
  11. package/es/NFTDisplay/index.js +2 -1
  12. package/es/QRCode/index.js +2 -1
  13. package/es/SessionBlocklet/index.js +169 -0
  14. package/es/SessionManager/index.js +2 -381
  15. package/es/SessionPermission/index.js +28 -0
  16. package/es/SessionUser/components/logged-in.js +224 -0
  17. package/es/SessionUser/components/session-user-item.js +148 -0
  18. package/es/SessionUser/components/session-user-switch.js +213 -0
  19. package/es/SessionUser/components/un-login.js +64 -0
  20. package/es/SessionUser/components/user-info.js +163 -0
  21. package/es/SessionUser/index.js +49 -0
  22. package/es/SessionUser/libs/translation.js +19 -0
  23. package/es/SessionUser/libs/utils.js +4 -0
  24. package/es/SplitButton/index.js +2 -1
  25. package/es/Toast/index.js +1 -1
  26. package/es/Util/constant.js +10 -0
  27. package/es/Util/index.js +11 -0
  28. package/lib/Address/did-address.js +36 -22
  29. package/lib/AnimationWaiter/index.js +2 -1
  30. package/lib/Avatar/index.js +1 -1
  31. package/lib/BlockletContext/index.js +1 -1
  32. package/lib/CardSelector/index.js +2 -1
  33. package/lib/Colors/index.js +7 -0
  34. package/lib/Colors/themes/temp.js +24 -0
  35. package/lib/Datatable/TableSearch.js +2 -1
  36. package/lib/Img/index.js +7 -6
  37. package/lib/Locale/selector.js +14 -13
  38. package/lib/NFTDisplay/index.js +2 -1
  39. package/lib/QRCode/index.js +2 -1
  40. package/lib/SessionBlocklet/index.js +187 -0
  41. package/lib/SessionManager/index.js +2 -390
  42. package/lib/SessionPermission/index.js +38 -0
  43. package/lib/SessionUser/components/logged-in.js +243 -0
  44. package/lib/SessionUser/components/session-user-item.js +163 -0
  45. package/lib/SessionUser/components/session-user-switch.js +232 -0
  46. package/lib/SessionUser/components/un-login.js +72 -0
  47. package/lib/SessionUser/components/user-info.js +175 -0
  48. package/lib/SessionUser/index.js +57 -0
  49. package/lib/SessionUser/libs/translation.js +26 -0
  50. package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
  51. package/lib/SplitButton/index.js +2 -1
  52. package/lib/Toast/index.js +5 -5
  53. package/lib/Util/constant.js +26 -0
  54. package/lib/Util/index.js +16 -3
  55. package/package.json +19 -7
  56. package/src/Address/did-address.jsx +34 -20
  57. package/src/AnimationWaiter/index.js +2 -1
  58. package/src/Avatar/index.jsx +1 -1
  59. package/src/BlockletContext/index.jsx +1 -1
  60. package/src/CardSelector/index.jsx +2 -1
  61. package/src/Colors/index.js +1 -0
  62. package/src/Colors/themes/temp.js +18 -0
  63. package/src/Datatable/TableSearch.js +3 -1
  64. package/src/Img/{index.js → index.jsx} +8 -6
  65. package/src/Locale/selector.jsx +11 -8
  66. package/src/NFTDisplay/index.js +2 -1
  67. package/src/QRCode/index.js +2 -1
  68. package/src/SessionBlocklet/index.jsx +181 -0
  69. package/src/SessionManager/index.jsx +2 -369
  70. package/src/SessionPermission/index.jsx +28 -0
  71. package/src/SessionUser/components/logged-in.jsx +194 -0
  72. package/src/SessionUser/components/session-user-item.jsx +96 -0
  73. package/src/SessionUser/components/session-user-switch.jsx +222 -0
  74. package/src/SessionUser/components/un-login.jsx +55 -0
  75. package/src/SessionUser/components/user-info.jsx +165 -0
  76. package/src/SessionUser/index.jsx +38 -0
  77. package/src/SessionUser/libs/translation.js +19 -0
  78. package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
  79. package/src/SplitButton/index.js +2 -1
  80. package/src/Toast/index.js +1 -1
  81. package/src/Util/constant.js +12 -0
  82. package/src/Util/index.js +13 -0
  83. package/es/SessionManager/components/account-item.js +0 -212
  84. package/es/SessionManager/components/add-account-item.js +0 -57
  85. package/es/SessionManager/components/federated-login-detecter.js +0 -183
  86. package/es/SessionManager/components/manage-accounts.js +0 -219
  87. package/es/SessionManager/components/manage-blocklet.js +0 -70
  88. package/es/SessionManager/components/menu-accordion.js +0 -103
  89. package/es/SessionManager/components/responsive-popper.js +0 -24
  90. package/es/SessionManager/components/user-drawer.js +0 -68
  91. package/es/SessionManager/components/user-info.js +0 -143
  92. package/es/SessionManager/components/user-popper.js +0 -110
  93. package/es/SessionManager/hooks/use-config.js +0 -34
  94. package/es/SessionManager/libs/translation.js +0 -52
  95. package/es/SessionManager/libs/utils.js +0 -2
  96. package/lib/SessionManager/components/account-item.js +0 -219
  97. package/lib/SessionManager/components/add-account-item.js +0 -66
  98. package/lib/SessionManager/components/federated-login-detecter.js +0 -193
  99. package/lib/SessionManager/components/manage-accounts.js +0 -232
  100. package/lib/SessionManager/components/manage-blocklet.js +0 -86
  101. package/lib/SessionManager/components/menu-accordion.js +0 -111
  102. package/lib/SessionManager/components/responsive-popper.js +0 -34
  103. package/lib/SessionManager/components/user-drawer.js +0 -75
  104. package/lib/SessionManager/components/user-info.js +0 -160
  105. package/lib/SessionManager/components/user-popper.js +0 -104
  106. package/lib/SessionManager/hooks/use-config.js +0 -41
  107. package/lib/SessionManager/libs/translation.js +0 -59
  108. package/src/SessionManager/components/account-item.jsx +0 -156
  109. package/src/SessionManager/components/add-account-item.jsx +0 -49
  110. package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
  111. package/src/SessionManager/components/manage-accounts.jsx +0 -228
  112. package/src/SessionManager/components/manage-blocklet.jsx +0 -70
  113. package/src/SessionManager/components/menu-accordion.jsx +0 -93
  114. package/src/SessionManager/components/responsive-popper.jsx +0 -26
  115. package/src/SessionManager/components/user-drawer.jsx +0 -57
  116. package/src/SessionManager/components/user-info.jsx +0 -117
  117. package/src/SessionManager/components/user-popper.jsx +0 -95
  118. package/src/SessionManager/hooks/use-config.js +0 -33
  119. package/src/SessionManager/libs/translation.js +0 -52
@@ -1,381 +1,2 @@
1
- /* eslint-disable react/prop-types */
2
- /* eslint-disable react/jsx-no-bind */
3
- import { useEffect, useMemo, useRef, useState } from 'react';
4
- import PropTypes from 'prop-types';
5
- import { Box, IconButton, MenuList, Button, CircularProgress, Divider } from '@mui/material';
6
- import AccountIcon from '@arcblock/icons/lib/Account';
7
- import noop from 'lodash/noop';
8
- import cloneDeep from 'lodash/cloneDeep';
9
- import { useLatest, useMemoizedFn } from 'ahooks';
10
- import DidAvatar from '../Avatar';
11
- import { getUserAvatar, sleep } from '../Util';
12
- import FederatedLoginDetecter from './components/federated-login-detecter';
13
- import UserInfo from './components/user-info';
14
- import ResponsivePopper from './components/responsive-popper';
15
- import { translate } from '../Locale/util';
16
- import ManageAccounts from './components/manage-accounts';
17
- import ManageBlocklet from './components/manage-blocklet';
18
- import { translations } from './libs/translation';
19
- import { getConnectedAccounts, getSourceProvider } from './libs/utils';
20
- import useConfig from './hooks/use-config';
21
- import { getCurrentApp, getFederatedApp } from '../Util/federated';
22
- import { jsx as _jsx } from "react/jsx-runtime";
23
- import { jsxs as _jsxs } from "react/jsx-runtime";
24
- import { Fragment as _Fragment } from "react/jsx-runtime";
25
- function SessionManager({
26
- session,
27
- locale,
28
- showText,
29
- showRole,
30
- switchDid,
31
- switchProfile,
32
- switchPassport,
33
- disableLogout,
34
- onLogin,
35
- onLogout,
36
- onSwitchDid,
37
- onSwitchProfile,
38
- onSwitchPassport,
39
- onBindWallet,
40
- menu,
41
- menuRender,
42
- dark,
43
- size,
44
- showManageBlocklet,
45
- ...rest
46
- }) {
47
- const latestSession = useLatest(session);
48
- const {
49
- connectAccount,
50
- config,
51
- setConfig,
52
- deleteAccount
53
- } = useConfig();
54
- const t = useMemoizedFn((key, data = {}) => {
55
- return translate(translations, key, locale, 'en', data);
56
- });
57
- const userAnchorRef = useRef(null);
58
- const {
59
- logoutOAuth,
60
- switchOAuthPassport
61
- } = session.useOAuth();
62
- const [userOpen, setUserOpen] = useState(false);
63
-
64
- // base64 img maybe have some blank char, need encodeURIComponent to transform it
65
- const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')));
66
- const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
67
- const connectedAccounts = getConnectedAccounts(session.user);
68
- const isFirstLoading = useMemo(() => {
69
- return session?.initialized === false && session?.loading === true;
70
- }, [session?.initialized, session?.loading]);
71
- let hasBindWallet = false;
72
- let hasBindAccount = false;
73
- if (isRawWalletAccount) {
74
- if (connectedAccounts.some(item => item.provider !== 'wallet')) {
75
- hasBindAccount = true;
76
- }
77
- hasBindWallet = true;
78
- } else if (connectedAccounts.some(item => item.provider === 'wallet')) {
79
- hasBindAccount = true;
80
- hasBindWallet = true;
81
- }
82
- const _connectAccount = useMemoizedFn(async () => {
83
- // HACK: 强制等待组件渲染一轮,以拿到最新的 session 值
84
- await sleep();
85
- if (!latestSession.current?.user) {
86
- return;
87
- }
88
- if (typeof window === 'undefined') {
89
- return;
90
- }
91
- const blocklet = window?.blocklet;
92
- const currentApp = getCurrentApp(blocklet);
93
- const masterApp = getFederatedApp(blocklet);
94
- const targetApp = latestSession.current.user.sourceAppPid ? masterApp : currentApp;
95
- if (targetApp) {
96
- const loginAccount = {
97
- ...targetApp,
98
- did: latestSession.current.user.did,
99
- avatar: latestSession.current.user.avatar,
100
- provider: latestSession.current.provider || targetApp.provider,
101
- walletOS: latestSession.current.walletOS
102
- };
103
- connectAccount(loginAccount);
104
- }
105
- });
106
-
107
- // HACK: 用于处理 统一登录 的自动登录情况,添加一个已连接的账号
108
- // 同时可用于以前的站点,会自动生成一个已连接的账号
109
- useEffect(() => {
110
- if (session.user) {
111
- _connectAccount();
112
- }
113
- // eslint-disable-next-line react-hooks/exhaustive-deps
114
- }, [session.user]);
115
- if (!session.user) {
116
- return /*#__PURE__*/_jsxs(_Fragment, {
117
- children: [showText ? /*#__PURE__*/_jsxs(Button, {
118
- ref: userAnchorRef,
119
- sx: [{
120
- borderRadius: '100vw'
121
- }, dark && {
122
- color: '#fff',
123
- borderColor: '#fff'
124
- }],
125
- variant: "outlined",
126
- onClick: _onLogin,
127
- role: "button",
128
- "aria-label": "Login button",
129
- ...rest,
130
- "data-cy": "sessionManager-login",
131
- children: [isFirstLoading ? /*#__PURE__*/_jsx(CircularProgress, {}) : /*#__PURE__*/_jsx(AccountIcon, {}), /*#__PURE__*/_jsx("span", {
132
- style: {
133
- lineHeight: '25px'
134
- },
135
- children: t('connect')
136
- })]
137
- }) : /*#__PURE__*/_jsx(IconButton, {
138
- ref: userAnchorRef,
139
- ...rest,
140
- onClick: _onLogin,
141
- "data-cy": "sessionManager-login",
142
- size: "medium",
143
- role: "button",
144
- "aria-label": "Login button",
145
- children: isFirstLoading ? /*#__PURE__*/_jsx(Box, {
146
- width: size,
147
- height: size,
148
- display: "flex",
149
- justifyContent: "center",
150
- alignItems: "center",
151
- children: /*#__PURE__*/_jsx(CircularProgress, {
152
- style: {
153
- width: size - 4,
154
- height: size - 4,
155
- color: dark ? '#fff' : ''
156
- }
157
- })
158
- }) : /*#__PURE__*/_jsx(AccountIcon, {
159
- style: {
160
- width: size,
161
- height: size,
162
- color: dark ? '#fff' : ''
163
- }
164
- })
165
- }), /*#__PURE__*/_jsx(FederatedLoginDetecter, {
166
- locale: locale,
167
- dark: dark,
168
- session: session,
169
- anchorEl: userAnchorRef.current
170
- })]
171
- });
172
- }
173
- function onToggleUser() {
174
- setUserOpen(prevOpen => !prevOpen);
175
- }
176
- function close() {
177
- setUserOpen(false);
178
- }
179
- function onCloseUser(e) {
180
- if (userAnchorRef.current && userAnchorRef.current.contains(e.target)) {
181
- return;
182
- }
183
- close();
184
- }
185
- function _onLogin() {
186
- if (!isFirstLoading) {
187
- session.login((...args) => {
188
- _connectAccount();
189
- onLogin(...args);
190
- });
191
- }
192
- }
193
- function _onLogout() {
194
- return new Promise((resolve, reject) => {
195
- logoutOAuth({
196
- session,
197
- hack: true
198
- }).catch(err => {
199
- console.error(err);
200
- reject(err);
201
- }).finally(() => {
202
- session.logout((...args) => {
203
- onLogout(...args);
204
- resolve();
205
- close();
206
- });
207
- });
208
- });
209
- }
210
- /**
211
- * @name 切换账户
212
- * @description 该功能仅在登录后才能使用,目前仅用于切换普通登录和统一登录的账户,所以会增加一些与统一登录相关的逻辑
213
- */
214
-
215
- function _onSwitchProfile() {
216
- session.switchProfile((...args) => {
217
- close();
218
- onSwitchProfile(...args);
219
- });
220
- }
221
- function _onSwitchPassport() {
222
- const {
223
- user,
224
- provider
225
- } = session;
226
- if (['auth0'].includes(provider)) {
227
- switchOAuthPassport(user);
228
- } else {
229
- close();
230
- session.switchPassport((...args) => {
231
- close();
232
- onSwitchPassport(...args);
233
- });
234
- }
235
- }
236
- return /*#__PURE__*/_jsxs(_Fragment, {
237
- children: [/*#__PURE__*/_jsx(IconButton, {
238
- ref: userAnchorRef,
239
- onClick: onToggleUser,
240
- ...rest,
241
- "data-cy": "sessionManager-logout-popup",
242
- size: "medium",
243
- role: "button",
244
- "aria-label": "User info button",
245
- style: {
246
- lineHeight: 1
247
- },
248
- children: /*#__PURE__*/_jsx(DidAvatar, {
249
- variant: "circle",
250
- did: session.user.did,
251
- src: avatar,
252
- size: size,
253
- shape: "circle"
254
- })
255
- }), /*#__PURE__*/_jsx(ResponsivePopper, {
256
- open: userOpen,
257
- onClose: onCloseUser,
258
- anchorEl: userAnchorRef.current,
259
- dark: dark,
260
- children: /*#__PURE__*/_jsxs(MenuList, {
261
- sx: {
262
- p: 0
263
- },
264
- children: [/*#__PURE__*/_jsx(UserInfo, {
265
- session: session,
266
- size: size,
267
- locale: locale,
268
- onSwitchProfile: () => {
269
- close();
270
- _onSwitchProfile();
271
- },
272
- onSwitchPassport: () => {
273
- close();
274
- _onSwitchPassport();
275
- },
276
- close: close,
277
- switchProfile: switchProfile,
278
- hasBindWallet: hasBindWallet
279
- }), /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(ManageAccounts, {
280
- session: session,
281
- locale: locale,
282
- onBindWallet: onBindWallet,
283
- onSwitchDid: onSwitchDid,
284
- connectAccount: _connectAccount,
285
- close: close,
286
- hasBindAccount: hasBindAccount,
287
- onLogout: _onLogout,
288
- expanded: config.expandAccount,
289
- onExpand: value => {
290
- const cloneConfig = cloneDeep(config);
291
- cloneConfig.expandAccount = value;
292
- setConfig(cloneConfig);
293
- },
294
- deleteAccount: deleteAccount,
295
- accounts: config.accounts
296
- }), showManageBlocklet ? [/*#__PURE__*/_jsx(Divider, {}, "divider"), /*#__PURE__*/_jsx(ManageBlocklet, {
297
- menu: menu,
298
- menuRender: menuRender,
299
- locale: locale,
300
- expanded: config.expandBlocklet,
301
- onExpand: value => {
302
- const cloneConfig = cloneDeep(config);
303
- cloneConfig.expandBlocklet = value;
304
- setConfig(cloneConfig);
305
- }
306
- }, "manageBlocklet")] : null]
307
- })
308
- })]
309
- });
310
- }
311
- SessionManager.propTypes = {
312
- session: PropTypes.shape({
313
- federatedMaster: PropTypes.object,
314
- provider: PropTypes.oneOf(['wallet', 'auth0', '']),
315
- user: PropTypes.shape({
316
- did: PropTypes.string.isRequired,
317
- role: PropTypes.string.isRequired,
318
- fullName: PropTypes.string,
319
- email: PropTypes.string,
320
- avatar: PropTypes.string,
321
- sourceProvider: PropTypes.string,
322
- connectedAccounts: PropTypes.arrayOf(PropTypes.shape({
323
- provider: PropTypes.string.isRequired,
324
- did: PropTypes.string.isRequired,
325
- id: PropTypes.string
326
- })),
327
- passports: PropTypes.arrayOf(PropTypes.shape({
328
- name: PropTypes.string.isRequired,
329
- title: PropTypes.string.isRequired
330
- })),
331
- // Deprecated
332
- extraConfigs: PropTypes.object
333
- }),
334
- login: PropTypes.func.isRequired,
335
- logout: PropTypes.func.isRequired,
336
- switchDid: PropTypes.func.isRequired,
337
- switchProfile: PropTypes.func.isRequired,
338
- switchPassport: PropTypes.func.isRequired,
339
- bindWallet: PropTypes.func.isRequired,
340
- refresh: PropTypes.func.isRequired
341
- }).isRequired,
342
- locale: PropTypes.string,
343
- showText: PropTypes.bool,
344
- showRole: PropTypes.bool,
345
- switchDid: PropTypes.bool,
346
- switchProfile: PropTypes.bool,
347
- switchPassport: PropTypes.bool,
348
- disableLogout: PropTypes.bool,
349
- onLogin: PropTypes.func,
350
- onLogout: PropTypes.func,
351
- onSwitchDid: PropTypes.func,
352
- onSwitchProfile: PropTypes.func,
353
- onSwitchPassport: PropTypes.func,
354
- onBindWallet: PropTypes.func,
355
- menu: PropTypes.array,
356
- menuRender: PropTypes.func,
357
- dark: PropTypes.bool,
358
- size: PropTypes.number,
359
- showManageBlocklet: PropTypes.bool
360
- };
361
- SessionManager.defaultProps = {
362
- locale: 'en',
363
- showText: false,
364
- showRole: false,
365
- switchDid: true,
366
- switchProfile: true,
367
- switchPassport: true,
368
- disableLogout: false,
369
- menu: [],
370
- menuRender: noop,
371
- onLogin: noop,
372
- onLogout: noop,
373
- onSwitchDid: noop,
374
- onSwitchProfile: noop,
375
- onSwitchPassport: noop,
376
- onBindWallet: noop,
377
- dark: false,
378
- size: 24,
379
- showManageBlocklet: true
380
- };
381
- export default SessionManager;
1
+ import SessionUser from '../SessionUser';
2
+ export default SessionUser;
@@ -0,0 +1,28 @@
1
+ import PropTypes from 'prop-types';
2
+ import { useCreation } from 'ahooks';
3
+ const roleList = ['owner', 'admin', 'member', 'guest'];
4
+ export default function SessionPermission({
5
+ session,
6
+ roles,
7
+ children
8
+ }) {
9
+ const hasPermission = useCreation(() => {
10
+ return roles.includes(session?.user?.role || 'guest');
11
+ }, [session?.user?.role, roles]);
12
+ if (typeof children === 'function') {
13
+ return children({
14
+ hasPermission
15
+ });
16
+ }
17
+ if (hasPermission) {
18
+ return children;
19
+ }
20
+ }
21
+ SessionPermission.propTypes = {
22
+ children: PropTypes.any.isRequired,
23
+ session: PropTypes.object.isRequired,
24
+ roles: PropTypes.arrayOf(PropTypes.oneOf(roleList))
25
+ };
26
+ SessionPermission.defaultProps = {
27
+ roles: ['owner', 'admin']
28
+ };
@@ -0,0 +1,224 @@
1
+ import PropTypes from 'prop-types';
2
+ import { useRef } from 'react';
3
+ import { useMemoizedFn, useReactive } from 'ahooks';
4
+ import { Box, ClickAwayListener, Divider, Fade, IconButton, MenuItem, MenuList, Paper, Popper } from '@mui/material';
5
+ import { Icon } from '@iconify/react';
6
+ import PersonOutlineRoundedIcon from '@iconify-icons/material-symbols/person-outline-rounded';
7
+ import FilterVintageOutlineRoundedIcon from '@iconify-icons/material-symbols/filter-vintage-outline-rounded';
8
+ import AccountCircleOffOutlineRoundedIcon from '@iconify-icons/material-symbols/account-circle-off-outline-rounded';
9
+ import noop from 'lodash/noop';
10
+ import DidAvatar from '../../Avatar';
11
+ import { getUserAvatar } from '../../Util';
12
+ import UserInfo from './user-info';
13
+ import { temp as colors } from '../../Colors';
14
+ import { DASHBOARD_URL, PROFILE_URL } from '../../Util/constant';
15
+ import SessionPermission from '../../SessionPermission';
16
+ import { translations } from '../libs/translation';
17
+ import { translate } from '../../Locale/util';
18
+ import { jsx as _jsx } from "react/jsx-runtime";
19
+ import { Fragment as _Fragment } from "react/jsx-runtime";
20
+ import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ export default function LoggedIn({
22
+ session,
23
+ dark,
24
+ onBindWallet,
25
+ isBlocklet,
26
+ locale,
27
+ size
28
+ }) {
29
+ const t = useMemoizedFn((key, data = {}) => {
30
+ return translate(translations, key, locale, 'en', data);
31
+ });
32
+ const popperAnchorRef = useRef(null);
33
+ const currentState = useReactive({
34
+ open: false
35
+ });
36
+ const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
37
+ currentState.open = value;
38
+ });
39
+ // base64 img maybe have some blank char, need encodeURIComponent to transform it
40
+ const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')));
41
+ const handleSwitchPassport = useMemoizedFn(() => {
42
+ onTogglePopper(false);
43
+ session.switchPassport();
44
+ });
45
+ const handleSwitchAccount = useMemoizedFn(({
46
+ userSession
47
+ } = {}) => {
48
+ return new Promise(resolve => {
49
+ const options = {};
50
+ if (!userSession) {
51
+ onTogglePopper(false);
52
+ options.showQuickConnect = false;
53
+ } else {
54
+ options.userSession = userSession;
55
+ }
56
+ session.switchDid(() => {
57
+ onTogglePopper(false);
58
+ resolve();
59
+ }, {}, options);
60
+ });
61
+ });
62
+ const handleSwitchProfile = useMemoizedFn(() => {
63
+ onTogglePopper(false);
64
+ session.switchProfile();
65
+ });
66
+ const onLogout = useMemoizedFn(() => {
67
+ onTogglePopper(false);
68
+ session.logout();
69
+ });
70
+ const handleBindWallet = useMemoizedFn(() => {
71
+ onTogglePopper(false);
72
+ session.bindWallet(onBindWallet);
73
+ });
74
+ return /*#__PURE__*/_jsxs(_Fragment, {
75
+ children: [/*#__PURE__*/_jsx(IconButton, {
76
+ ref: popperAnchorRef,
77
+ onClick: () => onTogglePopper(),
78
+ size: "medium",
79
+ "data-cy": "sessionManager-logout-popup",
80
+ "aria-label": "User info button",
81
+ children: /*#__PURE__*/_jsx(DidAvatar, {
82
+ variant: "circle",
83
+ did: session.user.did,
84
+ src: avatar,
85
+ size: size,
86
+ shape: "circle"
87
+ })
88
+ }), /*#__PURE__*/_jsx(Popper, {
89
+ open: currentState.open,
90
+ onClose: () => onTogglePopper(false),
91
+ anchorEl: popperAnchorRef.current,
92
+ dark: dark,
93
+ transition: true,
94
+ placement: "bottom-end",
95
+ sx: {
96
+ zIndex: 1600
97
+ },
98
+ children: ({
99
+ TransitionProps
100
+ }) => /*#__PURE__*/_jsx(ClickAwayListener, {
101
+ onClickAway: e => {
102
+ e.preventDefault();
103
+ e.stopPropagation();
104
+ onTogglePopper(false);
105
+ },
106
+ children: /*#__PURE__*/_jsx(Fade, {
107
+ ...TransitionProps,
108
+ timeout: 350,
109
+ children: /*#__PURE__*/_jsxs(Paper, {
110
+ variant: "outlined",
111
+ sx: {
112
+ borderRadius: 3,
113
+ width: 350,
114
+ maxWidth: '90vw',
115
+ borderColor: colors.lineStep,
116
+ border: '0 !important',
117
+ boxShadow: `0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6}`
118
+ },
119
+ children: [/*#__PURE__*/_jsx(UserInfo, {
120
+ locale: locale,
121
+ isBlocklet: isBlocklet,
122
+ session: session,
123
+ onSwitchPassport: handleSwitchPassport,
124
+ onSwitchAccount: handleSwitchAccount,
125
+ onSwitchProfile: handleSwitchProfile,
126
+ onBindWallet: handleBindWallet
127
+ }), /*#__PURE__*/_jsxs(MenuList, {
128
+ sx: {
129
+ p: 0
130
+ },
131
+ children: [isBlocklet ? /*#__PURE__*/_jsxs(_Fragment, {
132
+ children: [/*#__PURE__*/_jsx(SessionPermission, {
133
+ session: session,
134
+ children: /*#__PURE__*/_jsx(SessionMenuItem, {
135
+ icon: FilterVintageOutlineRoundedIcon,
136
+ title: t('dashboard'),
137
+ component: "a",
138
+ href: DASHBOARD_URL,
139
+ sx: {
140
+ display: 'block',
141
+ textDecoration: 'none',
142
+ color: 'inherit'
143
+ }
144
+ })
145
+ }), /*#__PURE__*/_jsx(SessionMenuItem, {
146
+ icon: PersonOutlineRoundedIcon,
147
+ title: t('profile'),
148
+ component: "a",
149
+ href: PROFILE_URL,
150
+ sx: {
151
+ display: 'block',
152
+ textDecoration: 'none',
153
+ color: 'inherit'
154
+ }
155
+ }), /*#__PURE__*/_jsx(Divider, {
156
+ sx: {
157
+ m: '0!important',
158
+ borderColor: colors.lineStep
159
+ }
160
+ })]
161
+ }) : null, /*#__PURE__*/_jsx(SessionMenuItem, {
162
+ icon: AccountCircleOffOutlineRoundedIcon,
163
+ title: t('logout'),
164
+ sx: {
165
+ color: 'error.main'
166
+ },
167
+ onClick: onLogout,
168
+ "data-cy": "sessionManager-logout-trigger"
169
+ })]
170
+ })]
171
+ })
172
+ })
173
+ })
174
+ })]
175
+ });
176
+ }
177
+ LoggedIn.propTypes = {
178
+ session: PropTypes.object.isRequired,
179
+ onBindWallet: PropTypes.func,
180
+ dark: PropTypes.bool,
181
+ isBlocklet: PropTypes.bool,
182
+ locale: PropTypes.string,
183
+ size: PropTypes.number
184
+ };
185
+ LoggedIn.defaultProps = {
186
+ dark: false,
187
+ isBlocklet: true,
188
+ onBindWallet: noop,
189
+ locale: 'en',
190
+ size: 24
191
+ };
192
+ function SessionMenuItem({
193
+ icon,
194
+ title,
195
+ ...rest
196
+ }) {
197
+ return /*#__PURE__*/_jsx(Box, {
198
+ ...rest,
199
+ sx: {
200
+ p: 0.5,
201
+ ...rest?.sx
202
+ },
203
+ children: /*#__PURE__*/_jsxs(MenuItem, {
204
+ sx: {
205
+ display: 'flex',
206
+ gap: 1,
207
+ alignItems: 'center',
208
+ borderRadius: 2,
209
+ '&:hover': {
210
+ backgroundColor: `${colors.surfacePrimarySubtitle} !important`
211
+ },
212
+ py: 1
213
+ },
214
+ children: [/*#__PURE__*/_jsx(Icon, {
215
+ icon: icon,
216
+ fontSize: 24
217
+ }), title]
218
+ })
219
+ });
220
+ }
221
+ SessionMenuItem.propTypes = {
222
+ icon: PropTypes.string.isRequired,
223
+ title: PropTypes.string.isRequired
224
+ };