From 992477abe05068c9d1f8f9af2dad85dd0c47f641 Mon Sep 17 00:00:00 2001 From: cw <88217123+2bf@users.noreply.github.com> Date: Wed, 20 May 2026 02:28:38 -0700 Subject: [PATCH 1/2] Fix RHF bounty price fallback --- components/Bounty/lib/bountyUtil.ts | 47 +++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/components/Bounty/lib/bountyUtil.ts b/components/Bounty/lib/bountyUtil.ts index 902b51d39..84c759036 100644 --- a/components/Bounty/lib/bountyUtil.ts +++ b/components/Bounty/lib/bountyUtil.ts @@ -494,6 +494,43 @@ const getCreatorUserId = (bounty: Bounty): number | undefined => { return undefined; }; +const normalizeCreatorName = (value: unknown): string | undefined => { + if (typeof value !== 'string') return undefined; + + const normalized = value.trim().replace(/\s+/g, ' ').toLowerCase(); + return normalized || undefined; +}; + +const getProfileName = (profile: any): string | undefined => { + if (!profile) return undefined; + + return ( + normalizeCreatorName(profile.fullName) || + normalizeCreatorName(profile.full_name) || + normalizeCreatorName([profile.firstName, profile.lastName].filter(Boolean).join(' ')) || + normalizeCreatorName([profile.first_name, profile.last_name].filter(Boolean).join(' ')) + ); +}; + +const getCreatorNames = (bounty: Bounty): string[] => { + const raw = bounty.raw; + const firstContribution = bounty.contributions?.[0]; + + return [ + getProfileName(bounty.createdBy), + getProfileName(bounty.createdBy?.authorProfile), + getProfileName(raw?.created_by), + getProfileName(raw?.created_by?.author_profile), + getProfileName(raw?.created_by?.user), + getProfileName(raw?.author), + getProfileName(raw?.author?.user), + getProfileName(firstContribution?.createdBy), + getProfileName(firstContribution?.createdBy?.authorProfile), + getProfileName(firstContribution?.raw?.user), + getProfileName(firstContribution?.raw?.author), + ].filter((name): name is string => Boolean(name)); +}; + /** * Checks if a bounty was created by the ResearchHub Foundation account. * @@ -501,10 +538,14 @@ const getCreatorUserId = (bounty: Bounty): number | undefined => { * @returns True if the bounty was created by the Foundation account */ export const isFoundationBounty = (bounty: Bounty): boolean => { - if (!FOUNDATION_USER_ID) return false; - const creatorUserId = getCreatorUserId(bounty); - return creatorUserId === FOUNDATION_USER_ID; + if (FOUNDATION_USER_ID && creatorUserId === FOUNDATION_USER_ID) { + return true; + } + + // Fall back to the public account name so RHF bounty pricing still renders + // correctly when the public Foundation user ID env var is unavailable. + return getCreatorNames(bounty).some((name) => name === 'researchhub foundation'); }; /** From 315bc00d462400506e553610d6de8d534712db95 Mon Sep 17 00:00:00 2001 From: cw <88217123+2bf@users.noreply.github.com> Date: Wed, 20 May 2026 08:52:47 -0700 Subject: [PATCH 2/2] chore: satisfy bounty display sonar hint --- components/Bounty/lib/bountyUtil.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Bounty/lib/bountyUtil.ts b/components/Bounty/lib/bountyUtil.ts index 84c759036..382285511 100644 --- a/components/Bounty/lib/bountyUtil.ts +++ b/components/Bounty/lib/bountyUtil.ts @@ -545,7 +545,7 @@ export const isFoundationBounty = (bounty: Bounty): boolean => { // Fall back to the public account name so RHF bounty pricing still renders // correctly when the public Foundation user ID env var is unavailable. - return getCreatorNames(bounty).some((name) => name === 'researchhub foundation'); + return getCreatorNames(bounty).includes('researchhub foundation'); }; /**