Page MenuHomePhabricator

D6419.diff
No OneTemporary

D6419.diff

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
@@ -11,9 +11,6 @@
function useStringForUser(
user: ?(RelativeUserInfo | RelativeMemberInfo),
): ?string {
- const rawStringForUser = user ? stringForUser(user) : null;
- const [ensName, setENSName] = React.useState<?string>(null);
-
const ethAddress = React.useMemo(() => {
if (
!user ||
@@ -26,15 +23,22 @@
return user.username;
}, [user]);
+ const cacheContext = React.useContext(ENSCacheContext);
+ const { ensCache } = cacheContext;
+ const cachedResult =
+ ethAddress && ensCache
+ ? ensCache.getCachedNameForAddress(ethAddress)
+ : null;
+
+ const [ensName, setENSName] = React.useState<?string>(null);
+
React.useEffect(() => {
// Whenever the ETH address changes, clear out ENS name before requery below
setENSName(null);
}, [ethAddress]);
- const cacheContext = React.useContext(ENSCacheContext);
- const { ensCache } = cacheContext;
React.useEffect(() => {
- if (!ethAddress || !ensCache) {
+ if (cachedResult || !ethAddress || !ensCache) {
return;
}
let cancelled = false;
@@ -47,9 +51,17 @@
return () => {
cancelled = true;
};
- }, [ethAddress, ensCache]);
+ }, [cachedResult, ethAddress, ensCache]);
- return ensName ?? rawStringForUser;
+ if (ensName) {
+ return ensName;
+ } else if (cachedResult) {
+ return cachedResult;
+ } else if (user) {
+ return stringForUser(user);
+ } else {
+ return null;
+ }
}
export { useStringForUser };

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 12:41 AM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2679332
Default Alt Text
D6419.diff (1 KB)

Event Timeline