Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions components/Notification/NotificationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
formatNotificationMessage,
getHubDetailsFromNotification,
formatNavigationUrl,
getBountyForYouUsdOverride,
getRSCAmountFromNotification,
} from './lib/formatNotification';
import { Avatar } from '@/components/ui/Avatar';
Expand Down Expand Up @@ -32,6 +33,7 @@
const formattedNavigationUrl = formatNavigationUrl(notification);
const hasNavigationUrl = !!formattedNavigationUrl && formattedNavigationUrl.trim() !== '';
const rscAmount = getRSCAmountFromNotification(notification);
const bountyUsdOverride = getBountyForYouUsdOverride(notification);

const hubDetails = getHubDetailsFromNotification(notification);

Expand Down Expand Up @@ -83,10 +85,12 @@
<TopicAndJournalBadge name={hubDetails.name} slug={hubDetails.slug} size="sm" />
</div>
)}
{rscAmount && (
{(rscAmount || bountyUsdOverride !== null) && (
<div className="inline-block">
<CurrencyBadge
amount={rscAmount}
amount={bountyUsdOverride ?? rscAmount ?? 0}
currency={bountyUsdOverride !== null ? 'USD' : 'RSC'}

Check warning on line 92 in components/Notification/NotificationItem.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrLCvFFhzEQA0_A8_&open=AZ8IrLCvFFhzEQA0_A8_&pullRequest=749
skipConversion={bountyUsdOverride !== null}
size="xs"
variant={isReceivedRSC ? 'received' : 'badge'}
showText
Expand Down
27 changes: 26 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';

Expand Down Expand Up @@ -195,6 +196,26 @@
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 !== undefined &&
bountyCreatorId.toString() === FOUNDATION_USER_ID.toString()

Check warning on line 207 in components/Notification/lib/formatNotification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrK_PFFhzEQA0_A89&open=AZ8IrK_PFFhzEQA0_A89&pullRequest=749
);
};
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;
}

/**
* Transform ResearchHub URLs to relative paths and convert #comments to /conversation
* Examples:
Expand Down Expand Up @@ -313,7 +334,11 @@
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

Check warning on line 339 in components/Notification/lib/formatNotification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected negated condition.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrK_PFFhzEQA0_A8-&open=AZ8IrK_PFFhzEQA0_A8-&pullRequest=749
? `$${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
@@ -1,10 +1,10 @@
import { createTransformer, BaseTransformed } from './transformer';
import { User, transformUser } from './user';
import { ContentType } from './work';

Check warning on line 3 in types/notification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'ContentType'.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrLDAFFhzEQA0_A9A&open=AZ8IrLDAFFhzEQA0_A9A&pullRequest=749
import { ContentMetrics } from './metrics';

Check warning on line 4 in types/notification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'ContentMetrics'.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrLDAFFhzEQA0_A9B&open=AZ8IrLDAFFhzEQA0_A9B&pullRequest=749
import { Journal } from './journal';

Check warning on line 5 in types/notification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'Journal'.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrLDAFFhzEQA0_A9C&open=AZ8IrLDAFFhzEQA0_A9C&pullRequest=749
import { Topic } from './topic';

Check warning on line 6 in types/notification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'Topic'.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrLDAFFhzEQA0_A9D&open=AZ8IrLDAFFhzEQA0_A9D&pullRequest=749
import { AuthorProfile } from './authorProfile';

Check warning on line 7 in types/notification.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this unused import of 'AuthorProfile'.

See more on https://sonarcloud.io/project/issues?id=ResearchHub_web&issues=AZ8IrLDAFFhzEQA0_A9E&open=AZ8IrLDAFFhzEQA0_A9E&pullRequest=749

export interface NotificationHub {
name: string;
Expand All @@ -14,11 +14,13 @@
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 @@ -76,11 +78,13 @@
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