Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33065852
D7246.1768438305.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7246.1768438305.diff
View Options
diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js
--- a/lib/shared/avatar-utils.js
+++ b/lib/shared/avatar-utils.js
@@ -117,4 +117,9 @@
return getDefaultAvatar(thread.id, thread.color);
}
-export { getAvatarForUser, getUserAvatarForThread, useGetAvatarForThread };
+export {
+ defaultAnonymousUserEmojiAvatar,
+ getAvatarForUser,
+ getUserAvatarForThread,
+ useGetAvatarForThread,
+};
diff --git a/native/components/user-avatar.react.js b/native/components/user-avatar.react.js
new file mode 100644
--- /dev/null
+++ b/native/components/user-avatar.react.js
@@ -0,0 +1,58 @@
+// @flow
+
+import * as React from 'react';
+
+import { useENSAvatar } from 'lib/hooks/ens-cache.js';
+import { userIdentifiedByETHAddress } from 'lib/shared/account-utils.js';
+import {
+ defaultAnonymousUserEmojiAvatar,
+ getAvatarForUser,
+} from 'lib/shared/avatar-utils.js';
+
+import Avatar from './avatar.react.js';
+import { useSelector } from '../redux/redux-utils.js';
+
+type Props = {
+ +userID: ?string,
+ +size: 'micro' | 'small' | 'large' | 'profile',
+};
+
+function UserAvatar(props: Props): React.Node {
+ const { userID, size } = props;
+
+ const userInfo = useSelector(state =>
+ userID ? state.userStore.userInfos[userID] : null,
+ );
+ const avatarInfo = getAvatarForUser(userInfo);
+
+ const ethAddress = React.useMemo(() => {
+ let address = null;
+ if (userInfo && avatarInfo.type === 'ens') {
+ const { username } = userInfo;
+ address =
+ username && userIdentifiedByETHAddress(userInfo) ? username : null;
+ }
+ return address;
+ }, [avatarInfo.type, userInfo]);
+
+ const ensAvatarURI = useENSAvatar(ethAddress);
+
+ const userAvatarInfo = React.useMemo(() => {
+ if (avatarInfo.type !== 'ens') {
+ return avatarInfo;
+ }
+
+ if (ensAvatarURI) {
+ return {
+ type: 'image',
+ uri: ensAvatarURI,
+ };
+ }
+
+ return defaultAnonymousUserEmojiAvatar;
+ }, [ensAvatarURI, avatarInfo]);
+
+ return <Avatar size={size} avatarInfo={userAvatarInfo} />;
+}
+
+export default UserAvatar;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 15, 12:51 AM (15 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5934935
Default Alt Text
D7246.1768438305.diff (2 KB)
Attached To
Mode
D7246: [native] introduce user avatar component
Attached
Detach File
Event Timeline
Log In to Comment