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 @@ -9,7 +9,7 @@ import { getENSNames } from '../utils/ens-helpers.js'; type BaseUserInfo = { +username?: ?string, ... }; -export type UseENSNamesOptions = { +type UseENSNamesOptions = { +allAtOnce?: ?boolean, }; function useENSNames( diff --git a/lib/utils/entity-helpers.js b/lib/utils/entity-helpers.js --- a/lib/utils/entity-helpers.js +++ b/lib/utils/entity-helpers.js @@ -6,9 +6,9 @@ import { entityTextToRawString, ET, - useENSNamesForEntityText, + useResolvedEntityText, + type UseResolvedEntityTextOptions, } from './entity-text.js'; -import type { UseENSNamesOptions } from '../hooks/ens-cache.js'; import type { ResolvedThreadInfo, ThreadInfo, @@ -17,16 +17,16 @@ function useResolvedThreadInfos( threadInfos: $ReadOnlyArray, - options?: ?UseENSNamesOptions, + options?: ?UseResolvedEntityTextOptions, ): $ReadOnlyArray { const entityText = React.useMemo( () => threadInfos.map(threadInfo => threadInfo.uiName), [threadInfos], ); - const withENSNames = useENSNamesForEntityText(entityText, options); + const resolvedEntityText = useResolvedEntityText(entityText, options); invariant( - withENSNames, - 'useENSNamesForEntityText only returns falsey when passed falsey', + resolvedEntityText, + 'useResolvedEntityText only returns falsey when passed falsey', ); return React.useMemo( () => @@ -36,13 +36,13 @@ // but that's wasteful and unneeded, so we any-cast here return (threadInfo: any); } - const resolvedThreadEntity = withENSNames[i]; + const resolvedThreadEntity = resolvedEntityText[i]; return { ...threadInfo, uiName: entityTextToRawString([resolvedThreadEntity]), }; }), - [threadInfos, withENSNames], + [threadInfos, resolvedEntityText], ); } @@ -57,14 +57,14 @@ ET.thread({ display: 'uiName', threadInfo }), ); }, [threadInfos]); - const withENSNames = useENSNamesForEntityText(entityText); + const resolvedEntityText = useResolvedEntityText(entityText); return React.useMemo(() => { if (!threadInfos) { return threadInfos; } invariant( - withENSNames, - 'useENSNamesForEntityText only returns falsey when passed falsey', + resolvedEntityText, + 'useResolvedEntityText only returns falsey when passed falsey', ); return threadInfos.map((threadInfo, i) => { if (typeof threadInfo.uiName === 'string') { @@ -72,20 +72,20 @@ // but that's wasteful and unneeded, so we any-cast here return (threadInfo: any); } - const resolvedThreadEntity = withENSNames[i]; + const resolvedThreadEntity = resolvedEntityText[i]; return { ...threadInfo, uiName: entityTextToRawString([resolvedThreadEntity]), }; }); - }, [threadInfos, withENSNames]); + }, [threadInfos, resolvedEntityText]); } function useResolvedThreadInfosObj( threadInfosObj: { +[id: string]: ThreadInfo, }, - options?: ?UseENSNamesOptions, + options?: ?UseResolvedEntityTextOptions, ): { +[id: string]: ResolvedThreadInfo, } { diff --git a/lib/utils/entity-text.js b/lib/utils/entity-text.js --- a/lib/utils/entity-text.js +++ b/lib/utils/entity-text.js @@ -6,7 +6,7 @@ import type { GetENSNames } from './ens-helpers.js'; import { tID, tShape, tString } from './validation-utils.js'; -import { useENSNames, type UseENSNamesOptions } from '../hooks/ens-cache.js'; +import { useENSNames } from '../hooks/ens-cache.js'; import { threadNoun } from '../shared/thread-utils.js'; import { stringForUser } from '../shared/user-utils.js'; import type { @@ -536,9 +536,13 @@ .filter(Boolean); } -function useENSNamesForEntityText( +export type UseResolvedEntityTextOptions = { + +allAtOnce?: ?boolean, +}; + +function useResolvedEntityText( entityText: ?EntityText, - options?: ?UseENSNamesOptions, + options?: ?UseResolvedEntityTextOptions, ): ?EntityText { const allObjects = React.useMemo( () => (entityText ? entityTextToObjects(entityText) : []), @@ -556,7 +560,7 @@ entityText: ?EntityText, params?: EntityTextToRawStringParams, ): ?string { - const withENSNames = useENSNamesForEntityText(entityText); + const withENSNames = useResolvedEntityText(entityText); return React.useMemo(() => { if (!withENSNames) { return withENSNames; @@ -590,7 +594,7 @@ entityTextToReact, getNameForThreadEntity, pluralizeEntityText, - useENSNamesForEntityText, + useResolvedEntityText, useEntityTextAsString, getEntityTextAsString, }; diff --git a/native/chat/inner-robotext-message.react.js b/native/chat/inner-robotext-message.react.js --- a/native/chat/inner-robotext-message.react.js +++ b/native/chat/inner-robotext-message.react.js @@ -11,7 +11,7 @@ type EntityText, entityTextToRawString, entityTextToReact, - useENSNamesForEntityText, + useResolvedEntityText, } from 'lib/utils/entity-text.js'; import { DummyInlineEngagementNode } from './inline-engagement.react.js'; @@ -56,14 +56,14 @@ const { messageInfo, robotext } = item; const { threadID } = messageInfo; - const robotextWithENSNames = useENSNamesForEntityText(robotext); + const resolvedRobotext = useResolvedEntityText(robotext); invariant( - robotextWithENSNames, - 'useENSNamesForEntityText only returns falsey when passed falsey', + resolvedRobotext, + 'useResolvedEntityText only returns falsey when passed falsey', ); const textParts = React.useMemo(() => { const darkColor = activeTheme === 'dark'; - return entityTextToReact(robotextWithENSNames, threadID, { + return entityTextToReact(resolvedRobotext, threadID, { renderText: ({ text }) => ( , }); - }, [robotextWithENSNames, activeTheme, threadID, styles.robotext]); + }, [resolvedRobotext, activeTheme, threadID, styles.robotext]); return ( diff --git a/web/chat/robotext-message.react.js b/web/chat/robotext-message.react.js --- a/web/chat/robotext-message.react.js +++ b/web/chat/robotext-message.react.js @@ -9,7 +9,7 @@ import type { Dispatch } from 'lib/types/redux-types.js'; import { entityTextToReact, - useENSNamesForEntityText, + useResolvedEntityText, } from 'lib/utils/entity-text.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; @@ -56,13 +56,13 @@ const { messageInfo, robotext } = item; const { threadID } = messageInfo; - const robotextWithENSNames = useENSNamesForEntityText(robotext); + const resolvedRobotext = useResolvedEntityText(robotext); invariant( - robotextWithENSNames, - 'useENSNamesForEntityText only returns falsey when passed falsey', + resolvedRobotext, + 'useResolvedEntityText only returns falsey when passed falsey', ); const textParts = React.useMemo(() => { - return entityTextToReact(robotextWithENSNames, threadID, { + return entityTextToReact(resolvedRobotext, threadID, { renderText: ({ text }) => ( {text} ), @@ -72,7 +72,7 @@ ), renderColor: ({ hex }) => , }); - }, [robotextWithENSNames, threadID]); + }, [resolvedRobotext, threadID]); const { onMouseEnter, onMouseLeave } = useMessageTooltip({ item,