Skip to content
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
46 changes: 7 additions & 39 deletions constants/manualPolls.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { PollsQuery } from "apollo";

/**
* TEMPORARY stopgap: manually surface governance polls that were created while
* the subgraph was behind on indexing, so voting stays functional during the
* outage. Entries are shaped like subgraph poll results and merged into the
* voting list/detail pages, deduped by poll address — once the subgraph
* reindexes a poll, its real (tallied) copy wins and the manual entry drops out.
*
* The subgraph normally computes the stake-weighted counts, so these carry no
* tally of their own: the UI fills it in from `/api/polls/tally/[poll]`, which
* recomputes it from chain state. Voting itself is on-chain and works regardless.
* These carry no vote tally (the subgraph computes the stake-weighted counts),
* so the UI shows a "counts not loaded" note for them; voting itself is on-chain
* and works regardless.
*
* Remove entries (or delete this file and its imports) once indexing recovers.
*/

import { PollTally } from "@lib/api/types/get-poll-tally";
import { PollsQuery } from "apollo";

type SubgraphPoll = PollsQuery["polls"][number];

type ManualPoll = SubgraphPoll & {
/** L2 block the poll was created in — lower bound for on-chain vote lookups. */
startBlockL2: number;
};

export const MANUAL_POLLS: ManualPoll[] = [
export const MANUAL_POLLS: SubgraphPoll[] = [
{
// LIP-118 "Delegated Reward Calling" — created during the subgraph indexing halt.
// tx: 0xb8ab2a824b4a5b16b76be99f1313a8238f35acc2259b139562277e1df8ba02e4
Expand All @@ -34,7 +27,6 @@ export const MANUAL_POLLS: ManualPoll[] = [
quota: "500000",
tally: null,
votes: [],
startBlockL2: 485384564,
},
];

Expand All @@ -43,7 +35,7 @@ const norm = (id: string) => id.toLowerCase();
/** The manually-listed poll for `id`, if any. */
export const getManualPoll = (
id: string | undefined | null
): ManualPoll | undefined =>
): SubgraphPoll | undefined =>
id ? MANUAL_POLLS.find((p) => norm(p.id) === norm(id)) : undefined;

/** Whether `id` is a manually-listed poll (i.e. not sourced from the subgraph). */
Expand All @@ -64,27 +56,3 @@ export const mergeManualPolls = (
}
return list;
};

/**
* Fill a manual poll's missing tally with the one computed on-chain by
* `/api/polls/tally/[poll]`. Subgraph-sourced polls are returned untouched, so
* this becomes a no-op as soon as indexing catches up.
*/
export const withManualTally = (
poll: SubgraphPoll,
tally: PollTally | undefined | null
): SubgraphPoll => {
if (!tally || norm(tally.poll) !== norm(poll.id) || !isManualPoll(poll.id)) {
return poll;
}

return {
...poll,
tally: { __typename: "PollTally", ...tally.tally },
// The list/widget show a vote count, which the subgraph would supply.
votes: tally.votes.map((vote) => ({
__typename: "Vote" as const,
id: `${vote.voter}-${norm(poll.id)}`,
})),
};
};
17 changes: 0 additions & 17 deletions hooks/useSwr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
AllPerformanceMetrics,
PerformanceMetrics,
} from "@lib/api/types/get-performance";
import { PollTally } from "@lib/api/types/get-poll-tally";
import { ProtocolDayData } from "@lib/api/types/get-protocol-day-data";
import { Regions } from "@lib/api/types/get-regions";
import { SupplyChangeData } from "@lib/api/types/get-supply-change";
Expand All @@ -25,7 +24,6 @@ import {
VotingPower,
} from "@lib/api/types/get-treasury-proposal";
import { formatAddress } from "@utils/web3";
import { isManualPoll } from "constants/manualPolls";
import useSWR from "swr";
import { Address } from "viem";

Expand Down Expand Up @@ -129,21 +127,6 @@ export const useCurrentRoundData = () => {
return data ?? null;
};

/**
* TEMPORARY stopgap: on-chain tally for a poll the subgraph hasn't indexed yet.
* Remove together with `constants/manualPolls` once indexing recovers.
*/
export const useManualPollTally = (id: string | undefined | null) => {
const { data } = useSWR<PollTally>(
id && isManualPoll(id) ? `/polls/tally/${id.toLowerCase()}` : null,
// Matches the endpoint's cache window — polling faster just re-reads the
// same cached object.
{ refreshInterval: 60000 }
);

return data ?? null;
};

export const usePendingFeesAndStakeData = (
address: string | undefined | null
) => {
Expand Down
262 changes: 0 additions & 262 deletions lib/api/pollTally.ts

This file was deleted.

Loading
Loading