@arcblock/ux 2.7.15 → 2.7.16

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 (51) hide show
  1. package/es/Dialog/confirm.js +10 -8
  2. package/es/Img/index.js +7 -7
  3. package/es/SessionManager/account-item.js +132 -0
  4. package/es/SessionManager/add-account-item.js +118 -0
  5. package/es/SessionManager/federated-login-detecter.js +5 -7
  6. package/es/SessionManager/index.js +117 -244
  7. package/es/SessionManager/manage-accounts.js +143 -0
  8. package/es/SessionManager/manage-blocklet.js +62 -0
  9. package/es/SessionManager/menu-accordion.js +95 -0
  10. package/es/SessionManager/translation.js +52 -0
  11. package/es/SessionManager/use-accounts.js +19 -0
  12. package/es/SessionManager/user-info.js +139 -0
  13. package/es/SessionManager/user-popper.js +10 -36
  14. package/es/SessionManager/utils.js +2 -0
  15. package/es/Util/index.js +7 -0
  16. package/lib/Dialog/confirm.js +9 -7
  17. package/lib/Img/index.js +7 -7
  18. package/lib/SessionManager/account-item.js +140 -0
  19. package/lib/SessionManager/add-account-item.js +126 -0
  20. package/lib/SessionManager/federated-login-detecter.js +5 -7
  21. package/lib/SessionManager/index.js +120 -257
  22. package/lib/SessionManager/manage-accounts.js +155 -0
  23. package/lib/SessionManager/manage-blocklet.js +78 -0
  24. package/lib/SessionManager/menu-accordion.js +103 -0
  25. package/lib/SessionManager/translation.js +59 -0
  26. package/lib/SessionManager/use-accounts.js +25 -0
  27. package/lib/SessionManager/user-info.js +155 -0
  28. package/lib/SessionManager/user-popper.js +8 -3
  29. package/lib/SessionManager/utils.js +16 -0
  30. package/lib/Util/index.js +11 -2
  31. package/package.json +8 -5
  32. package/src/Dialog/confirm.js +9 -6
  33. package/src/Img/index.js +5 -5
  34. package/src/SessionManager/account-item.jsx +111 -0
  35. package/src/SessionManager/add-account-item.jsx +115 -0
  36. package/src/SessionManager/federated-login-detecter.jsx +3 -3
  37. package/src/SessionManager/index.jsx +130 -238
  38. package/src/SessionManager/manage-accounts.jsx +143 -0
  39. package/src/SessionManager/manage-blocklet.jsx +64 -0
  40. package/src/SessionManager/menu-accordion.jsx +87 -0
  41. package/src/SessionManager/translation.js +52 -0
  42. package/src/SessionManager/use-accounts.js +18 -0
  43. package/src/SessionManager/user-info.jsx +116 -0
  44. package/src/SessionManager/user-popper.jsx +6 -36
  45. package/src/SessionManager/utils.js +3 -0
  46. package/src/Util/index.js +8 -0
  47. /package/src/Avatar/{did-motif.js → did-motif.jsx} +0 -0
  48. /package/src/Avatar/{index.js → index.jsx} +0 -0
  49. /package/src/Header/{auto-hidden.js → auto-hidden.jsx} +0 -0
  50. /package/src/Header/{header.js → header.jsx} +0 -0
  51. /package/src/Header/{responsive-header.js → responsive-header.jsx} +0 -0
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = AddAccountItem;
7
+ var _react = require("@iconify/react");
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _material = require("@mui/material");
10
+ var _iosAddCircleOutline = _interopRequireDefault(require("@iconify-icons/ion/ios-add-circle-outline"));
11
+ var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
12
+ var _ahooks = require("ahooks");
13
+ var _react2 = require("react");
14
+ var _util = require("../Locale/util");
15
+ var _translation = require("./translation");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function AddAccountItem(_ref) {
19
+ let {
20
+ onAdd,
21
+ locale
22
+ } = _ref;
23
+ const addRef = (0, _react2.useRef)(null);
24
+ const state = (0, _ahooks.useReactive)({
25
+ open: false
26
+ });
27
+ const t = (0, _ahooks.useMemoizedFn)(function (key) {
28
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
29
+ return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
30
+ });
31
+ const apps = (0, _ahooks.useCreation)(() => {
32
+ var _window, _blocklet$settings, _blocklet$settings$fe;
33
+ const appList = [];
34
+ if (typeof window === 'undefined') {
35
+ return appList;
36
+ }
37
+ const blocklet = (_window = window) === null || _window === void 0 ? void 0 : _window.blocklet;
38
+ if (!blocklet) {
39
+ return appList;
40
+ }
41
+ const currentApp = {
42
+ appId: blocklet.appId,
43
+ appName: blocklet.appName,
44
+ appDescription: blocklet.appDescription,
45
+ appLogo: blocklet.appLogo,
46
+ appPid: blocklet.appPid,
47
+ appUrl: blocklet.appUrl,
48
+ version: blocklet.version,
49
+ provider: 'wallet'
50
+ };
51
+ appList.push(currentApp);
52
+ const isFederatedMember = !(0, _isEmpty.default)((_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 ? void 0 : (_blocklet$settings$fe = _blocklet$settings.federated) === null || _blocklet$settings$fe === void 0 ? void 0 : _blocklet$settings$fe.master);
53
+ if (isFederatedMember) {
54
+ const federatedMaster = blocklet.settings.federated.master;
55
+ const masterApp = {
56
+ appId: federatedMaster.appId,
57
+ appName: federatedMaster.appName,
58
+ appDescription: federatedMaster.appDescription,
59
+ appLogo: federatedMaster.appLogo,
60
+ appPid: federatedMaster.appPid,
61
+ appUrl: federatedMaster.appUrl,
62
+ version: federatedMaster.version,
63
+ provider: 'federated'
64
+ };
65
+ return [masterApp, currentApp];
66
+ }
67
+ return appList;
68
+ }, [window.blocklet]);
69
+ const _onAdd = (0, _ahooks.useMemoizedFn)(() => {
70
+ if (apps.length <= 1) {
71
+ onAdd(apps[0]);
72
+ } else {
73
+ state.open = true;
74
+ }
75
+ });
76
+ const onClose = (0, _ahooks.useMemoizedFn)(() => {
77
+ state.open = false;
78
+ });
79
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
80
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
81
+ ref: addRef,
82
+ onClick: _onAdd,
83
+ className: "session-manager-menu-item",
84
+ sx: {
85
+ display: 'flex',
86
+ gap: '8px'
87
+ },
88
+ "data-cy": "sessionManager-switch-trigger",
89
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
90
+ icon: _iosAddCircleOutline.default,
91
+ width: 24,
92
+ height: 24
93
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
94
+ children: t('addAnotherAccount')
95
+ })]
96
+ }), addRef.current ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Menu, {
97
+ anchorEl: addRef.current,
98
+ open: state.open,
99
+ onClose: onClose,
100
+ elevation: 0,
101
+ PaperProps: {
102
+ variant: 'outlined'
103
+ },
104
+ anchorOrigin: {
105
+ vertical: 'top',
106
+ horizontal: 'left'
107
+ },
108
+ transformOrigin: {
109
+ vertical: 'top',
110
+ horizontal: 'left'
111
+ },
112
+ children: apps.map(app => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
113
+ onClick: () => onAdd(app),
114
+ children: ["Connect with ", app.appName, " account"]
115
+ }, app.appId))
116
+ }) : null]
117
+ });
118
+ }
119
+ AddAccountItem.propTypes = {
120
+ onAdd: _propTypes.default.func,
121
+ locale: _propTypes.default.string
122
+ };
123
+ AddAccountItem.defaultProps = {
124
+ onAdd: () => {},
125
+ locale: 'en'
126
+ };
@@ -9,8 +9,8 @@ var _react = require("react");
9
9
  var _Box = _interopRequireDefault(require("@mui/material/Box"));
10
10
  var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
11
11
  var _Divider = _interopRequireDefault(require("@mui/material/Divider"));
12
- var _SvgIcon = _interopRequireDefault(require("@mui/material/SvgIcon"));
13
- var _ShieldCheck = _interopRequireDefault(require("mdi-material-ui/ShieldCheck"));
12
+ var _shieldCheck = _interopRequireDefault(require("@iconify-icons/mdi/shield-check"));
13
+ var _react2 = require("@iconify/react");
14
14
  var _userPopper = _interopRequireDefault(require("./user-popper"));
15
15
  var _Avatar = _interopRequireDefault(require("../Avatar"));
16
16
  var _Address = _interopRequireDefault(require("../Address"));
@@ -149,11 +149,9 @@ function FederatedLoginDetecter(_ref3) {
149
149
  marginRight: 0,
150
150
  fontSize: 12
151
151
  },
152
- icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
153
- component: _ShieldCheck.default,
154
- style: {
155
- fontSize: '14px'
156
- }
152
+ icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
153
+ icon: _shieldCheck.default,
154
+ fontSize: 14
157
155
  })
158
156
  })]
159
157
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
@@ -7,26 +7,25 @@ exports.default = void 0;
7
7
  var _react = require("react");
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _material = require("@mui/material");
10
- var _PersonOutline = _interopRequireDefault(require("@mui/icons-material/PersonOutline"));
11
- var _Link = _interopRequireDefault(require("@mui/icons-material/Link"));
12
- var _VpnKeyOutlined = _interopRequireDefault(require("@mui/icons-material/VpnKeyOutlined"));
13
- var _ShieldCheck = _interopRequireDefault(require("mdi-material-ui/ShieldCheck"));
14
10
  var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
15
- var _OpenIn = _interopRequireDefault(require("@arcblock/icons/lib/OpenIn"));
16
11
  var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
17
- var _Switch = _interopRequireDefault(require("@arcblock/icons/lib/Switch"));
18
- var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
19
12
  var _noop = _interopRequireDefault(require("lodash/noop"));
20
13
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
14
+ var _ahooks = require("ahooks");
21
15
  var _Avatar = _interopRequireDefault(require("../Avatar"));
22
- var _Address = _interopRequireDefault(require("../Address"));
23
16
  var _Util = require("../Util");
24
17
  var _federatedLoginDetecter = _interopRequireDefault(require("./federated-login-detecter"));
25
18
  var _userPopper = _interopRequireDefault(require("./user-popper"));
19
+ var _userInfo = _interopRequireDefault(require("./user-info"));
20
+ var _util = require("../Locale/util");
21
+ var _manageAccounts = _interopRequireDefault(require("./manage-accounts"));
22
+ var _manageBlocklet = _interopRequireDefault(require("./manage-blocklet"));
23
+ var _translation = require("./translation");
24
+ var _utils = require("./utils");
25
+ var _useAccounts = _interopRequireDefault(require("./use-accounts"));
26
26
  var _jsxRuntime = require("react/jsx-runtime");
27
- const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "onBindWallet", "menu", "menuRender", "dark", "size"],
28
- _excluded2 = ["svgIcon"];
29
- /* eslint-disable react/no-array-index-key */
27
+ const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "onBindWallet", "menu", "menuRender", "dark", "size"];
28
+ /* eslint-disable react/prop-types */
30
29
  /* eslint-disable react/jsx-no-bind */
31
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
31
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -36,47 +35,8 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
36
35
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
37
36
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
38
37
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
39
- const translations = {
40
- en: {
41
- account: 'account',
42
- switchDid: 'Switch DID',
43
- switchTo: 'Switch to',
44
- switchProfile: 'Switch Profile',
45
- switchPassport: 'Switch Passport',
46
- disconnect: 'Disconnect',
47
- connect: 'Connect',
48
- openInWallet: 'Open DID Wallet',
49
- alreadyBindOAuth: 'Already bind Auth0',
50
- bind: 'Bind ',
51
- thirdParty: 'Third Party Login',
52
- connectedWith: 'Connected with'
53
- },
54
- zh: {
55
- account: '账号',
56
- switchDid: '切换账户',
57
- switchTo: '切换至',
58
- switchProfile: '切换用户信息',
59
- switchPassport: '切换通行证',
60
- disconnect: '退出',
61
- connect: '登录',
62
- openInWallet: '打开 DID 钱包',
63
- // NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
64
- alreadyBindOAuth: '已绑定 Auth0 账号',
65
- bind: '绑定',
66
- thirdParty: '第三方登录',
67
- connectedWith: '连接至'
68
- }
69
- };
70
- const getConnectedAccounts = user => {
71
- var _user$extraConfigs;
72
- return (user === null || user === void 0 ? void 0 : user.connectedAccounts) || (user === null || user === void 0 ? void 0 : (_user$extraConfigs = user.extraConfigs) === null || _user$extraConfigs === void 0 ? void 0 : _user$extraConfigs.connectedAccounts) || [];
73
- };
74
- const getSourceProvider = user => {
75
- var _user$extraConfigs2;
76
- return (user === null || user === void 0 ? void 0 : user.sourceProvider) || (user === null || user === void 0 ? void 0 : (_user$extraConfigs2 = user.extraConfigs) === null || _user$extraConfigs2 === void 0 ? void 0 : _user$extraConfigs2.sourceProvider) || 'wallet';
77
- };
78
38
  function SessionManager(_ref) {
79
- var _session$user, _session$user$avatar, _window$blocklet, _window$blocklet$sett, _window$blocklet$sett2, _session$user3, _session$user4, _session$user5;
39
+ var _session$user, _session$user$avatar;
80
40
  let {
81
41
  session,
82
42
  locale,
@@ -98,33 +58,30 @@ function SessionManager(_ref) {
98
58
  size
99
59
  } = _ref,
100
60
  rest = _objectWithoutProperties(_ref, _excluded);
101
- const translation = translations[locale] || translations.en;
61
+ const latestSession = (0, _ahooks.useLatest)(session);
62
+ const {
63
+ connectAccount
64
+ } = (0, _useAccounts.default)();
65
+ const t = (0, _ahooks.useMemoizedFn)(function (key) {
66
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
67
+ return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
68
+ });
102
69
  const userAnchorRef = (0, _react.useRef)(null);
103
- // eslint-disable-next-line react/prop-types
104
70
  const {
105
71
  logoutOAuth,
106
- bindOAuth,
107
- configs: oauthConfigs,
108
72
  switchOAuthPassport
109
73
  } = session.useOAuth();
110
74
  const [userOpen, setUserOpen] = (0, _react.useState)(false);
111
75
 
112
76
  // base64 img maybe have some blank char, need encodeURIComponent to transform it
113
77
  const avatar = (0, _Util.getUserAvatar)((_session$user = session.user) === null || _session$user === void 0 ? void 0 : (_session$user$avatar = _session$user.avatar) === null || _session$user$avatar === void 0 ? void 0 : _session$user$avatar.replace(/\s/g, encodeURIComponent(' ')));
114
- const currentRole = (0, _react.useMemo)(() => {
115
- var _session$user2, _session$user2$passpo;
116
- return (_session$user2 = session.user) === null || _session$user2 === void 0 ? void 0 : (_session$user2$passpo = _session$user2.passports) === null || _session$user2$passpo === void 0 ? void 0 : _session$user2$passpo.find(item => item.name === session.user.role);
117
- }, [session.user]);
118
- const browser = (0, _useBrowser.default)();
119
- // eslint-disable-next-line react/prop-types
120
- const {
121
- walletDid
122
- } = session.useDid({
123
- session
124
- });
125
- const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
126
- const connectedAccounts = getConnectedAccounts(session.user);
127
- const federatedAccount = connectedAccounts.find(item => item.provider === 'federated');
78
+ const isRawWalletAccount = (0, _utils.getSourceProvider)(session.user) === 'wallet';
79
+ const connectedAccounts = (0, _utils.getConnectedAccounts)(session.user);
80
+ const isFirstLoading = (0, _react.useMemo)(() => {
81
+ return (session === null || session === void 0 ? void 0 : session.initialized) === false && (session === null || session === void 0 ? void 0 : session.loading) === true;
82
+ }, [session === null || session === void 0 ? void 0 : session.initialized, session === null || session === void 0 ? void 0 : session.loading]);
83
+
84
+ // const federatedAccount = connectedAccounts.find((item) => item.provider === 'federated');
128
85
  let hasBindWallet = false;
129
86
  let hasBindAccount = false;
130
87
  if (isRawWalletAccount) {
@@ -136,19 +93,57 @@ function SessionManager(_ref) {
136
93
  hasBindAccount = true;
137
94
  hasBindWallet = true;
138
95
  }
139
- const oauthConfigList = Object.entries(oauthConfigs).map(_ref2 => {
140
- let [key, value] = _ref2;
141
- return _objectSpread(_objectSpread({}, value), {}, {
142
- provider: key
143
- });
144
- }).filter(item => item.enabled);
145
- const isFirstLoading = (0, _react.useMemo)(() => {
146
- // eslint-disable-next-line react/prop-types
147
- return (session === null || session === void 0 ? void 0 : session.initialized) === false && (session === null || session === void 0 ? void 0 : session.loading) === true;
148
- // eslint-disable-next-line react/prop-types
149
- }, [session === null || session === void 0 ? void 0 : session.initialized, session === null || session === void 0 ? void 0 : session.loading]);
150
- const masterSiteInfo = (_window$blocklet = window.blocklet) === null || _window$blocklet === void 0 ? void 0 : (_window$blocklet$sett = _window$blocklet.settings) === null || _window$blocklet$sett === void 0 ? void 0 : (_window$blocklet$sett2 = _window$blocklet$sett.federated) === null || _window$blocklet$sett2 === void 0 ? void 0 : _window$blocklet$sett2.master;
151
- const currentSiteInfo = window.blocklet;
96
+ const _connectAccount = (0, _ahooks.useMemoizedFn)(async () => {
97
+ var _latestSession$curren, _window, _blocklet$settings, _blocklet$settings$fe;
98
+ // HACK: 强制等待组件渲染一轮,以拿到最新的 session
99
+ await (0, _Util.sleep)();
100
+ if (!((_latestSession$curren = latestSession.current) !== null && _latestSession$curren !== void 0 && _latestSession$curren.user)) {
101
+ return;
102
+ }
103
+ if (typeof window === 'undefined') {
104
+ return;
105
+ }
106
+ const blocklet = (_window = window) === null || _window === void 0 ? void 0 : _window.blocklet;
107
+ if (!blocklet) {
108
+ return;
109
+ }
110
+ const currentApp = {
111
+ appId: blocklet.appId,
112
+ appPid: blocklet.appPid,
113
+ appName: blocklet.appName,
114
+ appDescription: blocklet.appDescription,
115
+ appLogo: blocklet.appLogo,
116
+ appUrl: blocklet.appUrl,
117
+ version: blocklet.version,
118
+ provider: 'wallet'
119
+ };
120
+ const federatedMaster = (_blocklet$settings = blocklet.settings) === null || _blocklet$settings === void 0 ? void 0 : (_blocklet$settings$fe = _blocklet$settings.federated) === null || _blocklet$settings$fe === void 0 ? void 0 : _blocklet$settings$fe.master;
121
+ const masterApp = (0, _isEmpty.default)(federatedMaster) ? null : {
122
+ appId: federatedMaster.appId,
123
+ appName: federatedMaster.appName,
124
+ appDescription: federatedMaster.appDescription,
125
+ appLogo: federatedMaster.appLogo,
126
+ appPid: federatedMaster.appPid,
127
+ appUrl: federatedMaster.appUrl,
128
+ version: federatedMaster.version,
129
+ provider: 'federated'
130
+ };
131
+ const loginAccount = _objectSpread({
132
+ did: latestSession.current.user.did,
133
+ avatar: latestSession.current.user.avatar,
134
+ provider: latestSession.current.provider
135
+ }, latestSession.current.provider === 'federated' ? masterApp : currentApp);
136
+ connectAccount(loginAccount);
137
+ });
138
+
139
+ // HACK: 用于处理 统一登录 的自动登录情况,添加一个已连接的账号
140
+ // 同时可用于以前的站点,会自动生成一个已连接的账号
141
+ (0, _react.useEffect)(() => {
142
+ if (session.user) {
143
+ _connectAccount();
144
+ }
145
+ // eslint-disable-next-line react-hooks/exhaustive-deps
146
+ }, [session.user]);
152
147
  if (!session.user) {
153
148
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
154
149
  children: [showText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Button, _objectSpread(_objectSpread({
@@ -169,7 +164,7 @@ function SessionManager(_ref) {
169
164
  style: {
170
165
  lineHeight: '25px'
171
166
  },
172
- children: translation.connect
167
+ children: t('connect')
173
168
  })]
174
169
  })) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
175
170
  ref: userAnchorRef
@@ -210,15 +205,21 @@ function SessionManager(_ref) {
210
205
  function onToggleUser() {
211
206
  setUserOpen(prevOpen => !prevOpen);
212
207
  }
208
+ function close() {
209
+ setUserOpen(false);
210
+ }
213
211
  function onCloseUser(e) {
214
212
  if (userAnchorRef.current && userAnchorRef.current.contains(e.target)) {
215
213
  return;
216
214
  }
217
- setUserOpen(false);
215
+ close();
218
216
  }
219
217
  function _onLogin() {
220
218
  if (!isFirstLoading) {
221
- session.login(onLogin);
219
+ session.login(function () {
220
+ _connectAccount();
221
+ onLogin(...arguments);
222
+ });
222
223
  }
223
224
  }
224
225
  function _onLogout() {
@@ -234,7 +235,7 @@ function SessionManager(_ref) {
234
235
  }).catch(err => {
235
236
  console.error(err);
236
237
  }).finally(() => {
237
- setUserOpen(false);
238
+ close();
238
239
  });
239
240
  });
240
241
  }
@@ -242,29 +243,10 @@ function SessionManager(_ref) {
242
243
  * @name 切换账户
243
244
  * @description 该功能仅在登录后才能使用,目前仅用于切换普通登录和统一登录的账户,所以会增加一些与统一登录相关的逻辑
244
245
  */
245
- function _onSwitchDid() {
246
- const {
247
- provider,
248
- user
249
- } = session;
250
- if (!user) return;
251
- let targetProvider = provider;
252
- if (provider === 'federated') {
253
- targetProvider = 'wallet';
254
- } else if (['auth0', 'wallet'].includes(provider)) {
255
- targetProvider = 'federated';
256
- }
257
- session.switchDid(function () {
258
- setUserOpen(false);
259
- onSwitchDid(...arguments);
260
- }, {
261
- provider: targetProvider,
262
- providerMode: 'paramsFirst'
263
- });
264
- }
246
+
265
247
  function _onSwitchProfile() {
266
248
  session.switchProfile(function () {
267
- setUserOpen(false);
249
+ close();
268
250
  onSwitchProfile(...arguments);
269
251
  });
270
252
  }
@@ -276,25 +258,13 @@ function SessionManager(_ref) {
276
258
  if (!isRawWalletAccount && provider !== 'federated') {
277
259
  switchOAuthPassport(user);
278
260
  } else {
279
- setUserOpen(false);
261
+ close();
280
262
  session.switchPassport(function () {
281
- setUserOpen(false);
263
+ close();
282
264
  onSwitchPassport(...arguments);
283
265
  });
284
266
  }
285
267
  }
286
- function _onBindWallet() {
287
- setUserOpen(false);
288
- // FIXME: @zhanghan 暂时切换回 isRawWalletAccount 的方式来判断,在 did-connect 改版时,简化这里的关系判断
289
- if (!isRawWalletAccount) {
290
- session.bindWallet(function () {
291
- setUserOpen(false);
292
- onBindWallet(...arguments);
293
- });
294
- } else {
295
- bindOAuth();
296
- }
297
- }
298
268
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
299
269
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
300
270
  ref: userAnchorRef,
@@ -323,141 +293,34 @@ function SessionManager(_ref) {
323
293
  sx: {
324
294
  p: 0
325
295
  },
326
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
327
- className: "session-manager-user",
328
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
329
- className: "session-manager-user-name",
330
- role: "button",
331
- "aria-label": "User info panel",
332
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
333
- children: session.user.fullName
334
- }), !!showRole && ((currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user3 = session.user) === null || _session$user3 === void 0 ? void 0 : _session$user3.role.toUpperCase())) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
335
- label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user4 = session.user) === null || _session$user4 === void 0 ? void 0 : _session$user4.role.toUpperCase()),
336
- size: "small",
337
- variant: "outlined",
338
- sx: {
339
- height: 'auto',
340
- marginRight: 0
341
- },
342
- icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
343
- component: _ShieldCheck.default,
344
- size: "small"
345
- })
346
- })]
347
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
348
- className: "session-manager-id-list",
349
- "aria-label": "User DID list",
350
- children: [walletDid && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
351
- className: "session-manager-id-item",
352
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
353
- responsive: false,
354
- children: walletDid
355
- })
356
- }), federatedAccount && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
357
- className: "session-manager-id-item",
358
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
359
- responsive: false,
360
- children: federatedAccount.did
361
- })
362
- }), (session === null || session === void 0 ? void 0 : (_session$user5 = session.user) === null || _session$user5 === void 0 ? void 0 : _session$user5.email) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
363
- className: "session-manager-id-item",
364
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
365
- responsive: false,
366
- children: session.user.email
367
- })
368
- })]
369
- })]
370
- }), Array.isArray(menu) && menu.map((menuItem, index) => {
371
- const {
372
- svgIcon
373
- } = menuItem,
374
- menuProps = _objectWithoutProperties(menuItem, _excluded2);
375
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, _objectSpread(_objectSpread({
376
- className: "session-manager-menu-item"
377
- }, _objectSpread(_objectSpread({}, menuProps), {}, {
378
- icon: undefined,
379
- label: undefined
380
- })), {}, {
381
- children: [svgIcon ? svgIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
382
- component: svgIcon,
383
- className: "session-manager-menu-icon"
384
- }) : menuItem.icon, menuItem.label]
385
- }), index);
386
- }), menuRender({
387
- classes: {
388
- menuItem: 'session-manager-menu-item',
389
- menuIcon: 'session-manager-menu-icon'
390
- }
391
- }), !browser.wallet && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
392
- component: "a",
393
- className: "session-manager-menu-item",
394
- "data-cy": "sessionManager-openInWallet",
395
- href: "https://www.abtwallet.io/",
396
- "aria-label": translation.openInWallet,
397
- target: "_blank",
398
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
399
- component: _OpenIn.default,
400
- className: "session-manager-menu-icon"
401
- }), translation.openInWallet]
402
- }), !(0, _isEmpty.default)(masterSiteInfo) && !!switchDid && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
403
- className: "session-manager-menu-item",
404
- onClick: _onSwitchDid,
405
- "aria-label": translation.switchDid,
406
- "data-cy": "sessionManager-switch-trigger",
407
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
408
- component: _Switch.default,
409
- className: "session-manager-menu-icon"
410
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
411
- sx: {
412
- whiteSpace: 'normal',
413
- wordBreak: 'break-all'
414
- },
415
- children: [translation.switchTo, session.provider === 'federated' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
416
- mx: 1,
417
- href: currentSiteInfo.appUrl,
418
- underline: "hover",
419
- target: "_blank",
420
- title: currentSiteInfo.appName,
421
- "aria-label": "Open current site url",
422
- children: currentSiteInfo.appName
423
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
424
- mx: 1,
425
- href: masterSiteInfo.appUrl,
426
- underline: "hover",
427
- target: "_blank",
428
- title: masterSiteInfo.appName,
429
- "aria-label": "Open federated master site url",
430
- children: masterSiteInfo.appName
431
- }), translation.account]
432
- })]
433
- }), !!switchProfile && hasBindWallet && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
434
- className: "session-manager-menu-item",
435
- onClick: _onSwitchProfile,
436
- "aria-label": translation.switchProfile,
437
- "data-cy": "sessionManager-switch-profile-trigger",
438
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
439
- component: _PersonOutline.default,
440
- className: "session-manager-menu-icon"
441
- }), translation.switchProfile]
442
- }), !!switchPassport && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
443
- className: "session-manager-menu-item",
444
- onClick: _onSwitchPassport,
445
- "aria-label": translation.switchPassport,
446
- "data-cy": "sessionManager-switch-passport-trigger",
447
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
448
- component: _VpnKeyOutlined.default,
449
- className: "session-manager-menu-icon"
450
- }), translation.switchPassport]
451
- }), oauthConfigList.length > 0 && !hasBindAccount && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
452
- className: "session-manager-menu-item",
453
- onClick: _onBindWallet,
454
- "aria-label": !isRawWalletAccount ? "".concat(translation.bind, "DID Wallet") : "".concat(translation.bind).concat(translation.thirdParty),
455
- "data-cy": "sessionManager-bind-trigger",
456
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
457
- component: _Link.default,
458
- className: "session-manager-menu-icon"
459
- }), !isRawWalletAccount ? "".concat(translation.bind, "DID Wallet") : "".concat(translation.bind).concat(translation.thirdParty)]
460
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
296
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_userInfo.default, {
297
+ session: session,
298
+ size: size,
299
+ locale: locale,
300
+ onEditUser: () => {
301
+ close();
302
+ _onSwitchProfile();
303
+ },
304
+ onSwitchPassport: () => {
305
+ close();
306
+ _onSwitchPassport();
307
+ },
308
+ close: close,
309
+ switchProfile: switchProfile,
310
+ hasBindWallet: hasBindWallet
311
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_manageAccounts.default, {
312
+ session: session,
313
+ locale: locale,
314
+ onBindWallet: onBindWallet,
315
+ onSwitchDid: onSwitchDid,
316
+ connectAccount: _connectAccount,
317
+ close: close,
318
+ hasBindAccount: hasBindAccount
319
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_manageBlocklet.default, {
320
+ menu: menu,
321
+ menuRender: menuRender,
322
+ locale: locale
323
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
461
324
  className: "session-manager-menu-item",
462
325
  onClick: _onLogout,
463
326
  disabled: disableLogout,
@@ -466,7 +329,7 @@ function SessionManager(_ref) {
466
329
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
467
330
  component: _Disconnect.default,
468
331
  className: "session-manager-menu-icon"
469
- }), translation.disconnect]
332
+ }), t('disconnect')]
470
333
  })]
471
334
  })
472
335
  })]