Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3505090
D7461.id25206.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D7461.id25206.diff
View Options
diff --git a/lib/hooks/ens-cache.js b/lib/hooks/ens-cache.js
--- a/lib/hooks/ens-cache.js
+++ b/lib/hooks/ens-cache.js
@@ -4,8 +4,8 @@
import * as React from 'react';
import { ENSCacheContext } from '../components/ens-cache-provider.react.js';
-import { userIdentifiedByETHAddress } from '../shared/account-utils.js';
import { stringForUser } from '../shared/user-utils.js';
+import { getEthAddressForUserInfo } from '../utils/ens-helpers.js';
type BaseUserInfo = { +username?: ?string, ... };
function useENSNames<T: ?BaseUserInfo>(users: $ReadOnlyArray<T>): T[] {
@@ -18,9 +18,7 @@
if (!user) {
return user;
}
- const { username } = user;
- const ethAddress =
- username && userIdentifiedByETHAddress(user) ? username : null;
+ const ethAddress = getEthAddressForUserInfo(user);
const cachedResult =
ethAddress && ensCache
? ensCache.getCachedNameForAddress(ethAddress)
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
@@ -4,7 +4,6 @@
import * as React from 'react';
import stringHash from 'string-hash';
-import { userIdentifiedByETHAddress } from './account-utils.js';
import { selectedThreadColors } from './color-utils.js';
import { threadOtherMembers } from './thread-utils.js';
import genesis from '../facts/genesis.js';
@@ -21,6 +20,7 @@
threadTypes,
} from '../types/thread-types.js';
import type { UserInfos, UserInfo } from '../types/user-types.js';
+import { getEthAddressForUserInfo } from '../utils/ens-helpers.js';
import { useSelector } from '../utils/redux-utils.js';
const defaultAnonymousUserEmojiAvatar: ClientEmojiAvatar = {
@@ -136,15 +136,10 @@
avatarInfo: ClientAvatar,
userInfo: ?UserInfo,
): ResolvedClientAvatar {
- 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 ethAddress = React.useMemo(
+ () => getEthAddressForUserInfo(userInfo),
+ [userInfo],
+ );
const ensAvatarURI = useENSAvatar(ethAddress);
diff --git a/lib/utils/ens-helpers.js b/lib/utils/ens-helpers.js
--- a/lib/utils/ens-helpers.js
+++ b/lib/utils/ens-helpers.js
@@ -8,6 +8,17 @@
users: $ReadOnlyArray<T>,
) => Promise<T[]>;
+function getEthAddressForUserInfo(userInfo: ?BaseUserInfo): ?string {
+ if (!userInfo) {
+ return null;
+ }
+ const { username } = userInfo;
+ const ethAddress =
+ username && userIdentifiedByETHAddress(userInfo) ? username : null;
+
+ return ethAddress;
+}
+
async function getENSNames<T: ?BaseUserInfo>(
ensCache: ENSCache,
users: $ReadOnlyArray<T>,
@@ -16,9 +27,7 @@
if (!user) {
return user;
}
- const { username } = user;
- const ethAddress =
- username && userIdentifiedByETHAddress(user) ? username : null;
+ const ethAddress = getEthAddressForUserInfo(user);
const cachedResult = ethAddress
? ensCache.getCachedNameForAddress(ethAddress)
: null;
@@ -72,4 +81,4 @@
});
}
-export { getENSNames };
+export { getEthAddressForUserInfo, getENSNames };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 12:08 PM (19 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2687626
Default Alt Text
D7461.id25206.diff (3 KB)
Attached To
Mode
D7461: [lib] introduce getEthAddressForUserInfo helper function
Attached
Detach File
Event Timeline
Log In to Comment