-
Notifications
You must be signed in to change notification settings - Fork 4
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 #2 from 0xjei/feat/dev-mode
Implement developer mode for custom ticket fields to reveal choices
- Loading branch information
Showing
7 changed files
with
226 additions
and
38 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { EdDSATicketFieldsToReveal } from "@pcd/zk-eddsa-event-ticket-pcd"; | ||
import Toggle from '@/components/Toggle'; | ||
|
||
interface DeveloperPanelProps { | ||
fieldsToReveal: EdDSATicketFieldsToReveal; | ||
onToggleField: (fieldName: keyof EdDSATicketFieldsToReveal) => void; | ||
disabled?: boolean; | ||
} | ||
|
||
// Display a set of toggles associated with ticket fields. When a toggle is activated, | ||
// the ticket proof will reveal the corresponding ticket field. | ||
const DeveloperPanel: React.FC<DeveloperPanelProps> = ({ fieldsToReveal, onToggleField, disabled = false }) => { | ||
const toggleKeys = Object.keys(fieldsToReveal) as Array<keyof EdDSATicketFieldsToReveal>; | ||
|
||
return ( | ||
<div className="grid grid-cols-4 gap-4"> | ||
{toggleKeys.map(fieldName => ( | ||
<div key={fieldName} className="flex flex-col items-center"> | ||
<p className="text-center">{fieldName}</p> | ||
<Toggle | ||
checked={fieldsToReveal[fieldName]} | ||
onToggle={() => onToggleField(fieldName)} | ||
disabled={disabled} | ||
/> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default DeveloperPanel; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { EdDSATicketFieldsToReveal } from "@pcd/zk-eddsa-event-ticket-pcd"; | ||
|
||
interface DisplayRevealedFieldsProps { | ||
user: { | ||
[key: string]: boolean | string | number; | ||
}; | ||
revealedFields: EdDSATicketFieldsToReveal; | ||
} | ||
|
||
|
||
// Display the field name and corresponent value for each one that were revealed. | ||
const DisplayRevealedFields: React.FC<DisplayRevealedFieldsProps> = ({ user, revealedFields }) => { | ||
const renderedFields = Object.entries(revealedFields).map(([fieldName, shouldReveal]) => { | ||
if (shouldReveal) { | ||
// Remove the 'reveal' substring and lower the subsequent capitalized letter. | ||
// eg., from 'revealTicketId' to 'ticketId'. | ||
const replaced = fieldName.replace('reveal', '').charAt(0).toLowerCase() + fieldName.slice(7) | ||
|
||
const fieldValue = user[replaced]; | ||
return ( | ||
<div key={fieldName} className="my-2 text-center"> | ||
<div className="font-bold">{replaced}</div> | ||
<div className="ml-4">{fieldValue.toString()}</div> | ||
</div> | ||
); | ||
} | ||
return null; | ||
}); | ||
|
||
return ( | ||
<div> | ||
{renderedFields.filter(field => field !== null).length === 0 ? ( | ||
<div className="text-center">You're in, anon! No ticket info has been revealed 🕶</div> | ||
) : ( | ||
renderedFields | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DisplayRevealedFields; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import { FaToggleOff, FaToggleOn } from "react-icons/fa"; | ||
|
||
interface ToggleProps { | ||
checked?: boolean; | ||
onToggle: () => void; | ||
disabled?: boolean; | ||
} | ||
|
||
const Toggle: React.FC<ToggleProps> = ({ checked = false, onToggle, disabled }) => { | ||
const handleClick = () => { | ||
if (!disabled) { | ||
onToggle(); | ||
} | ||
}; | ||
|
||
return ( | ||
<button | ||
className={`toggle-icon ${checked ? 'active' : ''}`} | ||
onClick={handleClick} | ||
disabled={disabled} | ||
> | ||
{checked ? <FaToggleOn size={30} className="text-blue-800"/> : <FaToggleOff size={30} />} | ||
</button> | ||
); | ||
} | ||
|
||
export default Toggle; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,4 @@ body { | |
rgb(var(--background-end-rgb)) | ||
) | ||
rgb(var(--background-start-rgb)); | ||
} | ||
} |
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