@arcblock/ux 2.8.26 → 2.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/es/Address/did-address.js +33 -21
  2. package/es/AnimationWaiter/index.js +2 -1
  3. package/es/Avatar/index.js +1 -1
  4. package/es/BlockletContext/index.js +1 -1
  5. package/es/CardSelector/index.js +2 -1
  6. package/es/Colors/index.js +2 -1
  7. package/es/Colors/themes/temp.js +17 -0
  8. package/es/Datatable/TableSearch.js +2 -1
  9. package/es/Img/index.js +7 -6
  10. package/es/Locale/selector.js +15 -13
  11. package/es/NFTDisplay/index.js +2 -1
  12. package/es/QRCode/index.js +2 -1
  13. package/es/SessionBlocklet/index.js +169 -0
  14. package/es/SessionManager/index.js +2 -381
  15. package/es/SessionPermission/index.js +28 -0
  16. package/es/SessionUser/components/logged-in.js +224 -0
  17. package/es/SessionUser/components/session-user-item.js +148 -0
  18. package/es/SessionUser/components/session-user-switch.js +213 -0
  19. package/es/SessionUser/components/un-login.js +64 -0
  20. package/es/SessionUser/components/user-info.js +163 -0
  21. package/es/SessionUser/index.js +49 -0
  22. package/es/SessionUser/libs/translation.js +19 -0
  23. package/es/SessionUser/libs/utils.js +4 -0
  24. package/es/SplitButton/index.js +2 -1
  25. package/es/Toast/index.js +1 -1
  26. package/es/Util/constant.js +10 -0
  27. package/es/Util/index.js +11 -0
  28. package/lib/Address/did-address.js +36 -22
  29. package/lib/AnimationWaiter/index.js +2 -1
  30. package/lib/Avatar/index.js +1 -1
  31. package/lib/BlockletContext/index.js +1 -1
  32. package/lib/CardSelector/index.js +2 -1
  33. package/lib/Colors/index.js +7 -0
  34. package/lib/Colors/themes/temp.js +24 -0
  35. package/lib/Datatable/TableSearch.js +2 -1
  36. package/lib/Img/index.js +7 -6
  37. package/lib/Locale/selector.js +14 -13
  38. package/lib/NFTDisplay/index.js +2 -1
  39. package/lib/QRCode/index.js +2 -1
  40. package/lib/SessionBlocklet/index.js +187 -0
  41. package/lib/SessionManager/index.js +2 -390
  42. package/lib/SessionPermission/index.js +38 -0
  43. package/lib/SessionUser/components/logged-in.js +243 -0
  44. package/lib/SessionUser/components/session-user-item.js +163 -0
  45. package/lib/SessionUser/components/session-user-switch.js +232 -0
  46. package/lib/SessionUser/components/un-login.js +72 -0
  47. package/lib/SessionUser/components/user-info.js +175 -0
  48. package/lib/SessionUser/index.js +57 -0
  49. package/lib/SessionUser/libs/translation.js +26 -0
  50. package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
  51. package/lib/SplitButton/index.js +2 -1
  52. package/lib/Toast/index.js +5 -5
  53. package/lib/Util/constant.js +26 -0
  54. package/lib/Util/index.js +16 -3
  55. package/package.json +19 -7
  56. package/src/Address/did-address.jsx +34 -20
  57. package/src/AnimationWaiter/index.js +2 -1
  58. package/src/Avatar/index.jsx +1 -1
  59. package/src/BlockletContext/index.jsx +1 -1
  60. package/src/CardSelector/index.jsx +2 -1
  61. package/src/Colors/index.js +1 -0
  62. package/src/Colors/themes/temp.js +18 -0
  63. package/src/Datatable/TableSearch.js +3 -1
  64. package/src/Img/{index.js → index.jsx} +8 -6
  65. package/src/Locale/selector.jsx +11 -8
  66. package/src/NFTDisplay/index.js +2 -1
  67. package/src/QRCode/index.js +2 -1
  68. package/src/SessionBlocklet/index.jsx +181 -0
  69. package/src/SessionManager/index.jsx +2 -369
  70. package/src/SessionPermission/index.jsx +28 -0
  71. package/src/SessionUser/components/logged-in.jsx +194 -0
  72. package/src/SessionUser/components/session-user-item.jsx +96 -0
  73. package/src/SessionUser/components/session-user-switch.jsx +222 -0
  74. package/src/SessionUser/components/un-login.jsx +55 -0
  75. package/src/SessionUser/components/user-info.jsx +165 -0
  76. package/src/SessionUser/index.jsx +38 -0
  77. package/src/SessionUser/libs/translation.js +19 -0
  78. package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
  79. package/src/SplitButton/index.js +2 -1
  80. package/src/Toast/index.js +1 -1
  81. package/src/Util/constant.js +12 -0
  82. package/src/Util/index.js +13 -0
  83. package/es/SessionManager/components/account-item.js +0 -212
  84. package/es/SessionManager/components/add-account-item.js +0 -57
  85. package/es/SessionManager/components/federated-login-detecter.js +0 -183
  86. package/es/SessionManager/components/manage-accounts.js +0 -219
  87. package/es/SessionManager/components/manage-blocklet.js +0 -70
  88. package/es/SessionManager/components/menu-accordion.js +0 -103
  89. package/es/SessionManager/components/responsive-popper.js +0 -24
  90. package/es/SessionManager/components/user-drawer.js +0 -68
  91. package/es/SessionManager/components/user-info.js +0 -143
  92. package/es/SessionManager/components/user-popper.js +0 -110
  93. package/es/SessionManager/hooks/use-config.js +0 -34
  94. package/es/SessionManager/libs/translation.js +0 -52
  95. package/es/SessionManager/libs/utils.js +0 -2
  96. package/lib/SessionManager/components/account-item.js +0 -219
  97. package/lib/SessionManager/components/add-account-item.js +0 -66
  98. package/lib/SessionManager/components/federated-login-detecter.js +0 -193
  99. package/lib/SessionManager/components/manage-accounts.js +0 -232
  100. package/lib/SessionManager/components/manage-blocklet.js +0 -86
  101. package/lib/SessionManager/components/menu-accordion.js +0 -111
  102. package/lib/SessionManager/components/responsive-popper.js +0 -34
  103. package/lib/SessionManager/components/user-drawer.js +0 -75
  104. package/lib/SessionManager/components/user-info.js +0 -160
  105. package/lib/SessionManager/components/user-popper.js +0 -104
  106. package/lib/SessionManager/hooks/use-config.js +0 -41
  107. package/lib/SessionManager/libs/translation.js +0 -59
  108. package/src/SessionManager/components/account-item.jsx +0 -156
  109. package/src/SessionManager/components/add-account-item.jsx +0 -49
  110. package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
  111. package/src/SessionManager/components/manage-accounts.jsx +0 -228
  112. package/src/SessionManager/components/manage-blocklet.jsx +0 -70
  113. package/src/SessionManager/components/menu-accordion.jsx +0 -93
  114. package/src/SessionManager/components/responsive-popper.jsx +0 -26
  115. package/src/SessionManager/components/user-drawer.jsx +0 -57
  116. package/src/SessionManager/components/user-info.jsx +0 -117
  117. package/src/SessionManager/components/user-popper.jsx +0 -95
  118. package/src/SessionManager/hooks/use-config.js +0 -33
  119. package/src/SessionManager/libs/translation.js +0 -52
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _react = require("react");
9
+ var _material = require("@mui/material");
10
+ var _ahooks = require("ahooks");
11
+ var _react2 = require("@iconify/react");
12
+ var _api = _interopRequireDefault(require("@iconify-icons/mdi/api"));
13
+ var _iosRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/ios-rounded"));
14
+ var _language = _interopRequireDefault(require("@iconify-icons/material-symbols/language"));
15
+ var _lens = _interopRequireDefault(require("@iconify-icons/material-symbols/lens"));
16
+ var _android = _interopRequireDefault(require("@iconify-icons/material-symbols/android"));
17
+ var _auth0Icon = _interopRequireDefault(require("@iconify-icons/logos/auth0-icon"));
18
+ var _Avatar = _interopRequireDefault(require("../../Avatar"));
19
+ var _DID = _interopRequireDefault(require("../../DID"));
20
+ var _Colors = require("../../Colors");
21
+ var _utils = require("../libs/utils");
22
+ var _jsxRuntime = require("react/jsx-runtime");
23
+ const _excluded = ["sessionItem", "statusContent", "active"];
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
+ 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; }
26
+ 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; }
27
+ 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; }
28
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
29
+ 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); }
30
+ 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; }
31
+ 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; }
32
+ const SessionUserItem = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
33
+ var _sessionItem$extra, _sessionItem$extra2;
34
+ let {
35
+ sessionItem,
36
+ statusContent,
37
+ active
38
+ } = _ref,
39
+ rest = _objectWithoutProperties(_ref, _excluded);
40
+ const isRawWalletAccount = (0, _utils.getSourceProvider)(sessionItem === null || sessionItem === void 0 ? void 0 : sessionItem.user) === 'wallet';
41
+ const walletIcon = (0, _ahooks.useCreation)(() => {
42
+ const {
43
+ walletOS,
44
+ provider
45
+ } = (sessionItem === null || sessionItem === void 0 ? void 0 : sessionItem.extra) || {};
46
+ if (provider === 'auth0') {
47
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
48
+ icon: _auth0Icon.default,
49
+ width: 10,
50
+ height: 10,
51
+ style: {
52
+ color: 'black'
53
+ }
54
+ });
55
+ }
56
+ if (walletOS === 'ios') {
57
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
58
+ icon: _iosRounded.default,
59
+ width: 16,
60
+ height: 16,
61
+ style: {
62
+ color: 'black'
63
+ }
64
+ });
65
+ }
66
+ if (walletOS === 'android') {
67
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
68
+ icon: _android.default,
69
+ width: 14,
70
+ height: 14,
71
+ style: {
72
+ color: 'black'
73
+ }
74
+ });
75
+ }
76
+ if (walletOS === 'web') {
77
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
78
+ icon: _language.default,
79
+ style: {
80
+ color: 'black'
81
+ }
82
+ });
83
+ }
84
+ if (walletOS === 'api') {
85
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
86
+ icon: _api.default,
87
+ width: 14,
88
+ height: 14,
89
+ style: {
90
+ color: 'black'
91
+ }
92
+ });
93
+ }
94
+ return null;
95
+ }, [sessionItem === null || sessionItem === void 0 ? void 0 : (_sessionItem$extra = sessionItem.extra) === null || _sessionItem$extra === void 0 ? void 0 : _sessionItem$extra.walletOS, sessionItem === null || sessionItem === void 0 ? void 0 : (_sessionItem$extra2 = sessionItem.extra) === null || _sessionItem$extra2 === void 0 ? void 0 : _sessionItem$extra2.provider]);
96
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, _objectSpread(_objectSpread({}, rest), {}, {
97
+ ref: ref,
98
+ sx: _objectSpread({
99
+ display: 'flex',
100
+ alignItems: 'center',
101
+ justifyContent: 'space-between',
102
+ py: 0.75,
103
+ px: 1,
104
+ width: '100%'
105
+ }, rest === null || rest === void 0 ? void 0 : rest.sx),
106
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
107
+ sx: {
108
+ display: 'flex',
109
+ alignItems: 'center',
110
+ gap: 0.5,
111
+ '& .did-address-avatar': {
112
+ display: 'none !important'
113
+ },
114
+ '& .did-address-text': {
115
+ color: "".concat(_Colors.temp.textBase, " !important")
116
+ }
117
+ },
118
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
119
+ sx: {
120
+ mr: 0.5,
121
+ fontSize: 0
122
+ },
123
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
124
+ did: sessionItem.userDid,
125
+ size: 36
126
+ })
127
+ }), walletIcon, isRawWalletAccount ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
128
+ did: sessionItem.userDid,
129
+ copyable: false,
130
+ size: 14,
131
+ responsive: false,
132
+ compact: true,
133
+ sx: {
134
+ lineHeight: 1
135
+ }
136
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
137
+ sx: {
138
+ fontSize: 14
139
+ },
140
+ children: sessionItem.user.email
141
+ })]
142
+ }), statusContent || active && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
143
+ size: "small",
144
+ disableRipple: true,
145
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
146
+ icon: _lens.default,
147
+ fontSize: 6,
148
+ color: _Colors.temp.surfaceSuccess
149
+ })
150
+ })]
151
+ }));
152
+ });
153
+ SessionUserItem.propTypes = {
154
+ sessionItem: _propTypes.default.object.isRequired,
155
+ statusContent: _propTypes.default.node,
156
+ active: _propTypes.default.bool
157
+ };
158
+ SessionUserItem.defaultProps = {
159
+ statusContent: null,
160
+ active: false
161
+ };
162
+ var _default = SessionUserItem;
163
+ exports.default = _default;
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = SessionUserSwitch;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _material = require("@mui/material");
9
+ var _react = require("react");
10
+ var _ahooks = require("ahooks");
11
+ var _react2 = require("@iconify/react");
12
+ var _addCircleOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/add-circle-outline-rounded"));
13
+ var _expandMoreRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/expand-more-rounded"));
14
+ var _swapHorizRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/swap-horiz-rounded"));
15
+ var _pick = _interopRequireDefault(require("lodash/pick"));
16
+ var _sessionUserItem = _interopRequireDefault(require("./session-user-item"));
17
+ var _Colors = require("../../Colors");
18
+ var _Util = require("../../Util");
19
+ var _util = require("../../Locale/util");
20
+ var _translation = require("../libs/translation");
21
+ var _jsxRuntime = require("react/jsx-runtime");
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+ 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; }
24
+ 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; }
25
+ 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; }
26
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
27
+ 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); }
28
+ function SessionUserSwitch(_ref) {
29
+ let {
30
+ session,
31
+ onSwitch,
32
+ isBlocklet,
33
+ locale
34
+ } = _ref;
35
+ const popperAnchorRef = (0, _react.useRef)(null);
36
+ const t = (0, _ahooks.useMemoizedFn)(function (key) {
37
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
+ return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
39
+ });
40
+ const currentState = (0, _ahooks.useReactive)({
41
+ open: false,
42
+ userSessions: [],
43
+ loadingSessionId: null
44
+ });
45
+ (0, _ahooks.useMount)(async () => {
46
+ if (isBlocklet) {
47
+ const userSessions = await session.getUserSessions();
48
+ currentState.userSessions = userSessions;
49
+ }
50
+ });
51
+ const currentSession = (0, _ahooks.useCreation)(() => {
52
+ var _globalThis$blocklet2, _globalThis$env, _globalThis$blocklet3, _globalThis$env2, _session$user2;
53
+ const matchSession = (currentState.userSessions || []).find(item => {
54
+ var _globalThis$blocklet, _session$user;
55
+ return item.appPid === (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$blocklet = globalThis.blocklet) === null || _globalThis$blocklet === void 0 ? void 0 : _globalThis$blocklet.appPid) && item.userDid === (session === null || session === void 0 ? void 0 : (_session$user = session.user) === null || _session$user === void 0 ? void 0 : _session$user.did);
56
+ });
57
+ if (matchSession) {
58
+ return matchSession;
59
+ }
60
+ return {
61
+ appName: (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$blocklet2 = globalThis.blocklet) === null || _globalThis$blocklet2 === void 0 ? void 0 : _globalThis$blocklet2.appName) || (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$env = globalThis.env) === null || _globalThis$env === void 0 ? void 0 : _globalThis$env.appName),
62
+ appPid: (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$blocklet3 = globalThis.blocklet) === null || _globalThis$blocklet3 === void 0 ? void 0 : _globalThis$blocklet3.appPid) || (globalThis === null || globalThis === void 0 ? void 0 : (_globalThis$env2 = globalThis.env) === null || _globalThis$env2 === void 0 ? void 0 : _globalThis$env2.appPid),
63
+ userDid: session === null || session === void 0 ? void 0 : (_session$user2 = session.user) === null || _session$user2 === void 0 ? void 0 : _session$user2.did,
64
+ visitorId: (0, _Util.getVisitorId)(),
65
+ // passportId: '', // 无法从当前 session 获取 passportId 的值
66
+ // updatedAt: '', // 当前 session 拼凑的信息无法得到 userSession 的更新时间
67
+ user: (0, _pick.default)(session === null || session === void 0 ? void 0 : session.user, ['did', 'sourceProvider', 'fullName', 'email', 'avatar', 'remark', 'sourceAppPid', 'role'])
68
+ };
69
+ }, [currentState.userSessions, session === null || session === void 0 ? void 0 : session.user]);
70
+ const onTogglePopper = (0, _ahooks.useMemoizedFn)(function () {
71
+ let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : !currentState.open;
72
+ currentState.open = value;
73
+ });
74
+ const size = (0, _ahooks.useSize)(popperAnchorRef.current);
75
+ const handleAddAccount = (0, _ahooks.useMemoizedFn)(() => {
76
+ onTogglePopper(false);
77
+ onSwitch();
78
+ });
79
+ const handleSwitch = (0, _ahooks.useMemoizedFn)(async userSession => {
80
+ try {
81
+ currentState.loadingSessionId = userSession === null || userSession === void 0 ? void 0 : userSession.id;
82
+ await onSwitch({
83
+ userSession
84
+ });
85
+ onTogglePopper(false);
86
+ } finally {
87
+ currentState.loadingSessionId = null;
88
+ }
89
+ });
90
+ if (!isBlocklet) {
91
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_sessionUserItem.default, {
92
+ sessionItem: currentSession,
93
+ statusContent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
94
+ icon: _swapHorizRounded.default,
95
+ color: _Colors.temp.textMuted
96
+ }),
97
+ sx: {
98
+ border: "1px solid ".concat(_Colors.temp.borderBase),
99
+ borderRadius: 2,
100
+ cursor: 'pointer',
101
+ py: 1.25,
102
+ px: 1.5
103
+ },
104
+ "data-cy": "sessionManager-switch-trigger",
105
+ onClick: handleAddAccount,
106
+ ref: popperAnchorRef
107
+ });
108
+ }
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
110
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_sessionUserItem.default, {
111
+ sessionItem: currentSession,
112
+ statusContent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.Icon, {
113
+ icon: _expandMoreRounded.default,
114
+ color: _Colors.temp.textMuted
115
+ }),
116
+ sx: {
117
+ border: "1px solid ".concat(_Colors.temp.borderBase),
118
+ borderRadius: 2,
119
+ cursor: 'pointer',
120
+ py: 1.25,
121
+ px: 1.5
122
+ },
123
+ onClick: () => onTogglePopper(),
124
+ ref: popperAnchorRef
125
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Popper, {
126
+ open: currentState.open,
127
+ onClose: () => onTogglePopper(false),
128
+ anchorEl: popperAnchorRef.current,
129
+ transition: true,
130
+ sx: {
131
+ zIndex: 1600
132
+ },
133
+ children: _ref2 => {
134
+ let {
135
+ TransitionProps
136
+ } = _ref2;
137
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ClickAwayListener, {
138
+ onClickAway: e => {
139
+ e.preventDefault();
140
+ e.stopPropagation();
141
+ onTogglePopper(false);
142
+ },
143
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Fade, _objectSpread(_objectSpread({}, TransitionProps), {}, {
144
+ timeout: 350,
145
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Paper, {
146
+ variant: "outlined",
147
+ sx: {
148
+ borderRadius: 3,
149
+ width: (size === null || size === void 0 ? void 0 : size.width) || 0,
150
+ borderColor: _Colors.temp.lineStep,
151
+ mt: 0.5,
152
+ border: '0 !important',
153
+ boxShadow: "0px 8px 16px 0px ".concat(_Colors.temp.gray6, ", 0px 0px 0px 1px ").concat(_Colors.temp.gray6)
154
+ },
155
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuList, {
156
+ sx: {
157
+ p: 0.5
158
+ },
159
+ children: [currentState.userSessions.map(userSessionItem => {
160
+ const isLoading = currentState.loadingSessionId === userSessionItem.id;
161
+ const isActive = userSessionItem.id === currentSession.id;
162
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
163
+ sx: {
164
+ position: 'relative',
165
+ p: 0,
166
+ '&:hover': {
167
+ backgroundColor: "".concat(_Colors.temp.surfacePrimarySubtitle, " !important")
168
+ }
169
+ },
170
+ onClick: () => {
171
+ if (!isActive) {
172
+ handleSwitch(userSessionItem);
173
+ }
174
+ },
175
+ children: [isLoading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.LinearProgress, {
176
+ sx: {
177
+ height: '2px',
178
+ position: 'absolute',
179
+ top: 0,
180
+ left: 0,
181
+ right: 0
182
+ }
183
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_sessionUserItem.default, {
184
+ sessionItem: userSessionItem,
185
+ active: isActive
186
+ })]
187
+ }, userSessionItem.id);
188
+ }), currentState.userSessions.length > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Divider, {
189
+ sx: {
190
+ m: '0!important',
191
+ borderColor: _Colors.temp.lineStep
192
+ }
193
+ }) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
194
+ sx: {
195
+ color: _Colors.temp.primaryBase,
196
+ borderRadius: 2,
197
+ '&:hover': {
198
+ backgroundColor: "".concat(_Colors.temp.surfacePrimarySubtitle, " !important")
199
+ },
200
+ px: 1,
201
+ py: 1.5,
202
+ lineHeight: 1
203
+ },
204
+ onClick: handleAddAccount,
205
+ "data-cy": "sessionManager-switch-trigger",
206
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
207
+ component: _react2.Icon,
208
+ icon: _addCircleOutlineRounded.default,
209
+ fontSize: 20,
210
+ sx: {
211
+ mr: 0.5
212
+ }
213
+ }), t('addAnotherAccount')]
214
+ })]
215
+ })
216
+ })
217
+ }))
218
+ });
219
+ }
220
+ })]
221
+ });
222
+ }
223
+ SessionUserSwitch.propTypes = {
224
+ session: _propTypes.default.object.isRequired,
225
+ onSwitch: _propTypes.default.func.isRequired,
226
+ isBlocklet: _propTypes.default.bool,
227
+ locale: _propTypes.default.string
228
+ };
229
+ SessionUserSwitch.defaultProps = {
230
+ isBlocklet: true,
231
+ locale: 'en'
232
+ };
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = UnLogin;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _material = require("@mui/material");
9
+ var _react = require("@iconify/react");
10
+ var _personOutlineRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/person-outline-rounded"));
11
+ var _react2 = require("react");
12
+ var _ahooks = require("ahooks");
13
+ var _noop = _interopRequireDefault(require("lodash/noop"));
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ function UnLogin(_ref) {
17
+ let {
18
+ session,
19
+ onLogin,
20
+ size,
21
+ dark
22
+ } = _ref;
23
+ const isFirstLoading = false;
24
+ const userAnchorRef = (0, _react2.useRef)(null);
25
+ const _onLogin = (0, _ahooks.useMemoizedFn)(() => {
26
+ if (isFirstLoading) {
27
+ return;
28
+ }
29
+ session.login(onLogin);
30
+ });
31
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
32
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
33
+ ref: userAnchorRef,
34
+ onClick: _onLogin,
35
+ "data-cy": "sessionManager-login",
36
+ size: "medium",
37
+ "aria-label": "Login button",
38
+ children: isFirstLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
39
+ width: size,
40
+ height: size,
41
+ display: "flex",
42
+ justifyContent: "center",
43
+ alignItems: "center",
44
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.CircularProgress, {
45
+ style: {
46
+ width: size - 4,
47
+ height: size - 4,
48
+ color: dark ? '#fff' : ''
49
+ }
50
+ })
51
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
52
+ icon: _personOutlineRounded.default,
53
+ fontSize: size,
54
+ color: dark ? '#fff' : 'inherit',
55
+ style: {
56
+ transform: 'scale(1.08)'
57
+ }
58
+ })
59
+ })
60
+ });
61
+ }
62
+ UnLogin.propTypes = {
63
+ session: _propTypes.default.object.isRequired,
64
+ onLogin: _propTypes.default.func,
65
+ size: _propTypes.default.number,
66
+ dark: _propTypes.default.bool
67
+ };
68
+ UnLogin.defaultProps = {
69
+ onLogin: _noop.default,
70
+ size: 24,
71
+ dark: false
72
+ };
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = UserInfo;
7
+ var _propTypes = _interopRequireDefault(require("prop-types"));
8
+ var _material = require("@mui/material");
9
+ var _react = require("@iconify/react");
10
+ var _swapHorizRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/swap-horiz-rounded"));
11
+ var _arrowRightAltRounded = _interopRequireDefault(require("@iconify-icons/material-symbols/arrow-right-alt-rounded"));
12
+ var _ahooks = require("ahooks");
13
+ var _noop = _interopRequireDefault(require("lodash/noop"));
14
+ var _Avatar = _interopRequireDefault(require("../../Avatar"));
15
+ var _Util = require("../../Util");
16
+ var _sessionUserSwitch = _interopRequireDefault(require("./session-user-switch"));
17
+ var _Colors = require("../../Colors");
18
+ var _utils = require("../libs/utils");
19
+ var _translation = require("../libs/translation");
20
+ var _util = require("../../Locale/util");
21
+ var _jsxRuntime = require("react/jsx-runtime");
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+ function UserInfo(_ref) {
24
+ var _session$user, _session$user$avatar, _session$user3, _session$user4, _session$user5;
25
+ let {
26
+ session,
27
+ onSwitchPassport,
28
+ onSwitchAccount,
29
+ onBindWallet,
30
+ onSwitchProfile,
31
+ locale,
32
+ isBlocklet
33
+ } = _ref;
34
+ const t = (0, _ahooks.useMemoizedFn)(function (key) {
35
+ let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
36
+ return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
37
+ });
38
+ 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(' ')), 64);
39
+ const currentRole = (0, _ahooks.useCreation)(() => {
40
+ var _session$user2, _session$user2$passpo;
41
+ 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);
42
+ }, [session === null || session === void 0 ? void 0 : (_session$user3 = session.user) === null || _session$user3 === void 0 ? void 0 : _session$user3.passports, session === null || session === void 0 ? void 0 : (_session$user4 = session.user) === null || _session$user4 === void 0 ? void 0 : _session$user4.role]);
43
+ const isRawWalletAccount = (0, _utils.getSourceProvider)(session.user) === 'wallet';
44
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
45
+ sx: {
46
+ p: 2,
47
+ pb: 1,
48
+ display: 'flex',
49
+ flexDirection: 'column',
50
+ gap: 1.5
51
+ },
52
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
53
+ sx: {
54
+ display: 'flex',
55
+ justifyContent: 'space-between',
56
+ alignItems: 'center',
57
+ gap: 1
58
+ },
59
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
60
+ sx: {
61
+ display: 'flex',
62
+ alignItems: 'center',
63
+ gap: 1.5
64
+ },
65
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
66
+ onClick: isBlocklet ? _noop.default : onSwitchProfile,
67
+ "data-cy": "sessionManager-switch-profile-trigger",
68
+ sx: {
69
+ cursor: isBlocklet ? 'default' : 'pointer',
70
+ position: 'relative',
71
+ borderRadius: '100%',
72
+ overflow: 'hidden',
73
+ fontSize: 0,
74
+ flexShrink: 0,
75
+ '&:hover': isBlocklet ? {} : {
76
+ '&::after': {
77
+ content: "\"".concat(t('switch'), "\""),
78
+ position: 'absolute',
79
+ bottom: 0,
80
+ background: 'rgba(0, 0, 0, 0.2)',
81
+ left: 0,
82
+ right: 0,
83
+ height: '2.2em',
84
+ color: 'white',
85
+ textAlign: 'center',
86
+ fontSize: '12px',
87
+ lineHeight: '2em'
88
+ }
89
+ }
90
+ },
91
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
92
+ variant: "circle",
93
+ did: session.user.did,
94
+ src: avatar,
95
+ size: 48,
96
+ shape: "circle",
97
+ sx: {
98
+ cursor: isBlocklet ? 'unset' : 'pointer'
99
+ }
100
+ })
101
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
102
+ variant: "h6",
103
+ sx: {
104
+ wordBreak: 'break-all'
105
+ },
106
+ children: session.user.fullName
107
+ })]
108
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
109
+ label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user5 = session.user) === null || _session$user5 === void 0 ? void 0 : _session$user5.role.toUpperCase()),
110
+ size: "small",
111
+ variant: "outlined",
112
+ clickable: true,
113
+ sx: {
114
+ flexShrink: 0,
115
+ fontWeight: 'bold',
116
+ fontSize: '12px',
117
+ color: _Colors.temp.textBase,
118
+ borderColor: _Colors.temp.borderBase,
119
+ pr: 1,
120
+ pl: 0.5,
121
+ '&:active': {
122
+ boxShadow: 'none'
123
+ }
124
+ },
125
+ deleteIcon: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
126
+ icon: _swapHorizRounded.default,
127
+ color: _Colors.temp.textBase
128
+ }),
129
+ onDelete: onSwitchPassport,
130
+ onClick: onSwitchPassport,
131
+ "data-cy": "sessionManager-switch-passport-trigger"
132
+ })]
133
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_sessionUserSwitch.default, {
134
+ session: session,
135
+ onSwitch: onSwitchAccount,
136
+ isBlocklet: isBlocklet,
137
+ locale: locale
138
+ }), isRawWalletAccount ? null : /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
139
+ sx: {
140
+ color: _Colors.temp.primaryBase,
141
+ backgroundColor: _Colors.temp.surfacePrimarySubtitle,
142
+ borderRadius: 1,
143
+ display: 'flex',
144
+ justifyContent: 'space-between',
145
+ alignItems: 'center',
146
+ fontSize: 12,
147
+ py: 0.75,
148
+ px: 1.5,
149
+ cursor: 'pointer',
150
+ mt: -0.75
151
+ },
152
+ onClick: onBindWallet,
153
+ "data-cy": "sessionManager-bind-trigger",
154
+ children: [t('connectDIDWallet'), /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
155
+ icon: _arrowRightAltRounded.default,
156
+ color: _Colors.temp.primaryBase,
157
+ fontSize: 16
158
+ })]
159
+ })]
160
+ });
161
+ }
162
+ UserInfo.propTypes = {
163
+ session: _propTypes.default.object.isRequired,
164
+ onSwitchPassport: _propTypes.default.func.isRequired,
165
+ onSwitchAccount: _propTypes.default.func.isRequired,
166
+ onBindWallet: _propTypes.default.func.isRequired,
167
+ onSwitchProfile: _propTypes.default.func,
168
+ locale: _propTypes.default.string,
169
+ isBlocklet: _propTypes.default.bool
170
+ };
171
+ UserInfo.defaultProps = {
172
+ locale: 'en',
173
+ isBlocklet: true,
174
+ onSwitchProfile: _noop.default
175
+ };