@arcblock/ux 2.7.14 → 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.
- package/es/Dialog/confirm.js +10 -8
- package/es/Img/index.js +7 -7
- package/es/Locale/selector.js +9 -9
- package/es/SessionManager/account-item.js +132 -0
- package/es/SessionManager/add-account-item.js +118 -0
- package/es/SessionManager/federated-login-detecter.js +15 -9
- package/es/SessionManager/index.js +122 -224
- package/es/SessionManager/manage-accounts.js +143 -0
- package/es/SessionManager/manage-blocklet.js +62 -0
- package/es/SessionManager/menu-accordion.js +95 -0
- package/es/SessionManager/translation.js +52 -0
- package/es/SessionManager/use-accounts.js +19 -0
- package/es/SessionManager/user-info.js +139 -0
- package/es/SessionManager/user-popper.js +13 -37
- package/es/SessionManager/utils.js +2 -0
- package/es/Util/index.js +7 -0
- package/lib/Dialog/confirm.js +9 -7
- package/lib/Img/index.js +7 -7
- package/lib/Locale/selector.js +16 -17
- package/lib/SessionManager/account-item.js +140 -0
- package/lib/SessionManager/add-account-item.js +126 -0
- package/lib/SessionManager/federated-login-detecter.js +15 -9
- package/lib/SessionManager/index.js +125 -237
- package/lib/SessionManager/manage-accounts.js +155 -0
- package/lib/SessionManager/manage-blocklet.js +78 -0
- package/lib/SessionManager/menu-accordion.js +103 -0
- package/lib/SessionManager/translation.js +59 -0
- package/lib/SessionManager/use-accounts.js +25 -0
- package/lib/SessionManager/user-info.js +155 -0
- package/lib/SessionManager/user-popper.js +8 -3
- package/lib/SessionManager/utils.js +16 -0
- package/lib/Util/index.js +11 -2
- package/package.json +8 -5
- package/src/Dialog/confirm.js +9 -6
- package/src/Img/index.js +5 -5
- package/src/Locale/{selector.js → selector.jsx} +9 -10
- package/src/SessionManager/account-item.jsx +111 -0
- package/src/SessionManager/add-account-item.jsx +115 -0
- package/src/SessionManager/federated-login-detecter.jsx +14 -12
- package/src/SessionManager/index.jsx +135 -214
- package/src/SessionManager/manage-accounts.jsx +143 -0
- package/src/SessionManager/manage-blocklet.jsx +64 -0
- package/src/SessionManager/menu-accordion.jsx +87 -0
- package/src/SessionManager/translation.js +52 -0
- package/src/SessionManager/use-accounts.js +18 -0
- package/src/SessionManager/user-info.jsx +116 -0
- package/src/SessionManager/user-popper.jsx +9 -37
- package/src/SessionManager/utils.js +3 -0
- package/src/Util/index.js +8 -0
- /package/src/Avatar/{did-motif.js → did-motif.jsx} +0 -0
- /package/src/Avatar/{index.js → index.jsx} +0 -0
- /package/src/Header/{auto-hidden.js → auto-hidden.jsx} +0 -0
- /package/src/Header/{header.js → header.jsx} +0 -0
- /package/src/Header/{responsive-header.js → responsive-header.jsx} +0 -0
- /package/src/Locale/{context.js → context.jsx} +0 -0
@@ -7,27 +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 _ConnectWithoutContact = _interopRequireDefault(require("@mui/icons-material/ConnectWithoutContact"));
|
14
|
-
var _ShieldCheck = _interopRequireDefault(require("mdi-material-ui/ShieldCheck"));
|
15
10
|
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
16
|
-
var _OpenIn = _interopRequireDefault(require("@arcblock/icons/lib/OpenIn"));
|
17
11
|
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
18
|
-
var _Switch = _interopRequireDefault(require("@arcblock/icons/lib/Switch"));
|
19
|
-
var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
|
20
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
21
12
|
var _noop = _interopRequireDefault(require("lodash/noop"));
|
13
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
14
|
+
var _ahooks = require("ahooks");
|
22
15
|
var _Avatar = _interopRequireDefault(require("../Avatar"));
|
23
|
-
var _Address = _interopRequireDefault(require("../Address"));
|
24
16
|
var _Util = require("../Util");
|
25
17
|
var _federatedLoginDetecter = _interopRequireDefault(require("./federated-login-detecter"));
|
26
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"));
|
27
26
|
var _jsxRuntime = require("react/jsx-runtime");
|
28
|
-
const _excluded = ["session", "locale", "showText", "showRole", "switchDid", "switchProfile", "switchPassport", "disableLogout", "onLogin", "onLogout", "onSwitchDid", "onSwitchProfile", "onSwitchPassport", "onBindWallet", "menu", "menuRender", "dark", "size"]
|
29
|
-
|
30
|
-
/* 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 */
|
31
29
|
/* eslint-disable react/jsx-no-bind */
|
32
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
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; }
|
@@ -37,43 +35,8 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
37
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); }
|
38
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; }
|
39
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; }
|
40
|
-
const translations = {
|
41
|
-
en: {
|
42
|
-
switchDid: 'Switch DID',
|
43
|
-
switchProfile: 'Switch Profile',
|
44
|
-
switchPassport: 'Switch Passport',
|
45
|
-
disconnect: 'Disconnect',
|
46
|
-
connect: 'Connect',
|
47
|
-
openInWallet: 'Open DID Wallet',
|
48
|
-
alreadyBindOAuth: 'Already bind Auth0',
|
49
|
-
bind: 'Bind ',
|
50
|
-
thirdParty: 'Third Party Login',
|
51
|
-
connectedWith: 'Connected with'
|
52
|
-
},
|
53
|
-
zh: {
|
54
|
-
switchDid: '切换账户',
|
55
|
-
switchProfile: '切换用户信息',
|
56
|
-
switchPassport: '切换通行证',
|
57
|
-
disconnect: '退出',
|
58
|
-
connect: '登录',
|
59
|
-
openInWallet: '打开 DID 钱包',
|
60
|
-
// NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
|
61
|
-
alreadyBindOAuth: '已绑定 Auth0 账号',
|
62
|
-
bind: '绑定',
|
63
|
-
thirdParty: '第三方登录',
|
64
|
-
connectedWith: '连接至'
|
65
|
-
}
|
66
|
-
};
|
67
|
-
const getConnectedAccounts = user => {
|
68
|
-
var _user$extraConfigs;
|
69
|
-
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) || [];
|
70
|
-
};
|
71
|
-
const getSourceProvider = user => {
|
72
|
-
var _user$extraConfigs2;
|
73
|
-
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';
|
74
|
-
};
|
75
38
|
function SessionManager(_ref) {
|
76
|
-
var _session$user, _session$user$avatar
|
39
|
+
var _session$user, _session$user$avatar;
|
77
40
|
let {
|
78
41
|
session,
|
79
42
|
locale,
|
@@ -95,33 +58,30 @@ function SessionManager(_ref) {
|
|
95
58
|
size
|
96
59
|
} = _ref,
|
97
60
|
rest = _objectWithoutProperties(_ref, _excluded);
|
98
|
-
const
|
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
|
+
});
|
99
69
|
const userAnchorRef = (0, _react.useRef)(null);
|
100
|
-
// eslint-disable-next-line react/prop-types
|
101
70
|
const {
|
102
71
|
logoutOAuth,
|
103
|
-
bindOAuth,
|
104
|
-
configs: oauthConfigs,
|
105
72
|
switchOAuthPassport
|
106
73
|
} = session.useOAuth();
|
107
74
|
const [userOpen, setUserOpen] = (0, _react.useState)(false);
|
108
75
|
|
109
76
|
// base64 img maybe have some blank char, need encodeURIComponent to transform it
|
110
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(' ')));
|
111
|
-
const
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
const
|
118
|
-
walletDid
|
119
|
-
} = session.useDid({
|
120
|
-
session
|
121
|
-
});
|
122
|
-
const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
|
123
|
-
const connectedAccounts = getConnectedAccounts(session.user);
|
124
|
-
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');
|
125
85
|
let hasBindWallet = false;
|
126
86
|
let hasBindAccount = false;
|
127
87
|
if (isRawWalletAccount) {
|
@@ -133,18 +93,57 @@ function SessionManager(_ref) {
|
|
133
93
|
hasBindAccount = true;
|
134
94
|
hasBindWallet = true;
|
135
95
|
}
|
136
|
-
const
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
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]);
|
148
147
|
if (!session.user) {
|
149
148
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
150
149
|
children: [showText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Button, _objectSpread(_objectSpread({
|
@@ -165,7 +164,7 @@ function SessionManager(_ref) {
|
|
165
164
|
style: {
|
166
165
|
lineHeight: '25px'
|
167
166
|
},
|
168
|
-
children:
|
167
|
+
children: t('connect')
|
169
168
|
})]
|
170
169
|
})) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
|
171
170
|
ref: userAnchorRef
|
@@ -206,15 +205,21 @@ function SessionManager(_ref) {
|
|
206
205
|
function onToggleUser() {
|
207
206
|
setUserOpen(prevOpen => !prevOpen);
|
208
207
|
}
|
208
|
+
function close() {
|
209
|
+
setUserOpen(false);
|
210
|
+
}
|
209
211
|
function onCloseUser(e) {
|
210
212
|
if (userAnchorRef.current && userAnchorRef.current.contains(e.target)) {
|
211
213
|
return;
|
212
214
|
}
|
213
|
-
|
215
|
+
close();
|
214
216
|
}
|
215
217
|
function _onLogin() {
|
216
218
|
if (!isFirstLoading) {
|
217
|
-
session.login(
|
219
|
+
session.login(function () {
|
220
|
+
_connectAccount();
|
221
|
+
onLogin(...arguments);
|
222
|
+
});
|
218
223
|
}
|
219
224
|
}
|
220
225
|
function _onLogout() {
|
@@ -230,19 +235,18 @@ function SessionManager(_ref) {
|
|
230
235
|
}).catch(err => {
|
231
236
|
console.error(err);
|
232
237
|
}).finally(() => {
|
233
|
-
|
238
|
+
close();
|
234
239
|
});
|
235
240
|
});
|
236
241
|
}
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
}
|
242
|
+
/**
|
243
|
+
* @name 切换账户
|
244
|
+
* @description 该功能仅在登录后才能使用,目前仅用于切换普通登录和统一登录的账户,所以会增加一些与统一登录相关的逻辑
|
245
|
+
*/
|
246
|
+
|
243
247
|
function _onSwitchProfile() {
|
244
248
|
session.switchProfile(function () {
|
245
|
-
|
249
|
+
close();
|
246
250
|
onSwitchProfile(...arguments);
|
247
251
|
});
|
248
252
|
}
|
@@ -254,25 +258,13 @@ function SessionManager(_ref) {
|
|
254
258
|
if (!isRawWalletAccount && provider !== 'federated') {
|
255
259
|
switchOAuthPassport(user);
|
256
260
|
} else {
|
257
|
-
|
261
|
+
close();
|
258
262
|
session.switchPassport(function () {
|
259
|
-
|
263
|
+
close();
|
260
264
|
onSwitchPassport(...arguments);
|
261
265
|
});
|
262
266
|
}
|
263
267
|
}
|
264
|
-
function _onBindWallet() {
|
265
|
-
setUserOpen(false);
|
266
|
-
// FIXME: @zhanghan 暂时切换回 isRawWalletAccount 的方式来判断,在 did-connect 改版时,简化这里的关系判断
|
267
|
-
if (!isRawWalletAccount) {
|
268
|
-
session.bindWallet(function () {
|
269
|
-
setUserOpen(false);
|
270
|
-
onBindWallet(...arguments);
|
271
|
-
});
|
272
|
-
} else {
|
273
|
-
bindOAuth();
|
274
|
-
}
|
275
|
-
}
|
276
268
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
277
269
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, _objectSpread(_objectSpread({
|
278
270
|
ref: userAnchorRef,
|
@@ -301,138 +293,34 @@ function SessionManager(_ref) {
|
|
301
293
|
sx: {
|
302
294
|
p: 0
|
303
295
|
},
|
304
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
children: walletDid
|
333
|
-
})
|
334
|
-
}), federatedAccount && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
335
|
-
className: "session-manager-id-item",
|
336
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
337
|
-
responsive: false,
|
338
|
-
children: federatedAccount.did
|
339
|
-
})
|
340
|
-
}), (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", {
|
341
|
-
className: "session-manager-id-item",
|
342
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
343
|
-
responsive: false,
|
344
|
-
children: session.user.email
|
345
|
-
})
|
346
|
-
})]
|
347
|
-
})]
|
348
|
-
}), federatedAccount && !(0, _isEmpty.default)(masterSiteInfo) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.MenuItem, {
|
349
|
-
className: "session-manager-menu-item",
|
350
|
-
"data-cy": "sessionManager-connectWithFederated",
|
351
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
352
|
-
overflow: "hidden",
|
353
|
-
textOverflow: "ellipsis",
|
354
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
355
|
-
component: _ConnectWithoutContact.default,
|
356
|
-
className: "session-manager-menu-icon"
|
357
|
-
}), translation.connectedWith, /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
|
358
|
-
ml: 1,
|
359
|
-
href: masterSiteInfo.appUrl,
|
360
|
-
underline: "hover",
|
361
|
-
target: "_blank",
|
362
|
-
title: masterSiteInfo.appName,
|
363
|
-
"aria-label": "Open federated master site url",
|
364
|
-
children: masterSiteInfo.appName
|
365
|
-
})]
|
366
|
-
})
|
367
|
-
}), Array.isArray(menu) && menu.map((menuItem, index) => {
|
368
|
-
const {
|
369
|
-
svgIcon
|
370
|
-
} = menuItem,
|
371
|
-
menuProps = _objectWithoutProperties(menuItem, _excluded2);
|
372
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, _objectSpread(_objectSpread({
|
373
|
-
className: "session-manager-menu-item"
|
374
|
-
}, _objectSpread(_objectSpread({}, menuProps), {}, {
|
375
|
-
icon: undefined,
|
376
|
-
label: undefined
|
377
|
-
})), {}, {
|
378
|
-
children: [svgIcon ? svgIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
379
|
-
component: svgIcon,
|
380
|
-
className: "session-manager-menu-icon"
|
381
|
-
}) : menuItem.icon, menuItem.label]
|
382
|
-
}), index);
|
383
|
-
}), menuRender({
|
384
|
-
classes: {
|
385
|
-
menuItem: 'session-manager-menu-item',
|
386
|
-
menuIcon: 'session-manager-menu-icon'
|
387
|
-
}
|
388
|
-
}), !browser.wallet && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
389
|
-
component: "a",
|
390
|
-
className: "session-manager-menu-item",
|
391
|
-
"data-cy": "sessionManager-openInWallet",
|
392
|
-
href: "https://www.abtwallet.io/",
|
393
|
-
"aria-label": translation.openInWallet,
|
394
|
-
target: "_blank",
|
395
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
396
|
-
component: _OpenIn.default,
|
397
|
-
className: "session-manager-menu-icon"
|
398
|
-
}), translation.openInWallet]
|
399
|
-
}), !!switchDid && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
400
|
-
className: "session-manager-menu-item",
|
401
|
-
onClick: _onSwitchDid,
|
402
|
-
"aria-label": translation.switchDid,
|
403
|
-
"data-cy": "sessionManager-switch-trigger",
|
404
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
405
|
-
component: _Switch.default,
|
406
|
-
className: "session-manager-menu-icon"
|
407
|
-
}), translation.switchDid]
|
408
|
-
}), !!switchProfile && hasBindWallet && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
409
|
-
className: "session-manager-menu-item",
|
410
|
-
onClick: _onSwitchProfile,
|
411
|
-
"aria-label": translation.switchProfile,
|
412
|
-
"data-cy": "sessionManager-switch-profile-trigger",
|
413
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
414
|
-
component: _PersonOutline.default,
|
415
|
-
className: "session-manager-menu-icon"
|
416
|
-
}), translation.switchProfile]
|
417
|
-
}), !!switchPassport && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
418
|
-
className: "session-manager-menu-item",
|
419
|
-
onClick: _onSwitchPassport,
|
420
|
-
"aria-label": translation.switchPassport,
|
421
|
-
"data-cy": "sessionManager-switch-passport-trigger",
|
422
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
423
|
-
component: _VpnKeyOutlined.default,
|
424
|
-
className: "session-manager-menu-icon"
|
425
|
-
}), translation.switchPassport]
|
426
|
-
}), oauthConfigList.length > 0 && !hasBindAccount && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
427
|
-
className: "session-manager-menu-item",
|
428
|
-
onClick: _onBindWallet,
|
429
|
-
"aria-label": !isRawWalletAccount ? "".concat(translation.bind, "DID Wallet") : "".concat(translation.bind).concat(translation.thirdParty),
|
430
|
-
"data-cy": "sessionManager-bind-trigger",
|
431
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
432
|
-
component: _Link.default,
|
433
|
-
className: "session-manager-menu-icon"
|
434
|
-
}), !isRawWalletAccount ? "".concat(translation.bind, "DID Wallet") : "".concat(translation.bind).concat(translation.thirdParty)]
|
435
|
-
}), /*#__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, {
|
436
324
|
className: "session-manager-menu-item",
|
437
325
|
onClick: _onLogout,
|
438
326
|
disabled: disableLogout,
|
@@ -441,7 +329,7 @@ function SessionManager(_ref) {
|
|
441
329
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
442
330
|
component: _Disconnect.default,
|
443
331
|
className: "session-manager-menu-icon"
|
444
|
-
}),
|
332
|
+
}), t('disconnect')]
|
445
333
|
})]
|
446
334
|
})
|
447
335
|
})]
|
@@ -0,0 +1,155 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = ManageAccounts;
|
7
|
+
var _ahooks = require("ahooks");
|
8
|
+
var _material = require("@mui/material");
|
9
|
+
var _react = require("@iconify/react");
|
10
|
+
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
11
|
+
var _link = _interopRequireDefault(require("@iconify-icons/mdi/link"));
|
12
|
+
var _accountItem = _interopRequireDefault(require("./account-item"));
|
13
|
+
var _menuAccordion = _interopRequireDefault(require("./menu-accordion"));
|
14
|
+
var _translation = require("./translation");
|
15
|
+
var _util = require("../Locale/util");
|
16
|
+
var _confirm = require("../Dialog/confirm");
|
17
|
+
var _utils = require("./utils");
|
18
|
+
var _addAccountItem = _interopRequireDefault(require("./add-account-item"));
|
19
|
+
var _useAccounts = _interopRequireDefault(require("./use-accounts"));
|
20
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22
|
+
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; }
|
23
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
24
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
25
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
26
|
+
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); } /* eslint-disable react/prop-types */ /* eslint-disable react/jsx-no-bind */
|
27
|
+
function ManageAccounts(_ref) {
|
28
|
+
let {
|
29
|
+
session,
|
30
|
+
locale,
|
31
|
+
onBindWallet,
|
32
|
+
onSwitchDid,
|
33
|
+
connectAccount,
|
34
|
+
close,
|
35
|
+
hasBindAccount
|
36
|
+
} = _ref;
|
37
|
+
const {
|
38
|
+
bindOAuth,
|
39
|
+
configs: oauthConfigs
|
40
|
+
} = session.useOAuth();
|
41
|
+
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
42
|
+
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
43
|
+
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
44
|
+
});
|
45
|
+
const {
|
46
|
+
confirmApi,
|
47
|
+
confirmHolder
|
48
|
+
} = (0, _confirm.useConfirm)();
|
49
|
+
const {
|
50
|
+
accounts,
|
51
|
+
setAccounts
|
52
|
+
} = (0, _useAccounts.default)();
|
53
|
+
const update = (0, _ahooks.useUpdate)();
|
54
|
+
const onChoose = (0, _ahooks.useMemoizedFn)((account, _ref2) => {
|
55
|
+
let {
|
56
|
+
active
|
57
|
+
} = _ref2;
|
58
|
+
if (active) {
|
59
|
+
return;
|
60
|
+
}
|
61
|
+
close();
|
62
|
+
session.switchDid(function () {
|
63
|
+
connectAccount();
|
64
|
+
onSwitchDid(...arguments);
|
65
|
+
}, {
|
66
|
+
provider: account.provider,
|
67
|
+
providerMode: 'paramsFirst'
|
68
|
+
});
|
69
|
+
});
|
70
|
+
const oauthConfigList = Object.entries(oauthConfigs).map(_ref3 => {
|
71
|
+
let [key, value] = _ref3;
|
72
|
+
return _objectSpread(_objectSpread({}, value), {}, {
|
73
|
+
provider: key
|
74
|
+
});
|
75
|
+
}).filter(item => item.enabled);
|
76
|
+
const isRawWalletAccount = (0, _utils.getSourceProvider)(session.user) === 'wallet';
|
77
|
+
const onDelete = (0, _ahooks.useMemoizedFn)((account, _ref4) => {
|
78
|
+
let {
|
79
|
+
active
|
80
|
+
} = _ref4;
|
81
|
+
if (active) {
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
confirmApi.open({
|
85
|
+
title: t('deleteAccountTitle'),
|
86
|
+
content: t('deleteAccountContent'),
|
87
|
+
confirmButtonText: t('confirm'),
|
88
|
+
cancelButtonText: t('cancel'),
|
89
|
+
onConfirm(done) {
|
90
|
+
const findIndex = accounts.findIndex(item => item.did === account.did);
|
91
|
+
if (findIndex >= 0) {
|
92
|
+
accounts.splice(findIndex, 1);
|
93
|
+
}
|
94
|
+
setAccounts(accounts);
|
95
|
+
update();
|
96
|
+
done();
|
97
|
+
}
|
98
|
+
});
|
99
|
+
});
|
100
|
+
const onAdd = (0, _ahooks.useMemoizedFn)(app => {
|
101
|
+
close();
|
102
|
+
session.switchDid(function () {
|
103
|
+
connectAccount();
|
104
|
+
update();
|
105
|
+
onSwitchDid(...arguments);
|
106
|
+
}, {
|
107
|
+
provider: app.provider,
|
108
|
+
providerMode: 'paramsFirst'
|
109
|
+
});
|
110
|
+
});
|
111
|
+
function _onBindWallet() {
|
112
|
+
close();
|
113
|
+
// FIXME: @zhanghan 暂时切换回 isRawWalletAccount 的方式来判断,在 did-connect 改版时,简化这里的关系判断
|
114
|
+
if (!isRawWalletAccount) {
|
115
|
+
session.bindWallet(onBindWallet);
|
116
|
+
} else {
|
117
|
+
bindOAuth();
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
121
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_menuAccordion.default, {
|
122
|
+
locale: locale,
|
123
|
+
title: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
124
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {
|
125
|
+
className: "session-manager-menu-icon",
|
126
|
+
style: {
|
127
|
+
width: 24,
|
128
|
+
height: 24
|
129
|
+
}
|
130
|
+
}), t('manageAccounts')]
|
131
|
+
}),
|
132
|
+
children: [accounts.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_accountItem.default, {
|
133
|
+
account: item,
|
134
|
+
locale: locale,
|
135
|
+
active: session.user.did === item.did,
|
136
|
+
onDelete: onDelete,
|
137
|
+
onChoose: onChoose
|
138
|
+
}, item.did)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_addAccountItem.default, {
|
139
|
+
locale: locale,
|
140
|
+
onAdd: onAdd
|
141
|
+
}), oauthConfigList.length > 0 && !hasBindAccount && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
142
|
+
className: "session-manager-menu-item",
|
143
|
+
onClick: _onBindWallet,
|
144
|
+
"aria-label": !isRawWalletAccount ? "".concat(t('bind'), "DID Wallet") : "".concat(t('bind')).concat(t('thirdParty')),
|
145
|
+
"data-cy": "sessionManager-bind-trigger",
|
146
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
147
|
+
icon: _link.default,
|
148
|
+
width: 24,
|
149
|
+
height: 24,
|
150
|
+
className: "session-manager-menu-icon"
|
151
|
+
}), !isRawWalletAccount ? "".concat(t('bind'), "DID Wallet") : "".concat(t('bind')).concat(t('thirdParty'))]
|
152
|
+
})]
|
153
|
+
}), confirmHolder]
|
154
|
+
});
|
155
|
+
}
|