Skip to content
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

[HOTFIX]: Donors with 0 value & project search projects in current open AW w/o values for total donation & ensure uniq project search results #628

Merged
merged 3 commits into from
Jan 15, 2025
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
9 changes: 5 additions & 4 deletions client/src/hooks/queries/donors/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { ProjectDonor } from './types';

export function mapDataToProjectDonors(data: Response): ProjectDonor[] {
return data
.map(({ address, amount }) => ({
address,
amount: parseUnitsBigInt(amount, 'wei'),
}))
.reduce((acc, { address, amount }) => {
if (amount === '0') {return acc;}
acc.push({ address, amount: parseUnitsBigInt(amount, 'wei') });
return acc;
}, [] as ProjectDonor[])
.sort((a, b) => {
if (a.amount > b.amount) {
return -1;
Expand Down
23 changes: 20 additions & 3 deletions client/src/hooks/queries/useSearchedProjects.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UseQueryResult, useQuery } from '@tanstack/react-query';
import uniqWith from 'lodash/uniqWith';

import { apiGetProjectsSearch } from 'api/calls/projects';
import { QUERY_KEYS } from 'api/queryKeys';
Expand Down Expand Up @@ -26,10 +27,26 @@ export default function useSearchedProjects(
),
// No point in strigifying params, they will just flood the memory.
queryKey: QUERY_KEYS.searchResults,
select: data =>
data.projectsDetails.map(element => ({
select: data => {
const dataWithEpochNumber = data.projectsDetails.map(element => ({
...element,
epoch: Number(element.epoch),
})),
}));

/**
* Because of the bug, BE sometimes returns the same
* name, address & epoch combination multiple times.
*
* Please check e.g.
* GET https://backend.mainnet.octant.app/projects/details?epochs=1,2,3,4,5,6,7&searchPhrases=Open,Source,Observer
*
* Hence the requirement to check uniqueness.
*
* More context: https://chat.wildland.dev/wildland/pl/gghcfgjndjyjieei8axn3opdeh
*/
return uniqWith(dataWithEpochNumber, (elementA, elementB) => {
return elementA.address === elementB.address && elementA.epoch === elementB.epoch;
});
},
});
}
2 changes: 1 addition & 1 deletion client/src/hooks/queries/useSearchedProjectsDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getRewards = ({
rewardsEstimated: ResponseRewards | undefined;
rewardsPast: ResponseRewards | undefined;
}): ResponseRewards['rewards'] | undefined => {
if (epoch === currentEpoch && isDecisionWindowOpen) {
if (epoch === currentEpoch! - 1 && isDecisionWindowOpen) {
return rewardsEstimated?.rewards;
}
if (epoch !== currentEpoch) {
Expand Down
Loading