Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3504291
D7461.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.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,7 +4,7 @@
import * as React from 'react';
import { ENSCacheContext } from '../components/ens-cache-provider.react.js';
-import { userIdentifiedByETHAddress } from '../shared/account-utils.js';
+import { getETHAddressForUserInfo } from '../shared/account-utils.js';
import { stringForUser } from '../shared/user-utils.js';
type BaseUserInfo = { +username?: ?string, ... };
@@ -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/account-utils.js b/lib/shared/account-utils.js
--- a/lib/shared/account-utils.js
+++ b/lib/shared/account-utils.js
@@ -89,6 +89,19 @@
: false;
}
+function getETHAddressForUserInfo(
+ userInfo: ?{ +username?: ?string, ... },
+): ?string {
+ if (!userInfo) {
+ return null;
+ }
+ const { username } = userInfo;
+ const ethAddress =
+ username && userIdentifiedByETHAddress(userInfo) ? username : null;
+
+ return ethAddress;
+}
+
export {
usernameMaxLength,
oldValidUsernameRegexString,
@@ -100,4 +113,5 @@
validHexColorRegex,
accountHasPassword,
userIdentifiedByETHAddress,
+ getETHAddressForUserInfo,
};
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,12 +4,12 @@
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';
import { useENSAvatar } from '../hooks/ens-cache.js';
import { threadInfoSelector } from '../selectors/thread-selectors.js';
+import { getETHAddressForUserInfo } from '../shared/account-utils.js';
import type {
ClientEmojiAvatar,
ClientAvatar,
@@ -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
@@ -1,7 +1,7 @@
// @flow
import { ENSCache } from './ens-cache.js';
-import { userIdentifiedByETHAddress } from '../shared/account-utils.js';
+import { getETHAddressForUserInfo } from '../shared/account-utils.js';
type BaseUserInfo = { +username?: ?string, ... };
export type GetENSNames = <T: ?BaseUserInfo>(
@@ -16,9 +16,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;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 21, 8:20 AM (19 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2687073
Default Alt Text
D7461.diff (3 KB)
Attached To
Mode
D7461: [lib] introduce getEthAddressForUserInfo helper function
Attached
Detach File
Event Timeline
Log In to Comment