Skip to content

Commit

Permalink
Merge pull request #410 from privacy-scaling-explorations/fix/zupass-…
Browse files Browse the repository at this point in the history
…multiround

fix(zupass-gatekeeper): added zupass gatekeeper signup
  • Loading branch information
ctrlc03 authored Oct 23, 2024
2 parents 26389e7 + c4a56ed commit 3b95975
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 20 deletions.
10 changes: 1 addition & 9 deletions packages/interface/public/round-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 72 additions & 8 deletions packages/interface/src/components/JoinButton.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,89 @@
/* eslint-disable no-console */
import { decStringToBigIntToUuid } from "@pcd/util";
import { ZKEdDSAEventTicketPCDPackage } from "@pcd/zk-eddsa-event-ticket-pcd";
import { zuAuthPopup } from "@pcd/zuauth";
import { GatekeeperTrait, getZupassGatekeeperData } from "maci-cli/sdk";
import { useCallback } from "react";
import { toast } from "sonner";
import { useAccount } from "wagmi";

import { zupass, config } from "~/config";
import { useMaci } from "~/contexts/Maci";
import { useEthersSigner } from "~/hooks/useEthersSigner";
import { jsonPCD } from "~/utils/types";

import type { EdDSAPublicKey } from "@pcd/eddsa-pcd";

import { Button } from "./ui/Button";

export const JoinButton = (): JSX.Element => {
const { isLoading, isRegistered, isEligibleToVote, onSignup } = useMaci();
const { isLoading, isRegistered, isEligibleToVote, onSignup, gatekeeperTrait, storeZupassProof } = useMaci();
const signer = useEthersSigner();
const { address } = useAccount();

const onError = useCallback(() => toast.error("Signup error"), []);
const handleSignup = useCallback(() => onSignup(onError), [onSignup, onError]);

return (
<div>
{!isEligibleToVote && <Button variant="disabled">You are not allowed to vote</Button>}
const handleZupassVerify = useCallback(async () => {
if (address !== undefined && signer) {
const zupassGatekeeperData = await getZupassGatekeeperData({ maciAddress: config.maciAddress!, signer });
const eventId = decStringToBigIntToUuid(zupassGatekeeperData.eventId);
console.log(eventId);
console.log(zupass);
const result = await zuAuthPopup({
fieldsToReveal: {
revealTicketId: true,
revealEventId: true,
},
watermark: address,
config: [
{
pcdType: zupass.pcdType,
publicKey: zupass.publicKey as EdDSAPublicKey,
eventId,
eventName: zupass.eventName,
},
],
});
if (result.type === "pcd") {
try {
const parsedPCD = (JSON.parse(result.pcdStr) as jsonPCD).pcd;
const pcd = await ZKEdDSAEventTicketPCDPackage.deserialize(parsedPCD);
await storeZupassProof(pcd);
} catch (e) {
console.error("zupass error:", e);
}
}
}
}, [signer, address, storeZupassProof]);

if (!isEligibleToVote && gatekeeperTrait === GatekeeperTrait.Zupass) {
return (
<div>
<Button variant={isRegistered === undefined || isLoading ? "disabled" : "primary"} onClick={handleZupassVerify}>
Generate Zupass Proof
</Button>
</div>
);
}

{isEligibleToVote && !isRegistered && (
if (isEligibleToVote && !isRegistered) {
return (
<div>
<Button variant={isRegistered === undefined || isLoading ? "disabled" : "primary"} onClick={handleSignup}>
Voter sign up
</Button>
)}
</div>
);
</div>
);
}

if (!isEligibleToVote) {
return (
<div>
<Button variant="disabled">You are not allowed to vote</Button>
</div>
);
}

return <div />;
};
2 changes: 1 addition & 1 deletion packages/interface/src/components/RoundInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const RoundInfo = ({ roundId }: IRoundInfoProps): JSX.Element => (
<h4>Round</h4>

<div className="flex items-center gap-2">
{config.roundLogo && <Image alt="round logo" height="20" src={`/${config.roundLogo}`} width="20" />}
{config.roundLogo && <Image alt="round logo" height="30" src={`/${config.roundLogo}`} width="30" />}

<Heading as="h3" size="3xl">
{roundId}
Expand Down
4 changes: 2 additions & 2 deletions packages/interface/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export const eas = {
export const zupass = {
pcdType: "eddsa-ticket-pcd",
publicKey: [
"1ebfb986fbac5113f8e2c72286fe9362f8e7d211dbc68227a468d7b919e75003",
"10ec38f11baacad5535525bbe8e343074a483c051aa1616266f3b1df3fb7d204",
"044e711fd3a1792a825aa896104da5276bbe710fd9b59dddea1aaf8d84535aaf",
"2b259329f0adf98c9b6cf2a11db7225fdcaa4f8796c61864e86154477da10663",
],
eventName: process.env.NEXT_PUBLIC_ZUPASS_EVENT_NAME!,
} as const;
Expand Down

0 comments on commit 3b95975

Please sign in to comment.