diff --git a/client/src/hooks/queries/useSearchedProjects.ts b/client/src/hooks/queries/useSearchedProjects.ts index 0bac36b27..357ca58d1 100644 --- a/client/src/hooks/queries/useSearchedProjects.ts +++ b/client/src/hooks/queries/useSearchedProjects.ts @@ -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'; @@ -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; + }); + }, }); }