Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2022 08:24
Show Gist options
  • Save Tundesamson26/33eb515e5870b914dc2edf3b46e38d8c to your computer and use it in GitHub Desktop.
Save Tundesamson26/33eb515e5870b914dc2edf3b46e38d8c to your computer and use it in GitHub Desktop.
if (hasClaimedNFT) {
return (
<div className="member-page">
<h1>🍪DAO Member Page</h1>
<p>Congratulations on being a member</p>
<h2>Member List</h2>
<table className="card">
<th>Token Amount</th>
{ => {
return (
<tr key={member.address}>
<h2>Active Proposals</h2>
onSubmit={async (e) => {
//before we do async things, we want to disable the button to prevent double clicks
// lets get the votes from the form for the values
const votes = => {
const voteResult = {
proposalId: proposal.proposalId,
//abstain by default
vote: 2,
proposal.votes.forEach((vote) => {
const elem = document.getElementById(
proposal.proposalId + "-" + vote.type
if (elem.checked) { = vote.type;
return voteResult;
// first we need to make sure the user delegates their token to vote
try {
//we'll check if the wallet still needs to delegate their tokens before they can vote
const delegation = await token.getDelegationOf(address);
// if the delegation is the 0x0 address that means they have not delegated their governance tokens yet
if (delegation === AddressZero) {
//if they haven't delegated their tokens yet, we'll have them delegate them before voting
await token.delegateTo(address);
// then we need to vote on the proposals
try {
await Promise.all( ({ proposalId, vote: _vote }) => {
// before voting we first need to check whether the proposal is open for voting
// we first need to get the latest state of the proposal
const proposal = await vote.get(proposalId);
// then we check if the proposal is open for voting (state === 1 means it is open)
if (proposal.state === 1) {
// if it is open for voting, we'll vote on it
return, _vote);
// if the proposal is not open for voting we just return nothing, letting us continue
try {
// if any of the propsals are ready to be executed we'll need to execute them
// a proposal is ready to be executed if it is in state 4
await Promise.all( ({ proposalId }) => {
// we'll first get the latest state of the proposal again, since we may have just voted before
const proposal = await vote.get(proposalId);
//if the state is in state 4 (meaning that it is ready to be executed), we'll execute the proposal
if (proposal.state === 4) {
return vote.execute(proposalId);
// if we get here that means we successfully voted, so let's set the "hasVoted" state to true
// and log out a success message
console.log("successfully voted");
} catch (err) {
console.error("failed to execute votes", err);
} catch (err) {
console.error("failed to vote", err);
} catch (err) {
console.error("failed to delegate tokens");
} finally {
// in *either* case we need to set the isVoting state to false to enable the button again
{ => (
<div key={proposal.proposalId} className="card">
{{ type, label }) => (
<div key={type}>
id={proposal.proposalId + "-" + type}
//default the "abstain" vote to checked
defaultChecked={type === 2}
<label htmlFor={proposal.proposalId + "-" + type}>
<button disabled={isVoting || hasVoted} type="submit">
? "Voting..."
: hasVoted
? "You Already Voted"
: "Submit Votes"}
{!hasVoted && (
This will trigger multiple transactions that you will need to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment