@arcblock/ux 2.5.18 → 2.5.20
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 +24 -26
- package/package.json +4 -4
- package/src/SessionManager/index.jsx +21 -27
@@ -58,10 +58,6 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
58
58
|
|
59
59
|
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; }
|
60
60
|
|
61
|
-
const USER_TYPE = Object.freeze({
|
62
|
-
DERIVED: 'derived',
|
63
|
-
WALLET: 'wallet'
|
64
|
-
});
|
65
61
|
const messages = {
|
66
62
|
zh: {
|
67
63
|
switchDid: '切换账户',
|
@@ -95,7 +91,7 @@ const translations = {
|
|
95
91
|
};
|
96
92
|
|
97
93
|
function SessionManager(_ref) {
|
98
|
-
var _session$user, _session$user$avatar, _session$user3, _session$
|
94
|
+
var _session$user, _session$user$avatar, _session$user3, _session$user3$extraC, _session$user4, _session$user4$extraC, _session$user5, _session$user6;
|
99
95
|
|
100
96
|
let {
|
101
97
|
session,
|
@@ -135,8 +131,18 @@ function SessionManager(_ref) {
|
|
135
131
|
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);
|
136
132
|
}, [session.user]);
|
137
133
|
const browser = (0, _useBrowser.default)();
|
138
|
-
const
|
139
|
-
const
|
134
|
+
const isRawWalletAccount = ((_session$user3 = session.user) === null || _session$user3 === void 0 ? void 0 : (_session$user3$extraC = _session$user3.extraConfigs) === null || _session$user3$extraC === void 0 ? void 0 : _session$user3$extraC.sourceProvider) === 'wallet';
|
135
|
+
const connectedAccounts = ((_session$user4 = session.user) === null || _session$user4 === void 0 ? void 0 : (_session$user4$extraC = _session$user4.extraConfigs) === null || _session$user4$extraC === void 0 ? void 0 : _session$user4$extraC.connectedAccounts) || [];
|
136
|
+
let hasBindAccount = false;
|
137
|
+
|
138
|
+
if (isRawWalletAccount) {
|
139
|
+
if (connectedAccounts.some(item => item.provider !== 'wallet')) {
|
140
|
+
hasBindAccount = true;
|
141
|
+
}
|
142
|
+
} else if (connectedAccounts.some(item => item.provider === 'wallet')) {
|
143
|
+
hasBindAccount = true;
|
144
|
+
}
|
145
|
+
|
140
146
|
const oauthConfigList = Object.entries(oauthConfigs).map(_ref2 => {
|
141
147
|
let [key, value] = _ref2;
|
142
148
|
return _objectSpread(_objectSpread({}, value), {}, {
|
@@ -228,27 +234,27 @@ function SessionManager(_ref) {
|
|
228
234
|
user
|
229
235
|
} = session;
|
230
236
|
|
231
|
-
if (
|
232
|
-
switchOAuthPassport(user);
|
233
|
-
} else {
|
237
|
+
if (isRawWalletAccount) {
|
234
238
|
setUserOpen(false);
|
235
239
|
session.switchPassport(function () {
|
236
240
|
setUserOpen(false);
|
237
241
|
onSwitchPassport(...arguments);
|
238
242
|
});
|
243
|
+
} else {
|
244
|
+
switchOAuthPassport(user);
|
239
245
|
}
|
240
246
|
}
|
241
247
|
|
242
248
|
function _onBindWallet() {
|
243
249
|
setUserOpen(false);
|
244
250
|
|
245
|
-
if (
|
251
|
+
if (isRawWalletAccount) {
|
252
|
+
bindOAuth();
|
253
|
+
} else {
|
246
254
|
session.bindWallet(function () {
|
247
255
|
setUserOpen(false);
|
248
256
|
onBindWallet(...arguments);
|
249
257
|
});
|
250
|
-
} else {
|
251
|
-
bindOAuth();
|
252
258
|
}
|
253
259
|
}
|
254
260
|
|
@@ -313,8 +319,8 @@ function SessionManager(_ref) {
|
|
313
319
|
className: "session-manager-user-name",
|
314
320
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
315
321
|
children: session.user.fullName
|
316
|
-
}), !!showRole && ((currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$
|
317
|
-
label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$
|
322
|
+
}), !!showRole && ((currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user5 = session.user) === null || _session$user5 === void 0 ? void 0 : _session$user5.role.toUpperCase())) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Chip, {
|
323
|
+
label: (currentRole === null || currentRole === void 0 ? void 0 : currentRole.title) || ((_session$user6 = session.user) === null || _session$user6 === void 0 ? void 0 : _session$user6.role.toUpperCase()),
|
318
324
|
size: "small",
|
319
325
|
variant: "outlined",
|
320
326
|
sx: {
|
@@ -328,7 +334,7 @@ function SessionManager(_ref) {
|
|
328
334
|
})]
|
329
335
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Address.default, {
|
330
336
|
responsive: false,
|
331
|
-
children:
|
337
|
+
children: session.user.did
|
332
338
|
})]
|
333
339
|
}), Array.isArray(menu) && menu.map((menuItem, index) => {
|
334
340
|
const {
|
@@ -386,21 +392,14 @@ function SessionManager(_ref) {
|
|
386
392
|
component: _VpnKeyOutlined.default,
|
387
393
|
className: "session-manager-menu-icon"
|
388
394
|
}), message.switchPassport]
|
389
|
-
}), oauthConfigList.length > 0 && !
|
395
|
+
}), oauthConfigList.length > 0 && !hasBindAccount && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
390
396
|
className: "session-manager-menu-item",
|
391
397
|
onClick: _onBindWallet,
|
392
398
|
"data-cy": "sessionManager-bind-trigger",
|
393
399
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
394
400
|
component: _Link.default,
|
395
401
|
className: "session-manager-menu-icon"
|
396
|
-
}),
|
397
|
-
}), oauthConfigList.length > 0 && hasBindOAuth && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
398
|
-
className: "session-manager-menu-item",
|
399
|
-
disabled: true,
|
400
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.SvgIcon, {
|
401
|
-
component: _Link.default,
|
402
|
-
className: "session-manager-menu-icon"
|
403
|
-
}), translations[locale].alreadyBindOAuth]
|
402
|
+
}), isRawWalletAccount ? "".concat(translations[locale].bind).concat(translations[locale].thirdParty) : "".concat(translations[locale].bind, "DID Wallet")]
|
404
403
|
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
405
404
|
className: "session-manager-menu-item",
|
406
405
|
onClick: _onLogout,
|
@@ -430,7 +429,6 @@ SessionManager.propTypes = {
|
|
430
429
|
name: _propTypes.default.string.isRequired,
|
431
430
|
title: _propTypes.default.string.isRequired
|
432
431
|
})),
|
433
|
-
source: _propTypes.default.oneOf([USER_TYPE.DERIVED, USER_TYPE.WALLET, undefined]),
|
434
432
|
extraConfigs: _propTypes.default.object
|
435
433
|
}),
|
436
434
|
login: _propTypes.default.func.isRequired,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.5.
|
3
|
+
"version": "2.5.20",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -47,11 +47,11 @@
|
|
47
47
|
"react": ">=18.1.0",
|
48
48
|
"react-ga": "^2.7.0"
|
49
49
|
},
|
50
|
-
"gitHead": "
|
50
|
+
"gitHead": "40f4ab8c046bf5d92d3a1fb5d477a6f4c197c86a",
|
51
51
|
"dependencies": {
|
52
52
|
"@arcblock/did-motif": "^1.1.10",
|
53
|
-
"@arcblock/icons": "^2.5.
|
54
|
-
"@arcblock/react-hooks": "^2.5.
|
53
|
+
"@arcblock/icons": "^2.5.20",
|
54
|
+
"@arcblock/react-hooks": "^2.5.20",
|
55
55
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
56
56
|
"@emotion/react": "^11.10.4",
|
57
57
|
"@emotion/styled": "^11.10.4",
|
@@ -18,11 +18,6 @@ import { styled } from '../Theme';
|
|
18
18
|
import DidAvatar from '../Avatar';
|
19
19
|
import DidAddress from '../Address';
|
20
20
|
|
21
|
-
const USER_TYPE = Object.freeze({
|
22
|
-
DERIVED: 'derived',
|
23
|
-
WALLET: 'wallet',
|
24
|
-
});
|
25
|
-
|
26
21
|
const messages = {
|
27
22
|
zh: {
|
28
23
|
switchDid: '切换账户',
|
@@ -88,8 +83,16 @@ function SessionManager({
|
|
88
83
|
);
|
89
84
|
const browser = useBrowser();
|
90
85
|
|
91
|
-
const
|
92
|
-
const
|
86
|
+
const isRawWalletAccount = session.user?.extraConfigs?.sourceProvider === 'wallet';
|
87
|
+
const connectedAccounts = session.user?.extraConfigs?.connectedAccounts || [];
|
88
|
+
let hasBindAccount = false;
|
89
|
+
if (isRawWalletAccount) {
|
90
|
+
if (connectedAccounts.some((item) => item.provider !== 'wallet')) {
|
91
|
+
hasBindAccount = true;
|
92
|
+
}
|
93
|
+
} else if (connectedAccounts.some((item) => item.provider === 'wallet')) {
|
94
|
+
hasBindAccount = true;
|
95
|
+
}
|
93
96
|
|
94
97
|
const oauthConfigList = Object.entries(oauthConfigs)
|
95
98
|
.map(([key, value]) => {
|
@@ -158,26 +161,26 @@ function SessionManager({
|
|
158
161
|
}
|
159
162
|
function _onSwitchPassport() {
|
160
163
|
const { user } = session;
|
161
|
-
if (
|
162
|
-
switchOAuthPassport(user);
|
163
|
-
} else {
|
164
|
+
if (isRawWalletAccount) {
|
164
165
|
setUserOpen(false);
|
165
166
|
session.switchPassport((...args) => {
|
166
167
|
setUserOpen(false);
|
167
168
|
onSwitchPassport(...args);
|
168
169
|
});
|
170
|
+
} else {
|
171
|
+
switchOAuthPassport(user);
|
169
172
|
}
|
170
173
|
}
|
171
174
|
|
172
175
|
function _onBindWallet() {
|
173
176
|
setUserOpen(false);
|
174
|
-
if (
|
177
|
+
if (isRawWalletAccount) {
|
178
|
+
bindOAuth();
|
179
|
+
} else {
|
175
180
|
session.bindWallet((...args) => {
|
176
181
|
setUserOpen(false);
|
177
182
|
onBindWallet(...args);
|
178
183
|
});
|
179
|
-
} else {
|
180
|
-
bindOAuth();
|
181
184
|
}
|
182
185
|
}
|
183
186
|
|
@@ -244,9 +247,7 @@ function SessionManager({
|
|
244
247
|
/>
|
245
248
|
)}
|
246
249
|
</div>
|
247
|
-
<DidAddress responsive={false}>
|
248
|
-
{isDerivedAccount ? session.user?.email : session.user.did}
|
249
|
-
</DidAddress>
|
250
|
+
<DidAddress responsive={false}>{session.user.did}</DidAddress>
|
250
251
|
</div>
|
251
252
|
{Array.isArray(menu) &&
|
252
253
|
menu.map((menuItem, index) => {
|
@@ -311,21 +312,15 @@ function SessionManager({
|
|
311
312
|
{message.switchPassport}
|
312
313
|
</MenuItem>
|
313
314
|
)}
|
314
|
-
{oauthConfigList.length > 0 && !
|
315
|
+
{oauthConfigList.length > 0 && !hasBindAccount && (
|
315
316
|
<MenuItem
|
316
317
|
className="session-manager-menu-item"
|
317
318
|
onClick={_onBindWallet}
|
318
319
|
data-cy="sessionManager-bind-trigger">
|
319
320
|
<SvgIcon component={BindWalletIcon} className="session-manager-menu-icon" />
|
320
|
-
{
|
321
|
-
? `${translations[locale].bind}
|
322
|
-
: `${translations[locale].bind}
|
323
|
-
</MenuItem>
|
324
|
-
)}
|
325
|
-
{oauthConfigList.length > 0 && hasBindOAuth && (
|
326
|
-
<MenuItem className="session-manager-menu-item" disabled>
|
327
|
-
<SvgIcon component={BindWalletIcon} className="session-manager-menu-icon" />
|
328
|
-
{translations[locale].alreadyBindOAuth}
|
321
|
+
{isRawWalletAccount
|
322
|
+
? `${translations[locale].bind}${translations[locale].thirdParty}`
|
323
|
+
: `${translations[locale].bind}DID Wallet`}
|
329
324
|
</MenuItem>
|
330
325
|
)}
|
331
326
|
|
@@ -360,7 +355,6 @@ SessionManager.propTypes = {
|
|
360
355
|
title: PropTypes.string.isRequired,
|
361
356
|
})
|
362
357
|
),
|
363
|
-
source: PropTypes.oneOf([USER_TYPE.DERIVED, USER_TYPE.WALLET, undefined]),
|
364
358
|
extraConfigs: PropTypes.object,
|
365
359
|
}),
|
366
360
|
login: PropTypes.func.isRequired,
|