@arcblock/ux 2.8.25 → 2.9.0

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 (122) 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/Header/header.js +0 -1
  10. package/es/Img/index.js +7 -6
  11. package/es/Locale/selector.js +15 -13
  12. package/es/NFTDisplay/index.js +2 -1
  13. package/es/QRCode/index.js +2 -1
  14. package/es/SessionBlocklet/index.js +169 -0
  15. package/es/SessionManager/index.js +2 -381
  16. package/es/SessionPermission/index.js +28 -0
  17. package/es/SessionUser/components/logged-in.js +224 -0
  18. package/es/SessionUser/components/session-user-item.js +148 -0
  19. package/es/SessionUser/components/session-user-switch.js +213 -0
  20. package/es/SessionUser/components/un-login.js +64 -0
  21. package/es/SessionUser/components/user-info.js +163 -0
  22. package/es/SessionUser/index.js +49 -0
  23. package/es/SessionUser/libs/translation.js +19 -0
  24. package/es/SessionUser/libs/utils.js +4 -0
  25. package/es/SplitButton/index.js +2 -1
  26. package/es/Toast/index.js +1 -1
  27. package/es/Util/constant.js +10 -0
  28. package/es/Util/index.js +11 -0
  29. package/lib/Address/did-address.js +36 -22
  30. package/lib/AnimationWaiter/index.js +2 -1
  31. package/lib/Avatar/index.js +1 -1
  32. package/lib/BlockletContext/index.js +1 -1
  33. package/lib/CardSelector/index.js +2 -1
  34. package/lib/Colors/index.js +7 -0
  35. package/lib/Colors/themes/temp.js +24 -0
  36. package/lib/Datatable/TableSearch.js +2 -1
  37. package/lib/Header/header.js +1 -1
  38. package/lib/Img/index.js +7 -6
  39. package/lib/Locale/selector.js +14 -13
  40. package/lib/NFTDisplay/index.js +2 -1
  41. package/lib/QRCode/index.js +2 -1
  42. package/lib/SessionBlocklet/index.js +187 -0
  43. package/lib/SessionManager/index.js +2 -390
  44. package/lib/SessionPermission/index.js +38 -0
  45. package/lib/SessionUser/components/logged-in.js +243 -0
  46. package/lib/SessionUser/components/session-user-item.js +163 -0
  47. package/lib/SessionUser/components/session-user-switch.js +232 -0
  48. package/lib/SessionUser/components/un-login.js +72 -0
  49. package/lib/SessionUser/components/user-info.js +175 -0
  50. package/lib/SessionUser/index.js +57 -0
  51. package/lib/SessionUser/libs/translation.js +26 -0
  52. package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
  53. package/lib/SplitButton/index.js +2 -1
  54. package/lib/Toast/index.js +5 -5
  55. package/lib/Util/constant.js +26 -0
  56. package/lib/Util/index.js +16 -3
  57. package/package.json +19 -7
  58. package/src/Address/did-address.jsx +34 -20
  59. package/src/AnimationWaiter/index.js +2 -1
  60. package/src/Avatar/index.jsx +1 -1
  61. package/src/BlockletContext/index.jsx +1 -1
  62. package/src/CardSelector/index.jsx +2 -1
  63. package/src/Colors/index.js +1 -0
  64. package/src/Colors/themes/temp.js +18 -0
  65. package/src/Datatable/TableSearch.js +3 -1
  66. package/src/Header/header.jsx +0 -1
  67. package/src/Img/{index.js → index.jsx} +8 -6
  68. package/src/Locale/selector.jsx +11 -8
  69. package/src/NFTDisplay/index.js +2 -1
  70. package/src/QRCode/index.js +2 -1
  71. package/src/SessionBlocklet/index.jsx +181 -0
  72. package/src/SessionManager/index.jsx +2 -369
  73. package/src/SessionPermission/index.jsx +28 -0
  74. package/src/SessionUser/components/logged-in.jsx +194 -0
  75. package/src/SessionUser/components/session-user-item.jsx +96 -0
  76. package/src/SessionUser/components/session-user-switch.jsx +222 -0
  77. package/src/SessionUser/components/un-login.jsx +55 -0
  78. package/src/SessionUser/components/user-info.jsx +165 -0
  79. package/src/SessionUser/index.jsx +38 -0
  80. package/src/SessionUser/libs/translation.js +19 -0
  81. package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
  82. package/src/SplitButton/index.js +2 -1
  83. package/src/Toast/index.js +1 -1
  84. package/src/Util/constant.js +12 -0
  85. package/src/Util/index.js +13 -0
  86. package/es/SessionManager/components/account-item.js +0 -212
  87. package/es/SessionManager/components/add-account-item.js +0 -57
  88. package/es/SessionManager/components/federated-login-detecter.js +0 -183
  89. package/es/SessionManager/components/manage-accounts.js +0 -219
  90. package/es/SessionManager/components/manage-blocklet.js +0 -70
  91. package/es/SessionManager/components/menu-accordion.js +0 -103
  92. package/es/SessionManager/components/responsive-popper.js +0 -24
  93. package/es/SessionManager/components/user-drawer.js +0 -68
  94. package/es/SessionManager/components/user-info.js +0 -143
  95. package/es/SessionManager/components/user-popper.js +0 -110
  96. package/es/SessionManager/hooks/use-config.js +0 -34
  97. package/es/SessionManager/libs/translation.js +0 -52
  98. package/es/SessionManager/libs/utils.js +0 -2
  99. package/lib/SessionManager/components/account-item.js +0 -219
  100. package/lib/SessionManager/components/add-account-item.js +0 -66
  101. package/lib/SessionManager/components/federated-login-detecter.js +0 -193
  102. package/lib/SessionManager/components/manage-accounts.js +0 -232
  103. package/lib/SessionManager/components/manage-blocklet.js +0 -86
  104. package/lib/SessionManager/components/menu-accordion.js +0 -111
  105. package/lib/SessionManager/components/responsive-popper.js +0 -34
  106. package/lib/SessionManager/components/user-drawer.js +0 -75
  107. package/lib/SessionManager/components/user-info.js +0 -160
  108. package/lib/SessionManager/components/user-popper.js +0 -104
  109. package/lib/SessionManager/hooks/use-config.js +0 -41
  110. package/lib/SessionManager/libs/translation.js +0 -59
  111. package/src/SessionManager/components/account-item.jsx +0 -156
  112. package/src/SessionManager/components/add-account-item.jsx +0 -49
  113. package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
  114. package/src/SessionManager/components/manage-accounts.jsx +0 -228
  115. package/src/SessionManager/components/manage-blocklet.jsx +0 -70
  116. package/src/SessionManager/components/menu-accordion.jsx +0 -93
  117. package/src/SessionManager/components/responsive-popper.jsx +0 -26
  118. package/src/SessionManager/components/user-drawer.jsx +0 -57
  119. package/src/SessionManager/components/user-info.jsx +0 -117
  120. package/src/SessionManager/components/user-popper.jsx +0 -95
  121. package/src/SessionManager/hooks/use-config.js +0 -33
  122. package/src/SessionManager/libs/translation.js +0 -52
@@ -0,0 +1,148 @@
1
+ import PropTypes from 'prop-types';
2
+ import { forwardRef } from 'react';
3
+ import { Box, IconButton, Typography } from '@mui/material';
4
+ import { useCreation } from 'ahooks';
5
+ import { Icon } from '@iconify/react';
6
+ import ApiIcon from '@iconify-icons/mdi/api';
7
+ import IOSRoundedIcon from '@iconify-icons/material-symbols/ios-rounded';
8
+ import LanguageIcon from '@iconify-icons/material-symbols/language';
9
+ import LensIcon from '@iconify-icons/material-symbols/lens';
10
+ import AndroidIcon from '@iconify-icons/material-symbols/android';
11
+ import Auth0Icon from '@iconify-icons/logos/auth0-icon';
12
+ import Avatar from '../../Avatar';
13
+ import DID from '../../DID';
14
+ import { temp as colors } from '../../Colors';
15
+ import { getSourceProvider } from '../libs/utils';
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ import { jsxs as _jsxs } from "react/jsx-runtime";
18
+ const SessionUserItem = /*#__PURE__*/forwardRef(({
19
+ sessionItem,
20
+ statusContent,
21
+ active,
22
+ ...rest
23
+ }, ref) => {
24
+ const isRawWalletAccount = getSourceProvider(sessionItem?.user) === 'wallet';
25
+ const walletIcon = useCreation(() => {
26
+ const {
27
+ walletOS,
28
+ provider
29
+ } = sessionItem?.extra || {};
30
+ if (provider === 'auth0') {
31
+ return /*#__PURE__*/_jsx(Icon, {
32
+ icon: Auth0Icon,
33
+ width: 10,
34
+ height: 10,
35
+ style: {
36
+ color: 'black'
37
+ }
38
+ });
39
+ }
40
+ if (walletOS === 'ios') {
41
+ return /*#__PURE__*/_jsx(Icon, {
42
+ icon: IOSRoundedIcon,
43
+ width: 16,
44
+ height: 16,
45
+ style: {
46
+ color: 'black'
47
+ }
48
+ });
49
+ }
50
+ if (walletOS === 'android') {
51
+ return /*#__PURE__*/_jsx(Icon, {
52
+ icon: AndroidIcon,
53
+ width: 14,
54
+ height: 14,
55
+ style: {
56
+ color: 'black'
57
+ }
58
+ });
59
+ }
60
+ if (walletOS === 'web') {
61
+ return /*#__PURE__*/_jsx(Icon, {
62
+ icon: LanguageIcon,
63
+ style: {
64
+ color: 'black'
65
+ }
66
+ });
67
+ }
68
+ if (walletOS === 'api') {
69
+ return /*#__PURE__*/_jsx(Icon, {
70
+ icon: ApiIcon,
71
+ width: 14,
72
+ height: 14,
73
+ style: {
74
+ color: 'black'
75
+ }
76
+ });
77
+ }
78
+ return null;
79
+ }, [sessionItem?.extra?.walletOS, sessionItem?.extra?.provider]);
80
+ return /*#__PURE__*/_jsxs(Box, {
81
+ ...rest,
82
+ ref: ref,
83
+ sx: {
84
+ display: 'flex',
85
+ alignItems: 'center',
86
+ justifyContent: 'space-between',
87
+ py: 0.75,
88
+ px: 1,
89
+ width: '100%',
90
+ ...rest?.sx
91
+ },
92
+ children: [/*#__PURE__*/_jsxs(Box, {
93
+ sx: {
94
+ display: 'flex',
95
+ alignItems: 'center',
96
+ gap: 0.5,
97
+ '& .did-address-avatar': {
98
+ display: 'none !important'
99
+ },
100
+ '& .did-address-text': {
101
+ color: `${colors.textBase} !important`
102
+ }
103
+ },
104
+ children: [/*#__PURE__*/_jsx(Box, {
105
+ sx: {
106
+ mr: 0.5,
107
+ fontSize: 0
108
+ },
109
+ children: /*#__PURE__*/_jsx(Avatar, {
110
+ did: sessionItem.userDid,
111
+ size: 36
112
+ })
113
+ }), walletIcon, isRawWalletAccount ? /*#__PURE__*/_jsx(DID, {
114
+ did: sessionItem.userDid,
115
+ copyable: false,
116
+ size: 14,
117
+ responsive: false,
118
+ compact: true,
119
+ sx: {
120
+ lineHeight: 1
121
+ }
122
+ }) : /*#__PURE__*/_jsx(Typography, {
123
+ sx: {
124
+ fontSize: 14
125
+ },
126
+ children: sessionItem.user.email
127
+ })]
128
+ }), statusContent || active && /*#__PURE__*/_jsx(IconButton, {
129
+ size: "small",
130
+ disableRipple: true,
131
+ children: /*#__PURE__*/_jsx(Icon, {
132
+ icon: LensIcon,
133
+ fontSize: 6,
134
+ color: colors.surfaceSuccess
135
+ })
136
+ })]
137
+ });
138
+ });
139
+ SessionUserItem.propTypes = {
140
+ sessionItem: PropTypes.object.isRequired,
141
+ statusContent: PropTypes.node,
142
+ active: PropTypes.bool
143
+ };
144
+ SessionUserItem.defaultProps = {
145
+ statusContent: null,
146
+ active: false
147
+ };
148
+ export default SessionUserItem;
@@ -0,0 +1,213 @@
1
+ import PropTypes from 'prop-types';
2
+ import { Box, ClickAwayListener, Divider, Fade, LinearProgress, MenuItem, MenuList, Paper, Popper } from '@mui/material';
3
+ import { useRef } from 'react';
4
+ import { useCreation, useMemoizedFn, useReactive, useSize, useMount } from 'ahooks';
5
+ import { Icon } from '@iconify/react';
6
+ import AddCircleOutlineRoundedIcon from '@iconify-icons/material-symbols/add-circle-outline-rounded';
7
+ import ExpandMoreRoundedIcon from '@iconify-icons/material-symbols/expand-more-rounded';
8
+ import SwapHorizRoundedIcon from '@iconify-icons/material-symbols/swap-horiz-rounded';
9
+ import pick from 'lodash/pick';
10
+ import SessionUserItem from './session-user-item';
11
+ import { temp as colors } from '../../Colors';
12
+ import { getVisitorId } from '../../Util';
13
+ import { translate } from '../../Locale/util';
14
+ import { translations } from '../libs/translation';
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ import { Fragment as _Fragment } from "react/jsx-runtime";
18
+ export default function SessionUserSwitch({
19
+ session,
20
+ onSwitch,
21
+ isBlocklet,
22
+ locale
23
+ }) {
24
+ const popperAnchorRef = useRef(null);
25
+ const t = useMemoizedFn((key, data = {}) => {
26
+ return translate(translations, key, locale, 'en', data);
27
+ });
28
+ const currentState = useReactive({
29
+ open: false,
30
+ userSessions: [],
31
+ loadingSessionId: null
32
+ });
33
+ useMount(async () => {
34
+ if (isBlocklet) {
35
+ const userSessions = await session.getUserSessions();
36
+ currentState.userSessions = userSessions;
37
+ }
38
+ });
39
+ const currentSession = useCreation(() => {
40
+ const matchSession = (currentState.userSessions || []).find(item => item.appPid === globalThis?.blocklet?.appPid && item.userDid === session?.user?.did);
41
+ if (matchSession) {
42
+ return matchSession;
43
+ }
44
+ return {
45
+ appName: globalThis?.blocklet?.appName || globalThis?.env?.appName,
46
+ appPid: globalThis?.blocklet?.appPid || globalThis?.env?.appPid,
47
+ userDid: session?.user?.did,
48
+ visitorId: getVisitorId(),
49
+ // passportId: '', // 无法从当前 session 获取 passportId 的值
50
+ // updatedAt: '', // 当前 session 拼凑的信息无法得到 userSession 的更新时间
51
+ user: pick(session?.user, ['did', 'sourceProvider', 'fullName', 'email', 'avatar', 'remark', 'sourceAppPid', 'role'])
52
+ };
53
+ }, [currentState.userSessions, session?.user]);
54
+ const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
55
+ currentState.open = value;
56
+ });
57
+ const size = useSize(popperAnchorRef.current);
58
+ const handleAddAccount = useMemoizedFn(() => {
59
+ onTogglePopper(false);
60
+ onSwitch();
61
+ });
62
+ const handleSwitch = useMemoizedFn(async userSession => {
63
+ try {
64
+ currentState.loadingSessionId = userSession?.id;
65
+ await onSwitch({
66
+ userSession
67
+ });
68
+ onTogglePopper(false);
69
+ } finally {
70
+ currentState.loadingSessionId = null;
71
+ }
72
+ });
73
+ if (!isBlocklet) {
74
+ return /*#__PURE__*/_jsx(SessionUserItem, {
75
+ sessionItem: currentSession,
76
+ statusContent: /*#__PURE__*/_jsx(Icon, {
77
+ icon: SwapHorizRoundedIcon,
78
+ color: colors.textMuted
79
+ }),
80
+ sx: {
81
+ border: `1px solid ${colors.borderBase}`,
82
+ borderRadius: 2,
83
+ cursor: 'pointer',
84
+ py: 1.25,
85
+ px: 1.5
86
+ },
87
+ "data-cy": "sessionManager-switch-trigger",
88
+ onClick: handleAddAccount,
89
+ ref: popperAnchorRef
90
+ });
91
+ }
92
+ return /*#__PURE__*/_jsxs(_Fragment, {
93
+ children: [/*#__PURE__*/_jsx(SessionUserItem, {
94
+ sessionItem: currentSession,
95
+ statusContent: /*#__PURE__*/_jsx(Icon, {
96
+ icon: ExpandMoreRoundedIcon,
97
+ color: colors.textMuted
98
+ }),
99
+ sx: {
100
+ border: `1px solid ${colors.borderBase}`,
101
+ borderRadius: 2,
102
+ cursor: 'pointer',
103
+ py: 1.25,
104
+ px: 1.5
105
+ },
106
+ onClick: () => onTogglePopper(),
107
+ ref: popperAnchorRef
108
+ }), /*#__PURE__*/_jsx(Popper, {
109
+ open: currentState.open,
110
+ onClose: () => onTogglePopper(false),
111
+ anchorEl: popperAnchorRef.current,
112
+ transition: true,
113
+ sx: {
114
+ zIndex: 1600
115
+ },
116
+ children: ({
117
+ TransitionProps
118
+ }) => /*#__PURE__*/_jsx(ClickAwayListener, {
119
+ onClickAway: e => {
120
+ e.preventDefault();
121
+ e.stopPropagation();
122
+ onTogglePopper(false);
123
+ },
124
+ children: /*#__PURE__*/_jsx(Fade, {
125
+ ...TransitionProps,
126
+ timeout: 350,
127
+ children: /*#__PURE__*/_jsx(Paper, {
128
+ variant: "outlined",
129
+ sx: {
130
+ borderRadius: 3,
131
+ width: size?.width || 0,
132
+ borderColor: colors.lineStep,
133
+ mt: 0.5,
134
+ border: '0 !important',
135
+ boxShadow: `0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6}`
136
+ },
137
+ children: /*#__PURE__*/_jsxs(MenuList, {
138
+ sx: {
139
+ p: 0.5
140
+ },
141
+ children: [currentState.userSessions.map(userSessionItem => {
142
+ const isLoading = currentState.loadingSessionId === userSessionItem.id;
143
+ const isActive = userSessionItem.id === currentSession.id;
144
+ return /*#__PURE__*/_jsxs(MenuItem, {
145
+ sx: {
146
+ position: 'relative',
147
+ p: 0,
148
+ '&:hover': {
149
+ backgroundColor: `${colors.surfacePrimarySubtitle} !important`
150
+ }
151
+ },
152
+ onClick: () => {
153
+ if (!isActive) {
154
+ handleSwitch(userSessionItem);
155
+ }
156
+ },
157
+ children: [isLoading && /*#__PURE__*/_jsx(LinearProgress, {
158
+ sx: {
159
+ height: '2px',
160
+ position: 'absolute',
161
+ top: 0,
162
+ left: 0,
163
+ right: 0
164
+ }
165
+ }), /*#__PURE__*/_jsx(SessionUserItem, {
166
+ sessionItem: userSessionItem,
167
+ active: isActive
168
+ })]
169
+ }, userSessionItem.id);
170
+ }), currentState.userSessions.length > 0 ? /*#__PURE__*/_jsx(Divider, {
171
+ sx: {
172
+ m: '0!important',
173
+ borderColor: colors.lineStep
174
+ }
175
+ }) : null, /*#__PURE__*/_jsxs(MenuItem, {
176
+ sx: {
177
+ color: colors.primaryBase,
178
+ borderRadius: 2,
179
+ '&:hover': {
180
+ backgroundColor: `${colors.surfacePrimarySubtitle} !important`
181
+ },
182
+ px: 1,
183
+ py: 1.5,
184
+ lineHeight: 1
185
+ },
186
+ onClick: handleAddAccount,
187
+ "data-cy": "sessionManager-switch-trigger",
188
+ children: [/*#__PURE__*/_jsx(Box, {
189
+ component: Icon,
190
+ icon: AddCircleOutlineRoundedIcon,
191
+ fontSize: 20,
192
+ sx: {
193
+ mr: 0.5
194
+ }
195
+ }), t('addAnotherAccount')]
196
+ })]
197
+ })
198
+ })
199
+ })
200
+ })
201
+ })]
202
+ });
203
+ }
204
+ SessionUserSwitch.propTypes = {
205
+ session: PropTypes.object.isRequired,
206
+ onSwitch: PropTypes.func.isRequired,
207
+ isBlocklet: PropTypes.bool,
208
+ locale: PropTypes.string
209
+ };
210
+ SessionUserSwitch.defaultProps = {
211
+ isBlocklet: true,
212
+ locale: 'en'
213
+ };
@@ -0,0 +1,64 @@
1
+ import PropTypes from 'prop-types';
2
+ import { Box, CircularProgress, IconButton } from '@mui/material';
3
+ import { Icon } from '@iconify/react';
4
+ import PersonOutlineRoundedIcon from '@iconify-icons/material-symbols/person-outline-rounded';
5
+ import { useRef } from 'react';
6
+ import { useMemoizedFn } from 'ahooks';
7
+ import noop from 'lodash/noop';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ export default function UnLogin({
10
+ session,
11
+ onLogin,
12
+ size,
13
+ dark
14
+ }) {
15
+ const isFirstLoading = false;
16
+ const userAnchorRef = useRef(null);
17
+ const _onLogin = useMemoizedFn(() => {
18
+ if (isFirstLoading) {
19
+ return;
20
+ }
21
+ session.login(onLogin);
22
+ });
23
+ return /*#__PURE__*/_jsx(Box, {
24
+ children: /*#__PURE__*/_jsx(IconButton, {
25
+ ref: userAnchorRef,
26
+ onClick: _onLogin,
27
+ "data-cy": "sessionManager-login",
28
+ size: "medium",
29
+ "aria-label": "Login button",
30
+ children: isFirstLoading ? /*#__PURE__*/_jsx(Box, {
31
+ width: size,
32
+ height: size,
33
+ display: "flex",
34
+ justifyContent: "center",
35
+ alignItems: "center",
36
+ children: /*#__PURE__*/_jsx(CircularProgress, {
37
+ style: {
38
+ width: size - 4,
39
+ height: size - 4,
40
+ color: dark ? '#fff' : ''
41
+ }
42
+ })
43
+ }) : /*#__PURE__*/_jsx(Icon, {
44
+ icon: PersonOutlineRoundedIcon,
45
+ fontSize: size,
46
+ color: dark ? '#fff' : 'inherit',
47
+ style: {
48
+ transform: 'scale(1.08)'
49
+ }
50
+ })
51
+ })
52
+ });
53
+ }
54
+ UnLogin.propTypes = {
55
+ session: PropTypes.object.isRequired,
56
+ onLogin: PropTypes.func,
57
+ size: PropTypes.number,
58
+ dark: PropTypes.bool
59
+ };
60
+ UnLogin.defaultProps = {
61
+ onLogin: noop,
62
+ size: 24,
63
+ dark: false
64
+ };
@@ -0,0 +1,163 @@
1
+ import PropTypes from 'prop-types';
2
+ import { Box, Chip, Typography } from '@mui/material';
3
+ import { Icon } from '@iconify/react';
4
+ import SwapHorizRoundedIcon from '@iconify-icons/material-symbols/swap-horiz-rounded';
5
+ import ArrowRightAltRoundedIcon from '@iconify-icons/material-symbols/arrow-right-alt-rounded';
6
+ import { useCreation, useMemoizedFn } from 'ahooks';
7
+ import noop from 'lodash/noop';
8
+ import DidAvatar from '../../Avatar';
9
+ import { getUserAvatar } from '../../Util';
10
+ import SessionUserSwitch from './session-user-switch';
11
+ import { temp as colors } from '../../Colors';
12
+ import { getSourceProvider } from '../libs/utils';
13
+ import { translations } from '../libs/translation';
14
+ import { translate } from '../../Locale/util';
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ export default function UserInfo({
18
+ session,
19
+ onSwitchPassport,
20
+ onSwitchAccount,
21
+ onBindWallet,
22
+ onSwitchProfile,
23
+ locale,
24
+ isBlocklet
25
+ }) {
26
+ const t = useMemoizedFn((key, data = {}) => {
27
+ return translate(translations, key, locale, 'en', data);
28
+ });
29
+ const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')), 64);
30
+ const currentRole = useCreation(() => session.user?.passports?.find(item => item.name === session.user.role), [session?.user?.passports, session?.user?.role]);
31
+ const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
32
+ return /*#__PURE__*/_jsxs(Box, {
33
+ sx: {
34
+ p: 2,
35
+ pb: 1,
36
+ display: 'flex',
37
+ flexDirection: 'column',
38
+ gap: 1.5
39
+ },
40
+ children: [/*#__PURE__*/_jsxs(Box, {
41
+ sx: {
42
+ display: 'flex',
43
+ justifyContent: 'space-between',
44
+ alignItems: 'center',
45
+ gap: 1
46
+ },
47
+ children: [/*#__PURE__*/_jsxs(Box, {
48
+ sx: {
49
+ display: 'flex',
50
+ alignItems: 'center',
51
+ gap: 1.5
52
+ },
53
+ children: [/*#__PURE__*/_jsx(Box, {
54
+ onClick: isBlocklet ? noop : onSwitchProfile,
55
+ "data-cy": "sessionManager-switch-profile-trigger",
56
+ sx: {
57
+ cursor: isBlocklet ? 'default' : 'pointer',
58
+ position: 'relative',
59
+ borderRadius: '100%',
60
+ overflow: 'hidden',
61
+ fontSize: 0,
62
+ flexShrink: 0,
63
+ '&:hover': isBlocklet ? {} : {
64
+ '&::after': {
65
+ content: `"${t('switch')}"`,
66
+ position: 'absolute',
67
+ bottom: 0,
68
+ background: 'rgba(0, 0, 0, 0.2)',
69
+ left: 0,
70
+ right: 0,
71
+ height: '2.2em',
72
+ color: 'white',
73
+ textAlign: 'center',
74
+ fontSize: '12px',
75
+ lineHeight: '2em'
76
+ }
77
+ }
78
+ },
79
+ children: /*#__PURE__*/_jsx(DidAvatar, {
80
+ variant: "circle",
81
+ did: session.user.did,
82
+ src: avatar,
83
+ size: 48,
84
+ shape: "circle",
85
+ sx: {
86
+ cursor: isBlocklet ? 'unset' : 'pointer'
87
+ }
88
+ })
89
+ }), /*#__PURE__*/_jsx(Typography, {
90
+ variant: "h6",
91
+ sx: {
92
+ wordBreak: 'break-all'
93
+ },
94
+ children: session.user.fullName
95
+ })]
96
+ }), /*#__PURE__*/_jsx(Chip, {
97
+ label: currentRole?.title || session.user?.role.toUpperCase(),
98
+ size: "small",
99
+ variant: "outlined",
100
+ clickable: true,
101
+ sx: {
102
+ flexShrink: 0,
103
+ fontWeight: 'bold',
104
+ fontSize: '12px',
105
+ color: colors.textBase,
106
+ borderColor: colors.borderBase,
107
+ pr: 1,
108
+ pl: 0.5,
109
+ '&:active': {
110
+ boxShadow: 'none'
111
+ }
112
+ },
113
+ deleteIcon: /*#__PURE__*/_jsx(Icon, {
114
+ icon: SwapHorizRoundedIcon,
115
+ color: colors.textBase
116
+ }),
117
+ onDelete: onSwitchPassport,
118
+ onClick: onSwitchPassport,
119
+ "data-cy": "sessionManager-switch-passport-trigger"
120
+ })]
121
+ }), /*#__PURE__*/_jsx(SessionUserSwitch, {
122
+ session: session,
123
+ onSwitch: onSwitchAccount,
124
+ isBlocklet: isBlocklet,
125
+ locale: locale
126
+ }), isRawWalletAccount ? null : /*#__PURE__*/_jsxs(Box, {
127
+ sx: {
128
+ color: colors.primaryBase,
129
+ backgroundColor: colors.surfacePrimarySubtitle,
130
+ borderRadius: 1,
131
+ display: 'flex',
132
+ justifyContent: 'space-between',
133
+ alignItems: 'center',
134
+ fontSize: 12,
135
+ py: 0.75,
136
+ px: 1.5,
137
+ cursor: 'pointer',
138
+ mt: -0.75
139
+ },
140
+ onClick: onBindWallet,
141
+ "data-cy": "sessionManager-bind-trigger",
142
+ children: [t('connectDIDWallet'), /*#__PURE__*/_jsx(Icon, {
143
+ icon: ArrowRightAltRoundedIcon,
144
+ color: colors.primaryBase,
145
+ fontSize: 16
146
+ })]
147
+ })]
148
+ });
149
+ }
150
+ UserInfo.propTypes = {
151
+ session: PropTypes.object.isRequired,
152
+ onSwitchPassport: PropTypes.func.isRequired,
153
+ onSwitchAccount: PropTypes.func.isRequired,
154
+ onBindWallet: PropTypes.func.isRequired,
155
+ onSwitchProfile: PropTypes.func,
156
+ locale: PropTypes.string,
157
+ isBlocklet: PropTypes.bool
158
+ };
159
+ UserInfo.defaultProps = {
160
+ locale: 'en',
161
+ isBlocklet: true,
162
+ onSwitchProfile: noop
163
+ };
@@ -0,0 +1,49 @@
1
+ import PropTypes from 'prop-types';
2
+ import noop from 'lodash/noop';
3
+ import { useCreation } from 'ahooks';
4
+ import LoggedIn from './components/logged-in';
5
+ import UnLogin from './components/un-login';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ export default function SessionUser({
8
+ session,
9
+ onBindWallet,
10
+ locale,
11
+ size
12
+ }) {
13
+ const isBlocklet = useCreation(() => {
14
+ return !!globalThis?.blocklet;
15
+ });
16
+ if (session.user) {
17
+ return /*#__PURE__*/_jsx(LoggedIn, {
18
+ isBlocklet: isBlocklet,
19
+ session: session,
20
+ onBindWallet: onBindWallet,
21
+ locale: locale,
22
+ size: size
23
+ });
24
+ }
25
+ return /*#__PURE__*/_jsx(UnLogin, {
26
+ session: session,
27
+ isBlocklet: isBlocklet,
28
+ locale: locale,
29
+ size: size
30
+ });
31
+ }
32
+ SessionUser.propTypes = {
33
+ session: PropTypes.shape({
34
+ user: PropTypes.shape({
35
+ did: PropTypes.string.isRequired,
36
+ fullName: PropTypes.string.isRequired,
37
+ email: PropTypes.string.isRequired,
38
+ avatar: PropTypes.string.isRequired
39
+ })
40
+ }).isRequired,
41
+ onBindWallet: PropTypes.func,
42
+ locale: PropTypes.string,
43
+ size: PropTypes.number
44
+ };
45
+ SessionUser.defaultProps = {
46
+ onBindWallet: noop,
47
+ locale: 'en',
48
+ size: 24
49
+ };
@@ -0,0 +1,19 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export const translations = {
3
+ en: {
4
+ connectDIDWallet: 'Connect your DID Wallet for full functionality',
5
+ switch: 'Switch',
6
+ profile: 'Profile',
7
+ dashboard: 'Dashboard',
8
+ logout: 'Sign Out',
9
+ addAnotherAccount: 'Add another account'
10
+ },
11
+ zh: {
12
+ connectDIDWallet: '连接你的 DID Wallet 获得更全的功能',
13
+ switch: '切换',
14
+ profile: '个人中心',
15
+ dashboard: '控制台',
16
+ logout: '退出登录',
17
+ addAnotherAccount: '添加账户'
18
+ }
19
+ };
@@ -0,0 +1,4 @@
1
+ export const getSourceProvider = user => user?.sourceProvider || user?.extraConfigs?.sourceProvider || 'wallet';
2
+ export const getSourceAppPid = user => user?.sourceAppPid;
3
+ export const getCurrentAppPid = user => user?.sourceAppPid || window?.blocklet?.appPid;
4
+ export const getConnectedAccounts = user => user?.connectedAccounts || user?.extraConfigs?.connectedAccounts || [];
@@ -8,6 +8,7 @@ import MenuList from '@mui/material/MenuList';
8
8
  import MenuItem from '@mui/material/MenuItem';
9
9
  import ButtonGroup from '@mui/material/ButtonGroup';
10
10
  import Button from '@mui/material/Button';
11
+ import noop from 'lodash/noop';
11
12
  import { styled } from '../Theme';
12
13
 
13
14
  /**
@@ -118,7 +119,7 @@ SplitButton.defaultProps = {
118
119
  menu: [],
119
120
  children: null,
120
121
  variant: 'contained',
121
- onClick: () => {},
122
+ onClick: noop,
122
123
  menuButtonProps: {}
123
124
  };
124
125
  /**
package/es/Toast/index.js CHANGED
@@ -2,6 +2,7 @@ import { createRef } from 'react';
2
2
  import { SnackbarProvider, useSnackbar } from 'notistack';
3
3
  import IconButton from '@mui/material/IconButton';
4
4
  import CloseIcon from '@mui/icons-material/Close';
5
+ import noop from 'lodash/noop';
5
6
 
6
7
  /**
7
8
  *
@@ -14,7 +15,6 @@ import CloseIcon from '@mui/icons-material/Close';
14
15
  */
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
- const noop = () => {};
18
18
  let success = noop;
19
19
  let error = noop;
20
20
  let warning = noop;