@blocklet/ui-react 3.4.15 → 3.5.0
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/common/org-switch/use-org.d.ts +4 -4
- package/package.json +9 -6
- package/.aigne/doc-smith/.local/afs-storage.sqlite3 +0 -0
- package/.aigne/doc-smith/config.yaml +0 -78
- package/.aigne/doc-smith/history.yaml +0 -14
- package/.aigne/doc-smith/media-description.yaml +0 -11
- package/.aigne/doc-smith/output/structure-plan.json +0 -255
- package/.aigne/doc-smith/translation-cache.yaml +0 -11
- package/.aigne/doc-smith/upload-cache.yaml +0 -528
- package/build.config.ts +0 -24
- package/docs/_sidebar.md +0 -19
- package/docs/assets/diagram/component-installer-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/component-installer-diagram-0.jpg +0 -0
- package/docs/assets/diagram/component-installer-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/component-installer-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/component-management-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/core-concepts-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/dashboard-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/header-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/layout-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/notifications-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/overview-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/user-center-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/user-management-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/user-sessions-diagram-0.zh.jpg +0 -0
- package/docs/components-component-management-blocklet-studio.ja.md +0 -194
- package/docs/components-component-management-blocklet-studio.md +0 -194
- package/docs/components-component-management-blocklet-studio.zh-TW.md +0 -194
- package/docs/components-component-management-blocklet-studio.zh.md +0 -194
- package/docs/components-component-management-component-installer.ja.md +0 -182
- package/docs/components-component-management-component-installer.md +0 -182
- package/docs/components-component-management-component-installer.zh-TW.md +0 -182
- package/docs/components-component-management-component-installer.zh.md +0 -182
- package/docs/components-component-management.ja.md +0 -30
- package/docs/components-component-management.md +0 -30
- package/docs/components-component-management.zh-TW.md +0 -30
- package/docs/components-component-management.zh.md +0 -30
- package/docs/components-layout-dashboard.ja.md +0 -185
- package/docs/components-layout-dashboard.md +0 -187
- package/docs/components-layout-dashboard.zh-TW.md +0 -185
- package/docs/components-layout-dashboard.zh.md +0 -185
- package/docs/components-layout-footer.ja.md +0 -165
- package/docs/components-layout-footer.md +0 -165
- package/docs/components-layout-footer.zh-TW.md +0 -165
- package/docs/components-layout-footer.zh.md +0 -165
- package/docs/components-layout-header.ja.md +0 -183
- package/docs/components-layout-header.md +0 -183
- package/docs/components-layout-header.zh-TW.md +0 -183
- package/docs/components-layout-header.zh.md +0 -183
- package/docs/components-layout.ja.md +0 -31
- package/docs/components-layout.md +0 -31
- package/docs/components-layout.zh-TW.md +0 -31
- package/docs/components-layout.zh.md +0 -31
- package/docs/components-notifications.ja.md +0 -125
- package/docs/components-notifications.md +0 -125
- package/docs/components-notifications.zh-TW.md +0 -125
- package/docs/components-notifications.zh.md +0 -125
- package/docs/components-user-management-user-center.ja.md +0 -148
- package/docs/components-user-management-user-center.md +0 -147
- package/docs/components-user-management-user-center.zh-TW.md +0 -148
- package/docs/components-user-management-user-center.zh.md +0 -148
- package/docs/components-user-management-user-sessions.ja.md +0 -121
- package/docs/components-user-management-user-sessions.md +0 -123
- package/docs/components-user-management-user-sessions.zh-TW.md +0 -121
- package/docs/components-user-management-user-sessions.zh.md +0 -121
- package/docs/components-user-management.ja.md +0 -49
- package/docs/components-user-management.md +0 -51
- package/docs/components-user-management.zh-TW.md +0 -49
- package/docs/components-user-management.zh.md +0 -49
- package/docs/components-utilities-icon.ja.md +0 -106
- package/docs/components-utilities-icon.md +0 -106
- package/docs/components-utilities-icon.zh-TW.md +0 -106
- package/docs/components-utilities-icon.zh.md +0 -106
- package/docs/components-utilities.ja.md +0 -136
- package/docs/components-utilities.md +0 -136
- package/docs/components-utilities.zh-TW.md +0 -136
- package/docs/components-utilities.zh.md +0 -136
- package/docs/components.ja.md +0 -27
- package/docs/components.md +0 -27
- package/docs/components.zh-TW.md +0 -27
- package/docs/components.zh.md +0 -27
- package/docs/core-concepts.ja.md +0 -134
- package/docs/core-concepts.md +0 -135
- package/docs/core-concepts.zh-TW.md +0 -134
- package/docs/core-concepts.zh.md +0 -134
- package/docs/getting-started.ja.md +0 -132
- package/docs/getting-started.md +0 -132
- package/docs/getting-started.zh-TW.md +0 -132
- package/docs/getting-started.zh.md +0 -132
- package/docs/hooks-api.ja.md +0 -214
- package/docs/hooks-api.md +0 -214
- package/docs/hooks-api.zh-TW.md +0 -214
- package/docs/hooks-api.zh.md +0 -214
- package/docs/how-to-guides.ja.md +0 -413
- package/docs/how-to-guides.md +0 -413
- package/docs/how-to-guides.zh-TW.md +0 -413
- package/docs/how-to-guides.zh.md +0 -413
- package/docs/overview.ja.md +0 -51
- package/docs/overview.md +0 -51
- package/docs/overview.zh-TW.md +0 -51
- package/docs/overview.zh.md +0 -51
- package/glossary.md +0 -12
- package/src/@types/index.ts +0 -230
- package/src/@types/shims.d.ts +0 -18
- package/src/BlockletStudio/README.md +0 -116
- package/src/BlockletStudio/index.tsx +0 -145
- package/src/ComponentInstaller/ComponentInstaller.stories.jsx +0 -16
- package/src/ComponentInstaller/index.jsx +0 -207
- package/src/ComponentInstaller/installer-item.jsx +0 -129
- package/src/ComponentInstaller/locales.js +0 -22
- package/src/ComponentInstaller/use-component-installed.js +0 -88
- package/src/ComponentManager/components/add-component.tsx +0 -136
- package/src/ComponentManager/components/check-component.tsx +0 -3
- package/src/ComponentManager/components/publish-component.tsx +0 -90
- package/src/ComponentManager/components/resource-dialog.tsx +0 -91
- package/src/ComponentManager/index.tsx +0 -3
- package/src/ComponentManager/libs/locales.ts +0 -15
- package/src/Dashboard/Dashboard.stories.jsx +0 -20
- package/src/Dashboard/app-shell/app-badge.stories.tsx +0 -64
- package/src/Dashboard/app-shell/app-badge.tsx +0 -94
- package/src/Dashboard/app-shell/app-header.tsx +0 -104
- package/src/Dashboard/app-shell/app-info-context.tsx +0 -182
- package/src/Dashboard/app-shell/badges/app-badge-default.tsx +0 -130
- package/src/Dashboard/app-shell/badges/app-badge-did.tsx +0 -28
- package/src/Dashboard/app-shell/badges/app-badge-state.tsx +0 -40
- package/src/Dashboard/app-shell/badges/app-badge-switch.tsx +0 -72
- package/src/Dashboard/app-shell/badges/app-badge-version.tsx +0 -60
- package/src/Dashboard/app-shell/index.ts +0 -5
- package/src/Dashboard/index.jsx +0 -184
- package/src/Footer/Footer.stories.jsx +0 -33
- package/src/Footer/brand.jsx +0 -81
- package/src/Footer/copyright.jsx +0 -22
- package/src/Footer/index.jsx +0 -111
- package/src/Footer/internal-footer.jsx +0 -139
- package/src/Footer/layout/plain.jsx +0 -55
- package/src/Footer/layout/row.jsx +0 -43
- package/src/Footer/layout/standard.jsx +0 -114
- package/src/Footer/links.jsx +0 -321
- package/src/Footer/social-media.jsx +0 -55
- package/src/Header/Header.stories.jsx +0 -30
- package/src/Header/index.tsx +0 -259
- package/src/Icon/Icon.stories.jsx +0 -12
- package/src/Icon/index.tsx +0 -87
- package/src/Notifications/Snackbar.tsx +0 -261
- package/src/Notifications/hooks/use-title.tsx +0 -254
- package/src/Notifications/hooks/use-width.tsx +0 -16
- package/src/Notifications/utils.ts +0 -246
- package/src/UserCenter/assets/banner.png +0 -0
- package/src/UserCenter/components/config-inviter.tsx +0 -48
- package/src/UserCenter/components/config-profile.tsx +0 -99
- package/src/UserCenter/components/danger-zone.tsx +0 -82
- package/src/UserCenter/components/editable-field.tsx +0 -273
- package/src/UserCenter/components/fallback.tsx +0 -57
- package/src/UserCenter/components/nft-preview.tsx +0 -84
- package/src/UserCenter/components/nft.tsx +0 -279
- package/src/UserCenter/components/notification.tsx +0 -319
- package/src/UserCenter/components/passport.tsx +0 -107
- package/src/UserCenter/components/privacy.tsx +0 -120
- package/src/UserCenter/components/settings.tsx +0 -170
- package/src/UserCenter/components/status-dialog/date-picker.tsx +0 -77
- package/src/UserCenter/components/status-dialog/index.tsx +0 -293
- package/src/UserCenter/components/status-selector/duration-menu.tsx +0 -90
- package/src/UserCenter/components/status-selector/index.tsx +0 -58
- package/src/UserCenter/components/status-selector/menu-item.tsx +0 -56
- package/src/UserCenter/components/storage/action.tsx +0 -49
- package/src/UserCenter/components/storage/connected.tsx +0 -61
- package/src/UserCenter/components/storage/delete.tsx +0 -72
- package/src/UserCenter/components/storage/disconnect.tsx +0 -40
- package/src/UserCenter/components/storage/icons/empty-spaces-nft.svg +0 -1
- package/src/UserCenter/components/storage/icons/long-arrow.svg +0 -5
- package/src/UserCenter/components/storage/icons/space-connected.svg +0 -3
- package/src/UserCenter/components/storage/icons/space-disconnect.svg +0 -3
- package/src/UserCenter/components/storage/index.tsx +0 -41
- package/src/UserCenter/components/storage/preview-nft.tsx +0 -72
- package/src/UserCenter/components/third-party-login/index.tsx +0 -199
- package/src/UserCenter/components/third-party-login/third-party-item.tsx +0 -296
- package/src/UserCenter/components/user-center.tsx +0 -787
- package/src/UserCenter/components/user-info/address.tsx +0 -143
- package/src/UserCenter/components/user-info/index.tsx +0 -4
- package/src/UserCenter/components/user-info/link-preview-input.tsx +0 -274
- package/src/UserCenter/components/user-info/metadata.tsx +0 -658
- package/src/UserCenter/components/user-info/social-actions/chat.tsx +0 -43
- package/src/UserCenter/components/user-info/social-actions/follow.tsx +0 -23
- package/src/UserCenter/components/user-info/social-actions/index.tsx +0 -17
- package/src/UserCenter/components/user-info/switch-role.tsx +0 -42
- package/src/UserCenter/components/user-info/timezone-select.tsx +0 -119
- package/src/UserCenter/components/user-info/user-basic-info.tsx +0 -292
- package/src/UserCenter/components/user-info/user-info-item.tsx +0 -54
- package/src/UserCenter/components/user-info/user-info.tsx +0 -91
- package/src/UserCenter/components/user-info/user-status.tsx +0 -234
- package/src/UserCenter/components/user-info/utils.ts +0 -320
- package/src/UserCenter/components/webhook-item.tsx +0 -248
- package/src/UserCenter/index.tsx +0 -1
- package/src/UserCenter/libs/locales.ts +0 -378
- package/src/UserCenter/libs/utils.ts +0 -30
- package/src/UserSessions/components/user-session-info.tsx +0 -78
- package/src/UserSessions/components/user-sessions.tsx +0 -545
- package/src/UserSessions/index.tsx +0 -1
- package/src/UserSessions/libs/locales.ts +0 -60
- package/src/UserSessions/libs/utils.ts +0 -82
- package/src/blocklets.js +0 -195
- package/src/common/domain-warning.jsx +0 -178
- package/src/common/header-addons.jsx +0 -119
- package/src/common/link-blocker.jsx +0 -20
- package/src/common/notification-addon.jsx +0 -135
- package/src/common/org-switch/avatar-uploader.jsx +0 -271
- package/src/common/org-switch/create.jsx +0 -267
- package/src/common/org-switch/index.jsx +0 -407
- package/src/common/org-switch/locales.js +0 -52
- package/src/common/org-switch/use-org.jsx +0 -79
- package/src/common/overridable-theme-provider.jsx +0 -17
- package/src/common/wallet-hidden-topbar.js +0 -14
- package/src/common/wizard-modal.jsx +0 -200
- package/src/common/ws.js +0 -68
- package/src/contexts/config-user-space.tsx +0 -88
- package/src/contexts/user-followers.tsx +0 -54
- package/src/hooks/use-follow.tsx +0 -75
- package/src/hooks/use-mobile.tsx +0 -6
- package/src/index.ts +0 -16
- package/src/libs/constant.ts +0 -1
- package/src/libs/spaces.tsx +0 -18
- package/src/libs/with-hide-when-embed.tsx +0 -24
- package/src/types.js +0 -45
- package/src/utils.js +0 -161
- package/vite.config.mjs +0 -34
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import noop from 'lodash/noop';
|
|
2
|
-
import { use, useState } from 'react';
|
|
3
|
-
import { Box } from '@mui/material';
|
|
4
|
-
import { useAsyncEffect, useCreation } from 'ahooks';
|
|
5
|
-
import { getConnectedAccounts, getSourceProvider } from '@arcblock/ux/lib/SessionUser/libs/utils';
|
|
6
|
-
import { LOGIN_PROVIDER } from '@arcblock/ux/lib/Util/constant';
|
|
7
|
-
import { SessionContext } from '@arcblock/did-connect-react/lib/Session';
|
|
8
|
-
import { PasskeyActions } from '@arcblock/did-connect-react/lib/Passkey';
|
|
9
|
-
import { useBrowser } from '@arcblock/react-hooks';
|
|
10
|
-
|
|
11
|
-
import type { ConnectedAccount, OAuthAccount, User, SessionContext as TSessionContext } from '../../../@types';
|
|
12
|
-
import ThirdPartyItem from './third-party-item';
|
|
13
|
-
|
|
14
|
-
type ConnectedAccountProps = OAuthAccount & {
|
|
15
|
-
enabled: boolean;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export default function ThirdPartyLogin({ user }: { user: User }) {
|
|
19
|
-
const { session } = use<TSessionContext>(SessionContext);
|
|
20
|
-
const [oauthConfigs, setOauthConfigs] = useState<Record<string, ConnectedAccountProps>>({});
|
|
21
|
-
const { getOAuthConfigs } = session.useOAuth();
|
|
22
|
-
const browser = useBrowser();
|
|
23
|
-
|
|
24
|
-
useAsyncEffect(async () => {
|
|
25
|
-
const data = await getOAuthConfigs({
|
|
26
|
-
sourceAppPid: user?.sourceAppPid,
|
|
27
|
-
});
|
|
28
|
-
setOauthConfigs(data);
|
|
29
|
-
}, [user?.sourceAppPid]);
|
|
30
|
-
|
|
31
|
-
const availableProviders = useCreation(() => {
|
|
32
|
-
const oauthList = Object.keys(oauthConfigs)
|
|
33
|
-
.map((x) => {
|
|
34
|
-
return {
|
|
35
|
-
...oauthConfigs[x],
|
|
36
|
-
provider: x,
|
|
37
|
-
};
|
|
38
|
-
})
|
|
39
|
-
.filter((x) => x.enabled);
|
|
40
|
-
return oauthList;
|
|
41
|
-
}, [oauthConfigs]);
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 1. 如果 connectedAccount 中存在 auth0,则应该将 auth0 转换为 google, apple, github 中的一种。如果可以转换,则标记需要移除 auth0;如果无法转换,则保留 auth0
|
|
45
|
-
* 2. 如果标记移除了 auth0,则还需要对 sourceProvider 进行转换,转换的值为 google, apple, github 中的一种
|
|
46
|
-
* 3. 如果标记移除了 auth0,还需要将 auth0 的 userInfo 数据添加到转换后的 provider 上
|
|
47
|
-
*/
|
|
48
|
-
const oauthAccounts = useCreation(() => {
|
|
49
|
-
const connectedAccounts: ConnectedAccount[] = getConnectedAccounts(user);
|
|
50
|
-
let removeAuth0 = false;
|
|
51
|
-
let patchProvider = '';
|
|
52
|
-
let sourceProvider = getSourceProvider(user);
|
|
53
|
-
const auth0ConnectedAccount = connectedAccounts.find((x) => x.provider === LOGIN_PROVIDER.AUTH0) as OAuthAccount;
|
|
54
|
-
if (auth0ConnectedAccount) {
|
|
55
|
-
if (auth0ConnectedAccount.id.startsWith('google-oauth2|')) {
|
|
56
|
-
if (!connectedAccounts.some((x) => x.provider === 'google')) {
|
|
57
|
-
removeAuth0 = true;
|
|
58
|
-
patchProvider = LOGIN_PROVIDER.GOOGLE;
|
|
59
|
-
if (sourceProvider === LOGIN_PROVIDER.AUTH0) {
|
|
60
|
-
sourceProvider = LOGIN_PROVIDER.GOOGLE;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (auth0ConnectedAccount.id.startsWith('appleid|')) {
|
|
65
|
-
if (!connectedAccounts.some((x) => x.provider === LOGIN_PROVIDER.APPLE)) {
|
|
66
|
-
removeAuth0 = true;
|
|
67
|
-
patchProvider = LOGIN_PROVIDER.APPLE;
|
|
68
|
-
if (sourceProvider === LOGIN_PROVIDER.AUTH0) {
|
|
69
|
-
sourceProvider = LOGIN_PROVIDER.APPLE;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (auth0ConnectedAccount.id.startsWith('github|')) {
|
|
74
|
-
if (!connectedAccounts.some((x) => x.provider === LOGIN_PROVIDER.GITHUB)) {
|
|
75
|
-
removeAuth0 = true;
|
|
76
|
-
patchProvider = LOGIN_PROVIDER.GITHUB;
|
|
77
|
-
if (sourceProvider === LOGIN_PROVIDER.AUTH0) {
|
|
78
|
-
sourceProvider = LOGIN_PROVIDER.GITHUB;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const transformedProviders = availableProviders
|
|
85
|
-
.map((x) => {
|
|
86
|
-
if (x.provider === LOGIN_PROVIDER.AUTH0 && removeAuth0) {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
const findConnectedAccount =
|
|
90
|
-
removeAuth0 && x.provider === patchProvider
|
|
91
|
-
? (connectedAccounts.find((i) => i.provider === LOGIN_PROVIDER.AUTH0) as OAuthAccount)
|
|
92
|
-
: (connectedAccounts.find((i) => i.provider === x.provider) as OAuthAccount);
|
|
93
|
-
if (findConnectedAccount) {
|
|
94
|
-
return {
|
|
95
|
-
...x,
|
|
96
|
-
provider: x.provider,
|
|
97
|
-
did: findConnectedAccount.did,
|
|
98
|
-
pk: findConnectedAccount.pk,
|
|
99
|
-
userInfo: findConnectedAccount.userInfo,
|
|
100
|
-
_bind: true,
|
|
101
|
-
_rawProvider: findConnectedAccount.provider,
|
|
102
|
-
_mainProvider: x.provider === sourceProvider,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
...x,
|
|
107
|
-
provider: x.provider,
|
|
108
|
-
_rawProvider: x.provider,
|
|
109
|
-
_mainProvider: x.provider === sourceProvider,
|
|
110
|
-
};
|
|
111
|
-
})
|
|
112
|
-
.filter(Boolean)
|
|
113
|
-
.sort((a, b) => {
|
|
114
|
-
if (a?.order !== undefined && b?.order !== undefined) {
|
|
115
|
-
return a.order - b.order;
|
|
116
|
-
}
|
|
117
|
-
if (a?.order !== undefined) {
|
|
118
|
-
return -1;
|
|
119
|
-
}
|
|
120
|
-
return 1;
|
|
121
|
-
});
|
|
122
|
-
return transformedProviders;
|
|
123
|
-
}, [user?.connectedAccounts, availableProviders]);
|
|
124
|
-
|
|
125
|
-
const passkeyAccounts = useCreation(() => {
|
|
126
|
-
const connectedAccounts: ConnectedAccount[] = getConnectedAccounts(user);
|
|
127
|
-
const passkeyConnectedAccount = connectedAccounts.filter(
|
|
128
|
-
(x) => x.provider === LOGIN_PROVIDER.PASSKEY && x.did !== user?.did
|
|
129
|
-
) as OAuthAccount[];
|
|
130
|
-
return passkeyConnectedAccount.map((x) => {
|
|
131
|
-
return {
|
|
132
|
-
...x,
|
|
133
|
-
_bind: true,
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
}, [user]);
|
|
137
|
-
|
|
138
|
-
const walletAccounts = useCreation(() => {
|
|
139
|
-
const connectedAccounts: ConnectedAccount[] = getConnectedAccounts(user);
|
|
140
|
-
const walletConnectedAccount = connectedAccounts.filter(
|
|
141
|
-
(x) => x.provider === LOGIN_PROVIDER.WALLET && x.did !== user?.did
|
|
142
|
-
) as OAuthAccount[];
|
|
143
|
-
return walletConnectedAccount.map((x) => {
|
|
144
|
-
return {
|
|
145
|
-
...x,
|
|
146
|
-
_mainProvider: true,
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
|
-
}, [user]);
|
|
150
|
-
|
|
151
|
-
return (
|
|
152
|
-
<Box
|
|
153
|
-
sx={{
|
|
154
|
-
gap: 1,
|
|
155
|
-
display: 'grid',
|
|
156
|
-
gridTemplateColumns: '1fr min-content',
|
|
157
|
-
}}>
|
|
158
|
-
{!oauthAccounts.length && !passkeyAccounts.length && !walletAccounts.length ? (
|
|
159
|
-
<PasskeyActions
|
|
160
|
-
behavior="only-new"
|
|
161
|
-
action="connect"
|
|
162
|
-
createMode="connect"
|
|
163
|
-
createButtonText="Add Passkey"
|
|
164
|
-
onSuccess={noop}
|
|
165
|
-
onError={noop}
|
|
166
|
-
dense
|
|
167
|
-
/>
|
|
168
|
-
) : (
|
|
169
|
-
<>
|
|
170
|
-
{oauthAccounts.map((account) => {
|
|
171
|
-
return <ThirdPartyItem key={account?.provider} item={account as OAuthAccount} />;
|
|
172
|
-
})}
|
|
173
|
-
{passkeyAccounts.map((account) => {
|
|
174
|
-
return <ThirdPartyItem key={account.id} item={account as OAuthAccount} />;
|
|
175
|
-
})}
|
|
176
|
-
{walletAccounts.map((account) => {
|
|
177
|
-
return <ThirdPartyItem key={account.id} item={account as OAuthAccount} />;
|
|
178
|
-
})}
|
|
179
|
-
{browser.wallet || browser.arcSphere ? null : (
|
|
180
|
-
<PasskeyActions
|
|
181
|
-
behavior="only-new"
|
|
182
|
-
action="connect"
|
|
183
|
-
createMode="connect"
|
|
184
|
-
createButtonText="Add New Passkey"
|
|
185
|
-
onSuccess={noop}
|
|
186
|
-
onError={noop}
|
|
187
|
-
dense
|
|
188
|
-
sx={{
|
|
189
|
-
px: 1.5,
|
|
190
|
-
py: 1,
|
|
191
|
-
gap: 0.75,
|
|
192
|
-
}}
|
|
193
|
-
/>
|
|
194
|
-
)}
|
|
195
|
-
</>
|
|
196
|
-
)}
|
|
197
|
-
</Box>
|
|
198
|
-
);
|
|
199
|
-
}
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import { Icon } from '@iconify/react';
|
|
2
|
-
import { Box, Tooltip, Typography } from '@mui/material';
|
|
3
|
-
import LinkRoundedIcon from '@iconify-icons/material-symbols/link-rounded';
|
|
4
|
-
import Button from '@arcblock/ux/lib/Button';
|
|
5
|
-
import Avatar from '@arcblock/ux/lib/Avatar';
|
|
6
|
-
import { useCreation, useMemoizedFn, useReactive } from 'ahooks';
|
|
7
|
-
import { translate } from '@arcblock/ux/lib/Locale/util';
|
|
8
|
-
import { useConfirm } from '@arcblock/ux/lib/Dialog';
|
|
9
|
-
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
10
|
-
import MailOutlineRoundedIcon from '@iconify-icons/material-symbols/mail-outline-rounded';
|
|
11
|
-
import InfoOutlineRoundedIcon from '@iconify-icons/material-symbols/info-outline-rounded';
|
|
12
|
-
import PasskeyIcon from '@iconify-icons/material-symbols/passkey';
|
|
13
|
-
import WalletIcon from '@iconify-icons/material-symbols/wallet-sharp';
|
|
14
|
-
import AppleIcon from '@iconify-icons/logos/apple';
|
|
15
|
-
import GithubIcon from '@iconify-icons/logos/github-icon';
|
|
16
|
-
import GoogleIcon from '@iconify-icons/logos/google-icon';
|
|
17
|
-
// import Auth0Icon from '@iconify-icons/logos/auth0-icon';
|
|
18
|
-
import { SessionContext } from '@arcblock/did-connect-react/lib/Session';
|
|
19
|
-
import { use } from 'react';
|
|
20
|
-
import pick from 'lodash/pick';
|
|
21
|
-
import { getFederatedEnabled, getMaster } from '@arcblock/ux/lib/Util/federated';
|
|
22
|
-
import { LOGIN_PROVIDER, LOGIN_PROVIDER_NAME, OAUTH_PROVIDER } from '@arcblock/ux/lib/Util/constant';
|
|
23
|
-
import { useStateContext } from '@arcblock/did-connect-react/lib/Connect/contexts/state';
|
|
24
|
-
|
|
25
|
-
import { translations } from '../../libs/locales';
|
|
26
|
-
import type { OAuthAccount, SessionContext as TSessionContext } from '../../../@types';
|
|
27
|
-
|
|
28
|
-
export default function ThirdPartyItem({
|
|
29
|
-
item,
|
|
30
|
-
}: {
|
|
31
|
-
item: {
|
|
32
|
-
provider: string;
|
|
33
|
-
did: string;
|
|
34
|
-
pk: string;
|
|
35
|
-
userInfo?: OAuthAccount['userInfo'];
|
|
36
|
-
id: string;
|
|
37
|
-
_bind?: boolean;
|
|
38
|
-
_rawProvider?: string;
|
|
39
|
-
_mainProvider?: boolean;
|
|
40
|
-
};
|
|
41
|
-
}) {
|
|
42
|
-
const { blocklet: targetBlocklet } = useStateContext();
|
|
43
|
-
const { confirmApi, confirmHolder } = useConfirm();
|
|
44
|
-
const currentState = useReactive({
|
|
45
|
-
loading: false,
|
|
46
|
-
});
|
|
47
|
-
const { locale } = useLocaleContext();
|
|
48
|
-
const t = useMemoizedFn((key, data = {}) => {
|
|
49
|
-
return translate(translations, key, locale, 'en', data);
|
|
50
|
-
});
|
|
51
|
-
const { session } = use<TSessionContext>(SessionContext);
|
|
52
|
-
const { bindOAuth, unbindOAuth, setBaseUrl, baseUrl: oauthBaseUrl } = session.useOAuth();
|
|
53
|
-
const { disconnectPasskey, setTargetAppPid } = session.usePasskey();
|
|
54
|
-
|
|
55
|
-
const iconMap = {
|
|
56
|
-
// email: MailOutlineRoundedIcon,
|
|
57
|
-
[LOGIN_PROVIDER.AUTH0]: MailOutlineRoundedIcon,
|
|
58
|
-
[LOGIN_PROVIDER.APPLE]: AppleIcon,
|
|
59
|
-
[LOGIN_PROVIDER.GITHUB]: GithubIcon,
|
|
60
|
-
[LOGIN_PROVIDER.GOOGLE]: GoogleIcon,
|
|
61
|
-
[LOGIN_PROVIDER.PASSKEY]: PasskeyIcon,
|
|
62
|
-
[LOGIN_PROVIDER.WALLET]: WalletIcon,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const icon = useCreation(() => {
|
|
66
|
-
return iconMap[item?.provider];
|
|
67
|
-
}, [item?.provider]);
|
|
68
|
-
const title = useCreation(() => {
|
|
69
|
-
return LOGIN_PROVIDER_NAME[item?.provider as keyof typeof OAUTH_PROVIDER] || 'unknown';
|
|
70
|
-
}, [item?.provider]);
|
|
71
|
-
|
|
72
|
-
const toggleBind = useMemoizedFn(async () => {
|
|
73
|
-
if (item?.provider === LOGIN_PROVIDER.PASSKEY) {
|
|
74
|
-
await new Promise((resolve, reject) => {
|
|
75
|
-
confirmApi.open({
|
|
76
|
-
title: t('thirdPartyLogin.disconnectPasskey', { name: title }),
|
|
77
|
-
content: t('thirdPartyLogin.disconnectPasskeyDescription', { name: title }),
|
|
78
|
-
confirmButtonText: t('common.confirm'),
|
|
79
|
-
confirmButtonProps: {
|
|
80
|
-
color: 'error',
|
|
81
|
-
},
|
|
82
|
-
cancelButtonText: t('common.cancel'),
|
|
83
|
-
onConfirm(close: () => void) {
|
|
84
|
-
disconnectPasskey({ session, connectedAccount: item }).then(resolve).catch(reject);
|
|
85
|
-
close();
|
|
86
|
-
},
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
onCancel: resolve,
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
currentState.loading = true;
|
|
96
|
-
await new Promise((resolve, reject) => {
|
|
97
|
-
if (item?._bind) {
|
|
98
|
-
confirmApi.open({
|
|
99
|
-
title: t('thirdPartyLogin.confirmUnbind', { name: title }),
|
|
100
|
-
content: t('thirdPartyLogin.confirmUnbindDescription', { name: title }),
|
|
101
|
-
confirmButtonText: t('common.confirm'),
|
|
102
|
-
confirmButtonProps: {
|
|
103
|
-
color: 'error',
|
|
104
|
-
},
|
|
105
|
-
cancelButtonText: t('common.cancel'),
|
|
106
|
-
onConfirm(close: () => void) {
|
|
107
|
-
unbindOAuth({
|
|
108
|
-
session,
|
|
109
|
-
connectedAccount: {
|
|
110
|
-
...pick(item, ['did', 'pk']),
|
|
111
|
-
showProvider: item.provider,
|
|
112
|
-
provider: item._rawProvider,
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
.then(resolve)
|
|
116
|
-
.catch(reject);
|
|
117
|
-
close();
|
|
118
|
-
},
|
|
119
|
-
// @ts-ignore
|
|
120
|
-
onCancel: resolve,
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
const backupBaseUrl = oauthBaseUrl;
|
|
124
|
-
const blocklet = window?.blocklet;
|
|
125
|
-
let baseUrl = '/';
|
|
126
|
-
const federatedEnabled = getFederatedEnabled(blocklet);
|
|
127
|
-
const master = getMaster(blocklet);
|
|
128
|
-
if (federatedEnabled && master?.appPid && session?.user?.sourceAppPid) {
|
|
129
|
-
baseUrl = master.appUrl;
|
|
130
|
-
}
|
|
131
|
-
setBaseUrl(baseUrl);
|
|
132
|
-
// @ts-ignore
|
|
133
|
-
setTargetAppPid(targetBlocklet?.appPid);
|
|
134
|
-
bindOAuth({
|
|
135
|
-
session,
|
|
136
|
-
oauthItem: {
|
|
137
|
-
...item,
|
|
138
|
-
provider: item._rawProvider,
|
|
139
|
-
},
|
|
140
|
-
})
|
|
141
|
-
.then(resolve)
|
|
142
|
-
.catch(reject)
|
|
143
|
-
.finally(() => {
|
|
144
|
-
setBaseUrl(backupBaseUrl);
|
|
145
|
-
setTargetAppPid();
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
} catch (err) {
|
|
150
|
-
console.error(`Failed to ${item?._bind ? 'unbind' : 'bind'} oauth account`, err);
|
|
151
|
-
} finally {
|
|
152
|
-
currentState.loading = false;
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
return (
|
|
157
|
-
<>
|
|
158
|
-
<Box
|
|
159
|
-
sx={{
|
|
160
|
-
borderRadius: 1,
|
|
161
|
-
border: '1px solid',
|
|
162
|
-
borderColor: 'divider',
|
|
163
|
-
backgroundColor: 'grey.50',
|
|
164
|
-
display: 'flex',
|
|
165
|
-
alignItems: 'center',
|
|
166
|
-
py: 1,
|
|
167
|
-
px: 1.5,
|
|
168
|
-
gap: 0.75,
|
|
169
|
-
fontSize: '14px',
|
|
170
|
-
lineHeight: 1,
|
|
171
|
-
overflow: 'hidden',
|
|
172
|
-
}}>
|
|
173
|
-
<Box
|
|
174
|
-
component={Icon}
|
|
175
|
-
icon={icon}
|
|
176
|
-
fill="currentColor"
|
|
177
|
-
sx={{
|
|
178
|
-
width: '1em',
|
|
179
|
-
height: '1em',
|
|
180
|
-
flexShrink: 0,
|
|
181
|
-
fontSize: 16,
|
|
182
|
-
|
|
183
|
-
// githubIcon 不支持变色,dark 模式做一个反色处理
|
|
184
|
-
filter: ({ palette }) =>
|
|
185
|
-
item?.provider === LOGIN_PROVIDER.GITHUB && palette.mode === 'dark' ? 'invert(1)' : 'none',
|
|
186
|
-
}}
|
|
187
|
-
/>
|
|
188
|
-
<Box
|
|
189
|
-
sx={{
|
|
190
|
-
flex: 1,
|
|
191
|
-
}}>
|
|
192
|
-
{title}
|
|
193
|
-
</Box>
|
|
194
|
-
<Box
|
|
195
|
-
sx={{
|
|
196
|
-
display: 'flex',
|
|
197
|
-
alignItems: 'center',
|
|
198
|
-
gap: 0.5,
|
|
199
|
-
}}>
|
|
200
|
-
<Box
|
|
201
|
-
sx={{
|
|
202
|
-
flex: 1,
|
|
203
|
-
textOverflow: 'ellipsis',
|
|
204
|
-
overflow: 'hidden',
|
|
205
|
-
lineHeight: 'normal',
|
|
206
|
-
}}>
|
|
207
|
-
{item.userInfo?.email || item.did}
|
|
208
|
-
</Box>
|
|
209
|
-
{item.userInfo?.name ? (
|
|
210
|
-
<Tooltip
|
|
211
|
-
title={
|
|
212
|
-
<>
|
|
213
|
-
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
|
214
|
-
<Avatar size={36} variant="circle" shape="circle" src={item.userInfo?.picture} did={item.did} />
|
|
215
|
-
<Box>
|
|
216
|
-
<Typography
|
|
217
|
-
sx={{
|
|
218
|
-
whiteSpace: 'normal',
|
|
219
|
-
wordBreak: 'break-all',
|
|
220
|
-
fontSize: '0.9rem',
|
|
221
|
-
}}>
|
|
222
|
-
{item.userInfo?.name}
|
|
223
|
-
</Typography>
|
|
224
|
-
<Typography
|
|
225
|
-
sx={{
|
|
226
|
-
whiteSpace: 'normal',
|
|
227
|
-
wordBreak: 'break-all',
|
|
228
|
-
fontSize: '0.9rem',
|
|
229
|
-
}}>
|
|
230
|
-
{item.userInfo?.email}
|
|
231
|
-
</Typography>
|
|
232
|
-
</Box>
|
|
233
|
-
</Box>
|
|
234
|
-
{/* 暂不显示 oauth 账户的 did */}
|
|
235
|
-
{/* <Box
|
|
236
|
-
component={DID}
|
|
237
|
-
did={item.did}
|
|
238
|
-
sx={{
|
|
239
|
-
'& .did-address-text': {
|
|
240
|
-
color: 'white',
|
|
241
|
-
},
|
|
242
|
-
}}
|
|
243
|
-
/> */}
|
|
244
|
-
</>
|
|
245
|
-
}>
|
|
246
|
-
<Box
|
|
247
|
-
component={Icon}
|
|
248
|
-
icon={InfoOutlineRoundedIcon}
|
|
249
|
-
sx={{
|
|
250
|
-
color: 'text.secondary',
|
|
251
|
-
fontSize: 16,
|
|
252
|
-
cursor: 'pointer',
|
|
253
|
-
flexShrink: 0,
|
|
254
|
-
}}
|
|
255
|
-
/>
|
|
256
|
-
</Tooltip>
|
|
257
|
-
) : null}
|
|
258
|
-
</Box>
|
|
259
|
-
</Box>
|
|
260
|
-
<Tooltip title={item._mainProvider ? t('thirdPartyLogin.mainProviderCantRemove') : ''}>
|
|
261
|
-
{/* HACK: 结合下面的 button disable 使用,必须增加这一层 */}
|
|
262
|
-
<Box>
|
|
263
|
-
<Button
|
|
264
|
-
variant="outlined"
|
|
265
|
-
size="small"
|
|
266
|
-
sx={(theme) => {
|
|
267
|
-
const textRed = theme.palette.error.main;
|
|
268
|
-
const textPrimary = theme.palette.primary.main;
|
|
269
|
-
|
|
270
|
-
return {
|
|
271
|
-
color: item?._bind ? textRed : textPrimary,
|
|
272
|
-
borderColor: item?._bind ? textRed : textPrimary,
|
|
273
|
-
backgroundColor: 'background.default',
|
|
274
|
-
'&:hover': {
|
|
275
|
-
borderColor: item?._bind ? textRed : textPrimary,
|
|
276
|
-
backgroundColor: 'action.hover',
|
|
277
|
-
},
|
|
278
|
-
py: 0.5,
|
|
279
|
-
borderRadius: 1,
|
|
280
|
-
fontWeight: 500,
|
|
281
|
-
whiteSpace: 'nowrap',
|
|
282
|
-
};
|
|
283
|
-
}}
|
|
284
|
-
fullWidth
|
|
285
|
-
startIcon={currentState.loading ? null : <Icon icon={LinkRoundedIcon} />}
|
|
286
|
-
onClick={toggleBind}
|
|
287
|
-
disabled={item._mainProvider}
|
|
288
|
-
loading={currentState.loading}>
|
|
289
|
-
{item?._bind ? t('thirdPartyLogin.disconnect') : t('thirdPartyLogin.connect')}
|
|
290
|
-
</Button>
|
|
291
|
-
</Box>
|
|
292
|
-
</Tooltip>
|
|
293
|
-
{confirmHolder}
|
|
294
|
-
</>
|
|
295
|
-
);
|
|
296
|
-
}
|