@arcblock/ux 2.6.4 → 2.6.6
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/lib/SessionManager/index.js +67 -37
- package/package.json +4 -4
- package/src/SessionManager/index.jsx +37 -11
@@ -6,16 +6,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.default = void 0;
|
7
7
|
var _react = require("react");
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
|
-
var
|
10
|
-
var
|
9
|
+
var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
|
10
|
+
var _MenuList = _interopRequireDefault(require("@mui/material/MenuList"));
|
11
|
+
var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
|
12
|
+
var _SvgIcon = _interopRequireDefault(require("@mui/material/SvgIcon"));
|
13
|
+
var _Button = _interopRequireDefault(require("@mui/material/Button"));
|
14
|
+
var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
|
15
|
+
var _Link = _interopRequireDefault(require("@mui/material/Link"));
|
16
|
+
var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
|
17
|
+
var _PersonOutline = _interopRequireDefault(require("@mui/icons-material/PersonOutline"));
|
18
|
+
var _Link2 = _interopRequireDefault(require("@mui/icons-material/Link"));
|
19
|
+
var _VpnKeyOutlined = _interopRequireDefault(require("@mui/icons-material/VpnKeyOutlined"));
|
20
|
+
var _ConnectWithoutContact = _interopRequireDefault(require("@mui/icons-material/ConnectWithoutContact"));
|
11
21
|
var _ShieldCheck = _interopRequireDefault(require("mdi-material-ui/ShieldCheck"));
|
22
|
+
var _Account = _interopRequireDefault(require("@arcblock/icons/lib/Account"));
|
12
23
|
var _OpenIn = _interopRequireDefault(require("@arcblock/icons/lib/OpenIn"));
|
13
24
|
var _Disconnect = _interopRequireDefault(require("@arcblock/icons/lib/Disconnect"));
|
14
25
|
var _Switch = _interopRequireDefault(require("@arcblock/icons/lib/Switch"));
|
15
|
-
var _PersonOutline = _interopRequireDefault(require("@mui/icons-material/PersonOutline"));
|
16
|
-
var _Link = _interopRequireDefault(require("@mui/icons-material/Link"));
|
17
|
-
var _VpnKeyOutlined = _interopRequireDefault(require("@mui/icons-material/VpnKeyOutlined"));
|
18
26
|
var _useBrowser = _interopRequireDefault(require("@arcblock/react-hooks/lib/useBrowser"));
|
27
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
19
28
|
var _Avatar = _interopRequireDefault(require("../Avatar"));
|
20
29
|
var _Address = _interopRequireDefault(require("../Address"));
|
21
30
|
var _Util = require("../Util");
|
@@ -44,7 +53,8 @@ const translations = {
|
|
44
53
|
openInWallet: 'Open DID Wallet',
|
45
54
|
alreadyBindOAuth: 'Already bind Auth0',
|
46
55
|
bind: 'Bind ',
|
47
|
-
thirdParty: 'Third Party Login'
|
56
|
+
thirdParty: 'Third Party Login',
|
57
|
+
connectedWith: 'Connected with'
|
48
58
|
},
|
49
59
|
zh: {
|
50
60
|
switchDid: '切换账户',
|
@@ -56,7 +66,8 @@ const translations = {
|
|
56
66
|
// NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
|
57
67
|
alreadyBindOAuth: '已绑定 Auth0 账号',
|
58
68
|
bind: '绑定',
|
59
|
-
thirdParty: '第三方登录'
|
69
|
+
thirdParty: '第三方登录',
|
70
|
+
connectedWith: '连接至'
|
60
71
|
}
|
61
72
|
};
|
62
73
|
const getConnectedAccounts = user => {
|
@@ -68,7 +79,7 @@ const getSourceProvider = user => {
|
|
68
79
|
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';
|
69
80
|
};
|
70
81
|
function SessionManager(_ref) {
|
71
|
-
var _session$user, _session$user$avatar, _session$user3, _session$user4, _session$user5;
|
82
|
+
var _session$user, _session$user$avatar, _window$blocklet, _window$blocklet$sett, _window$blocklet$sett2, _session$user3, _session$user4, _session$user5;
|
72
83
|
let {
|
73
84
|
session,
|
74
85
|
locale,
|
@@ -116,6 +127,7 @@ function SessionManager(_ref) {
|
|
116
127
|
});
|
117
128
|
const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
|
118
129
|
const connectedAccounts = getConnectedAccounts(session.user);
|
130
|
+
const federatedAccount = connectedAccounts.find(item => item.provider === 'federated');
|
119
131
|
let hasBindWallet = false;
|
120
132
|
let hasBindAccount = false;
|
121
133
|
if (isRawWalletAccount) {
|
@@ -138,9 +150,10 @@ function SessionManager(_ref) {
|
|
138
150
|
return (session === null || session === void 0 ? void 0 : session.initialized) === false && (session === null || session === void 0 ? void 0 : session.loading) === true;
|
139
151
|
// eslint-disable-next-line react/prop-types
|
140
152
|
}, [session === null || session === void 0 ? void 0 : session.initialized, session === null || session === void 0 ? void 0 : session.loading]);
|
153
|
+
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;
|
141
154
|
if (!session.user) {
|
142
155
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
143
|
-
children: [showText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
156
|
+
children: [showText ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, _objectSpread(_objectSpread({
|
144
157
|
ref: userAnchorRef,
|
145
158
|
sx: [{
|
146
159
|
borderRadius: '100vw'
|
@@ -153,19 +166,19 @@ function SessionManager(_ref) {
|
|
153
166
|
"aria-label": "login button"
|
154
167
|
}, rest), {}, {
|
155
168
|
"data-cy": "sessionManager-login",
|
156
|
-
children: [isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
169
|
+
children: [isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Account.default, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
157
170
|
style: {
|
158
171
|
lineHeight: '25px'
|
159
172
|
},
|
160
173
|
children: translation.connect
|
161
174
|
})]
|
162
|
-
})) : /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
175
|
+
})) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, _objectSpread(_objectSpread({
|
163
176
|
ref: userAnchorRef
|
164
177
|
}, rest), {}, {
|
165
178
|
onClick: _onLogin,
|
166
179
|
"data-cy": "sessionManager-login",
|
167
180
|
size: "medium",
|
168
|
-
children: isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
181
|
+
children: isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
|
169
182
|
style: {
|
170
183
|
width: size - 4,
|
171
184
|
height: size - 4,
|
@@ -233,7 +246,7 @@ function SessionManager(_ref) {
|
|
233
246
|
user,
|
234
247
|
provider
|
235
248
|
} = session;
|
236
|
-
if (provider
|
249
|
+
if (!isRawWalletAccount && provider !== 'federated') {
|
237
250
|
switchOAuthPassport(user);
|
238
251
|
} else {
|
239
252
|
setUserOpen(false);
|
@@ -244,11 +257,9 @@ function SessionManager(_ref) {
|
|
244
257
|
}
|
245
258
|
}
|
246
259
|
function _onBindWallet() {
|
247
|
-
const {
|
248
|
-
provider
|
249
|
-
} = session;
|
250
260
|
setUserOpen(false);
|
251
|
-
|
261
|
+
// FIXME: @zhanghan 暂时切换回 isRawWalletAccount 的方式来判断,在 did-connect 改版时,简化这里的关系判断
|
262
|
+
if (!isRawWalletAccount) {
|
252
263
|
session.bindWallet(function () {
|
253
264
|
setUserOpen(false);
|
254
265
|
onBindWallet(...arguments);
|
@@ -258,7 +269,7 @@ function SessionManager(_ref) {
|
|
258
269
|
}
|
259
270
|
}
|
260
271
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
261
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
272
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_IconButton.default, _objectSpread(_objectSpread({
|
262
273
|
ref: userAnchorRef,
|
263
274
|
onClick: onToggleUser
|
264
275
|
}, rest), {}, {
|
@@ -279,7 +290,7 @@ function SessionManager(_ref) {
|
|
279
290
|
onClose: onCloseUser,
|
280
291
|
anchorEl: userAnchorRef.current,
|
281
292
|
dark: dark,
|
282
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
293
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuList.default, {
|
283
294
|
sx: {
|
284
295
|
p: 0
|
285
296
|
},
|
@@ -289,7 +300,7 @@ function SessionManager(_ref) {
|
|
289
300
|
className: "session-manager-user-name",
|
290
301
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
291
302
|
children: session.user.fullName
|
292
|
-
}), !!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)(
|
303
|
+
}), !!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)(_Chip.default, {
|
293
304
|
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()),
|
294
305
|
size: "small",
|
295
306
|
variant: "outlined",
|
@@ -297,7 +308,7 @@ function SessionManager(_ref) {
|
|
297
308
|
height: 'auto',
|
298
309
|
marginRight: 0
|
299
310
|
},
|
300
|
-
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
311
|
+
icon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
301
312
|
component: _ShieldCheck.default,
|
302
313
|
size: "small"
|
303
314
|
})
|
@@ -310,6 +321,12 @@ function SessionManager(_ref) {
|
|
310
321
|
responsive: false,
|
311
322
|
children: walletDid
|
312
323
|
})
|
324
|
+
}), federatedAccount && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
325
|
+
className: "session-manager-id-item",
|
326
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
327
|
+
responsive: false,
|
328
|
+
children: federatedAccount.did
|
329
|
+
})
|
313
330
|
}), (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", {
|
314
331
|
className: "session-manager-id-item",
|
315
332
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
@@ -318,18 +335,31 @@ function SessionManager(_ref) {
|
|
318
335
|
})
|
319
336
|
})]
|
320
337
|
})]
|
338
|
+
}), federatedAccount && !(0, _isEmpty.default)(masterSiteInfo) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
339
|
+
className: "session-manager-menu-item",
|
340
|
+
"data-cy": "sessionManager-connectWithFederated",
|
341
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
342
|
+
component: _ConnectWithoutContact.default,
|
343
|
+
className: "session-manager-menu-icon"
|
344
|
+
}), translation.connectedWith, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Link.default, {
|
345
|
+
ml: 1,
|
346
|
+
href: masterSiteInfo.appUrl,
|
347
|
+
underline: "hover",
|
348
|
+
target: "_blank",
|
349
|
+
children: masterSiteInfo.appName
|
350
|
+
})]
|
321
351
|
}), Array.isArray(menu) && menu.map((menuItem, index) => {
|
322
352
|
const {
|
323
353
|
svgIcon
|
324
354
|
} = menuItem,
|
325
355
|
menuProps = _objectWithoutProperties(menuItem, _excluded2);
|
326
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
356
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, _objectSpread(_objectSpread({
|
327
357
|
className: "session-manager-menu-item"
|
328
358
|
}, _objectSpread(_objectSpread({}, menuProps), {}, {
|
329
359
|
icon: undefined,
|
330
360
|
label: undefined
|
331
361
|
})), {}, {
|
332
|
-
children: [svgIcon ? svgIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
362
|
+
children: [svgIcon ? svgIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
333
363
|
component: svgIcon,
|
334
364
|
className: "session-manager-menu-icon"
|
335
365
|
}) : menuItem.icon, menuItem.label]
|
@@ -339,54 +369,54 @@ function SessionManager(_ref) {
|
|
339
369
|
menuItem: 'session-manager-menu-item',
|
340
370
|
menuIcon: 'session-manager-menu-icon'
|
341
371
|
}
|
342
|
-
}), !browser.wallet && /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
372
|
+
}), !browser.wallet && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
343
373
|
component: "a",
|
344
374
|
className: "session-manager-menu-item",
|
345
375
|
"data-cy": "sessionManager-openInWallet",
|
346
376
|
href: "https://www.abtwallet.io/",
|
347
377
|
target: "_blank",
|
348
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
378
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
349
379
|
component: _OpenIn.default,
|
350
380
|
className: "session-manager-menu-icon"
|
351
381
|
}), translation.openInWallet]
|
352
|
-
}), !!switchDid && /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
382
|
+
}), !!switchDid && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
353
383
|
className: "session-manager-menu-item",
|
354
384
|
onClick: _onSwitchDid,
|
355
385
|
"data-cy": "sessionManager-switch-trigger",
|
356
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
386
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
357
387
|
component: _Switch.default,
|
358
388
|
className: "session-manager-menu-icon"
|
359
389
|
}), translation.switchDid]
|
360
|
-
}), !!switchProfile && hasBindWallet && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
390
|
+
}), !!switchProfile && hasBindWallet && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
361
391
|
className: "session-manager-menu-item",
|
362
392
|
onClick: _onSwitchProfile,
|
363
393
|
"data-cy": "sessionManager-switch-profile-trigger",
|
364
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
394
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
365
395
|
component: _PersonOutline.default,
|
366
396
|
className: "session-manager-menu-icon"
|
367
397
|
}), translation.switchProfile]
|
368
|
-
}), !!switchPassport && /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
398
|
+
}), !!switchPassport && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
369
399
|
className: "session-manager-menu-item",
|
370
400
|
onClick: _onSwitchPassport,
|
371
401
|
"data-cy": "sessionManager-switch-passport-trigger",
|
372
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
402
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
373
403
|
component: _VpnKeyOutlined.default,
|
374
404
|
className: "session-manager-menu-icon"
|
375
405
|
}), translation.switchPassport]
|
376
|
-
}), oauthConfigList.length > 0 && !hasBindAccount && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
406
|
+
}), oauthConfigList.length > 0 && !hasBindAccount && session.provider !== 'federated' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
377
407
|
className: "session-manager-menu-item",
|
378
408
|
onClick: _onBindWallet,
|
379
409
|
"data-cy": "sessionManager-bind-trigger",
|
380
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
381
|
-
component:
|
410
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
411
|
+
component: _Link2.default,
|
382
412
|
className: "session-manager-menu-icon"
|
383
|
-
}),
|
384
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
413
|
+
}), !isRawWalletAccount ? "".concat(translation.bind, "DID Wallet") : "".concat(translation.bind).concat(translation.thirdParty)]
|
414
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_MenuItem.default, {
|
385
415
|
className: "session-manager-menu-item",
|
386
416
|
onClick: _onLogout,
|
387
417
|
disabled: disableLogout,
|
388
418
|
"data-cy": "sessionManager-logout-trigger",
|
389
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
419
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SvgIcon.default, {
|
390
420
|
component: _Disconnect.default,
|
391
421
|
className: "session-manager-menu-icon"
|
392
422
|
}), translation.disconnect]
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.6.
|
3
|
+
"version": "2.6.6",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -47,11 +47,11 @@
|
|
47
47
|
"peerDependencies": {
|
48
48
|
"react": ">=18.1.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "88c400a42296362b453d58766cbf2ae1ca2a1ee3",
|
51
51
|
"dependencies": {
|
52
52
|
"@arcblock/did-motif": "^1.1.13",
|
53
|
-
"@arcblock/icons": "^2.6.
|
54
|
-
"@arcblock/react-hooks": "^2.6.
|
53
|
+
"@arcblock/icons": "^2.6.6",
|
54
|
+
"@arcblock/react-hooks": "^2.6.6",
|
55
55
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
56
56
|
"@emotion/react": "^11.10.4",
|
57
57
|
"@emotion/styled": "^11.10.4",
|
@@ -2,16 +2,25 @@
|
|
2
2
|
/* eslint-disable react/jsx-no-bind */
|
3
3
|
import { useMemo, useRef, useState } from 'react';
|
4
4
|
import PropTypes from 'prop-types';
|
5
|
-
import
|
6
|
-
import
|
5
|
+
import IconButton from '@mui/material/IconButton';
|
6
|
+
import MenuList from '@mui/material/MenuList';
|
7
|
+
import MenuItem from '@mui/material/MenuItem';
|
8
|
+
import SvgIcon from '@mui/material/SvgIcon';
|
9
|
+
import Button from '@mui/material/Button';
|
10
|
+
import Chip from '@mui/material/Chip';
|
11
|
+
import Link from '@mui/material/Link';
|
12
|
+
import CircularProgress from '@mui/material/CircularProgress';
|
13
|
+
import SwitchProfileIcon from '@mui/icons-material/PersonOutline';
|
14
|
+
import BindWalletIcon from '@mui/icons-material/Link';
|
15
|
+
import SwitchPassportIcon from '@mui/icons-material/VpnKeyOutlined';
|
16
|
+
import ConnectWithoutContactIcon from '@mui/icons-material/ConnectWithoutContact';
|
7
17
|
import ShieldCheck from 'mdi-material-ui/ShieldCheck';
|
18
|
+
import AccountIcon from '@arcblock/icons/lib/Account';
|
8
19
|
import OpenInIcon from '@arcblock/icons/lib/OpenIn';
|
9
20
|
import DisconnectIcon from '@arcblock/icons/lib/Disconnect';
|
10
21
|
import SwitchDidIcon from '@arcblock/icons/lib/Switch';
|
11
|
-
import SwitchProfileIcon from '@mui/icons-material/PersonOutline';
|
12
|
-
import BindWalletIcon from '@mui/icons-material/Link';
|
13
|
-
import SwitchPassportIcon from '@mui/icons-material/VpnKeyOutlined';
|
14
22
|
import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
|
23
|
+
import isEmpty from 'lodash/isEmpty';
|
15
24
|
|
16
25
|
import DidAvatar from '../Avatar';
|
17
26
|
import DidAddress from '../Address';
|
@@ -30,6 +39,7 @@ const translations = {
|
|
30
39
|
alreadyBindOAuth: 'Already bind Auth0',
|
31
40
|
bind: 'Bind ',
|
32
41
|
thirdParty: 'Third Party Login',
|
42
|
+
connectedWith: 'Connected with',
|
33
43
|
},
|
34
44
|
zh: {
|
35
45
|
switchDid: '切换账户',
|
@@ -42,6 +52,7 @@ const translations = {
|
|
42
52
|
alreadyBindOAuth: '已绑定 Auth0 账号',
|
43
53
|
bind: '绑定',
|
44
54
|
thirdParty: '第三方登录',
|
55
|
+
connectedWith: '连接至',
|
45
56
|
},
|
46
57
|
};
|
47
58
|
|
@@ -87,6 +98,7 @@ function SessionManager({
|
|
87
98
|
|
88
99
|
const isRawWalletAccount = getSourceProvider(session.user) === 'wallet';
|
89
100
|
const connectedAccounts = getConnectedAccounts(session.user);
|
101
|
+
const federatedAccount = connectedAccounts.find((item) => item.provider === 'federated');
|
90
102
|
let hasBindWallet = false;
|
91
103
|
let hasBindAccount = false;
|
92
104
|
if (isRawWalletAccount) {
|
@@ -111,6 +123,8 @@ function SessionManager({
|
|
111
123
|
// eslint-disable-next-line react/prop-types
|
112
124
|
}, [session?.initialized, session?.loading]);
|
113
125
|
|
126
|
+
const masterSiteInfo = window.blocklet?.settings?.federated?.master;
|
127
|
+
|
114
128
|
if (!session.user) {
|
115
129
|
return (
|
116
130
|
<>
|
@@ -185,7 +199,7 @@ function SessionManager({
|
|
185
199
|
}
|
186
200
|
function _onSwitchPassport() {
|
187
201
|
const { user, provider } = session;
|
188
|
-
if (provider
|
202
|
+
if (!isRawWalletAccount && provider !== 'federated') {
|
189
203
|
switchOAuthPassport(user);
|
190
204
|
} else {
|
191
205
|
setUserOpen(false);
|
@@ -197,9 +211,9 @@ function SessionManager({
|
|
197
211
|
}
|
198
212
|
|
199
213
|
function _onBindWallet() {
|
200
|
-
const { provider } = session;
|
201
214
|
setUserOpen(false);
|
202
|
-
|
215
|
+
// FIXME: @zhanghan 暂时切换回 isRawWalletAccount 的方式来判断,在 did-connect 改版时,简化这里的关系判断
|
216
|
+
if (!isRawWalletAccount) {
|
203
217
|
session.bindWallet((...args) => {
|
204
218
|
setUserOpen(false);
|
205
219
|
onBindWallet(...args);
|
@@ -242,6 +256,11 @@ function SessionManager({
|
|
242
256
|
<DidAddress responsive={false}>{walletDid}</DidAddress>
|
243
257
|
</div>
|
244
258
|
)}
|
259
|
+
{federatedAccount && (
|
260
|
+
<div className="session-manager-id-item">
|
261
|
+
<DidAddress responsive={false}>{federatedAccount.did}</DidAddress>
|
262
|
+
</div>
|
263
|
+
)}
|
245
264
|
{session?.user?.email && (
|
246
265
|
<div className="session-manager-id-item">
|
247
266
|
<DidAddress responsive={false}>{session.user.email}</DidAddress>
|
@@ -249,6 +268,15 @@ function SessionManager({
|
|
249
268
|
)}
|
250
269
|
</div>
|
251
270
|
</div>
|
271
|
+
{federatedAccount && !isEmpty(masterSiteInfo) && (
|
272
|
+
<MenuItem className="session-manager-menu-item" data-cy="sessionManager-connectWithFederated">
|
273
|
+
<SvgIcon component={ConnectWithoutContactIcon} className="session-manager-menu-icon" />
|
274
|
+
{translation.connectedWith}
|
275
|
+
<Link ml={1} href={masterSiteInfo.appUrl} underline="hover" target="_blank">
|
276
|
+
{masterSiteInfo.appName}
|
277
|
+
</Link>
|
278
|
+
</MenuItem>
|
279
|
+
)}
|
252
280
|
{Array.isArray(menu) &&
|
253
281
|
menu.map((menuItem, index) => {
|
254
282
|
const { svgIcon, ...menuProps } = menuItem;
|
@@ -319,9 +347,7 @@ function SessionManager({
|
|
319
347
|
onClick={_onBindWallet}
|
320
348
|
data-cy="sessionManager-bind-trigger">
|
321
349
|
<SvgIcon component={BindWalletIcon} className="session-manager-menu-icon" />
|
322
|
-
{
|
323
|
-
? `${translation.bind}DID Wallet`
|
324
|
-
: `${translation.bind}${translation.thirdParty}`}
|
350
|
+
{!isRawWalletAccount ? `${translation.bind}DID Wallet` : `${translation.bind}${translation.thirdParty}`}
|
325
351
|
</MenuItem>
|
326
352
|
)}
|
327
353
|
|