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

feat: allow per poll qv or non qv mode #297

Merged
merged 1 commit into from
Sep 3, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/coordinator-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ env:
NEXT_PUBLIC_REVIEW_END_DATE: ${{ vars.NEXT_PUBLIC_REVIEW_END_DATE }}
NEXT_PUBLIC_VOTING_END_DATE: ${{ vars.NEXT_PUBLIC_VOTING_END_DATE }}
NEXT_PUBLIC_RESULTS_DATE: ${{ vars.NEXT_PUBLIC_RESULTS_DATE }}
NEXT_PUBLIC_POLL_MODE: ${{ vars.NEXT_PUBLIC_POLL_MODE }}
TEST_MNEMONIC: ${{ secrets.TEST_MNEMONIC }}
WALLET_PRIVATE_KEY: ""

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ env:
NEXT_PUBLIC_REVIEW_END_DATE: ${{ vars.NEXT_PUBLIC_REVIEW_END_DATE }}
NEXT_PUBLIC_VOTING_END_DATE: ${{ vars.NEXT_PUBLIC_VOTING_END_DATE }}
NEXT_PUBLIC_RESULTS_DATE: ${{ vars.NEXT_PUBLIC_RESULTS_DATE }}
NEXT_PUBLIC_POLL_MODE: ${{ vars.NEXT_PUBLIC_POLL_MODE }}
TEST_MNEMONIC: ${{ secrets.TEST_MNEMONIC }}
WALLET_PRIVATE_KEY: ""

Expand Down
3 changes: 0 additions & 3 deletions packages/interface/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,4 @@ NEXT_PUBLIC_MACI_SUBGRAPH_URL=
# URL with tally-{pollId}.json hosted
NEXT_PUBLIC_TALLY_URL=https://upblxu2duoxmkobt.public.blob.vercel-storage.com

# Whether the poll is in qv or non qv mode
NEXT_PUBLIC_POLL_MODE="non-qv"

NEXT_PUBLIC_ROUND_LOGO="round-logo.png"
2 changes: 1 addition & 1 deletion packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"graphql-request": "^6.1.0",
"lowdb": "^1.0.0",
"lucide-react": "^0.316.0",
"maci-cli": "^2.2.0",
"maci-cli": "0.0.0-ci.d071f07",
"maci-domainobjs": "^2.2.0",
"next": "^14.1.0",
"next-auth": "^4.24.5",
Expand Down
1 change: 0 additions & 1 deletion packages/interface/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const config = {
maciSubgraphUrl: process.env.NEXT_PUBLIC_MACI_SUBGRAPH_URL ?? "",
tallyUrl: process.env.NEXT_PUBLIC_TALLY_URL,
roundOrganizer: process.env.NEXT_PUBLIC_ROUND_ORGANIZER ?? "PSE",
pollMode: process.env.NEXT_PUBLIC_POLL_MODE ?? "non-qv",
roundLogo: process.env.NEXT_PUBLIC_ROUND_LOGO,
semaphoreSubgraphUrl: process.env.NEXT_PUBLIC_SEMAPHORE_SUBGRAPH,
};
Expand Down
7 changes: 4 additions & 3 deletions packages/interface/src/contexts/Ballot.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { createContext, useContext, useState, useEffect, useMemo, useCallback } from "react";
import { useAccount } from "wagmi";

import { config } from "~/config";

import type { BallotContextType, BallotProviderProps } from "./types";
import type { Ballot, Vote } from "~/features/ballot/types";

import { useMaci } from "./Maci";

export const BallotContext = createContext<BallotContextType | undefined>(undefined);

const defaultBallot = { votes: [], published: false, edited: false };
Expand All @@ -15,14 +15,15 @@ export const BallotProvider: React.FC<BallotProviderProps> = ({ children }: Ball
const [isLoading, setLoading] = useState<boolean>(true);

const { isDisconnected } = useAccount();
const { pollData } = useMaci();

// when summing the ballot we take the individual vote and square it
// if the mode is quadratic voting, otherwise we just add the amount
const sumBallot = useCallback(
(votes?: Vote[]) =>
(votes ?? []).reduce((sum, x) => {
const amount = !Number.isNaN(Number(x.amount)) ? Number(x.amount) : 0;
return sum + (config.pollMode === "qv" ? amount ** 2 : amount);
return sum + (pollData && pollData.mode.toString() === "0" ? amount ** 2 : amount);
}, 0),
[],
);
Expand Down
2 changes: 0 additions & 2 deletions packages/interface/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = createEnv({

NEXT_PUBLIC_TALLY_URL: z.string().url(),

NEXT_PUBLIC_POLL_MODE: z.enum(["qv", "non-qv"]).default("non-qv"),
NEXT_PUBLIC_ROUND_LOGO: z.string().optional(),

NEXT_PUBLIC_SEMAPHORE_SUBGRAPH: z.string().url().optional(),
Expand Down Expand Up @@ -105,7 +104,6 @@ module.exports = createEnv({

NEXT_PUBLIC_TALLY_URL: process.env.NEXT_PUBLIC_TALLY_URL,

NEXT_PUBLIC_POLL_MODE: process.env.NEXT_PUBLIC_POLL_MODE,
NEXT_PUBLIC_ROUND_LOGO: process.env.NEXT_PUBLIC_ROUND_LOGO,

NEXT_PUBLIC_SEMAPHORE_SUBGRAPH: process.env.NEXT_PUBLIC_SEMAPHORE_SUBGRAPH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export const AllocationInput = ({
render={({ field }) => (
<NumericFormat
allowNegative={false}
decimalScale={0}
aria-label="allocation-input"
customInput={Input}
decimalScale={0}
error={props.error}
{...field}
autoComplete="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export const VotingWidget = ({ projectId }: IVotingWidgetProps): JSX.Element =>
<div className="flex items-center justify-center gap-5 rounded-xl border border-gray-200 p-5 dark:border-gray-800">
<NumericFormat
allowNegative={false}
decimalScale={0}
aria-label="allocation-input"
autoComplete="off"
className="dark:bg-lightBlack w-auto dark:text-white"
customInput={Input}
decimalScale={0}
defaultValue={amount}
isAllowed={({ floatValue }) => (floatValue ?? 0) <= initialVoiceCredits && (floatValue ?? 0) >= 0}
thousandSeparator=","
Expand Down
3 changes: 3 additions & 0 deletions packages/interface/src/utils/fetchPoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Poll {
messageRoot: string;
numSignups: string;
id: string;
mode: string;
}

export interface GraphQLResponse {
Expand All @@ -32,6 +33,7 @@ const PollQuery = `
messageRoot
numSignups
id
mode
}
}
`;
Expand All @@ -54,5 +56,6 @@ export async function fetchPoll(): Promise<IGetPollData> {
deployTime: poll?.createdAt ?? 0,
numSignups: poll?.numSignups ?? 0,
address: poll?.id ?? "",
mode: poll?.mode ?? "",
};
}
Loading
Loading