Skip to content

Commit

Permalink
fix: api down (#439)
Browse files Browse the repository at this point in the history
* fix: api down

* ref: removed unused var
  • Loading branch information
MrX-SNX authored Sep 5, 2024
1 parent de4164c commit 0116924
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions governance/ui/src/queries/useGetHistoricalVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@ export function useGetHistoricalVotes() {
return useQuery({
queryKey: ['historical-votes', network?.id],
queryFn: async () => {
const res = await fetch(network?.id !== 2192 ? mainnetURL : testnetURL);
let votesRaw: Record<CouncilSlugs, Vote[]> = await res.json();
if (!('spartan' in votesRaw)) {
votesRaw = { spartan: votesRaw[0], ambassador: [], treasury: [] };
try {
const res = await fetch(network?.id !== 2192 ? mainnetURL : testnetURL);
let votesRaw: Record<CouncilSlugs, Vote[]> = await res.json();
if (!('spartan' in votesRaw)) {
votesRaw = { spartan: votesRaw[0], ambassador: [], treasury: [] };
}
return councils.reduce(
(cur, next) => {
cur[next.slug] = votesRaw[next.slug].sort((a, b) => {
if (a.epochId === b.epochId) {
return a.blockTimestamp - b.blockTimestamp;
}
return a.epochId - b.epochId;
});
return cur;
},
{} as Record<CouncilSlugs, Vote[]>
);
} catch (err) {
console.error(err);
return { spartan: [], ambassador: [], treasury: [] } as Record<CouncilSlugs, Vote[]>;
}
return councils.reduce(
(cur, next) => {
cur[next.slug] = votesRaw[next.slug].sort((a, b) => {
if (a.epochId === b.epochId) {
return a.blockTimestamp - b.blockTimestamp;
}
return a.epochId - b.epochId;
});
return cur;
},
{} as Record<CouncilSlugs, Vote[]>
);
},
staleTime: 900000,
});
Expand Down

0 comments on commit 0116924

Please sign in to comment.