-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #410 from privacy-scaling-explorations/fix/zupass-…
…multiround fix(zupass-gatekeeper): added zupass gatekeeper signup
- Loading branch information
Showing
4 changed files
with
76 additions
and
20 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters