-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: change estimated matching to a range #4305
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,18 +78,33 @@ const QFSection: FC<IQFSectionProps> = ({ projectData }) => { | |
const isForeignOrg = | ||
orgLabel !== ORGANIZATION.trace && orgLabel !== ORGANIZATION.giveth; | ||
|
||
const formatWithCurrency = ( | ||
amount: number, | ||
currency: string, | ||
locale: string, | ||
) => { | ||
return ( | ||
formatDonation(amount, currency, locale, true) + | ||
(currency ? '' : ` ${allocatedTokenSymbol}`) | ||
); | ||
}; | ||
|
||
const getEstimatedMatchingRange = (esMatching: number) => { | ||
if (esMatching >= 1) { | ||
return `${formatWithCurrency((esMatching * 30) / 100, allocatedFundUSDPreferred ? '$' : '', locale)} - ${formatWithCurrency(esMatching, allocatedFundUSDPreferred ? '$' : '', locale)}`; | ||
} | ||
return formatWithCurrency( | ||
esMatching, | ||
allocatedFundUSDPreferred ? '$' : '', | ||
locale, | ||
); | ||
}; | ||
|
||
const EstimatedMatchingSection = () => | ||
totalEstimatedMatching !== 0 ? ( | ||
<Flex $flexDirection='column' gap='4px'> | ||
<EstimatedMatchingPrice> | ||
{'+ ' + | ||
formatDonation( | ||
totalEstimatedMatching, | ||
allocatedFundUSDPreferred ? '$' : '', | ||
locale, | ||
true, | ||
)}{' '} | ||
{allocatedFundUSDPreferred ? '' : allocatedTokenSymbol} | ||
{getEstimatedMatchingRange(totalEstimatedMatching)} | ||
</EstimatedMatchingPrice> | ||
<Flex $alignItems='center' gap='4px'> | ||
<LightCaption> | ||
|
@@ -109,6 +124,29 @@ const QFSection: FC<IQFSectionProps> = ({ projectData }) => { | |
</Flex> | ||
) : null; | ||
|
||
const DonationMatch = ({ amount }: { amount: number }) => ( | ||
<FlexSameSize $justifyContent='space-between'> | ||
<Subline> | ||
{allocatedFundUSDPreferred && '$'} | ||
{amount} {!allocatedFundUSDPreferred && allocatedTokenSymbol} | ||
</Subline> | ||
<IconArrowRight16 color={brandColors.cyan[500]} /> | ||
<EndAlignedSubline> | ||
{getEstimatedMatchingRange( | ||
calculateEstimatedMatchingWithDonationAmount( | ||
amount, | ||
projectDonationsSqrtRootSum, | ||
allProjectsSum, | ||
allocatedFundUSDPreferred | ||
? allocatedFundUSD | ||
: matchingPool, | ||
activeStartedRound?.maximumReward, | ||
), | ||
)} | ||
</EndAlignedSubline> | ||
</FlexSameSize> | ||
); | ||
Comment on lines
+127
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification The
To ensure robustness, consider adding explicit checks for negative values and unusual currency formats within these functions.
Analysis chainReview the The Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify handling of edge cases in `DonationMatch`.
# Test: Search for any additional calls to `DonationMatch`. Expect: Proper handling of edge cases.
ast-grep --lang typescript --pattern $'DonationMatch($_)'
Length of output: 58 Script: #!/bin/bash
# Description: Search for the usage of `DonationMatch` in the codebase to verify edge cases handling.
# Find all files containing `DonationMatch` to locate its usage.
rg 'DonationMatch' --type tsx --type ts
Length of output: 67 Script: #!/bin/bash
# Description: Search for the usage of `DonationMatch` in the codebase to verify edge cases handling.
# Find all files containing `DonationMatch` to locate its usage.
rg 'DonationMatch' --type ts --type tsx
Length of output: 67 Script: #!/bin/bash
# Description: Search for the usage of `DonationMatch` in the codebase to verify edge cases handling.
# Find all files containing `DonationMatch` to locate its usage.
rg 'DonationMatch' --type ts
Length of output: 444 Script: #!/bin/bash
# Description: Review the implementations of `getEstimatedMatchingRange` and `calculateEstimatedMatchingWithDonationAmount` for edge case handling.
# Find the implementation of `getEstimatedMatchingRange`.
rg 'function getEstimatedMatchingRange' --type ts
# Find the implementation of `calculateEstimatedMatchingWithDonationAmount`.
rg 'function calculateEstimatedMatchingWithDonationAmount' --type ts
Length of output: 122 Script: #!/bin/bash
# Description: Review the implementations of `getEstimatedMatchingRange` and `calculateEstimatedMatchingWithDonationAmount` for edge case handling.
# Find the implementation of `getEstimatedMatchingRange`.
ast-grep --lang typescript --pattern 'function getEstimatedMatchingRange($_) { $$$ }'
# Find the implementation of `calculateEstimatedMatchingWithDonationAmount`.
ast-grep --lang typescript --pattern 'function calculateEstimatedMatchingWithDonationAmount($_) { $$$ }'
Length of output: 194 Script: #!/bin/bash
# Description: Verify if `getEstimatedMatchingRange` and `calculateEstimatedMatchingWithDonationAmount` are defined or imported in the codebase.
# Search for `getEstimatedMatchingRange` function definition or import.
rg 'getEstimatedMatchingRange' --type ts
# Search for `calculateEstimatedMatchingWithDonationAmount` function definition or import.
rg 'calculateEstimatedMatchingWithDonationAmount' --type ts
Length of output: 1169 Script: #!/bin/bash
# Description: Extract the definition of `getEstimatedMatchingRange` from `QFSection.tsx`.
# Extract the definition of `getEstimatedMatchingRange`.
sed -n '/const getEstimatedMatchingRange =/,/};/p' src/components/views/project/projectActionCard/QFSection.tsx
Length of output: 496 Script: #!/bin/bash
# Description: Extract the definition of `calculateEstimatedMatchingWithDonationAmount` from `qf.ts`.
# Extract the definition of `calculateEstimatedMatchingWithDonationAmount`.
sed -n '/export const calculateEstimatedMatchingWithDonationAmount =/,/^};/p' src/helpers/qf.ts
Length of output: 1087 |
||
|
||
return ( | ||
<DonationSectionWrapper gap={isOnDonatePage ? '8px' : '24px'}> | ||
{isOnDonatePage && ( | ||
|
@@ -225,93 +263,9 @@ const QFSection: FC<IQFSectionProps> = ({ projectData }) => { | |
</Flex> | ||
<ContributionsContainer> | ||
<Flex $flexDirection='column' gap='4px'> | ||
<FlexSameSize $justifyContent='space-between'> | ||
<Subline> | ||
{allocatedFundUSDPreferred && '$'}1{' '} | ||
{!allocatedFundUSDPreferred && | ||
allocatedTokenSymbol} | ||
</Subline> | ||
<IconArrowRight16 | ||
color={brandColors.cyan[500]} | ||
/> | ||
<EndAlignedSubline> | ||
+{' '} | ||
{formatDonation( | ||
calculateEstimatedMatchingWithDonationAmount( | ||
1, | ||
projectDonationsSqrtRootSum, | ||
allProjectsSum, | ||
allocatedFundUSDPreferred | ||
? allocatedFundUSD | ||
: matchingPool, | ||
activeStartedRound?.maximumReward, | ||
), | ||
allocatedFundUSDPreferred ? '$' : '', | ||
locale, | ||
true, | ||
)}{' '} | ||
{!allocatedFundUSDPreferred && | ||
allocatedTokenSymbol} | ||
</EndAlignedSubline> | ||
</FlexSameSize> | ||
<FlexSameSize $justifyContent='space-between'> | ||
<Subline> | ||
{allocatedFundUSDPreferred && '$'}10{' '} | ||
{!allocatedFundUSDPreferred && | ||
allocatedTokenSymbol} | ||
</Subline> | ||
<IconArrowRight16 | ||
color={brandColors.cyan[500]} | ||
/> | ||
<EndAlignedSubline> | ||
+{' '} | ||
{formatDonation( | ||
calculateEstimatedMatchingWithDonationAmount( | ||
10, | ||
projectDonationsSqrtRootSum, | ||
allProjectsSum, | ||
allocatedFundUSDPreferred | ||
? allocatedFundUSD | ||
: matchingPool, | ||
activeStartedRound?.maximumReward, | ||
), | ||
allocatedFundUSDPreferred ? '$' : '', | ||
locale, | ||
true, | ||
)}{' '} | ||
{!allocatedFundUSDPreferred && | ||
allocatedTokenSymbol} | ||
</EndAlignedSubline> | ||
</FlexSameSize> | ||
<FlexSameSize $justifyContent='space-between'> | ||
<Subline> | ||
{allocatedFundUSDPreferred && '$'}100{' '} | ||
{!allocatedFundUSDPreferred && | ||
allocatedTokenSymbol} | ||
</Subline> | ||
<IconArrowRight16 | ||
color={brandColors.cyan[500]} | ||
/> | ||
<EndAlignedSubline> | ||
+{' '} | ||
{formatDonation( | ||
calculateEstimatedMatchingWithDonationAmount( | ||
100, | ||
projectDonationsSqrtRootSum, | ||
allProjectsSum, | ||
allocatedFundUSDPreferred | ||
? allocatedFundUSD | ||
: matchingPool, | ||
activeStartedRound?.maximumReward, | ||
), | ||
allocatedFundUSDPreferred ? '$' : '', | ||
locale, | ||
true, | ||
)}{' '} | ||
{!allocatedFundUSDPreferred && | ||
allocatedTokenSymbol} | ||
</EndAlignedSubline> | ||
</FlexSameSize> | ||
<DonationMatch amount={1} /> | ||
<DonationMatch amount={10} /> | ||
<DonationMatch amount={100} /> | ||
{/* <Flex $justifyContent='space-between'> | ||
<LightSubline>Last updated: 3h ago</LightSubline> | ||
<LightSubline>|</LightSubline> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The implementation of the
getEstimatedMatchingRange
function has been located. The function currently does not include explicit error handling for edge cases, such as negative values foresMatching
.src/components/views/project/projectActionCard/QFSection.tsx
Recommendation: Add error handling to manage edge cases like negative
esMatching
values.Analysis chain
Ensure robust error handling in
getEstimatedMatchingRange
function.The function
getEstimatedMatchingRange
calculates a range for estimated matching. It's crucial to ensure that the function handles possible edge cases or unusual inputs robustly, such as negative values foresMatching
.The initial check using
ast-grep
did not return any results, which means we need to gather more information. First, let's examine the implementation of thegetEstimatedMatchingRange
function for any built-in error handling.Let's refine our search to ensure we capture the function definition accurately. We'll look for all function definitions in the
QFSection.tsx
file and specifically for thegetEstimatedMatchingRange
function.Let's expand our search to include arrow functions and traditional function definitions within
QFSection.tsx
.Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 70
Script:
Length of output: 89
Script:
Length of output: 96
Script:
Length of output: 2072