@arcblock/ux 2.12.5 → 2.12.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/Colors/themes/did-connect.d.ts +3 -0
- package/lib/Colors/themes/did-connect.js +5 -2
- package/lib/Header/header.js +0 -1
- package/lib/Locale/selector.js +36 -35
- package/lib/SessionUser/components/quick-login-item.js +4 -2
- package/lib/SessionUser/components/un-login.js +53 -25
- package/lib/SessionUser/libs/translation.js +2 -2
- package/package.json +5 -5
- package/src/Colors/themes/did-connect.ts +4 -1
- package/src/Header/header.tsx +0 -1
- package/src/Locale/selector.tsx +37 -36
- package/src/SessionUser/components/logged-in.tsx +1 -2
- package/src/SessionUser/components/quick-login-item.tsx +5 -2
- package/src/SessionUser/components/un-login.tsx +55 -16
- package/src/SessionUser/libs/translation.ts +2 -2
@@ -5,6 +5,7 @@ declare const colors: {
|
|
5
5
|
paper0: string;
|
6
6
|
paper1: string;
|
7
7
|
paper2: string;
|
8
|
+
paper3: string;
|
8
9
|
};
|
9
10
|
text: {
|
10
11
|
primary: string;
|
@@ -50,6 +51,8 @@ declare const colors: {
|
|
50
51
|
};
|
51
52
|
divider: {
|
52
53
|
main: string;
|
54
|
+
light: string;
|
55
|
+
dark: string;
|
53
56
|
};
|
54
57
|
};
|
55
58
|
export default colors;
|
@@ -4,7 +4,8 @@ const colors = {
|
|
4
4
|
default: 'white',
|
5
5
|
paper0: 'white',
|
6
6
|
paper1: '#FAFAFA',
|
7
|
-
paper2: '#F4F4F5'
|
7
|
+
paper2: '#F4F4F5',
|
8
|
+
paper3: '#F0F0F1'
|
8
9
|
},
|
9
10
|
text: {
|
10
11
|
primary: '#18181B',
|
@@ -49,7 +50,9 @@ const colors = {
|
|
49
50
|
dark: '#00A63E'
|
50
51
|
},
|
51
52
|
divider: {
|
52
|
-
main: '
|
53
|
+
main: 'rgba(18, 22, 24, 0.06)',
|
54
|
+
light: '#F4F4F5',
|
55
|
+
dark: '#D4D4D5'
|
53
56
|
}
|
54
57
|
};
|
55
58
|
export default colors;
|
package/lib/Header/header.js
CHANGED
package/lib/Locale/selector.js
CHANGED
@@ -86,13 +86,20 @@ export default function LocaleSelector(props) {
|
|
86
86
|
children: languages.find(x => x.code === locale)?.name
|
87
87
|
}) : '']
|
88
88
|
})
|
89
|
-
}), /*#__PURE__*/_jsx(
|
89
|
+
}), /*#__PURE__*/_jsx(Popper, {
|
90
90
|
open: open,
|
91
91
|
anchorEl: anchorEl.current,
|
92
92
|
...popperProps,
|
93
|
-
|
94
|
-
children: /*#__PURE__*/_jsx("div", {
|
93
|
+
children: /*#__PURE__*/_jsx(Box, {
|
95
94
|
className: "locales",
|
95
|
+
sx: {
|
96
|
+
background: getBackground({
|
97
|
+
...popperProps,
|
98
|
+
theme
|
99
|
+
}),
|
100
|
+
boxShadow: `0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6}`,
|
101
|
+
borderRadius: 2
|
102
|
+
},
|
96
103
|
children: /*#__PURE__*/_jsx(ClickAwayListener, {
|
97
104
|
onClickAway: onClose,
|
98
105
|
children: /*#__PURE__*/_jsx(MenuList, {
|
@@ -102,9 +109,32 @@ export default function LocaleSelector(props) {
|
|
102
109
|
}) => /*#__PURE__*/_jsxs(MenuItem, {
|
103
110
|
className: "locale-item",
|
104
111
|
onClick: () => onSelect(code),
|
105
|
-
|
112
|
+
sx: {
|
113
|
+
fontSize: 16,
|
114
|
+
fontStyle: 'normal',
|
115
|
+
fontStretch: 'normal',
|
116
|
+
lineHeight: 'normal',
|
117
|
+
letterSpacing: '2px',
|
118
|
+
textAlign: 'center',
|
119
|
+
color: getColor({
|
120
|
+
...popperProps,
|
121
|
+
theme
|
122
|
+
}),
|
123
|
+
cursor: 'pointer',
|
124
|
+
display: 'flex',
|
125
|
+
padding: '16px',
|
126
|
+
alignItems: 'center'
|
127
|
+
},
|
128
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
129
|
+
component: IconifyIcon,
|
106
130
|
icon: CheckIcon,
|
107
|
-
className: code === locale ? 'check-icon check-icon-visible' : 'check-icon'
|
131
|
+
className: code === locale ? 'check-icon check-icon-visible' : 'check-icon',
|
132
|
+
sx: [code === locale ? {
|
133
|
+
visibility: 'visible'
|
134
|
+
} : {}, {
|
135
|
+
visibility: 'hidden',
|
136
|
+
marginRight: 0.5
|
137
|
+
}]
|
108
138
|
}), name]
|
109
139
|
}, code))
|
110
140
|
})
|
@@ -131,40 +161,11 @@ const Div = styled('div', {
|
|
131
161
|
color: ${props => getColor(props)};
|
132
162
|
}
|
133
163
|
}
|
134
|
-
|
135
|
-
.locales {
|
136
|
-
background: ${props => getBackground(props)};
|
137
|
-
box-shadow:
|
138
|
-
0px 8px 16px 0px ${colors.gray6},
|
139
|
-
0px 0px 0px 1px ${colors.gray6};
|
140
|
-
border-radius: 8px;
|
141
|
-
}
|
142
|
-
|
143
|
-
.locale-item {
|
144
|
-
font-size: 16px;
|
145
|
-
font-style: normal;
|
146
|
-
font-stretch: normal;
|
147
|
-
line-height: normal;
|
148
|
-
letter-spacing: 2px;
|
149
|
-
text-align: center;
|
150
|
-
color: ${props => getColor(props)};
|
151
|
-
cursor: pointer;
|
152
|
-
display: flex;
|
153
|
-
padding: 16px;
|
154
|
-
align-items: center;
|
155
|
-
.check-icon {
|
156
|
-
visibility: hidden;
|
157
|
-
margin-right: 4px;
|
158
|
-
}
|
159
|
-
.check-icon-visible {
|
160
|
-
visibility: visible;
|
161
|
-
}
|
162
|
-
}
|
163
164
|
`;
|
164
165
|
const StyledPopper = styled(Popper)`
|
165
166
|
z-index: ${({
|
166
167
|
theme
|
167
168
|
}) => {
|
168
|
-
return theme.zIndex.
|
169
|
+
return theme.zIndex.modal + 1;
|
169
170
|
}};
|
170
171
|
`;
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import DID from '@arcblock/ux/lib/DID';
|
3
3
|
import RelativeTime from '@arcblock/ux/lib/RelativeTime';
|
4
4
|
import WalletOSIcon from '@arcblock/ux/lib/WalletOSIcon';
|
5
|
-
import { Box, Chip, Typography } from '@mui/material';
|
5
|
+
import { Box, Chip, Typography, useMediaQuery } from '@mui/material';
|
6
6
|
import { temp as colors } from '@arcblock/ux/lib/Colors';
|
7
7
|
import noop from 'lodash/noop';
|
8
8
|
import Avatar from '../../Avatar';
|
@@ -12,6 +12,7 @@ export default function QuickLoginItem({
|
|
12
12
|
locale = 'en',
|
13
13
|
onClick = noop
|
14
14
|
}) {
|
15
|
+
const isMobile = useMediaQuery(theme => theme.breakpoints.down('md'));
|
15
16
|
const isRawWalletAccount = getSourceProvider(userSession?.user) === 'wallet';
|
16
17
|
return /*#__PURE__*/_jsxs(Box, {
|
17
18
|
sx: {
|
@@ -52,6 +53,7 @@ export default function QuickLoginItem({
|
|
52
53
|
overflow: 'hidden'
|
53
54
|
},
|
54
55
|
children: [/*#__PURE__*/_jsxs(Typography, {
|
56
|
+
component: Box,
|
55
57
|
sx: {
|
56
58
|
fontSize: '16px',
|
57
59
|
fontWeight: 500,
|
@@ -106,7 +108,7 @@ export default function QuickLoginItem({
|
|
106
108
|
children: userSession.user.email
|
107
109
|
})]
|
108
110
|
})]
|
109
|
-
}), userSession.updatedAt && /*#__PURE__*/_jsx(Box, {
|
111
|
+
}), userSession.updatedAt && !isMobile && /*#__PURE__*/_jsx(Box, {
|
110
112
|
component: "span",
|
111
113
|
sx: {
|
112
114
|
color: colors.textMuted,
|
@@ -2,16 +2,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
2
2
|
import { Box, CircularProgress, Divider, Fade, IconButton, LinearProgress, MenuItem, MenuList, Paper, Popper } from '@mui/material';
|
3
3
|
import { Icon } from '@iconify/react';
|
4
4
|
import UserIcon from '@iconify-icons/tabler/user';
|
5
|
-
import { useEffect, useRef } from 'react';
|
5
|
+
import { Fragment, useEffect, useRef } from 'react';
|
6
6
|
import { useMemoizedFn, useReactive } from 'ahooks';
|
7
7
|
import noop from 'lodash/noop';
|
8
|
-
import
|
8
|
+
import DidBrandLogo from '@arcblock/icons/lib/DidBrandLogo';
|
9
|
+
import { useBrowser } from '@arcblock/react-hooks';
|
10
|
+
import { joinURL } from 'ufo';
|
9
11
|
import { temp as colors, didConnectColors } from '../../Colors';
|
10
12
|
import CloseButton from '../../CloseButton';
|
11
13
|
import { translate } from '../../Locale/util';
|
12
14
|
import { translations } from '../libs/translation';
|
13
15
|
import Typography from '../../Typography';
|
14
16
|
import QuickLoginItem from './quick-login-item';
|
17
|
+
import { getFederatedEnabled, getMaster } from '../../Util/federated';
|
15
18
|
export default function UnLogin({
|
16
19
|
session,
|
17
20
|
onLogin = noop,
|
@@ -22,12 +25,14 @@ export default function UnLogin({
|
|
22
25
|
const t = useMemoizedFn((key, data = {}) => {
|
23
26
|
return translate(translations, key, locale, 'en', data);
|
24
27
|
});
|
28
|
+
const browser = useBrowser();
|
25
29
|
const isFirstLoading = false;
|
26
30
|
const userAnchorRef = useRef(null);
|
27
31
|
const currentState = useReactive({
|
28
32
|
open: false,
|
29
33
|
userSessions: [],
|
30
|
-
loadingSessionId: null
|
34
|
+
loadingSessionId: null,
|
35
|
+
loadAppLogoError: false
|
31
36
|
});
|
32
37
|
const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
|
33
38
|
currentState.open = value;
|
@@ -38,13 +43,24 @@ export default function UnLogin({
|
|
38
43
|
}
|
39
44
|
session.login(onLogin);
|
40
45
|
});
|
46
|
+
const blocklet = window?.blocklet;
|
47
|
+
const federatedEnabled = getFederatedEnabled(blocklet);
|
48
|
+
const master = getMaster(blocklet);
|
49
|
+
const loginApp = federatedEnabled && master ? master : blocklet;
|
50
|
+
const loginAppName = loginApp?.appName || 'DID Connect';
|
51
|
+
const loginAppLogo = joinURL(loginApp?.appUrl || '/', loginApp?.appLogo || '/.well-known/service/blocklet/logo?imageFilter=convert&f=png&h=80');
|
41
52
|
useEffect(() => {
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
let timer;
|
54
|
+
|
55
|
+
// NOTICE: ArcSphere 中使用原生的快捷登录
|
56
|
+
if (!browser.arcSphere) {
|
57
|
+
timer = setTimeout(async () => {
|
58
|
+
currentState.userSessions = await session.getUserSessions();
|
59
|
+
if (currentState.userSessions.length > 0) {
|
60
|
+
currentState.open = true;
|
61
|
+
}
|
62
|
+
}, 1500);
|
63
|
+
}
|
48
64
|
return () => {
|
49
65
|
clearTimeout(timer);
|
50
66
|
};
|
@@ -96,15 +112,9 @@ export default function UnLogin({
|
|
96
112
|
})
|
97
113
|
}), /*#__PURE__*/_jsx(Popper, {
|
98
114
|
open: currentState.open,
|
99
|
-
anchorEl: userAnchorRef.current
|
100
|
-
// @ts-expect-error
|
101
|
-
,
|
102
|
-
dark: dark,
|
115
|
+
anchorEl: userAnchorRef.current,
|
103
116
|
transition: true,
|
104
117
|
placement: "bottom-end",
|
105
|
-
sx: {
|
106
|
-
zIndex: 1100
|
107
|
-
},
|
108
118
|
modifiers: [{
|
109
119
|
name: 'offset',
|
110
120
|
options: {
|
@@ -129,21 +139,39 @@ export default function UnLogin({
|
|
129
139
|
sx: {
|
130
140
|
display: 'flex',
|
131
141
|
alignItems: 'center',
|
132
|
-
gap:
|
142
|
+
gap: 1,
|
133
143
|
p: 2,
|
134
144
|
borderBottom: '1px solid #eee'
|
135
145
|
},
|
136
|
-
children: [/*#__PURE__*/_jsx(
|
137
|
-
|
138
|
-
height:
|
146
|
+
children: [loginAppLogo && !currentState.loadAppLogoError ? /*#__PURE__*/_jsx("img", {
|
147
|
+
src: loginAppLogo,
|
148
|
+
height: 20,
|
149
|
+
style: {
|
150
|
+
maxWidth: 100
|
151
|
+
},
|
152
|
+
onError: () => {
|
153
|
+
currentState.loadAppLogoError = true;
|
154
|
+
},
|
155
|
+
alt: "Login App Logo"
|
156
|
+
}) : /*#__PURE__*/_jsx(DidBrandLogo, {
|
157
|
+
height: 24,
|
158
|
+
width: 24
|
139
159
|
}), /*#__PURE__*/_jsx(Typography, {
|
140
160
|
fontSize: "auto",
|
141
161
|
sx: {
|
142
162
|
fontSize: '16',
|
143
163
|
flex: 1,
|
144
|
-
color: didConnectColors.text.secondary
|
164
|
+
color: didConnectColors.text.secondary,
|
165
|
+
// 最多展示三行
|
166
|
+
overflow: 'hidden',
|
167
|
+
textOverflow: 'ellipsis',
|
168
|
+
display: '-webkit-box',
|
169
|
+
WebkitLineClamp: 3,
|
170
|
+
WebkitBoxOrient: 'vertical'
|
145
171
|
},
|
146
|
-
children: t('useQuickLogin'
|
172
|
+
children: t('useQuickLogin', {
|
173
|
+
name: loginAppName
|
174
|
+
})
|
147
175
|
}), /*#__PURE__*/_jsx(CloseButton, {
|
148
176
|
onClose: () => onTogglePopper(false)
|
149
177
|
})]
|
@@ -154,7 +182,7 @@ export default function UnLogin({
|
|
154
182
|
},
|
155
183
|
children: currentState.userSessions.map((userSessionItem, index) => {
|
156
184
|
const isLoading = currentState.loadingSessionId === userSessionItem.id;
|
157
|
-
return /*#__PURE__*/_jsxs(
|
185
|
+
return /*#__PURE__*/_jsxs(Fragment, {
|
158
186
|
children: [/*#__PURE__*/_jsxs(MenuItem, {
|
159
187
|
sx: {
|
160
188
|
overflow: 'hidden',
|
@@ -185,8 +213,8 @@ export default function UnLogin({
|
|
185
213
|
my: '0px !important',
|
186
214
|
borderColor: '#e4e4e7'
|
187
215
|
}
|
188
|
-
}) : null]
|
189
|
-
});
|
216
|
+
}, `${userSessionItem.id}-divider`) : null]
|
217
|
+
}, `${userSessionItem.id}-root`);
|
190
218
|
})
|
191
219
|
})]
|
192
220
|
})
|
@@ -11,7 +11,7 @@ export const translations = {
|
|
11
11
|
logout: 'Sign Out',
|
12
12
|
addAnotherAccount: 'Add another account',
|
13
13
|
disconnected: 'Disconnected',
|
14
|
-
useQuickLogin: 'Use
|
14
|
+
useQuickLogin: 'Use {name} account to login'
|
15
15
|
},
|
16
16
|
zh: {
|
17
17
|
connectDIDWallet: '连接你的 DID Wallet 获得更高的安全性',
|
@@ -23,6 +23,6 @@ export const translations = {
|
|
23
23
|
logout: '退出登录',
|
24
24
|
addAnotherAccount: '添加账户',
|
25
25
|
disconnected: '未连接',
|
26
|
-
useQuickLogin: '使用
|
26
|
+
useQuickLogin: '使用 {name} 账号登录'
|
27
27
|
}
|
28
28
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.12.
|
3
|
+
"version": "2.12.6",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -68,12 +68,12 @@
|
|
68
68
|
"react": ">=18.2.0",
|
69
69
|
"react-router-dom": ">=6.22.3"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "7b92b4bc17fc44c8c331c61a4e41da117340329a",
|
72
72
|
"dependencies": {
|
73
73
|
"@arcblock/did-motif": "^1.1.13",
|
74
|
-
"@arcblock/icons": "^2.12.
|
75
|
-
"@arcblock/nft-display": "^2.12.
|
76
|
-
"@arcblock/react-hooks": "^2.12.
|
74
|
+
"@arcblock/icons": "^2.12.6",
|
75
|
+
"@arcblock/nft-display": "^2.12.6",
|
76
|
+
"@arcblock/react-hooks": "^2.12.6",
|
77
77
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
78
78
|
"@fontsource/inter": "^5.0.16",
|
79
79
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
@@ -5,6 +5,7 @@ const colors = {
|
|
5
5
|
paper0: 'white',
|
6
6
|
paper1: '#FAFAFA',
|
7
7
|
paper2: '#F4F4F5',
|
8
|
+
paper3: '#F0F0F1',
|
8
9
|
},
|
9
10
|
text: {
|
10
11
|
primary: '#18181B',
|
@@ -49,7 +50,9 @@ const colors = {
|
|
49
50
|
dark: '#00A63E',
|
50
51
|
},
|
51
52
|
divider: {
|
52
|
-
main: '
|
53
|
+
main: 'rgba(18, 22, 24, 0.06)',
|
54
|
+
light: '#F4F4F5',
|
55
|
+
dark: '#D4D4D5',
|
53
56
|
},
|
54
57
|
};
|
55
58
|
|
package/src/Header/header.tsx
CHANGED
package/src/Locale/selector.tsx
CHANGED
@@ -94,23 +94,53 @@ export default function LocaleSelector(props: LocaleSelectorProps) {
|
|
94
94
|
</Box>
|
95
95
|
</ButtonComponent>
|
96
96
|
|
97
|
-
<
|
98
|
-
<
|
97
|
+
<Popper open={open} anchorEl={anchorEl.current} {...popperProps}>
|
98
|
+
<Box
|
99
|
+
className="locales"
|
100
|
+
sx={{
|
101
|
+
background: getBackground({ ...popperProps, theme }),
|
102
|
+
boxShadow: `0px 8px 16px 0px ${colors.gray6}, 0px 0px 0px 1px ${colors.gray6}`,
|
103
|
+
borderRadius: 2,
|
104
|
+
}}>
|
99
105
|
<ClickAwayListener onClickAway={onClose}>
|
100
106
|
<MenuList>
|
101
107
|
{languages.map(({ code, name }) => (
|
102
|
-
<MenuItem
|
103
|
-
|
108
|
+
<MenuItem
|
109
|
+
key={code}
|
110
|
+
className="locale-item"
|
111
|
+
onClick={() => onSelect(code)}
|
112
|
+
sx={{
|
113
|
+
fontSize: 16,
|
114
|
+
fontStyle: 'normal',
|
115
|
+
fontStretch: 'normal',
|
116
|
+
lineHeight: 'normal',
|
117
|
+
letterSpacing: '2px',
|
118
|
+
textAlign: 'center',
|
119
|
+
color: getColor({ ...popperProps, theme }),
|
120
|
+
cursor: 'pointer',
|
121
|
+
display: 'flex',
|
122
|
+
padding: '16px',
|
123
|
+
alignItems: 'center',
|
124
|
+
}}>
|
125
|
+
<Box
|
126
|
+
component={IconifyIcon}
|
104
127
|
icon={CheckIcon}
|
105
128
|
className={code === locale ? 'check-icon check-icon-visible' : 'check-icon'}
|
129
|
+
sx={[
|
130
|
+
code === locale ? { visibility: 'visible' } : {},
|
131
|
+
{
|
132
|
+
visibility: 'hidden',
|
133
|
+
marginRight: 0.5,
|
134
|
+
},
|
135
|
+
]}
|
106
136
|
/>
|
107
137
|
{name}
|
108
138
|
</MenuItem>
|
109
139
|
))}
|
110
140
|
</MenuList>
|
111
141
|
</ClickAwayListener>
|
112
|
-
</
|
113
|
-
</
|
142
|
+
</Box>
|
143
|
+
</Popper>
|
114
144
|
</Div>
|
115
145
|
);
|
116
146
|
}
|
@@ -137,39 +167,10 @@ const Div = styled('div', {
|
|
137
167
|
color: ${(props) => getColor(props)};
|
138
168
|
}
|
139
169
|
}
|
140
|
-
|
141
|
-
.locales {
|
142
|
-
background: ${(props) => getBackground(props)};
|
143
|
-
box-shadow:
|
144
|
-
0px 8px 16px 0px ${colors.gray6},
|
145
|
-
0px 0px 0px 1px ${colors.gray6};
|
146
|
-
border-radius: 8px;
|
147
|
-
}
|
148
|
-
|
149
|
-
.locale-item {
|
150
|
-
font-size: 16px;
|
151
|
-
font-style: normal;
|
152
|
-
font-stretch: normal;
|
153
|
-
line-height: normal;
|
154
|
-
letter-spacing: 2px;
|
155
|
-
text-align: center;
|
156
|
-
color: ${(props) => getColor(props)};
|
157
|
-
cursor: pointer;
|
158
|
-
display: flex;
|
159
|
-
padding: 16px;
|
160
|
-
align-items: center;
|
161
|
-
.check-icon {
|
162
|
-
visibility: hidden;
|
163
|
-
margin-right: 4px;
|
164
|
-
}
|
165
|
-
.check-icon-visible {
|
166
|
-
visibility: visible;
|
167
|
-
}
|
168
|
-
}
|
169
170
|
`;
|
170
171
|
|
171
172
|
const StyledPopper = styled(Popper)`
|
172
173
|
z-index: ${({ theme }) => {
|
173
|
-
return theme.zIndex.
|
174
|
+
return theme.zIndex.modal + 1;
|
174
175
|
}};
|
175
176
|
`;
|
@@ -19,11 +19,10 @@ import AccountCircleOffOutlineRoundedIcon from '@iconify-icons/material-symbols/
|
|
19
19
|
import InviteIcon from '@iconify-icons/material-symbols/featured-seasonal-and-gifts-rounded';
|
20
20
|
import Copy from 'copy-to-clipboard';
|
21
21
|
import noop from 'lodash/noop';
|
22
|
-
import bridge from '@arcblock/bridge';
|
23
22
|
|
24
23
|
import Toast from '../../Toast';
|
25
24
|
import DidAvatar from '../../Avatar';
|
26
|
-
import { getUserAvatar
|
25
|
+
import { getUserAvatar } from '../../Util';
|
27
26
|
import UserInfo from './user-info';
|
28
27
|
import { temp as colors } from '../../Colors';
|
29
28
|
import { DASHBOARD_URL, PROFILE_URL } from '../../Util/constant';
|
@@ -2,7 +2,8 @@ import PropTypes from 'prop-types';
|
|
2
2
|
import DID from '@arcblock/ux/lib/DID';
|
3
3
|
import RelativeTime from '@arcblock/ux/lib/RelativeTime';
|
4
4
|
import WalletOSIcon from '@arcblock/ux/lib/WalletOSIcon';
|
5
|
-
import { Box, Chip, Typography } from '@mui/material';
|
5
|
+
import { Box, Chip, Typography, useMediaQuery } from '@mui/material';
|
6
|
+
import type { Theme } from '@mui/material';
|
6
7
|
import { temp as colors } from '@arcblock/ux/lib/Colors';
|
7
8
|
import noop from 'lodash/noop';
|
8
9
|
|
@@ -32,6 +33,7 @@ export default function QuickLoginItem({
|
|
32
33
|
updatedAt: string;
|
33
34
|
};
|
34
35
|
}) {
|
36
|
+
const isMobile = useMediaQuery((theme: Theme) => theme.breakpoints.down('md'));
|
35
37
|
const isRawWalletAccount = getSourceProvider(userSession?.user) === 'wallet';
|
36
38
|
|
37
39
|
return (
|
@@ -65,6 +67,7 @@ export default function QuickLoginItem({
|
|
65
67
|
<Avatar src={userSession.user.avatar} did={userSession.user.did} size={44} variant="circle" shape="circle" />
|
66
68
|
<Box sx={{ flex: 1, overflow: 'hidden' }}>
|
67
69
|
<Typography
|
70
|
+
component={Box}
|
68
71
|
sx={{
|
69
72
|
fontSize: '16px',
|
70
73
|
fontWeight: 500,
|
@@ -120,7 +123,7 @@ export default function QuickLoginItem({
|
|
120
123
|
)}
|
121
124
|
</Box>
|
122
125
|
</Box>
|
123
|
-
{userSession.updatedAt && (
|
126
|
+
{userSession.updatedAt && !isMobile && (
|
124
127
|
<Box component="span" sx={{ color: colors.textMuted, fontSize: '12px', flexShrink: 0 }}>
|
125
128
|
{/* @ts-ignore */}
|
126
129
|
<RelativeTime value={userSession.updatedAt} locale={locale} />
|
@@ -12,10 +12,12 @@ import {
|
|
12
12
|
} from '@mui/material';
|
13
13
|
import { Icon } from '@iconify/react';
|
14
14
|
import UserIcon from '@iconify-icons/tabler/user';
|
15
|
-
import { useEffect, useRef } from 'react';
|
15
|
+
import { Fragment, useEffect, useRef } from 'react';
|
16
16
|
import { useMemoizedFn, useReactive } from 'ahooks';
|
17
17
|
import noop from 'lodash/noop';
|
18
|
-
import
|
18
|
+
import DidBrandLogo from '@arcblock/icons/lib/DidBrandLogo';
|
19
|
+
import { useBrowser } from '@arcblock/react-hooks';
|
20
|
+
import { joinURL } from 'ufo';
|
19
21
|
|
20
22
|
import { Session } from '../../type';
|
21
23
|
import { temp as colors, didConnectColors } from '../../Colors';
|
@@ -24,6 +26,7 @@ import { translate } from '../../Locale/util';
|
|
24
26
|
import { translations } from '../libs/translation';
|
25
27
|
import Typography from '../../Typography';
|
26
28
|
import QuickLoginItem from './quick-login-item';
|
29
|
+
import { getFederatedEnabled, getMaster } from '../../Util/federated';
|
27
30
|
|
28
31
|
export interface UnLoginProps {
|
29
32
|
session: Session;
|
@@ -37,12 +40,15 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
37
40
|
const t = useMemoizedFn((key, data = {}) => {
|
38
41
|
return translate(translations, key, locale, 'en', data);
|
39
42
|
});
|
43
|
+
const browser = useBrowser();
|
44
|
+
|
40
45
|
const isFirstLoading = false;
|
41
46
|
const userAnchorRef = useRef(null);
|
42
47
|
const currentState = useReactive({
|
43
48
|
open: false,
|
44
49
|
userSessions: [] as Session[],
|
45
50
|
loadingSessionId: null,
|
51
|
+
loadAppLogoError: false,
|
46
52
|
});
|
47
53
|
const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
|
48
54
|
currentState.open = value;
|
@@ -54,13 +60,28 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
54
60
|
session.login(onLogin);
|
55
61
|
});
|
56
62
|
|
63
|
+
const blocklet = window?.blocklet;
|
64
|
+
const federatedEnabled = getFederatedEnabled(blocklet);
|
65
|
+
const master = getMaster(blocklet);
|
66
|
+
const loginApp = federatedEnabled && master ? master : blocklet;
|
67
|
+
const loginAppName = loginApp?.appName || 'DID Connect';
|
68
|
+
const loginAppLogo = joinURL(
|
69
|
+
loginApp?.appUrl || '/',
|
70
|
+
loginApp?.appLogo || '/.well-known/service/blocklet/logo?imageFilter=convert&f=png&h=80'
|
71
|
+
);
|
72
|
+
|
57
73
|
useEffect(() => {
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
74
|
+
let timer: NodeJS.Timeout;
|
75
|
+
|
76
|
+
// NOTICE: ArcSphere 中使用原生的快捷登录
|
77
|
+
if (!browser.arcSphere) {
|
78
|
+
timer = setTimeout(async () => {
|
79
|
+
currentState.userSessions = await session.getUserSessions();
|
80
|
+
if (currentState.userSessions.length > 0) {
|
81
|
+
currentState.open = true;
|
82
|
+
}
|
83
|
+
}, 1500);
|
84
|
+
}
|
64
85
|
|
65
86
|
return () => {
|
66
87
|
clearTimeout(timer);
|
@@ -106,11 +127,8 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
106
127
|
<Popper
|
107
128
|
open={currentState.open}
|
108
129
|
anchorEl={userAnchorRef.current}
|
109
|
-
// @ts-expect-error
|
110
|
-
dark={dark}
|
111
130
|
transition
|
112
131
|
placement="bottom-end"
|
113
|
-
sx={{ zIndex: 1100 }}
|
114
132
|
modifiers={[
|
115
133
|
{
|
116
134
|
name: 'offset',
|
@@ -135,19 +153,39 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
135
153
|
sx={{
|
136
154
|
display: 'flex',
|
137
155
|
alignItems: 'center',
|
138
|
-
gap:
|
156
|
+
gap: 1,
|
139
157
|
p: 2,
|
140
158
|
borderBottom: '1px solid #eee',
|
141
159
|
}}>
|
142
|
-
|
160
|
+
{loginAppLogo && !currentState.loadAppLogoError ? (
|
161
|
+
<img
|
162
|
+
src={loginAppLogo}
|
163
|
+
height={20}
|
164
|
+
style={{
|
165
|
+
maxWidth: 100,
|
166
|
+
}}
|
167
|
+
onError={() => {
|
168
|
+
currentState.loadAppLogoError = true;
|
169
|
+
}}
|
170
|
+
alt="Login App Logo"
|
171
|
+
/>
|
172
|
+
) : (
|
173
|
+
<DidBrandLogo height={24} width={24} />
|
174
|
+
)}
|
143
175
|
<Typography
|
144
176
|
fontSize="auto"
|
145
177
|
sx={{
|
146
178
|
fontSize: '16',
|
147
179
|
flex: 1,
|
148
180
|
color: didConnectColors.text.secondary,
|
181
|
+
// 最多展示三行
|
182
|
+
overflow: 'hidden',
|
183
|
+
textOverflow: 'ellipsis',
|
184
|
+
display: '-webkit-box',
|
185
|
+
WebkitLineClamp: 3,
|
186
|
+
WebkitBoxOrient: 'vertical',
|
149
187
|
}}>
|
150
|
-
{t('useQuickLogin')}
|
188
|
+
{t('useQuickLogin', { name: loginAppName })}
|
151
189
|
</Typography>
|
152
190
|
<CloseButton onClose={() => onTogglePopper(false)} />
|
153
191
|
</Box>
|
@@ -156,7 +194,7 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
156
194
|
const isLoading = currentState.loadingSessionId === userSessionItem.id;
|
157
195
|
|
158
196
|
return (
|
159
|
-
|
197
|
+
<Fragment key={`${userSessionItem.id}-root`}>
|
160
198
|
<MenuItem
|
161
199
|
key={userSessionItem.id}
|
162
200
|
sx={{
|
@@ -185,6 +223,7 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
185
223
|
</MenuItem>
|
186
224
|
{index < currentState.userSessions.length - 1 ? (
|
187
225
|
<Divider
|
226
|
+
key={`${userSessionItem.id}-divider`}
|
188
227
|
sx={{
|
189
228
|
mx: 2,
|
190
229
|
my: '0px !important',
|
@@ -192,7 +231,7 @@ export default function UnLogin({ session, onLogin = noop, size = 24, dark = fal
|
|
192
231
|
}}
|
193
232
|
/>
|
194
233
|
) : null}
|
195
|
-
|
234
|
+
</Fragment>
|
196
235
|
);
|
197
236
|
})}
|
198
237
|
</MenuList>
|
@@ -13,7 +13,7 @@ export const translations: Translations = {
|
|
13
13
|
logout: 'Sign Out',
|
14
14
|
addAnotherAccount: 'Add another account',
|
15
15
|
disconnected: 'Disconnected',
|
16
|
-
useQuickLogin: 'Use
|
16
|
+
useQuickLogin: 'Use {name} account to login',
|
17
17
|
},
|
18
18
|
zh: {
|
19
19
|
connectDIDWallet: '连接你的 DID Wallet 获得更高的安全性',
|
@@ -25,6 +25,6 @@ export const translations: Translations = {
|
|
25
25
|
logout: '退出登录',
|
26
26
|
addAnotherAccount: '添加账户',
|
27
27
|
disconnected: '未连接',
|
28
|
-
useQuickLogin: '使用
|
28
|
+
useQuickLogin: '使用 {name} 账号登录',
|
29
29
|
},
|
30
30
|
};
|