-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add prisma model for Snapshot Votes table * Add hello-world to query teh snapshot vote table * Minor refactor * Adds snapshot votes as a tab * Recovers ens contract from bang * Moves to dropdown based selector which is more compatible with existing UI * Adds 'gimmicks' (animation lol) * Adds tenant config * Adds empty votes placeholder for snapshot --------- Co-authored-by: Michael Gingras <mcg79@cornell.edu>
- Loading branch information
Showing
8 changed files
with
388 additions
and
25 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
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
110 changes: 110 additions & 0 deletions
110
src/components/Delegates/DelegateVotes/SnapshotVotes.tsx
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,110 @@ | ||
"use client"; | ||
|
||
import { useRef, useState } from "react"; | ||
import { HStack, VStack } from "../../Layout/Stack"; | ||
import { formatDistanceToNow } from "date-fns"; | ||
import InfiniteScroll from "react-infinite-scroller"; | ||
import styles from "./delegateVotes.module.scss"; | ||
import { pluralizeSnapshotVote } from "@/lib/tokenUtils"; | ||
|
||
const propHeader = (vote: any) => { | ||
let headerString = "Snapshot vote - "; | ||
headerString += `${formatDistanceToNow(new Date(vote.created * 1000))} ago`; | ||
return headerString; | ||
}; | ||
|
||
const VoteDetails = ({ vote }: { vote: any }) => { | ||
const choiceLabels = vote.choice_labels; | ||
const isFor = choiceLabels[0] === "For"; | ||
const isAgainst = choiceLabels[0] === "Against"; | ||
|
||
return ( | ||
<div | ||
className={`text-xs mt-1 font-medium space-x-[3px] ${isFor ? "text-green-700" : isAgainst ? "text-red-700" : "text-stone-500"}`} | ||
> | ||
{choiceLabels.map((label: string, idx: number) => { | ||
return ( | ||
<span key={`{choice-${idx}}`}> | ||
{label} | ||
{idx < choiceLabels.length - 1 ? ", " : ""} | ||
</span> | ||
); | ||
})} | ||
<span>{pluralizeSnapshotVote(BigInt(Math.trunc(vote.vp)))}</span> | ||
</div> | ||
); | ||
}; | ||
|
||
export default function SnapshotVotes({ | ||
meta, | ||
initialVotes, | ||
fetchSnapshotVotes, | ||
}: { | ||
meta: any; | ||
initialVotes: any; | ||
fetchSnapshotVotes: any; | ||
}) { | ||
const [snapshotVotes, setSnapshotVotes] = useState(initialVotes); | ||
const [snapshotMeta, setSnapshotMeta] = useState(meta); | ||
|
||
const fetching = useRef(false); | ||
|
||
const loadMore = async () => { | ||
if (!fetching.current && snapshotMeta?.hasNextPage) { | ||
fetching.current = true; | ||
const data = await fetchSnapshotVotes(snapshotMeta?.currentPage + 1); | ||
setSnapshotMeta(data.snapshotMeta); | ||
setSnapshotVotes((prev: any) => prev.concat(data.votes)); | ||
fetching.current = false; | ||
} | ||
}; | ||
|
||
return ( | ||
<InfiniteScroll | ||
hasMore={snapshotMeta?.hasNextPage} | ||
pageStart={0} | ||
loadMore={loadMore} | ||
useWindow={false} | ||
loader={ | ||
<div key={0}> | ||
<HStack | ||
key="loader" | ||
className="gl_loader justify-center py-6 text-sm text-stone-500" | ||
> | ||
Loading... | ||
</HStack> | ||
</div> | ||
} | ||
element="main" | ||
className="divide-y divide-gray-300 overflow-hidden bg-white shadow-newDefault ring-1 ring-gray-300 rounded-xl" | ||
> | ||
{snapshotVotes.map( | ||
(vote: any, idx: number) => | ||
vote && ( | ||
<div key={`vote-${idx}`}> | ||
<div className={styles.details_container}> | ||
<VStack className={styles.details_sub}> | ||
<div className="flex flex-row justify-between"> | ||
<div className="flex flex-col flex-1 pr-4"> | ||
<span className="text-[#66676b] text-xs font-medium"> | ||
{`${propHeader(vote)}`} | ||
</span> | ||
<h2 className="px-0 pt-1 overflow-hidden text-base text-black text-ellipsis"> | ||
{vote.title} | ||
</h2> | ||
<VoteDetails vote={vote} /> | ||
</div> | ||
<div className="flex-1 border-l border-stone-100 pl-4"> | ||
<span className="text-xs text-stone-500 leading-5 block"> | ||
{vote.reason} | ||
</span> | ||
</div> | ||
</div> | ||
</VStack> | ||
</div> | ||
</div> | ||
) | ||
)} | ||
</InfiniteScroll> | ||
); | ||
} |
Oops, something went wrong.