Page MenuHomePhorge

D7246.1768437274.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D7246.1768437274.diff

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

Mime Type
text/plain
Expires
Thu, Jan 15, 12:34 AM (8 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5934935
Default Alt Text
D7246.1768437274.diff (2 KB)

Event Timeline