Skip to content

Commit

Permalink
Merge pull request #4930 from Giveth/feat/estimated_matching
Browse files Browse the repository at this point in the history
Feat/Adding matching property
  • Loading branch information
kkatusic authored Jan 20, 2025
2 parents b8cc3a4 + f79c543 commit 6283689
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/apollo/gql/gqlDonations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const FETCH_QF_ROUND_HISTORY = gql`
projectDonationsSqrtRootSum
allProjectsSum
matchingPool
matching
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/apollo/gql/gqlProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const PROJECT_CORE_FIELDS = gql`
allocatedTokenSymbol
allocatedFundUSDPreferred
allocatedFundUSD
qfStrategy
}
}
`;
Expand Down Expand Up @@ -51,6 +52,7 @@ export const PROJECT_CARD_FIELDS = gql`
projectDonationsSqrtRootSum
allProjectsSum
matchingPool
matching
}
anchorContracts {
address
Expand Down Expand Up @@ -180,6 +182,7 @@ export const FETCH_PROJECT_BY_SLUG_DONATION = gql`
projectDonationsSqrtRootSum
allProjectsSum
matchingPool
matching
}
qfRounds {
id
Expand All @@ -193,6 +196,7 @@ export const FETCH_PROJECT_BY_SLUG_DONATION = gql`
allocatedFundUSDPreferred
allocatedFundUSD
minimumValidUsdValue
qfStrategy
}
anchorContracts {
address
Expand Down Expand Up @@ -276,6 +280,7 @@ export const FETCH_PROJECT_BY_SLUG_SINGLE_PROJECT = gql`
projectDonationsSqrtRootSum
allProjectsSum
matchingPool
matching
}
qfRounds {
id
Expand All @@ -288,6 +293,7 @@ export const FETCH_PROJECT_BY_SLUG_SINGLE_PROJECT = gql`
allocatedTokenSymbol
allocatedFundUSDPreferred
allocatedFundUSD
qfStrategy
}
campaigns {
id
Expand Down
7 changes: 7 additions & 0 deletions src/apollo/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IEstimatedMatching {
allProjectsSum: number;
matchingPool: number;
projectDonationsSqrtRootSum: number;
matching: number;
}

export interface IAnchorContractData {
Expand Down Expand Up @@ -488,6 +489,11 @@ export interface IUsersPFPTokens {
[key: string]: IGiverPFPToken[];
}

export enum QfStrategyEnum {
Cocm = 'Cocm',
Regular = 'Regular',
}

export interface IQFRound {
slug: string;
id: string;
Expand All @@ -509,6 +515,7 @@ export interface IQFRound {
allocatedTokenChainId: number;
minimumValidUsdValue?: number;
minMBDScore: number;
qfStrategy: QfStrategyEnum;
}

export interface IArchivedQFRound extends IQFRound {
Expand Down
11 changes: 9 additions & 2 deletions src/components/project-card/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ const ProjectCard = (props: IProjectCard) => {
const { formatMessage, formatRelativeTime, locale } = useIntl();
const router = useRouter();

const { allProjectsSum, matchingPool, projectDonationsSqrtRootSum } =
estimatedMatching || {};
const {
allProjectsSum,
matchingPool,
projectDonationsSqrtRootSum,
matching,
} = estimatedMatching || {};

const { activeStartedRound, activeQFRound } = getActiveRound(qfRounds);
const hasFooter = activeStartedRound || verified || isGivbackEligible;
Expand All @@ -101,6 +105,7 @@ const ProjectCard = (props: IProjectCard) => {
allocatedFundUSDPreferred,
allocatedFundUSD,
allocatedTokenSymbol,
qfStrategy,
} = activeQFRound || {};

const projectLink = slugToProjectView(slug);
Expand Down Expand Up @@ -300,6 +305,8 @@ const ProjectCard = (props: IProjectCard) => {
? allocatedFundUSD
: matchingPool,
activeStartedRound?.maximumReward,
matching,
qfStrategy,
),
allocatedFundUSDPreferred ? '$' : '',
locale,
Expand Down
11 changes: 9 additions & 2 deletions src/components/views/donate/DonatePageProjectDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ export const DonatePageProjectDescription: FC<
estimatedMatching,
} = projectData || {};

const { allProjectsSum, matchingPool, projectDonationsSqrtRootSum } =
estimatedMatching || {};
const {
allProjectsSum,
matchingPool,
projectDonationsSqrtRootSum,
matching,
} = estimatedMatching || {};
const isQRDonation = router.query.chain === ChainType.STELLAR.toLowerCase();
const orgLabel = organization?.label;
const isForeignOrg =
Expand All @@ -72,6 +76,7 @@ export const DonatePageProjectDescription: FC<
allocatedFundUSDPreferred,
allocatedFundUSD,
allocatedTokenSymbol,
qfStrategy,
} = activeQFRound || {};

return (
Expand Down Expand Up @@ -147,6 +152,8 @@ export const DonatePageProjectDescription: FC<
? allocatedFundUSD
: matchingPool,
activeStartedRound?.maximumReward,
matching,
qfStrategy,
),
allocatedFundUSDPreferred ? '$' : '',
locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface IProjectTotalFundCardProps {
const ProjectTotalFundCard = ({ selectedQF }: IProjectTotalFundCardProps) => {
const [qfRoundHistory, setQfRoundHistory] = useState<IGetQfRoundHistory>();
const { projectData, isAdmin } = useProjectContext();

const {
id,
totalDonations,
Expand Down Expand Up @@ -119,6 +120,8 @@ const ProjectTotalFundCard = ({ selectedQF }: IProjectTotalFundCardProps) => {
allProjectsSum,
allocatedFundUSDPreferred ? allocatedFundUSD : matchingPool,
selectedQF.maximumReward,
projectData?.estimatedMatching.matching,
selectedQF.qfStrategy,
)
: qfRoundHistory
? qfRoundHistory.matchingFund !== null
Expand All @@ -129,6 +132,8 @@ const ProjectTotalFundCard = ({ selectedQF }: IProjectTotalFundCardProps) => {
qfRoundHistory.estimatedMatching.allProjectsSum,
qfRoundHistory.estimatedMatching.matchingPool,
selectedQF.maximumReward,
projectData?.estimatedMatching.matching,
selectedQF.qfStrategy,
)
: 0
: 0;
Expand Down Expand Up @@ -217,7 +222,7 @@ const ProjectTotalFundCard = ({ selectedQF }: IProjectTotalFundCardProps) => {
<EstimatedMatchingPrice>
+{' '}
{formatDonation(
matchFund,
matchFund || 0,
allocatedFundUSDPreferred
? '$'
: '',
Expand Down
10 changes: 9 additions & 1 deletion src/helpers/qf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IQFRound } from '@/apollo/types/types';
import { IQFRound, QfStrategyEnum } from '@/apollo/types/types';
import { getNowUnixMS } from './time';
// import { formatDonation } from '@/helpers/number';

Expand Down Expand Up @@ -32,6 +32,8 @@ export const calculateTotalEstimatedMatching = (
allProjectsSum?: number,
matchingPool?: number,
matchingCapPercentage?: number,
matching: number = 0,
qfStrategy?: string,
) => {
if (
!matchingCapPercentage ||
Expand All @@ -40,6 +42,12 @@ export const calculateTotalEstimatedMatching = (
!allProjectsSum
)
return 0;

// For al new round return "matching" value
if (qfStrategy && qfStrategy === QfStrategyEnum.Cocm) {
return matching;
}

const result = Math.min(
(Math.pow(projectDonationsSqrtRootSum, 2) / allProjectsSum) *
matchingPool,
Expand Down

0 comments on commit 6283689

Please sign in to comment.