Skip to content
Merged
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
3 changes: 2 additions & 1 deletion components/Activity/lib/activityDisplay.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { buildWorkUrl } from '@/utils/url';
import { isFoundationUser } from '@/components/Bounty/lib/bountyUtil';
import { getGrantBadgeAmount } from '@/types/grant';
import type { CurrencyAmount } from '@/utils/currency';
import type {
FeedCommentContent,
Expand Down Expand Up @@ -367,7 +368,7 @@ export function getGrantAmount(entry: FeedEntry): ActivityGrantAmount | undefine
if (entry.contentType !== 'GRANT') return undefined;
const grant = (entry.content as FeedGrantContent).grant;
if (!grant?.amount) return undefined;
return { usd: grant.amount.usd, rsc: grant.amount.rsc };
return getGrantBadgeAmount(grant);
}

export interface ActivityCommentPreview {
Expand Down
23 changes: 16 additions & 7 deletions components/Activity/lib/activityWork.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from './activityDisplay.utils';
import { formatCurrency } from '@/utils/currency';
import { toOptionalNumber } from '@/utils/number';
import { getGrantBadgeAmount } from '@/types/grant';
import type {
ActivityAction,
FeedBountyContent,
Expand Down Expand Up @@ -104,7 +105,7 @@ function resolveWorkTab(entry: FeedEntry, workContentType?: ContentType): Activi

function resolveActivityBodySlot(
activityAction?: ActivityAction,
work?: Pick<ActivityWork, 'fundraise' | 'grant' | 'bounty'>,
work?: Pick<ActivityWork, 'documentType' | 'fundraise' | 'grant' | 'bounty'>,
options?: { isReview?: boolean }
): ActivityBodySlot {
if (activityAction === 'bounty_opened' || activityAction === 'bounty_contributed') {
Expand All @@ -113,6 +114,9 @@ function resolveActivityBodySlot(
if (activityAction === 'grant_opened') {
return work?.grant ? 'grant' : 'default';
}
if (work?.grant && work.documentType === 'funding_request') {
return 'grant';
}
Comment thread
nicktytarenko marked this conversation as resolved.
if (
activityAction === 'tip_review' ||
activityAction === 'bounty_payout' ||
Expand Down Expand Up @@ -230,17 +234,21 @@ function presentGrant(
exchangeRate: number
): WorkCardPresentation {
const stats: WorkCardStat[] = [];
const badge = getGrantBadgeAmount({
amount: { usd: grant.amount.usd, rsc: grant.amount.rsc ?? 0 },
fundingPool: grant.fundingPool,
});
let budgetAmount: number | null = null;
let skipConversion = showUSD;

if (showUSD) {
if (grant.amount.usd > 0) {
budgetAmount = grant.amount.usd;
if (badge.usd > 0) {
budgetAmount = badge.usd;
}
} else if (grant.amount.rsc != null && grant.amount.rsc > 0) {
budgetAmount = grant.amount.rsc;
} else if (grant.amount.usd > 0 && exchangeRate > 0) {
budgetAmount = grant.amount.usd / exchangeRate;
} else if (badge.rsc > 0) {
budgetAmount = badge.rsc;
} else if (badge.usd > 0 && exchangeRate > 0) {
budgetAmount = badge.usd / exchangeRate;
skipConversion = true;
}

Expand Down Expand Up @@ -312,6 +320,7 @@ function grantSummaryFromFeedGrant(content: FeedGrantContent): WorkGrantSummary
status: grant.status,
organization: grant.organization,
amount: { usd: grant.amount.usd, rsc: grant.amount.rsc ?? null },
fundingPool: grant.fundingPool ?? null,
numApplicants: grant.applicants?.length ?? 0,
endDate: grant.endDate,
};
Expand Down
6 changes: 3 additions & 3 deletions components/Feed/items/FeedItemGrant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useCurrencyPreference } from '@/contexts/CurrencyPreferenceContext';
import { useExchangeRate } from '@/contexts/ExchangeRateContext';
import { formatCurrency } from '@/utils/currency';
import { isDeadlineInFuture } from '@/utils/date';
import { getGrantBadgeAmount } from '@/types/grant';

interface FeedItemGrantProps {
entry: FeedEntry;
Expand Down Expand Up @@ -74,9 +75,8 @@ export const FeedItemGrant: FC<FeedItemGrantProps> = ({
authorId: profile.id || undefined,
})) || [];

const budgetAmount = showUSD
? Math.round(grant.grant?.amount?.usd || 0)
: Math.round(grant.grant?.amount?.rsc || 0);
const badgeAmount = grant.grant ? getGrantBadgeAmount(grant.grant) : { usd: 0, rsc: 0 };
const budgetAmount = showUSD ? Math.round(badgeAmount.usd) : Math.round(badgeAmount.rsc);

return (
<BaseFeedItem
Expand Down
2 changes: 2 additions & 0 deletions types/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ function transformActivityRelatedWorkGrant(rawGrant: unknown): WorkGrantSummary
amount?: { usd?: number; rsc?: number | null };
application_count?: number;
end_date?: string | null;
funding_pool?: unknown;
};

if (typeof grant.amount !== 'object' || grant.amount === null) {
Expand All @@ -651,6 +652,7 @@ function transformActivityRelatedWorkGrant(rawGrant: unknown): WorkGrantSummary
usd: grant.amount.usd ?? 0,
rsc: grant.amount.rsc ?? null,
},
fundingPool: grant.funding_pool ? transformFundingPool(grant.funding_pool) : null,
numApplicants: grant.application_count ?? 0,
endDate: grant.end_date ?? undefined,
};
Expand Down
3 changes: 2 additions & 1 deletion types/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { stripHtml } from '../utils/stringUtils';
import { transformUser, TransformedUser } from './user';
import { transformTip, Tip } from './tip';
import { transformProposalReview, type ProposalReview } from './aiPeerReview';
import type { GrantApplicationVisibility } from './grant';
import type { FundingPool, GrantApplicationVisibility } from './grant';
import { Fundraise, transformFundraise } from './funding';

export interface PeerReview {
Expand Down Expand Up @@ -144,6 +144,7 @@ export interface WorkGrantSummary {
status: string;
organization: string;
amount: { usd: number; rsc: number | null };
fundingPool?: FundingPool | null;
numApplicants: number;
endDate?: string;
}
Expand Down
Loading