@arcblock/ux 3.4.15 → 3.5.1
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/package.json.js +1 -1
- package/package.json +10 -7
- package/src/ActionButton/ActionButton.stories.jsx +0 -61
- package/src/ActionButton/index.jsx +0 -106
- package/src/ActivityIndicator/ActivityIndicator.stories.jsx +0 -9
- package/src/ActivityIndicator/index.jsx +0 -140
- package/src/Address/Address.stories.jsx +0 -38
- package/src/Address/compact-text.jsx +0 -76
- package/src/Address/did-address.tsx +0 -223
- package/src/Address/index.tsx +0 -21
- package/src/Address/responsive-did-address.tsx +0 -154
- package/src/Alert/Alert.stories.jsx +0 -100
- package/src/Alert/index.jsx +0 -130
- package/src/AnimationWaiter/AnimationWaiter.stories.jsx +0 -35
- package/src/AnimationWaiter/dark-animation.json +0 -1
- package/src/AnimationWaiter/default-animation.json +0 -1
- package/src/AnimationWaiter/index.jsx +0 -296
- package/src/Async/index.tsx +0 -44
- package/src/Avatar/Avatar.stories.jsx +0 -11
- package/src/Avatar/did-motif.jsx +0 -38
- package/src/Avatar/etherscan-blockies.js +0 -81
- package/src/Avatar/index.jsx +0 -195
- package/src/Badge/Badge.stories.jsx +0 -41
- package/src/Badge/index.jsx +0 -101
- package/src/Blocklet/Blocklet.stories.jsx +0 -21
- package/src/Blocklet/blocklet.jsx +0 -276
- package/src/Blocklet/index.js +0 -5
- package/src/Blocklet/utils.jsx +0 -58
- package/src/BlockletContext/index.tsx +0 -72
- package/src/BlockletNFT/BlockletNFT.stories.jsx +0 -21
- package/src/BlockletNFT/index.jsx +0 -378
- package/src/BlockletV2/Blocklet.stories.jsx +0 -34
- package/src/BlockletV2/blocklet.tsx +0 -247
- package/src/BlockletV2/components/icon-text.tsx +0 -47
- package/src/BlockletV2/components/tooltip-icon.tsx +0 -52
- package/src/BlockletV2/index.ts +0 -6
- package/src/BlockletV2/utils.js +0 -75
- package/src/Button/Button.stories.jsx +0 -24
- package/src/Button/index.js +0 -9
- package/src/Button/wrap.jsx +0 -126
- package/src/ButtonGroup/index.js +0 -16
- package/src/CardSelector/index.tsx +0 -136
- package/src/Center/Center.stories.jsx +0 -20
- package/src/Center/index.tsx +0 -33
- package/src/ClickToCopy/ClickToCopy.stories.jsx +0 -24
- package/src/ClickToCopy/copy-button.tsx +0 -43
- package/src/ClickToCopy/hook.ts +0 -42
- package/src/ClickToCopy/index.tsx +0 -96
- package/src/CloseButton/index.tsx +0 -37
- package/src/CodeBlock/CodeBlock.stories.jsx +0 -22
- package/src/CodeBlock/LightBox.tsx +0 -87
- package/src/CodeBlock/index.tsx +0 -217
- package/src/Colors/Colors.stories.jsx +0 -211
- package/src/Colors/index.ts +0 -4
- package/src/Colors/themes/default.ts +0 -8
- package/src/Colors/themes/did-connect.ts +0 -64
- package/src/Colors/themes/temp.ts +0 -52
- package/src/Config/Config.stories.jsx +0 -16
- package/src/Config/config-provider.tsx +0 -62
- package/src/Config/index.ts +0 -2
- package/src/Config/theme-mode-toggle.tsx +0 -38
- package/src/ContactForm/ContactForm.stories.jsx +0 -32
- package/src/ContactForm/index.tsx +0 -264
- package/src/CookieConsent/CookieConsent.stories.jsx +0 -33
- package/src/CookieConsent/index.tsx +0 -104
- package/src/CountDown/CountDown.stories.jsx +0 -15
- package/src/CountDown/index.tsx +0 -170
- package/src/DID/DID.stories.jsx +0 -37
- package/src/DID/index.tsx +0 -393
- package/src/DIDConnect/app-icon.tsx +0 -37
- package/src/DIDConnect/app-info-item.tsx +0 -93
- package/src/DIDConnect/auth-apps/auth-apps-info.tsx +0 -77
- package/src/DIDConnect/auth-apps/index.tsx +0 -278
- package/src/DIDConnect/auth-apps/switch-role.tsx +0 -47
- package/src/DIDConnect/did-connect-container.tsx +0 -326
- package/src/DIDConnect/did-connect-footer.tsx +0 -76
- package/src/DIDConnect/did-connect-logo.tsx +0 -8
- package/src/DIDConnect/icons/did-wallet-logo.tsx +0 -18
- package/src/DIDConnect/icons/github-logo.tsx +0 -17
- package/src/DIDConnect/index.ts +0 -11
- package/src/DIDConnect/landing-page.tsx +0 -218
- package/src/DIDConnect/powered-by.tsx +0 -48
- package/src/DIDConnect/provider-icon.tsx +0 -62
- package/src/DIDConnect/request-storage-access-api-dialog.tsx +0 -304
- package/src/DIDConnect/with-container.tsx +0 -323
- package/src/DIDConnect/with-ux-theme.tsx +0 -22
- package/src/DIDLogo/Logo.stories.jsx +0 -11
- package/src/DIDLogo/index.tsx +0 -168
- package/src/Datatable/CustomToolbar.jsx +0 -415
- package/src/Datatable/Datatable.stories.jsx +0 -92
- package/src/Datatable/DatatableContext.jsx +0 -35
- package/src/Datatable/TableSearch.jsx +0 -166
- package/src/Datatable/index.jsx +0 -652
- package/src/Datatable/utils.js +0 -161
- package/src/Dialog/Dialog.stories.jsx +0 -21
- package/src/Dialog/confirm.jsx +0 -143
- package/src/Dialog/dialog.jsx +0 -199
- package/src/Dialog/index.js +0 -4
- package/src/Dialog/types.d.ts +0 -20
- package/src/Dialog/use-confirm.jsx +0 -188
- package/src/DriftBot/index.tsx +0 -81
- package/src/Earth/Earth.stories.jsx +0 -39
- package/src/Earth/countries.json +0 -8057
- package/src/Earth/index.tsx +0 -515
- package/src/Earth/util.ts +0 -72
- package/src/Empty/Empty.stories.jsx +0 -23
- package/src/Empty/index.jsx +0 -48
- package/src/ErrorBoundary/ErrorBoundary.stories.jsx +0 -13
- package/src/ErrorBoundary/fallback.tsx +0 -85
- package/src/ErrorBoundary/index.ts +0 -1
- package/src/Footer/Footer.stories.jsx +0 -13
- package/src/Footer/index.tsx +0 -130
- package/src/Header/Header.stories.jsx +0 -30
- package/src/Header/addon-button.tsx +0 -41
- package/src/Header/auto-hidden.tsx +0 -31
- package/src/Header/header-addons.tsx +0 -37
- package/src/Header/header.tsx +0 -214
- package/src/Header/index.ts +0 -3
- package/src/Header/responsive-header.tsx +0 -145
- package/src/Icon/Icon.stories.jsx +0 -45
- package/src/Icon/image.tsx +0 -53
- package/src/Icon/index.tsx +0 -63
- package/src/Img/Img.stories.jsx +0 -17
- package/src/Img/index.jsx +0 -258
- package/src/InfoRow/InfoRow.stories.jsx +0 -14
- package/src/InfoRow/index.tsx +0 -91
- package/src/Layout/Layout.stories.jsx +0 -24
- package/src/Layout/dashboard/external-link.tsx +0 -59
- package/src/Layout/dashboard/full-page.tsx +0 -58
- package/src/Layout/dashboard/index.tsx +0 -260
- package/src/Layout/dashboard/sidebar.tsx +0 -198
- package/src/Layout/dashboard-legacy/header.tsx +0 -156
- package/src/Layout/dashboard-legacy/index.tsx +0 -127
- package/src/Layout/dashboard-legacy/sidebar.tsx +0 -129
- package/src/Layout/index.tsx +0 -310
- package/src/LoadingMask/index.tsx +0 -108
- package/src/Locale/LocaleSelector.stories.jsx +0 -44
- package/src/Locale/browser-lang.ts +0 -65
- package/src/Locale/context.tsx +0 -162
- package/src/Locale/languages.ts +0 -58
- package/src/Locale/selector.tsx +0 -174
- package/src/Locale/util.ts +0 -38
- package/src/Logo/Logo.stories.jsx +0 -23
- package/src/Logo/images/logo-dark-text.svg +0 -3
- package/src/Logo/images/logo-dark-top.svg +0 -6
- package/src/Logo/images/logo-light-text.svg +0 -3
- package/src/Logo/images/logo-light-top.svg +0 -6
- package/src/Logo/index.tsx +0 -58
- package/src/Metric/Metric.stories.jsx +0 -29
- package/src/Metric/index.tsx +0 -130
- package/src/MuiWrap/index.tsx +0 -10
- package/src/NFTDisplay/NFTBroken.svg +0 -34
- package/src/NFTDisplay/NFTDisplay.stories.jsx +0 -30
- package/src/NFTDisplay/README.md +0 -59
- package/src/NFTDisplay/aspect-ratio-container.tsx +0 -36
- package/src/NFTDisplay/broken.tsx +0 -51
- package/src/NFTDisplay/displayApi.ts +0 -43
- package/src/NFTDisplay/index.tsx +0 -393
- package/src/NFTDisplay/loading.tsx +0 -16
- package/src/NFTDisplay/preview.tsx +0 -84
- package/src/NFTDisplay/render-svg.tsx +0 -21
- package/src/NFTDisplay/svg-embedder/img.tsx +0 -27
- package/src/NFTDisplay/svg-embedder/inline-svg.tsx +0 -36
- package/src/NavMenu/NavMenu.stories.jsx +0 -17
- package/src/NavMenu/images/OCAP.svg +0 -1
- package/src/NavMenu/images/abt-network.svg +0 -1
- package/src/NavMenu/images/ai-kit.svg +0 -1
- package/src/NavMenu/images/aigne-image-smith.svg +0 -1
- package/src/NavMenu/images/aigne.svg +0 -1
- package/src/NavMenu/images/aistro.png +0 -0
- package/src/NavMenu/images/arcsphere.svg +0 -1
- package/src/NavMenu/images/blocklet-framework.svg +0 -1
- package/src/NavMenu/images/blocklet-launcher.svg +0 -1
- package/src/NavMenu/images/blocklet-server.svg +0 -1
- package/src/NavMenu/images/blocklet-store.svg +0 -1
- package/src/NavMenu/images/creator-studio.svg +0 -1
- package/src/NavMenu/images/did-wallet.svg +0 -1
- package/src/NavMenu/images/did.svg +0 -1
- package/src/NavMenu/images/nft-studio.svg +0 -1
- package/src/NavMenu/images/payment-kit.png +0 -0
- package/src/NavMenu/images/vc.svg +0 -1
- package/src/NavMenu/images/web3-kit.svg +0 -1
- package/src/NavMenu/index.ts +0 -3
- package/src/NavMenu/nav-menu-context.tsx +0 -30
- package/src/NavMenu/nav-menu.tsx +0 -441
- package/src/NavMenu/products.tsx +0 -830
- package/src/NavMenu/style.ts +0 -258
- package/src/NavMenu/sub-container.tsx +0 -125
- package/src/NavMenu/sub-item-group.tsx +0 -42
- package/src/OrgTransfer/index.tsx +0 -53
- package/src/OrgTransfer/locales.ts +0 -25
- package/src/OrgTransfer/selector.tsx +0 -252
- package/src/OrgTransfer/type.ts +0 -31
- package/src/PageScroller/index.tsx +0 -316
- package/src/PageScroller/story/FifthComponent.jsx +0 -7
- package/src/PageScroller/story/FirstComponent.jsx +0 -7
- package/src/PageScroller/story/FourthComponent.jsx +0 -7
- package/src/PageScroller/story/FullPage.jsx +0 -55
- package/src/PageScroller/story/PageContain.jsx +0 -59
- package/src/PageScroller/story/PageScroller.stories.jsx +0 -18
- package/src/PageScroller/story/SecondComponent.jsx +0 -7
- package/src/PageScroller/story/ThirdComponent.jsx +0 -7
- package/src/PageScroller/story/index.css +0 -115
- package/src/PageScroller/usePrevValue.ts +0 -11
- package/src/Passport/index.ts +0 -3
- package/src/Passport/passport.tsx +0 -118
- package/src/PhoneInput/PhoneInput.stories.jsx +0 -12
- package/src/PhoneInput/country-select.tsx +0 -148
- package/src/PhoneInput/index.tsx +0 -269
- package/src/PoweredByArcBlock/index.tsx +0 -27
- package/src/PricingTable/PricingPlan.tsx +0 -120
- package/src/PricingTable/PricingTable.stories.jsx +0 -38
- package/src/PricingTable/index.tsx +0 -59
- package/src/QRCode/QRCode.stories.jsx +0 -13
- package/src/QRCode/index.tsx +0 -66
- package/src/RelativeTime/RelativeTime.stories.jsx +0 -20
- package/src/RelativeTime/index.tsx +0 -334
- package/src/Result/Result.stories.jsx +0 -61
- package/src/Result/common.tsx +0 -119
- package/src/Result/index.tsx +0 -30
- package/src/Result/result.tsx +0 -65
- package/src/Result/translations.ts +0 -57
- package/src/Screenshot/BaseScreenshot/index.tsx +0 -73
- package/src/Screenshot/BaseScreenshot/shells/Macbook.tsx +0 -38
- package/src/Screenshot/BaseScreenshot/shells/Phone.tsx +0 -35
- package/src/Screenshot/Screenshot.stories.jsx +0 -44
- package/src/Screenshot/devices.css +0 -1366
- package/src/Screenshot/index.tsx +0 -300
- package/src/SessionBlocklet/index.tsx +0 -178
- package/src/SessionManager/SessionManager.stories.jsx +0 -9
- package/src/SessionManager/index.tsx +0 -3
- package/src/SessionPermission/index.tsx +0 -26
- package/src/SessionUser/components/did-space.tsx +0 -68
- package/src/SessionUser/components/logged-in.tsx +0 -338
- package/src/SessionUser/components/quick-login-item.tsx +0 -132
- package/src/SessionUser/components/session-user-item.tsx +0 -93
- package/src/SessionUser/components/session-user-switch.tsx +0 -240
- package/src/SessionUser/components/un-login.tsx +0 -257
- package/src/SessionUser/components/user-info.tsx +0 -201
- package/src/SessionUser/index.tsx +0 -68
- package/src/SessionUser/libs/translation.ts +0 -30
- package/src/SessionUser/libs/utils.ts +0 -39
- package/src/SharedBridge/index.tsx +0 -126
- package/src/SocialShare/index.tsx +0 -194
- package/src/Sparkline/Sparkline.stories.jsx +0 -13
- package/src/Sparkline/index.tsx +0 -231
- package/src/Spinner/Spinner.stories.jsx +0 -98
- package/src/Spinner/index.tsx +0 -20
- package/src/SplitButton/SplitButton.stories.jsx +0 -32
- package/src/SplitButton/index.tsx +0 -116
- package/src/SplitButton/useClickAway.tsx +0 -24
- package/src/Success/index.tsx +0 -175
- package/src/Switch/Switch.stories.jsx +0 -16
- package/src/Switch/index.jsx +0 -79
- package/src/Tabs/Tabs.stories.jsx +0 -18
- package/src/Tabs/index.tsx +0 -255
- package/src/Tag/Tag.stories.jsx +0 -15
- package/src/Tag/index.jsx +0 -106
- package/src/TextCollapse/TextCollapse.stories.jsx +0 -73
- package/src/TextCollapse/index.tsx +0 -85
- package/src/Theme/Theme.stories.jsx +0 -11
- package/src/Theme/index.ts +0 -21
- package/src/Theme/theme-provider.tsx +0 -374
- package/src/Theme/theme.ts +0 -229
- package/src/Toast/Toast.stories.jsx +0 -28
- package/src/Toast/index.tsx +0 -80
- package/src/Typography/index.tsx +0 -124
- package/src/UserCard/Cards/avatar-only.tsx +0 -27
- package/src/UserCard/Cards/basic-info.tsx +0 -43
- package/src/UserCard/Cards/index.tsx +0 -16
- package/src/UserCard/Cards/social-actions.tsx +0 -196
- package/src/UserCard/Container/card.tsx +0 -63
- package/src/UserCard/Container/dialog.tsx +0 -37
- package/src/UserCard/Content/basic.tsx +0 -330
- package/src/UserCard/Content/clock.tsx +0 -82
- package/src/UserCard/Content/minimal.tsx +0 -113
- package/src/UserCard/Content/shorten-label.tsx +0 -32
- package/src/UserCard/Content/tooltip-avatar.tsx +0 -80
- package/src/UserCard/UserCard.stories.jsx +0 -19
- package/src/UserCard/components.tsx +0 -81
- package/src/UserCard/index.tsx +0 -132
- package/src/UserCard/types.ts +0 -165
- package/src/UserCard/use-follow.tsx +0 -111
- package/src/UserCard/utils.ts +0 -155
- package/src/Util/WebWalletOpener.stories.jsx +0 -5
- package/src/Util/client.ts +0 -4
- package/src/Util/constant.ts +0 -70
- package/src/Util/deprecate.tsx +0 -29
- package/src/Util/federated.ts +0 -125
- package/src/Util/iframe.ts +0 -19
- package/src/Util/index.ts +0 -760
- package/src/Util/logger.ts +0 -44
- package/src/Util/passport.ts +0 -127
- package/src/Util/security.ts +0 -72
- package/src/Util/style.ts +0 -17
- package/src/Util/wallet.ts +0 -35
- package/src/VerificationCode/index.tsx +0 -83
- package/src/Video/Video.stories.jsx +0 -6
- package/src/Video/index.tsx +0 -70
- package/src/Wallet/Action.stories.jsx +0 -8
- package/src/Wallet/Action.tsx +0 -118
- package/src/Wallet/Download.stories.jsx +0 -9
- package/src/Wallet/Download.tsx +0 -157
- package/src/Wallet/Open.tsx +0 -47
- package/src/Wallet/OpenInWallet.stories.jsx +0 -5
- package/src/Wallet/images/abtwallet.png +0 -0
- package/src/Wallet/images/android_download.svg +0 -22
- package/src/Wallet/images/app-store.svg +0 -30
- package/src/Wallet/images/google-play.svg +0 -69
- package/src/WalletOSIcon/index.tsx +0 -47
- package/src/WebWalletSWKeeper/index.tsx +0 -117
- package/src/WechatPrompt/images/android.png +0 -0
- package/src/WechatPrompt/images/ios.png +0 -0
- package/src/WechatPrompt/index.tsx +0 -75
- package/src/global.d.ts +0 -28
- package/src/hooks/use-blocklet-logo.tsx +0 -32
- package/src/hooks/use-clock.tsx +0 -62
- package/src/hooks/use-location-state.tsx +0 -117
- package/src/hooks/use-mobile.tsx +0 -6
- package/src/index.ts +0 -79
- package/src/type.d.ts +0 -44
- package/src/withTheme/index.tsx +0 -72
- package/src/withTracker/README.md +0 -37
- package/src/withTracker/action/bind-wallet.tsx +0 -17
- package/src/withTracker/action/login.tsx +0 -18
- package/src/withTracker/action/pay.tsx +0 -14
- package/src/withTracker/action/switch-passport.tsx +0 -20
- package/src/withTracker/constant/index.tsx +0 -3
- package/src/withTracker/env.tsx +0 -1
- package/src/withTracker/error_boundary.jsx +0 -34
- package/src/withTracker/index.tsx +0 -50
- package/src/withTracker/libs/utm.ts +0 -46
- package/vite.config.mjs +0 -37
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Box, Avatar as MaterialAvatar } from '@mui/material';
|
|
3
|
-
import Avatar from '../Avatar';
|
|
4
|
-
import { User, UserCardProps } from './types';
|
|
5
|
-
import { createNameOnlyAvatar } from './utils';
|
|
6
|
-
|
|
7
|
-
// 渲染头像
|
|
8
|
-
export const renderAvatar = (
|
|
9
|
-
user: User,
|
|
10
|
-
avatarSize: number = 48,
|
|
11
|
-
avatarProps: UserCardProps['avatarProps'] = undefined,
|
|
12
|
-
onAvatarClick: UserCardProps['onAvatarClick'] = undefined,
|
|
13
|
-
shouldShowHoverCard: boolean = false
|
|
14
|
-
) => {
|
|
15
|
-
const onClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
16
|
-
onAvatarClick?.(user, e);
|
|
17
|
-
};
|
|
18
|
-
// 如果用户没有头像,则显示名称首字母头像
|
|
19
|
-
if (!user.avatar) {
|
|
20
|
-
const avatarContent = createNameOnlyAvatar(user);
|
|
21
|
-
// 从 avatarProps 中提取 MUI 的 Avatar 支持的基本 props
|
|
22
|
-
// className, style 等基本 React 属性
|
|
23
|
-
const { className, style, alt } = avatarProps || {};
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<MaterialAvatar
|
|
27
|
-
onClick={onClick}
|
|
28
|
-
className={className}
|
|
29
|
-
style={style}
|
|
30
|
-
alt={alt}
|
|
31
|
-
sx={{
|
|
32
|
-
width: avatarSize,
|
|
33
|
-
height: avatarSize,
|
|
34
|
-
fontSize: avatarSize * 0.4,
|
|
35
|
-
cursor: shouldShowHoverCard || onAvatarClick ? 'pointer' : 'default',
|
|
36
|
-
}}
|
|
37
|
-
variant="circular">
|
|
38
|
-
{avatarContent}
|
|
39
|
-
</MaterialAvatar>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 显示用户头像
|
|
44
|
-
return (
|
|
45
|
-
<Box
|
|
46
|
-
className="user-card__avatar"
|
|
47
|
-
sx={{
|
|
48
|
-
display: 'flex',
|
|
49
|
-
}}>
|
|
50
|
-
<Avatar
|
|
51
|
-
size={avatarSize}
|
|
52
|
-
did={user.did}
|
|
53
|
-
variant="circle"
|
|
54
|
-
useProxyFallback
|
|
55
|
-
style={{
|
|
56
|
-
cursor: shouldShowHoverCard || onAvatarClick ? 'pointer' : 'default',
|
|
57
|
-
}}
|
|
58
|
-
onClick={onClick}
|
|
59
|
-
src={user.avatar}
|
|
60
|
-
alt={user.fullName || ''}
|
|
61
|
-
{...(avatarProps || {})}
|
|
62
|
-
/>
|
|
63
|
-
</Box>
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// 渲染右上角内容
|
|
68
|
-
export const renderTopRight = (
|
|
69
|
-
renderTopRightContent: (() => React.ReactNode) | undefined,
|
|
70
|
-
topRightMaxWidth: number = 120
|
|
71
|
-
) => {
|
|
72
|
-
if (renderTopRightContent) {
|
|
73
|
-
return (
|
|
74
|
-
<Box sx={{ maxWidth: topRightMaxWidth }} className="user-card__top-right-content">
|
|
75
|
-
{renderTopRightContent()}
|
|
76
|
-
</Box>
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return null;
|
|
81
|
-
};
|
package/src/UserCard/index.tsx
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import type { User } from './types';
|
|
3
|
-
import { UserCardProps, CardType } from './types';
|
|
4
|
-
import AvatarOnlyCard from './Cards/avatar-only';
|
|
5
|
-
import DetailedCard from './Cards';
|
|
6
|
-
import DialogContainer from './Container/dialog';
|
|
7
|
-
import CardContainer from './Container/card';
|
|
8
|
-
import Avatar from '../Avatar';
|
|
9
|
-
import SocialActions from './Cards/social-actions';
|
|
10
|
-
import { getUserByDid, isUserDid } from './utils';
|
|
11
|
-
|
|
12
|
-
// 创建仅显示名称首字母的头像
|
|
13
|
-
export function createNameOnlyAvatar(user: User) {
|
|
14
|
-
if (!user) return null;
|
|
15
|
-
|
|
16
|
-
// 使用全名或邮箱前缀作为显示内容
|
|
17
|
-
let content = '';
|
|
18
|
-
if (user.fullName) {
|
|
19
|
-
// 提取名称首字母
|
|
20
|
-
content = user.fullName.charAt(0).toUpperCase();
|
|
21
|
-
} else if (user.email) {
|
|
22
|
-
// 使用邮箱前缀首字母
|
|
23
|
-
content = user.email.split('@')[0].charAt(0).toUpperCase();
|
|
24
|
-
} else {
|
|
25
|
-
// 如果都没有,使用DID的第一个字符
|
|
26
|
-
content = user.did ? user.did.charAt(0).toUpperCase() : '?';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return content;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// UserCard组件入口
|
|
33
|
-
function UserCard(props: UserCardProps) {
|
|
34
|
-
const { cardType = CardType.Detailed, showHoverCard } = props;
|
|
35
|
-
|
|
36
|
-
// 计算是否显示悬停卡片
|
|
37
|
-
// 默认规则:AvatarOnly模式下默认显示悬停卡片,Detailed模式下默认不显示
|
|
38
|
-
const shouldShowHoverCard = showHoverCard !== undefined ? showHoverCard : cardType === CardType.AvatarOnly;
|
|
39
|
-
|
|
40
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
41
|
-
const [user, setUser] = useState<User | null>(() => props.user || null);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
let isSubscribed = true;
|
|
45
|
-
if (props.user) {
|
|
46
|
-
setUser(props.user);
|
|
47
|
-
} else if (props.did && isUserDid(props.did) && !props.user) {
|
|
48
|
-
getUserByDid(props.did).then((_user) => {
|
|
49
|
-
if (isSubscribed) {
|
|
50
|
-
setUser(_user || { fullName: 'Anonymous', did: props.did as string, avatar: '' });
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return () => {
|
|
55
|
-
isSubscribed = false;
|
|
56
|
-
};
|
|
57
|
-
}, [props.did, props.user]);
|
|
58
|
-
|
|
59
|
-
// 补全 avatar 的 imageFilter 信息,以提高性能
|
|
60
|
-
const userInfo = useMemo(() => {
|
|
61
|
-
if (!user) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const { avatar = '', ...rest } = user;
|
|
66
|
-
if (avatar) {
|
|
67
|
-
const avatarParam = avatar.split('?')[1] || '';
|
|
68
|
-
return {
|
|
69
|
-
...rest,
|
|
70
|
-
avatar: avatarParam ? avatar : `${avatar}?imageFilter=resize&w=48&h=48`,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
return user;
|
|
74
|
-
}, [user]);
|
|
75
|
-
|
|
76
|
-
// 如果不存在,则使用 did 渲染头像
|
|
77
|
-
if (!userInfo) {
|
|
78
|
-
return <Avatar did={props.did} size={props.avatarSize} useProxyFallback {...props.avatarProps} />;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// user 存在,则使用 user 渲染头像
|
|
82
|
-
// 渲染卡片内容(用于Tooltip)
|
|
83
|
-
const renderCardContent = () => {
|
|
84
|
-
return (
|
|
85
|
-
<DialogContainer sx={props.popupSx}>
|
|
86
|
-
<DetailedCard
|
|
87
|
-
{...props}
|
|
88
|
-
shouldShowHoverCard={false}
|
|
89
|
-
user={userInfo!}
|
|
90
|
-
avatarProps={props.popupAvatarProps}
|
|
91
|
-
shortenLabelProps={props.popupShortenLabelProps || props.shortenLabelProps}
|
|
92
|
-
renderFields={props.popupRenderFields}
|
|
93
|
-
renderName={props.popupRenderName}
|
|
94
|
-
infoType={props.popupInfoType || props.infoType}
|
|
95
|
-
didProps={props.popupDidProps || props.didProps}
|
|
96
|
-
showDid={props.popupShowDid || props.showDid}
|
|
97
|
-
showSocialActions={
|
|
98
|
-
props.popupShowSocialActions === undefined ? props.showSocialActions : props.popupShowSocialActions
|
|
99
|
-
}
|
|
100
|
-
/>
|
|
101
|
-
</DialogContainer>
|
|
102
|
-
);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// 根据卡片类型选择合适的组件
|
|
106
|
-
if (cardType === CardType.AvatarOnly) {
|
|
107
|
-
return (
|
|
108
|
-
<AvatarOnlyCard
|
|
109
|
-
{...props}
|
|
110
|
-
shouldShowHoverCard={shouldShowHoverCard}
|
|
111
|
-
renderCardContent={renderCardContent}
|
|
112
|
-
user={userInfo!}
|
|
113
|
-
/>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 详细卡片模式
|
|
118
|
-
return (
|
|
119
|
-
<CardContainer containerRef={containerRef} cardType={cardType} sx={props.sx}>
|
|
120
|
-
<DetailedCard
|
|
121
|
-
{...props}
|
|
122
|
-
shouldShowHoverCard={shouldShowHoverCard}
|
|
123
|
-
renderCardContent={renderCardContent}
|
|
124
|
-
user={userInfo!}
|
|
125
|
-
/>
|
|
126
|
-
</CardContainer>
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export default UserCard;
|
|
131
|
-
|
|
132
|
-
export { SocialActions };
|
package/src/UserCard/types.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { SxProps, Theme, TooltipProps } from '@mui/material';
|
|
3
|
-
import { DIDProps } from '../DID';
|
|
4
|
-
import { AvatarProps } from '../Avatar';
|
|
5
|
-
import { ShortenLabelProps } from './Content/shorten-label';
|
|
6
|
-
import type { Session } from '../type';
|
|
7
|
-
|
|
8
|
-
type UserPublicInfo = {
|
|
9
|
-
avatar: string;
|
|
10
|
-
did: string;
|
|
11
|
-
fullName: string;
|
|
12
|
-
};
|
|
13
|
-
export type UserMetadataLink = {
|
|
14
|
-
url: string;
|
|
15
|
-
favicon?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export enum DurationEnum {
|
|
19
|
-
NoClear = 'no_clear',
|
|
20
|
-
ThirtyMinutes = '30_minutes',
|
|
21
|
-
OneHour = '1_hour',
|
|
22
|
-
FourHours = '4_hours',
|
|
23
|
-
Today = 'today',
|
|
24
|
-
ThisWeek = 'this_week',
|
|
25
|
-
Custom = 'custom',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export enum StatusEnum {
|
|
29
|
-
Meeting = 'meeting',
|
|
30
|
-
Community = 'community',
|
|
31
|
-
Holiday = 'holiday',
|
|
32
|
-
OffSick = 'off_sick',
|
|
33
|
-
WorkingRemotely = 'working_remotely',
|
|
34
|
-
}
|
|
35
|
-
export type UserPhoneProps = {
|
|
36
|
-
country: string;
|
|
37
|
-
phoneNumber?: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type UserMetadata = {
|
|
41
|
-
bio?: string;
|
|
42
|
-
location?: string;
|
|
43
|
-
timezone?: string;
|
|
44
|
-
joinedAt?: string;
|
|
45
|
-
status?: {
|
|
46
|
-
value: string;
|
|
47
|
-
duration?: DurationEnum;
|
|
48
|
-
dateRange?: Date[];
|
|
49
|
-
};
|
|
50
|
-
links?: UserMetadataLink[];
|
|
51
|
-
cover?: string;
|
|
52
|
-
// 这两个字段是 User, 方便数据更新,在保存时同步
|
|
53
|
-
email?: string;
|
|
54
|
-
phone?: UserPhoneProps;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export type UserAddress = {
|
|
58
|
-
country?: string;
|
|
59
|
-
province?: string;
|
|
60
|
-
city?: string;
|
|
61
|
-
line1?: string;
|
|
62
|
-
line2?: string;
|
|
63
|
-
postalCode?: string;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export type User = UserPublicInfo & {
|
|
67
|
-
email?: string;
|
|
68
|
-
phone?: string;
|
|
69
|
-
sourceProvider?: string;
|
|
70
|
-
sourceAppPid?: string;
|
|
71
|
-
lastLoginAt?: string;
|
|
72
|
-
lastLoginIp?: string;
|
|
73
|
-
createdAt?: string;
|
|
74
|
-
passports?: any[];
|
|
75
|
-
didSpace?: Record<string, any>;
|
|
76
|
-
connectedAccounts?: any[];
|
|
77
|
-
locale?: string;
|
|
78
|
-
url?: string;
|
|
79
|
-
inviter?: string;
|
|
80
|
-
emailVerified?: boolean;
|
|
81
|
-
phoneVerified?: boolean;
|
|
82
|
-
// 1.16.40 新增
|
|
83
|
-
metadata?: UserMetadata;
|
|
84
|
-
// 1.16.41 新增
|
|
85
|
-
address?: UserAddress;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// 头像大小
|
|
89
|
-
export const AvatarSize = {
|
|
90
|
-
small: 32,
|
|
91
|
-
medium: 40,
|
|
92
|
-
large: 48,
|
|
93
|
-
xlarge: 64,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// 卡片类型
|
|
97
|
-
export enum CardType {
|
|
98
|
-
AvatarOnly = 'AvatarOnly', // 仅头像
|
|
99
|
-
Detailed = 'Detailed', // 详细卡片
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 信息类型
|
|
103
|
-
export enum InfoType {
|
|
104
|
-
Minimal = 'Minimal', // 极简模式,显示头像、名称和DID
|
|
105
|
-
Basic = 'Basic', // 基本信息模式
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export type SocialActionProps = {
|
|
109
|
-
chat: boolean;
|
|
110
|
-
follow: boolean;
|
|
111
|
-
};
|
|
112
|
-
// 定义UserCard属性接口
|
|
113
|
-
export interface UserCardProps {
|
|
114
|
-
session?: Session;
|
|
115
|
-
user?: User;
|
|
116
|
-
did?: string;
|
|
117
|
-
cardType?: CardType;
|
|
118
|
-
infoType?: InfoType;
|
|
119
|
-
popupInfoType?: InfoType;
|
|
120
|
-
avatarSize?: number;
|
|
121
|
-
showHoverCard?: boolean;
|
|
122
|
-
showDid?: boolean;
|
|
123
|
-
didProps?: Partial<DIDProps>;
|
|
124
|
-
popupDidProps?: Partial<DIDProps>;
|
|
125
|
-
popupShowDid?: boolean;
|
|
126
|
-
|
|
127
|
-
avatarProps?: Partial<AvatarProps>;
|
|
128
|
-
popupAvatarProps?: Partial<AvatarProps>;
|
|
129
|
-
|
|
130
|
-
// 弹出层相关属性
|
|
131
|
-
tooltipProps?: Partial<TooltipProps>;
|
|
132
|
-
|
|
133
|
-
// 样式相关属性
|
|
134
|
-
sx?: SxProps<Theme>;
|
|
135
|
-
popupSx?: SxProps<Theme>;
|
|
136
|
-
|
|
137
|
-
// fullName 相关属性
|
|
138
|
-
shortenLabelProps?: Partial<ShortenLabelProps>;
|
|
139
|
-
popupShortenLabelProps?: Partial<ShortenLabelProps>;
|
|
140
|
-
|
|
141
|
-
// 自定义渲染 name
|
|
142
|
-
// 如果设置了 renderName,shortenLabelProps 无效
|
|
143
|
-
renderName?: (user: User) => React.ReactNode;
|
|
144
|
-
popupRenderName?: (user: User) => React.ReactNode;
|
|
145
|
-
|
|
146
|
-
// 自定义渲染字段
|
|
147
|
-
renderFields?: string[];
|
|
148
|
-
popupRenderFields?: string[];
|
|
149
|
-
|
|
150
|
-
// 右上角内容相关属性
|
|
151
|
-
renderTopRightContent?: () => React.ReactNode;
|
|
152
|
-
topRightMaxWidth?: number;
|
|
153
|
-
|
|
154
|
-
// 社交按钮相关属性
|
|
155
|
-
showSocialActions?: SocialActionProps | boolean;
|
|
156
|
-
popupShowSocialActions?: SocialActionProps | boolean;
|
|
157
|
-
|
|
158
|
-
// 自定义内容渲染函数
|
|
159
|
-
renderCustomContent?: () => React.ReactNode;
|
|
160
|
-
|
|
161
|
-
// 头像点击事件
|
|
162
|
-
onAvatarClick?: (user: User, e?: React.MouseEvent<HTMLDivElement>) => void;
|
|
163
|
-
// 点击follow按钮回调
|
|
164
|
-
onFollowClick?: (user: User, e?: React.MouseEvent) => void;
|
|
165
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { useMemoizedFn } from 'ahooks';
|
|
3
|
-
import isNil from 'lodash/isNil';
|
|
4
|
-
|
|
5
|
-
import type { AxiosError } from 'axios';
|
|
6
|
-
import { getBlockletSDK } from '@blocklet/js-sdk';
|
|
7
|
-
import type { BlockletSDK } from '@blocklet/js-sdk';
|
|
8
|
-
import Toast from '../Toast';
|
|
9
|
-
import { formatAxiosError } from '../Util';
|
|
10
|
-
import type { User } from './types';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 登录用户与当前用户(userDid)的关注关系
|
|
14
|
-
*/
|
|
15
|
-
export default function useFollow({
|
|
16
|
-
user,
|
|
17
|
-
t,
|
|
18
|
-
isMySelf,
|
|
19
|
-
visible,
|
|
20
|
-
}: {
|
|
21
|
-
user: User;
|
|
22
|
-
t: (k: string) => string;
|
|
23
|
-
isMySelf: boolean;
|
|
24
|
-
visible: boolean;
|
|
25
|
-
}) {
|
|
26
|
-
const [followed, setFollowed] = useState(false);
|
|
27
|
-
|
|
28
|
-
const userDid = useMemo(() => user?.did, [user]);
|
|
29
|
-
|
|
30
|
-
// 判断 user 对象中 isFollowing 值是否有效,有isFollowed字段并且值不为 undefined 或 null
|
|
31
|
-
// 如果为 true 则不需要通过 api 查询,直接使用 user.isFollowing 值
|
|
32
|
-
// 如果为 false 则需要通过 api 查询,并设置 user.isFollowing 值
|
|
33
|
-
const hasFollowedField = useMemo(() => {
|
|
34
|
-
return Object.prototype.hasOwnProperty.call(user, 'isFollowing') && !isNil((user as any).isFollowing);
|
|
35
|
-
}, [user]);
|
|
36
|
-
|
|
37
|
-
const client = useMemo(() => {
|
|
38
|
-
let _client: BlockletSDK | null = null;
|
|
39
|
-
try {
|
|
40
|
-
_client = getBlockletSDK();
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error('Failed to initialize BlockletSDK:', error);
|
|
43
|
-
_client = null;
|
|
44
|
-
}
|
|
45
|
-
return _client;
|
|
46
|
-
}, []);
|
|
47
|
-
|
|
48
|
-
const isFollowingUser = useMemoizedFn(async () => {
|
|
49
|
-
if (!client) {
|
|
50
|
-
setFollowed(false);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
if (isMySelf) {
|
|
55
|
-
setFollowed(true);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const res = await client.user.isFollowingUser({ userDid });
|
|
59
|
-
setFollowed(res);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error(error);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const followUser = useMemoizedFn(async (followUserDid: string = userDid) => {
|
|
66
|
-
if (!client || (isMySelf && followUserDid === userDid)) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
await client.user.followUser({ userDid: followUserDid });
|
|
71
|
-
Toast.success(t('follow_success'));
|
|
72
|
-
isFollowingUser();
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error(error);
|
|
75
|
-
Toast.error(formatAxiosError(error as AxiosError));
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
const unfollowUser = useMemoizedFn(async (unfollowUserDid: string = userDid) => {
|
|
79
|
-
if (!client || (isMySelf && unfollowUserDid === userDid)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
await client.user.unfollowUser({ userDid: unfollowUserDid });
|
|
84
|
-
Toast.success(t('unfollow_success'));
|
|
85
|
-
isFollowingUser();
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error(error);
|
|
88
|
-
Toast.error(formatAxiosError(error as AxiosError));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
// 如果 user 对象中已经存在了 isFollowing 字段,则不进行查询
|
|
94
|
-
if (visible && userDid && !isMySelf && !!client && !hasFollowedField) {
|
|
95
|
-
isFollowingUser();
|
|
96
|
-
}
|
|
97
|
-
}, [isFollowingUser, userDid, isMySelf, client, hasFollowedField, visible]);
|
|
98
|
-
|
|
99
|
-
// 如果 user 对象中已经存在了 isFollowing 字段,则直接设置 followed 状态
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (hasFollowedField) {
|
|
102
|
-
setFollowed((user as any)?.isFollowing || false);
|
|
103
|
-
}
|
|
104
|
-
}, [hasFollowedField, user]);
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
followed,
|
|
108
|
-
followUser,
|
|
109
|
-
unfollowUser,
|
|
110
|
-
};
|
|
111
|
-
}
|
package/src/UserCard/utils.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { toTypeInfo } from '@arcblock/did';
|
|
2
|
-
import { types } from '@ocap/mcrypto';
|
|
3
|
-
import { getBlockletSDK } from '@blocklet/js-sdk';
|
|
4
|
-
import type { BlockletSDK } from '@blocklet/js-sdk';
|
|
5
|
-
import { User } from './types';
|
|
6
|
-
|
|
7
|
-
let client: BlockletSDK | null = null;
|
|
8
|
-
|
|
9
|
-
// 用户信息缓存键前缀
|
|
10
|
-
const USER_CACHE_PREFIX = 'ux_user_';
|
|
11
|
-
// 用户缓存的有效期(毫秒),默认60分钟
|
|
12
|
-
const USER_CACHE_EXPIRATION = 60 * 60 * 1000;
|
|
13
|
-
|
|
14
|
-
// 从sessionStorage获取用户信息
|
|
15
|
-
const getUserFromStorage = (did: string): User | null => {
|
|
16
|
-
if (typeof sessionStorage === 'undefined') return null;
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const cacheKey = `${USER_CACHE_PREFIX}${did}`;
|
|
20
|
-
const cachedData = sessionStorage.getItem(cacheKey);
|
|
21
|
-
|
|
22
|
-
if (!cachedData) return null;
|
|
23
|
-
|
|
24
|
-
const parsedData = JSON.parse(cachedData);
|
|
25
|
-
const timestamp = parsedData.timestamp || 0;
|
|
26
|
-
const now = Date.now();
|
|
27
|
-
|
|
28
|
-
// 检查缓存是否过期
|
|
29
|
-
if (now - timestamp > USER_CACHE_EXPIRATION) {
|
|
30
|
-
// 缓存已过期,删除并返回null
|
|
31
|
-
sessionStorage.removeItem(cacheKey);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 返回用户数据
|
|
36
|
-
return parsedData.user;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
console.error(`Failed to load user cache for did ${did}:`, error);
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// 将用户信息保存到sessionStorage
|
|
44
|
-
const saveUserToStorage = (did: string, user: User): void => {
|
|
45
|
-
if (typeof sessionStorage === 'undefined') return;
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const cacheKey = `${USER_CACHE_PREFIX}${did}`;
|
|
49
|
-
// 创建包含用户数据和时间戳的缓存对象
|
|
50
|
-
const cacheData = {
|
|
51
|
-
user,
|
|
52
|
-
timestamp: Date.now(),
|
|
53
|
-
};
|
|
54
|
-
sessionStorage.setItem(cacheKey, JSON.stringify(cacheData));
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.error(`Failed to save user cache for did ${did}:`, error);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// 创建仅显示名称首字母的头像
|
|
61
|
-
// eslint-disable-next-line import/prefer-default-export
|
|
62
|
-
export function createNameOnlyAvatar(user: User) {
|
|
63
|
-
if (!user) return null;
|
|
64
|
-
|
|
65
|
-
// 使用全名或邮箱前缀作为显示内容
|
|
66
|
-
let content = '';
|
|
67
|
-
if (user.fullName) {
|
|
68
|
-
// 提取名称首字母
|
|
69
|
-
content = user.fullName.charAt(0).toUpperCase();
|
|
70
|
-
} else if (user.email) {
|
|
71
|
-
// 使用邮箱前缀首字母
|
|
72
|
-
content = user.email.split('@')[0].charAt(0).toUpperCase();
|
|
73
|
-
} else {
|
|
74
|
-
// 如果都没有,使用DID的第一个字符
|
|
75
|
-
content = user.did ? user.did.charAt(0).toUpperCase() : '?';
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return content;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function isUserDid(did: string) {
|
|
82
|
-
if (!did || typeof did !== 'string') return false;
|
|
83
|
-
try {
|
|
84
|
-
const didInfo = toTypeInfo(did);
|
|
85
|
-
return didInfo.role !== undefined && didInfo.role !== types.RoleType.ROLE_APPLICATION;
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error('Failed to check if did is user did:', error);
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function getUserByDid(did: string): Promise<User | null> {
|
|
93
|
-
if (!did) return null;
|
|
94
|
-
|
|
95
|
-
// 先检查sessionStorage中是否有缓存
|
|
96
|
-
const storedUser = getUserFromStorage(did);
|
|
97
|
-
if (storedUser) {
|
|
98
|
-
return storedUser;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!client) {
|
|
102
|
-
try {
|
|
103
|
-
client = getBlockletSDK();
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.error('Failed to initialize BlockletSDK:', error);
|
|
106
|
-
client = null;
|
|
107
|
-
}
|
|
108
|
-
if (!client) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (!client) return null;
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
const user = await client.user.getUserPublicInfo({ did });
|
|
116
|
-
// 将获取到的用户信息存入缓存
|
|
117
|
-
if (user) {
|
|
118
|
-
const userData = user as User;
|
|
119
|
-
saveUserToStorage(did, userData);
|
|
120
|
-
}
|
|
121
|
-
return user as User;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error('Failed to get user by did:', error);
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 清除缓存中特定用户的信息
|
|
129
|
-
export function clearUserCache(did?: string): void {
|
|
130
|
-
if (typeof sessionStorage === 'undefined') return;
|
|
131
|
-
|
|
132
|
-
if (did) {
|
|
133
|
-
// 清除指定用户缓存
|
|
134
|
-
try {
|
|
135
|
-
sessionStorage.removeItem(`${USER_CACHE_PREFIX}${did}`);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.error(`Failed to remove cache for did ${did}:`, error);
|
|
138
|
-
}
|
|
139
|
-
} else {
|
|
140
|
-
// 清除所有用户缓存
|
|
141
|
-
try {
|
|
142
|
-
// 只清除以USER_CACHE_PREFIX开头的项
|
|
143
|
-
const keysToRemove: string[] = [];
|
|
144
|
-
for (let i = 0; i < sessionStorage.length; i++) {
|
|
145
|
-
const key = sessionStorage.key(i);
|
|
146
|
-
if (key && key.startsWith(USER_CACHE_PREFIX)) {
|
|
147
|
-
keysToRemove.push(key);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
keysToRemove.forEach((key) => sessionStorage.removeItem(key));
|
|
151
|
-
} catch (error) {
|
|
152
|
-
console.error('Failed to clear all user caches:', error);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
package/src/Util/client.ts
DELETED