Skip to content
26 changes: 25 additions & 1 deletion components/Notification/lib/formatNotification.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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()
);
};
Comment thread
jeevan6996 marked this conversation as resolved.

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);
Expand Down Expand Up @@ -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}"`;
}

Expand Down
4 changes: 4 additions & 0 deletions types/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
};
Expand Down