Skip to content

Commit

Permalink
[HOTFIX]: Donors with 0 value & project search projects in current op…
Browse files Browse the repository at this point in the history
…en AW w/o values for total donation & ensure uniq project search results (#628)
  • Loading branch information
aziolek authored Jan 15, 2025
2 parents 5f6bed4 + 3de0e6b commit 9acaf8d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
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

0 comments on commit 9acaf8d

Please sign in to comment.