diff --git a/components/Notification/lib/formatNotification.ts b/components/Notification/lib/formatNotification.ts index 5c3baf282..639eaf2df 100644 --- a/components/Notification/lib/formatNotification.ts +++ b/components/Notification/lib/formatNotification.ts @@ -1,4 +1,5 @@ import { type IconName } from '@/components/ui/icons/Icon'; +import { FOUNDATION_BOUNTY_FLAT_USD, FOUNDATION_USER_ID } from '@/config/constants'; import { Notification } from '@/types/notification'; import { formatUsdValue, formatRSC } from '@/utils/number'; import { buildWorkUrl } from '@/utils/url'; @@ -256,6 +257,25 @@ export function getRSCAmountFromNotification(notification: Notification): number return null; } +const isFoundationPeerReviewBountyNotification = (notification: Notification): boolean => { + const bountyCreatorId = notification.extra?.bountyCreatorId; + + return ( + notification.type === 'BOUNTY_FOR_YOU' && + notification.extra?.bounty_type?.toUpperCase() === 'REVIEW' && + FOUNDATION_USER_ID !== null && + bountyCreatorId?.toString() === FOUNDATION_USER_ID.toString() + ); +}; + +export function getBountyForYouUsdOverride(notification: Notification): number | null { + if (isFoundationPeerReviewBountyNotification(notification)) { + return FOUNDATION_BOUNTY_FLAT_USD; + } + + return null; +} + /** Matches formatted USD (`$1,234.56 USD`) or RSC (`1,234 RSC`) amounts in notification copy. */ function notificationMessageIncludesAmount(message: string): boolean { return /\$[\d,]+(?:\.\d+)?\s*USD\b/.test(message) || /\b[\d,]+(?:\.\d+)?\s+RSC\b/.test(message); @@ -418,7 +438,11 @@ export function formatNotificationMessage( const amount = notification.extra?.amount || '0'; const bountyType = notification.extra?.bounty_type || ''; const bountyTypeAction = getBountyTypeAction(bountyType); - const usdValue = formatUsdValue(amount, exchangeRate); + const usdAmount = getBountyForYouUsdOverride(notification); + const usdValue = + usdAmount !== null + ? `$${usdAmount.toLocaleString()} USD` + : formatUsdValue(amount, exchangeRate); return `Your expertise is needed! Earn ${usdValue} for ${bountyTypeAction} "${truncatedTitle}"`; } diff --git a/types/notification.ts b/types/notification.ts index cda66aa1f..fd2e99f41 100644 --- a/types/notification.ts +++ b/types/notification.ts @@ -12,11 +12,13 @@ export interface NotificationHub { export interface NotificationExtra { amount?: string; bounty_id?: string; + bounty_creator_id?: string | number; bounty_type?: string; bounty_expiration_date?: string; hub_details?: string; user_hub_score?: string; rewardId?: string; + bountyCreatorId?: string | number; rewardType?: 'REVIEW' | 'CONTRIBUTION' | 'DISCUSSION'; hub?: NotificationHub; userHubScore?: string; @@ -77,11 +79,13 @@ const transformNotificationExtraRaw = (raw: any): NotificationExtra | undefined return { amount: raw.amount, bounty_id: raw.bounty_id, + bounty_creator_id: raw.bounty_creator_id ?? raw.bountyCreatorId, bounty_type: raw.bounty_type, bounty_expiration_date: raw.bounty_expiration_date, hub, user_hub_score: raw.user_hub_score, rewardId: raw.bounty_id, + bountyCreatorId: raw.bounty_creator_id ?? raw.bountyCreatorId, rewardType: raw.bounty_type, rewardExpirationDate: raw.bounty_expiration_date, };