@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.
- package/es/Address/did-address.js +33 -21
- package/es/AnimationWaiter/index.js +2 -1
- package/es/Avatar/index.js +1 -1
- package/es/BlockletContext/index.js +1 -1
- package/es/CardSelector/index.js +2 -1
- package/es/Colors/index.js +2 -1
- package/es/Colors/themes/temp.js +17 -0
- package/es/Datatable/TableSearch.js +2 -1
- package/es/Img/index.js +7 -6
- package/es/Locale/selector.js +15 -13
- package/es/NFTDisplay/index.js +2 -1
- package/es/QRCode/index.js +2 -1
- package/es/SessionBlocklet/index.js +169 -0
- package/es/SessionManager/index.js +2 -381
- package/es/SessionPermission/index.js +28 -0
- package/es/SessionUser/components/logged-in.js +224 -0
- package/es/SessionUser/components/session-user-item.js +148 -0
- package/es/SessionUser/components/session-user-switch.js +213 -0
- package/es/SessionUser/components/un-login.js +64 -0
- package/es/SessionUser/components/user-info.js +163 -0
- package/es/SessionUser/index.js +49 -0
- package/es/SessionUser/libs/translation.js +19 -0
- package/es/SessionUser/libs/utils.js +4 -0
- package/es/SplitButton/index.js +2 -1
- package/es/Toast/index.js +1 -1
- package/es/Util/constant.js +10 -0
- package/es/Util/index.js +11 -0
- package/lib/Address/did-address.js +36 -22
- package/lib/AnimationWaiter/index.js +2 -1
- package/lib/Avatar/index.js +1 -1
- package/lib/BlockletContext/index.js +1 -1
- package/lib/CardSelector/index.js +2 -1
- package/lib/Colors/index.js +7 -0
- package/lib/Colors/themes/temp.js +24 -0
- package/lib/Datatable/TableSearch.js +2 -1
- package/lib/Img/index.js +7 -6
- package/lib/Locale/selector.js +14 -13
- package/lib/NFTDisplay/index.js +2 -1
- package/lib/QRCode/index.js +2 -1
- package/lib/SessionBlocklet/index.js +187 -0
- package/lib/SessionManager/index.js +2 -390
- package/lib/SessionPermission/index.js +38 -0
- package/lib/SessionUser/components/logged-in.js +243 -0
- package/lib/SessionUser/components/session-user-item.js +163 -0
- package/lib/SessionUser/components/session-user-switch.js +232 -0
- package/lib/SessionUser/components/un-login.js +72 -0
- package/lib/SessionUser/components/user-info.js +175 -0
- package/lib/SessionUser/index.js +57 -0
- package/lib/SessionUser/libs/translation.js +26 -0
- package/lib/{SessionManager → SessionUser}/libs/utils.js +8 -1
- package/lib/SplitButton/index.js +2 -1
- package/lib/Toast/index.js +5 -5
- package/lib/Util/constant.js +26 -0
- package/lib/Util/index.js +16 -3
- package/package.json +19 -7
- package/src/Address/did-address.jsx +34 -20
- package/src/AnimationWaiter/index.js +2 -1
- package/src/Avatar/index.jsx +1 -1
- package/src/BlockletContext/index.jsx +1 -1
- package/src/CardSelector/index.jsx +2 -1
- package/src/Colors/index.js +1 -0
- package/src/Colors/themes/temp.js +18 -0
- package/src/Datatable/TableSearch.js +3 -1
- package/src/Img/{index.js → index.jsx} +8 -6
- package/src/Locale/selector.jsx +11 -8
- package/src/NFTDisplay/index.js +2 -1
- package/src/QRCode/index.js +2 -1
- package/src/SessionBlocklet/index.jsx +181 -0
- package/src/SessionManager/index.jsx +2 -369
- package/src/SessionPermission/index.jsx +28 -0
- package/src/SessionUser/components/logged-in.jsx +194 -0
- package/src/SessionUser/components/session-user-item.jsx +96 -0
- package/src/SessionUser/components/session-user-switch.jsx +222 -0
- package/src/SessionUser/components/un-login.jsx +55 -0
- package/src/SessionUser/components/user-info.jsx +165 -0
- package/src/SessionUser/index.jsx +38 -0
- package/src/SessionUser/libs/translation.js +19 -0
- package/src/{SessionManager → SessionUser}/libs/utils.js +4 -0
- package/src/SplitButton/index.js +2 -1
- package/src/Toast/index.js +1 -1
- package/src/Util/constant.js +12 -0
- package/src/Util/index.js +13 -0
- package/es/SessionManager/components/account-item.js +0 -212
- package/es/SessionManager/components/add-account-item.js +0 -57
- package/es/SessionManager/components/federated-login-detecter.js +0 -183
- package/es/SessionManager/components/manage-accounts.js +0 -219
- package/es/SessionManager/components/manage-blocklet.js +0 -70
- package/es/SessionManager/components/menu-accordion.js +0 -103
- package/es/SessionManager/components/responsive-popper.js +0 -24
- package/es/SessionManager/components/user-drawer.js +0 -68
- package/es/SessionManager/components/user-info.js +0 -143
- package/es/SessionManager/components/user-popper.js +0 -110
- package/es/SessionManager/hooks/use-config.js +0 -34
- package/es/SessionManager/libs/translation.js +0 -52
- package/es/SessionManager/libs/utils.js +0 -2
- package/lib/SessionManager/components/account-item.js +0 -219
- package/lib/SessionManager/components/add-account-item.js +0 -66
- package/lib/SessionManager/components/federated-login-detecter.js +0 -193
- package/lib/SessionManager/components/manage-accounts.js +0 -232
- package/lib/SessionManager/components/manage-blocklet.js +0 -86
- package/lib/SessionManager/components/menu-accordion.js +0 -111
- package/lib/SessionManager/components/responsive-popper.js +0 -34
- package/lib/SessionManager/components/user-drawer.js +0 -75
- package/lib/SessionManager/components/user-info.js +0 -160
- package/lib/SessionManager/components/user-popper.js +0 -104
- package/lib/SessionManager/hooks/use-config.js +0 -41
- package/lib/SessionManager/libs/translation.js +0 -59
- package/src/SessionManager/components/account-item.jsx +0 -156
- package/src/SessionManager/components/add-account-item.jsx +0 -49
- package/src/SessionManager/components/federated-login-detecter.jsx +0 -167
- package/src/SessionManager/components/manage-accounts.jsx +0 -228
- package/src/SessionManager/components/manage-blocklet.jsx +0 -70
- package/src/SessionManager/components/menu-accordion.jsx +0 -93
- package/src/SessionManager/components/responsive-popper.jsx +0 -26
- package/src/SessionManager/components/user-drawer.jsx +0 -57
- package/src/SessionManager/components/user-info.jsx +0 -117
- package/src/SessionManager/components/user-popper.jsx +0 -95
- package/src/SessionManager/hooks/use-config.js +0 -33
- package/src/SessionManager/libs/translation.js +0 -52
@@ -1,143 +0,0 @@
|
|
1
|
-
/* eslint-disable react/jsx-no-bind */
|
2
|
-
/* eslint-disable react/prop-types */
|
3
|
-
import { Box, Chip } from '@mui/material';
|
4
|
-
import ShieldCheckIcon from '@iconify-icons/mdi/shield-check';
|
5
|
-
import ExpandMoreIcon from '@iconify-icons/mdi/expand-more';
|
6
|
-
import { Icon } from '@iconify/react';
|
7
|
-
import { useCreation, useMemoizedFn } from 'ahooks';
|
8
|
-
import DidAvatar from '../../Avatar';
|
9
|
-
import DidAddress from '../../Address';
|
10
|
-
import DID from '../../DID';
|
11
|
-
import { getUserAvatar } from '../../Util';
|
12
|
-
import { t as translate } from '../../Locale/util';
|
13
|
-
import { translations } from '../libs/translation';
|
14
|
-
import Typography from '../../Typography';
|
15
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
16
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
17
|
-
export default function UserInfo({
|
18
|
-
session,
|
19
|
-
locale,
|
20
|
-
onSwitchProfile,
|
21
|
-
onSwitchPassport,
|
22
|
-
switchProfile,
|
23
|
-
hasBindWallet
|
24
|
-
}) {
|
25
|
-
const t = (key, data = {}) => {
|
26
|
-
return translate(translations, key, locale, 'en', data);
|
27
|
-
};
|
28
|
-
const avatar = getUserAvatar(session.user?.avatar?.replace(/\s/g, encodeURIComponent(' ')), 64);
|
29
|
-
const {
|
30
|
-
walletDid
|
31
|
-
} = session.useDid({
|
32
|
-
session
|
33
|
-
});
|
34
|
-
const currentRole = useCreation(() => session.user?.passports?.find(item => item.name === session.user.role), [session?.user?.passports, session?.user?.role]);
|
35
|
-
const userEmail = useCreation(() => session.user?.email, [session?.user]);
|
36
|
-
const canEdit = useCreation(() => {
|
37
|
-
if (onSwitchProfile instanceof Function) {
|
38
|
-
if (switchProfile && hasBindWallet) {
|
39
|
-
return true;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
return false;
|
43
|
-
}, [onSwitchProfile, switchProfile, hasBindWallet, session.provider]);
|
44
|
-
const _onSwitchProfile = useMemoizedFn(() => {
|
45
|
-
if (window.blocklet?.appPid) {
|
46
|
-
window.location.href = '/.well-known/service/user/profile';
|
47
|
-
} else if (canEdit) {
|
48
|
-
onSwitchProfile();
|
49
|
-
}
|
50
|
-
});
|
51
|
-
return /*#__PURE__*/_jsxs(Box, {
|
52
|
-
sx: {
|
53
|
-
display: 'flex',
|
54
|
-
alignItems: 'center',
|
55
|
-
gap: '12px',
|
56
|
-
padding: '15px'
|
57
|
-
},
|
58
|
-
children: [/*#__PURE__*/_jsx(Box, {
|
59
|
-
onClick: _onSwitchProfile,
|
60
|
-
"data-cy": "sessionManager-switch-profile-trigger",
|
61
|
-
sx: {
|
62
|
-
cursor: canEdit ? 'pointer' : 'default',
|
63
|
-
position: 'relative',
|
64
|
-
borderRadius: '100%',
|
65
|
-
overflow: 'hidden',
|
66
|
-
fontSize: 0,
|
67
|
-
'&:hover': canEdit ? {
|
68
|
-
'&::after': {
|
69
|
-
content: `"${t('switch')}"`,
|
70
|
-
position: 'absolute',
|
71
|
-
bottom: 0,
|
72
|
-
background: 'rgba(0, 0, 0, 0.2)',
|
73
|
-
left: 0,
|
74
|
-
right: 0,
|
75
|
-
height: '2.2em',
|
76
|
-
color: 'white',
|
77
|
-
textAlign: 'center',
|
78
|
-
fontSize: '12px',
|
79
|
-
lineHeight: '2em'
|
80
|
-
}
|
81
|
-
} : {}
|
82
|
-
},
|
83
|
-
children: /*#__PURE__*/_jsx(DidAvatar, {
|
84
|
-
variant: "circle",
|
85
|
-
did: session.user.did,
|
86
|
-
src: avatar,
|
87
|
-
size: 64,
|
88
|
-
shape: "circle"
|
89
|
-
})
|
90
|
-
}), /*#__PURE__*/_jsxs(Box, {
|
91
|
-
sx: {
|
92
|
-
flex: 1,
|
93
|
-
position: 'static',
|
94
|
-
overflow: 'hidden',
|
95
|
-
fontSize: '14px'
|
96
|
-
},
|
97
|
-
children: [/*#__PURE__*/_jsx(Typography, {
|
98
|
-
variant: "h5",
|
99
|
-
fontWeight: "bold",
|
100
|
-
sx: {
|
101
|
-
wordBreak: 'break-all',
|
102
|
-
lineHeight: 1
|
103
|
-
},
|
104
|
-
children: session.user.fullName
|
105
|
-
}), /*#__PURE__*/_jsx(Chip, {
|
106
|
-
label: currentRole?.title || session.user?.role.toUpperCase(),
|
107
|
-
size: "small",
|
108
|
-
variant: "outlined",
|
109
|
-
sx: {
|
110
|
-
height: 'auto',
|
111
|
-
marginRight: 0,
|
112
|
-
fontWeight: 'bold',
|
113
|
-
fontSize: '12px',
|
114
|
-
margin: '6px 0 4px 0'
|
115
|
-
},
|
116
|
-
icon: /*#__PURE__*/_jsx(Icon, {
|
117
|
-
icon: ShieldCheckIcon,
|
118
|
-
height: "0.8em"
|
119
|
-
}),
|
120
|
-
deleteIcon: /*#__PURE__*/_jsx(Icon, {
|
121
|
-
icon: ExpandMoreIcon,
|
122
|
-
height: "1em"
|
123
|
-
})
|
124
|
-
// HACK: 必须设置 onDelete 函数,deleteIcon 才能显示出来
|
125
|
-
,
|
126
|
-
onDelete: onSwitchPassport,
|
127
|
-
onClick: onSwitchPassport,
|
128
|
-
"data-cy": "sessionManager-switch-passport-trigger"
|
129
|
-
}), session.provider === 'auth0' ? walletDid ? /*#__PURE__*/_jsx(DID, {
|
130
|
-
responsive: false,
|
131
|
-
compact: true,
|
132
|
-
did: walletDid
|
133
|
-
}) : null : /*#__PURE__*/_jsx(DID, {
|
134
|
-
responsive: false,
|
135
|
-
compact: true,
|
136
|
-
did: session.user.did
|
137
|
-
}), userEmail ? /*#__PURE__*/_jsx(DidAddress, {
|
138
|
-
responsive: false,
|
139
|
-
children: userEmail
|
140
|
-
}) : null]
|
141
|
-
})]
|
142
|
-
});
|
143
|
-
}
|
@@ -1,110 +0,0 @@
|
|
1
|
-
import PropTypes from 'prop-types';
|
2
|
-
import { IconButton, Paper, Popper, ClickAwayListener } from '@mui/material';
|
3
|
-
import CloseIcon from '@iconify-icons/mdi/close';
|
4
|
-
import { Icon } from '@iconify/react';
|
5
|
-
import { styled } from '../../Theme';
|
6
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
7
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
8
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
9
|
-
export default function UserPopper({
|
10
|
-
anchorEl,
|
11
|
-
dark,
|
12
|
-
children,
|
13
|
-
open,
|
14
|
-
onClose,
|
15
|
-
autoClose
|
16
|
-
}) {
|
17
|
-
return anchorEl && /*#__PURE__*/_jsx(StyledPopper, {
|
18
|
-
open: open,
|
19
|
-
disablePortal: true,
|
20
|
-
anchorEl: anchorEl,
|
21
|
-
placement: "bottom-end",
|
22
|
-
$dark: dark,
|
23
|
-
children: /*#__PURE__*/_jsx(Paper, {
|
24
|
-
sx: [theme => ({
|
25
|
-
borderColor: '#F0F0F0',
|
26
|
-
boxShadow: '0px 8px 12px rgba(92, 92, 92, 0.04)',
|
27
|
-
borderRadius: theme.spacing(2),
|
28
|
-
overflow: 'auto',
|
29
|
-
maxWidth: 'calc(100vw - 10px)',
|
30
|
-
maxHeight: 'calc(100vh - 80px)',
|
31
|
-
'& .MuiChip-root .MuiChip-icon': {
|
32
|
-
color: theme.palette.success.main
|
33
|
-
},
|
34
|
-
'& .MuiList-root': {
|
35
|
-
width: '320px'
|
36
|
-
}
|
37
|
-
}), dark && {
|
38
|
-
backgroundColor: '#27282c',
|
39
|
-
color: '#fff',
|
40
|
-
border: 0,
|
41
|
-
'& .MuiChip-root': {
|
42
|
-
borderColor: '#aaa'
|
43
|
-
},
|
44
|
-
'& .MuiListItem-root, & .MuiChip-label': {
|
45
|
-
color: '#aaa'
|
46
|
-
},
|
47
|
-
'& .MuiListItem-root:hover': {
|
48
|
-
backgroundColor: '#363434'
|
49
|
-
}
|
50
|
-
}],
|
51
|
-
variant: "outlined",
|
52
|
-
children: autoClose ? /*#__PURE__*/_jsx(ClickAwayListener, {
|
53
|
-
onClickAway: onClose,
|
54
|
-
children: children
|
55
|
-
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
56
|
-
children: [/*#__PURE__*/_jsx(IconButton, {
|
57
|
-
size: "small",
|
58
|
-
sx: {
|
59
|
-
cursor: 'pointer',
|
60
|
-
position: 'absolute',
|
61
|
-
right: 0,
|
62
|
-
top: 0,
|
63
|
-
zIndex: 1
|
64
|
-
},
|
65
|
-
onClick: onClose,
|
66
|
-
children: /*#__PURE__*/_jsx(Icon, {
|
67
|
-
icon: CloseIcon,
|
68
|
-
width: 20,
|
69
|
-
height: 20
|
70
|
-
})
|
71
|
-
}), children]
|
72
|
-
})
|
73
|
-
})
|
74
|
-
});
|
75
|
-
}
|
76
|
-
UserPopper.propTypes = {
|
77
|
-
anchorEl: PropTypes.instanceOf(Element),
|
78
|
-
dark: PropTypes.bool,
|
79
|
-
open: PropTypes.bool,
|
80
|
-
children: PropTypes.any.isRequired,
|
81
|
-
onClose: PropTypes.func,
|
82
|
-
autoClose: PropTypes.bool
|
83
|
-
};
|
84
|
-
UserPopper.defaultProps = {
|
85
|
-
anchorEl: null,
|
86
|
-
dark: false,
|
87
|
-
open: false,
|
88
|
-
onClose: () => {},
|
89
|
-
autoClose: true
|
90
|
-
};
|
91
|
-
const StyledPopper = styled(Popper)`
|
92
|
-
z-index: ${({
|
93
|
-
theme
|
94
|
-
}) => {
|
95
|
-
return theme.zIndex.tooltip;
|
96
|
-
}};
|
97
|
-
|
98
|
-
.session-manager-menu-item {
|
99
|
-
padding: 15px;
|
100
|
-
color: #777;
|
101
|
-
font-size: 16px;
|
102
|
-
&:hover {
|
103
|
-
background-color: #fbfbfb;
|
104
|
-
}
|
105
|
-
}
|
106
|
-
.session-manager-menu-icon {
|
107
|
-
color: #999;
|
108
|
-
margin-right: 8px;
|
109
|
-
}
|
110
|
-
`;
|
@@ -1,34 +0,0 @@
|
|
1
|
-
import { useLocalStorageState, useMemoizedFn } from 'ahooks';
|
2
|
-
import cloneDeep from 'lodash/cloneDeep';
|
3
|
-
export default function useConfig() {
|
4
|
-
const [config, setConfig] = useLocalStorageState('blocklet:sessionManager:config', {
|
5
|
-
defaultValue: {
|
6
|
-
accounts: [],
|
7
|
-
expandAccount: true,
|
8
|
-
expandBlocklet: true
|
9
|
-
}
|
10
|
-
});
|
11
|
-
const connectAccount = useMemoizedFn(account => {
|
12
|
-
const cloneConfig = cloneDeep(config);
|
13
|
-
const accountIndex = cloneConfig.accounts.findIndex(x => x.did === account.did);
|
14
|
-
if (accountIndex >= 0) {
|
15
|
-
cloneConfig.accounts.splice(accountIndex, 1);
|
16
|
-
}
|
17
|
-
cloneConfig.accounts.unshift(account);
|
18
|
-
setConfig(cloneConfig);
|
19
|
-
});
|
20
|
-
const deleteAccount = useMemoizedFn(account => {
|
21
|
-
const cloneConfig = cloneDeep(config);
|
22
|
-
const findIndex = cloneConfig.accounts.findIndex(item => item.did === account.did);
|
23
|
-
if (findIndex >= 0) {
|
24
|
-
cloneConfig.accounts.splice(findIndex, 1);
|
25
|
-
}
|
26
|
-
setConfig(cloneConfig);
|
27
|
-
});
|
28
|
-
return {
|
29
|
-
config,
|
30
|
-
setConfig,
|
31
|
-
connectAccount,
|
32
|
-
deleteAccount
|
33
|
-
};
|
34
|
-
}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
/* eslint-disable import/prefer-default-export */
|
2
|
-
export const translations = {
|
3
|
-
en: {
|
4
|
-
switch: 'Switch',
|
5
|
-
account: 'account',
|
6
|
-
switchDid: 'Switch DID',
|
7
|
-
switchTo: 'Switch to',
|
8
|
-
switchProfile: 'Switch Profile',
|
9
|
-
switchPassport: 'Switch Passport',
|
10
|
-
disconnect: 'Disconnect',
|
11
|
-
connect: 'Connect',
|
12
|
-
openInWallet: 'Open DID Wallet',
|
13
|
-
alreadyBindOAuth: 'Already bind Auth0',
|
14
|
-
bind: 'Bind ',
|
15
|
-
thirdParty: 'Third Party Login',
|
16
|
-
addAppAccount: 'Add {appName} account',
|
17
|
-
accounts: 'Accounts',
|
18
|
-
blocklet: 'Blocklet',
|
19
|
-
from: 'From',
|
20
|
-
addAnotherAccount: 'Add another account',
|
21
|
-
deleteAccountTitle: 'Remove this account ?',
|
22
|
-
deleteAccountContent: 'After delete account, you can add it again',
|
23
|
-
confirm: 'Confirm',
|
24
|
-
cancel: 'Cancel',
|
25
|
-
noneMenu: 'Empty menu, maybe you should switch to another role'
|
26
|
-
},
|
27
|
-
zh: {
|
28
|
-
switch: '切换',
|
29
|
-
account: '账号',
|
30
|
-
switchDid: '切换账户',
|
31
|
-
switchTo: '切换至',
|
32
|
-
switchProfile: '切换用户信息',
|
33
|
-
switchPassport: '切换通行证',
|
34
|
-
disconnect: '退出登录',
|
35
|
-
connect: '登录',
|
36
|
-
openInWallet: '打开 DID 钱包',
|
37
|
-
// NOTE: 目前只有 Auth0,展示出具体的第三方名字会更好
|
38
|
-
alreadyBindOAuth: '已绑定 Auth0 账号',
|
39
|
-
bind: '绑定',
|
40
|
-
thirdParty: '第三方登录',
|
41
|
-
addAppAccount: '添加 {appName} 账户',
|
42
|
-
accounts: '账户',
|
43
|
-
blocklet: '应用',
|
44
|
-
from: '连接至',
|
45
|
-
addAnotherAccount: '添加账号',
|
46
|
-
deleteAccountTitle: '是否删除账户?',
|
47
|
-
deleteAccountContent: '账户删除后,可再次添加',
|
48
|
-
confirm: '确认',
|
49
|
-
cancel: '取消',
|
50
|
-
noneMenu: '无操作项,请尝试切换角色'
|
51
|
-
}
|
52
|
-
};
|
@@ -1,219 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = AccountItem;
|
7
|
-
var _material = require("@mui/material");
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
|
-
var _react = require("@iconify/react");
|
10
|
-
var _check = _interopRequireDefault(require("@iconify-icons/mdi/check"));
|
11
|
-
var _appleIos = _interopRequireDefault(require("@iconify-icons/mdi/apple-ios"));
|
12
|
-
var _android = _interopRequireDefault(require("@iconify-icons/mdi/android"));
|
13
|
-
var _web = _interopRequireDefault(require("@iconify-icons/mdi/web"));
|
14
|
-
var _api = _interopRequireDefault(require("@iconify-icons/mdi/api"));
|
15
|
-
var _auth0Icon = _interopRequireDefault(require("@iconify-icons/logos/auth0-icon"));
|
16
|
-
var _trashCanOutline = _interopRequireDefault(require("@iconify-icons/mdi/trash-can-outline"));
|
17
|
-
var _ahooks = require("ahooks");
|
18
|
-
var _Avatar = _interopRequireDefault(require("../../Avatar"));
|
19
|
-
var _DID = _interopRequireDefault(require("../../DID"));
|
20
|
-
var _util = require("../../Locale/util");
|
21
|
-
var _translation = require("../libs/translation");
|
22
|
-
var _federated = require("../../Util/federated");
|
23
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25
|
-
function AccountItem(_ref) {
|
26
|
-
let {
|
27
|
-
account,
|
28
|
-
active,
|
29
|
-
onDelete,
|
30
|
-
onChoose,
|
31
|
-
locale
|
32
|
-
} = _ref;
|
33
|
-
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
34
|
-
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
35
|
-
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
36
|
-
});
|
37
|
-
const federatedEnabled = (0, _federated.getFederatedEnabled)();
|
38
|
-
const _onChoose = (0, _ahooks.useMemoizedFn)(() => onChoose(account, {
|
39
|
-
active
|
40
|
-
}));
|
41
|
-
const _onDelete = (0, _ahooks.useMemoizedFn)(e => {
|
42
|
-
e.preventDefault();
|
43
|
-
e.stopPropagation();
|
44
|
-
onDelete(account, {
|
45
|
-
active
|
46
|
-
});
|
47
|
-
});
|
48
|
-
const stopPropagation = (0, _ahooks.useMemoizedFn)(e => {
|
49
|
-
e.stopPropagation();
|
50
|
-
});
|
51
|
-
const walletIcon = (0, _ahooks.useCreation)(() => {
|
52
|
-
const {
|
53
|
-
walletOS,
|
54
|
-
provider
|
55
|
-
} = account;
|
56
|
-
if (provider === 'auth0') {
|
57
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
58
|
-
icon: _auth0Icon.default,
|
59
|
-
width: 10,
|
60
|
-
height: 10,
|
61
|
-
style: {
|
62
|
-
color: 'black'
|
63
|
-
}
|
64
|
-
});
|
65
|
-
}
|
66
|
-
if (walletOS === 'ios') {
|
67
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
68
|
-
icon: _appleIos.default,
|
69
|
-
width: 16,
|
70
|
-
height: 16,
|
71
|
-
style: {
|
72
|
-
color: 'black'
|
73
|
-
}
|
74
|
-
});
|
75
|
-
}
|
76
|
-
if (walletOS === 'android') {
|
77
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
78
|
-
icon: _android.default,
|
79
|
-
width: 14,
|
80
|
-
height: 14,
|
81
|
-
style: {
|
82
|
-
color: 'black'
|
83
|
-
}
|
84
|
-
});
|
85
|
-
}
|
86
|
-
if (walletOS === 'web') {
|
87
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
88
|
-
icon: _web.default,
|
89
|
-
style: {
|
90
|
-
color: 'black'
|
91
|
-
}
|
92
|
-
});
|
93
|
-
}
|
94
|
-
if (walletOS === 'api') {
|
95
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
96
|
-
icon: _api.default,
|
97
|
-
width: 14,
|
98
|
-
height: 14,
|
99
|
-
style: {
|
100
|
-
color: 'black'
|
101
|
-
}
|
102
|
-
});
|
103
|
-
}
|
104
|
-
return null;
|
105
|
-
}, [account.walletOS]);
|
106
|
-
if (!(account !== null && account !== void 0 && account.did) || !(account !== null && account !== void 0 && account.appName)) {
|
107
|
-
return null;
|
108
|
-
}
|
109
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
110
|
-
onClick: _onChoose,
|
111
|
-
sx: {
|
112
|
-
display: 'flex',
|
113
|
-
alignItems: 'center',
|
114
|
-
overflow: 'hidden',
|
115
|
-
gap: '8px',
|
116
|
-
position: 'relative',
|
117
|
-
'.account-item-actions': {
|
118
|
-
position: 'absolute',
|
119
|
-
right: 0,
|
120
|
-
top: 0,
|
121
|
-
bottom: 0,
|
122
|
-
marginRight: '12px',
|
123
|
-
display: 'flex',
|
124
|
-
alignItems: 'center'
|
125
|
-
},
|
126
|
-
'.account-item-action': {
|
127
|
-
alignItems: 'center',
|
128
|
-
display: 'none'
|
129
|
-
},
|
130
|
-
'&:hover .account-item-action': {
|
131
|
-
display: 'flex'
|
132
|
-
}
|
133
|
-
},
|
134
|
-
className: "session-manager-menu-item",
|
135
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Avatar.default, {
|
136
|
-
did: account.did,
|
137
|
-
size: 42
|
138
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
|
139
|
-
sx: {
|
140
|
-
flex: 1,
|
141
|
-
overflow: 'hidden',
|
142
|
-
fontSize: 0,
|
143
|
-
'.did-address-avatar': {
|
144
|
-
display: 'none !important'
|
145
|
-
}
|
146
|
-
},
|
147
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
|
148
|
-
did: account.did,
|
149
|
-
copyable: false,
|
150
|
-
size: 14,
|
151
|
-
responsive: false,
|
152
|
-
compact: true,
|
153
|
-
sx: {
|
154
|
-
lineHeight: 1
|
155
|
-
}
|
156
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
|
157
|
-
variant: "caption",
|
158
|
-
display: "flex",
|
159
|
-
alignItems: "center",
|
160
|
-
gap: 0.5,
|
161
|
-
children: [walletIcon, federatedEnabled ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
162
|
-
children: [t('from'), ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Link, {
|
163
|
-
href: account.appUrl,
|
164
|
-
target: "_blank",
|
165
|
-
onClick: stopPropagation,
|
166
|
-
sx: {
|
167
|
-
textDecoration: 'none',
|
168
|
-
'&:hover': {
|
169
|
-
textDecoration: 'underline'
|
170
|
-
}
|
171
|
-
},
|
172
|
-
children: account.appName
|
173
|
-
})]
|
174
|
-
}) :
|
175
|
-
// HACK: 用于在有 icon 的情况下,该该行的高度撑高为文字高度
|
176
|
-
walletIcon && ' ']
|
177
|
-
})]
|
178
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
179
|
-
className: "account-item-actions",
|
180
|
-
children: active ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
181
|
-
className: "account-item-action",
|
182
|
-
style: {
|
183
|
-
display: 'flex'
|
184
|
-
},
|
185
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
|
186
|
-
color: "success",
|
187
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
188
|
-
icon: _check.default,
|
189
|
-
color: "success"
|
190
|
-
})
|
191
|
-
})
|
192
|
-
}, "CheckIcon") : /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Box, {
|
193
|
-
className: "account-item-action",
|
194
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.IconButton, {
|
195
|
-
color: "error",
|
196
|
-
onClick: _onDelete,
|
197
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
198
|
-
icon: _trashCanOutline.default,
|
199
|
-
color: "error"
|
200
|
-
})
|
201
|
-
})
|
202
|
-
}, "TrashCanOutlineIcon")
|
203
|
-
})]
|
204
|
-
});
|
205
|
-
}
|
206
|
-
AccountItem.propTypes = {
|
207
|
-
account: _propTypes.default.object,
|
208
|
-
active: _propTypes.default.bool,
|
209
|
-
locale: _propTypes.default.string,
|
210
|
-
onChoose: _propTypes.default.func,
|
211
|
-
onDelete: _propTypes.default.func
|
212
|
-
};
|
213
|
-
AccountItem.defaultProps = {
|
214
|
-
account: null,
|
215
|
-
active: false,
|
216
|
-
locale: 'en',
|
217
|
-
onChoose: () => {},
|
218
|
-
onDelete: () => {}
|
219
|
-
};
|
@@ -1,66 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.default = AddAccountItem;
|
7
|
-
var _react = require("@iconify/react");
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
9
|
-
var _material = require("@mui/material");
|
10
|
-
var _iosAddCircleOutline = _interopRequireDefault(require("@iconify-icons/ion/ios-add-circle-outline"));
|
11
|
-
var _ahooks = require("ahooks");
|
12
|
-
var _util = require("../../Locale/util");
|
13
|
-
var _translation = require("../libs/translation");
|
14
|
-
var _federated = require("../../Util/federated");
|
15
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
-
function AddAccountItem(_ref) {
|
18
|
-
let {
|
19
|
-
onAdd,
|
20
|
-
locale,
|
21
|
-
session
|
22
|
-
} = _ref;
|
23
|
-
const t = (0, _ahooks.useMemoizedFn)(function (key) {
|
24
|
-
let data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
25
|
-
return (0, _util.translate)(_translation.translations, key, locale, 'en', data);
|
26
|
-
});
|
27
|
-
const apps = (0, _ahooks.useCreation)(() => {
|
28
|
-
return (0, _federated.getApps)();
|
29
|
-
}, []);
|
30
|
-
const _onAdd = (0, _ahooks.useMemoizedFn)(() => {
|
31
|
-
var _session$user;
|
32
|
-
// HACK: 如果是非统一登录应用,则 sourceAppPid 的值为 null
|
33
|
-
const sourceAppPid = (session === null || session === void 0 ? void 0 : (_session$user = session.user) === null || _session$user === void 0 ? void 0 : _session$user.sourceAppPid) || null;
|
34
|
-
const app = apps.find(x => x.appPid === sourceAppPid);
|
35
|
-
if (app) {
|
36
|
-
onAdd(app);
|
37
|
-
} else {
|
38
|
-
onAdd(apps[0]);
|
39
|
-
}
|
40
|
-
});
|
41
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.MenuItem, {
|
42
|
-
onClick: _onAdd,
|
43
|
-
className: "session-manager-menu-item",
|
44
|
-
sx: {
|
45
|
-
display: 'flex',
|
46
|
-
gap: '8px'
|
47
|
-
},
|
48
|
-
"data-cy": "sessionManager-switch-trigger",
|
49
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Icon, {
|
50
|
-
icon: _iosAddCircleOutline.default,
|
51
|
-
width: 24,
|
52
|
-
height: 24
|
53
|
-
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
|
54
|
-
children: t('addAnotherAccount')
|
55
|
-
})]
|
56
|
-
});
|
57
|
-
}
|
58
|
-
AddAccountItem.propTypes = {
|
59
|
-
onAdd: _propTypes.default.func,
|
60
|
-
locale: _propTypes.default.string,
|
61
|
-
session: _propTypes.default.object.isRequired
|
62
|
-
};
|
63
|
-
AddAccountItem.defaultProps = {
|
64
|
-
onAdd: () => {},
|
65
|
-
locale: 'en'
|
66
|
-
};
|