-
Notifications
You must be signed in to change notification settings - Fork 24
feat: enhance polling functionality with voting transparency on the governance page #683
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ibsule
wants to merge
19
commits into
livepeer:main
Choose a base branch
from
ibsule:governance-vote-transparency
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,737
−149
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
87d20ea
feat: enhance polling functionality with voting transparency on the g…
ibsule 1660abd
refactor: clean up imports and improve code consistency across PollVo…
ibsule 9e80ed9
feat: enhance voting components with vote stake formatting
ibsule 488711c
refactor: update DesktopVoteTable to improve vote weight display
ibsule 5f3a532
refactor: rename formatVoteStake to formatWeight for consistency acro…
ibsule b0ad572
feat: enhance PollVote components with additional vote data and forma…
ibsule 28a60eb
feat: enhance PollVote components with error handling and improved vo…
ibsule 5e9077d
fix: update sorting logic in PollVote component for mobile view
ibsule 8601dba
fix: handle unknown voting support in MobileVoteView
ibsule 54b8512
fix: add error handling in PollVotePopover component
ibsule e8aa64f
feat: enhance subgraph and PollVote components with logging and query…
ibsule b90a266
fix: update sorting logic in PollVote component for mobile view
ibsule 698aac5
Merge branch 'main' into governance-vote-transparency
ECWireless 38ad71f
refactor: optimize GraphQL queries and update PollVote component
ibsule dceef1d
feat: increase pagination limit in PollVotePopover component
ibsule 26f545f
Merge branch 'governance-vote-transparency' of https://github.com/ibs…
ibsule d049a9c
fix: improve error handling in useGetAllVoteEvents hook
ibsule cdd64a7
fix: enhance loading state management in useVotes hook
ibsule 2ffa703
Merge branch 'main' into governance-vote-transparency
ibsule File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,221 @@ | ||
| import EthAddressBadge from "@components/EthAddressBadge"; | ||
| import { ExplorerTooltip } from "@components/ExplorerTooltip"; | ||
| import DataTable from "@components/Table"; | ||
| import TransactionBadge from "@components/TransactionBadge"; | ||
| import { VOTING_SUPPORT_MAP } from "@lib/api/types/votes"; | ||
| import { Badge, Box, Text } from "@livepeer/design-system"; | ||
| import { CounterClockwiseClockIcon } from "@radix-ui/react-icons"; | ||
| import dayjs from "dayjs"; | ||
| import React, { useMemo } from "react"; | ||
| import { Column } from "react-table"; | ||
|
|
||
| import { PollVoteType } from "."; | ||
|
|
||
| export interface PollVoteTableProps { | ||
| votes: PollVoteType[]; | ||
| onSelect: (voter: { | ||
| address: string; | ||
| voteStake: string; | ||
| ensName?: string; | ||
| }) => void; | ||
| pageSize?: number; | ||
| totalPages?: number; | ||
| currentPage?: number; | ||
| onPageChange?: (page: number) => void; | ||
| formatWeight: (stake: string) => string; | ||
| } | ||
|
|
||
| export const DesktopVoteTable: React.FC<PollVoteTableProps> = ({ | ||
| votes, | ||
| onSelect, | ||
| pageSize = 10, | ||
| formatWeight, | ||
| }) => { | ||
| const columns = useMemo<Column<PollVoteType>[]>( | ||
| () => [ | ||
| { | ||
| Header: "Voter", | ||
| accessor: "ensName", | ||
| id: "voter", | ||
| Cell: ({ row }) => ( | ||
| <Box css={{ minWidth: 120 }}> | ||
| <EthAddressBadge value={row.original.voter} /> | ||
| </Box> | ||
| ), | ||
| }, | ||
| { | ||
| Header: "Support", | ||
| accessor: "choiceID", | ||
| id: "support", | ||
| Cell: ({ row }) => { | ||
| const support = | ||
| VOTING_SUPPORT_MAP[row.original.choiceID] || | ||
| VOTING_SUPPORT_MAP["Unknown"]; | ||
|
|
||
| return ( | ||
| <Box css={{ minWidth: 100 }}> | ||
| <Badge | ||
| size="1" | ||
| css={{ | ||
| backgroundColor: support.style.backgroundColor, | ||
| color: support.style.color, | ||
| fontWeight: support.style.fontWeight, | ||
| border: "none", | ||
| width: "86px", | ||
| display: "inline-flex", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| gap: "$1", | ||
| }} | ||
| > | ||
| <Box as={support.icon} css={{ width: 12, height: 12 }} /> | ||
| {support.text} | ||
| </Badge> | ||
| </Box> | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| Header: "Weight", | ||
| accessor: "voteStake", | ||
| id: "weight", | ||
|
ibsule marked this conversation as resolved.
|
||
| Cell: ({ row }) => ( | ||
| <Box css={{ minWidth: 140 }}> | ||
| <Text | ||
| css={{ | ||
| fontWeight: 600, | ||
| color: "$hiContrast", | ||
| whiteSpace: "nowrap", | ||
| }} | ||
| size="2" | ||
| > | ||
| {formatWeight(row.original.voteStake)} | ||
| </Text> | ||
| </Box> | ||
| ), | ||
| sortType: (rowA, rowB) => { | ||
| return ( | ||
| parseFloat(rowA.original.voteStake) - | ||
| parseFloat(rowB.original.voteStake) | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| Header: "Timestamp", | ||
| accessor: "timestamp", | ||
| id: "timestamp", | ||
| Cell: ({ row }) => { | ||
| if (row.original.timestamp) { | ||
| return ( | ||
| <Text size="1" css={{ color: "$neutral11" }}> | ||
| {dayjs | ||
| .unix(row.original.timestamp) | ||
| .format("MMM D YYYY, h:mm a")} | ||
| </Text> | ||
| ); | ||
| } else { | ||
| return ( | ||
| <Text size="1" css={{ color: "$neutral9" }}> | ||
| N/A | ||
| </Text> | ||
| ); | ||
| } | ||
| }, | ||
| }, | ||
| { | ||
| Header: "Transaction", | ||
| accessor: "transactionHash", | ||
| id: "transaction", | ||
| Cell: ({ row }) => ( | ||
| <Box | ||
| css={{ | ||
| minWidth: 130, | ||
| display: "flex", | ||
| alignItems: "center", | ||
| height: "100%", | ||
| }} | ||
| > | ||
| {row.original.transactionHash ? ( | ||
| <TransactionBadge id={row.original.transactionHash} /> | ||
| ) : ( | ||
| <Text css={{ color: "$neutral9" }} size="2"> | ||
| N/A | ||
| </Text> | ||
| )} | ||
| </Box> | ||
| ), | ||
| }, | ||
| { | ||
| Header: "", | ||
| id: "history", | ||
| Cell: ({ row }) => ( | ||
| <Box | ||
| css={{ | ||
| minWidth: 40, | ||
| textAlign: "right", | ||
| color: "$primary11", | ||
| paddingRight: "$2", | ||
| }} | ||
| > | ||
| <ExplorerTooltip content="See their voting history"> | ||
| <Box | ||
| as="button" | ||
| onClick={(e) => { | ||
| e.stopPropagation(); | ||
| onSelect({ | ||
| address: row.original.voter, | ||
| ensName: row.original.ensName, | ||
| voteStake: row.original.voteStake, | ||
| }); | ||
| }} | ||
| css={{ | ||
| display: "inline-flex", | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| width: 32, | ||
| height: 32, | ||
| borderRadius: "50%", | ||
| cursor: "pointer", | ||
| border: "none", | ||
| backgroundColor: "transparent", | ||
| color: "$neutral10", | ||
| "&:hover": { | ||
| color: "$primary11", | ||
| backgroundColor: "$primary3", | ||
| transform: "rotate(-15deg)", | ||
| }, | ||
| transition: "color .2s, background-color .2s, transform .2s", | ||
| }} | ||
| > | ||
| <Box | ||
| as={CounterClockwiseClockIcon} | ||
| css={{ width: 16, height: 16 }} | ||
| /> | ||
| </Box> | ||
| </ExplorerTooltip> | ||
| </Box> | ||
| ), | ||
| disableSortBy: true, | ||
| }, | ||
| ], | ||
| [formatWeight, onSelect] | ||
| ); | ||
|
|
||
| return ( | ||
| <Box css={{ display: "none", "@bp2": { display: "block" } }}> | ||
| <DataTable | ||
| data={votes} | ||
| columns={columns} | ||
| initialState={{ | ||
| pageSize, | ||
| sortBy: [ | ||
| { | ||
| id: "weight", | ||
| desc: true, | ||
| }, | ||
| ], | ||
| }} | ||
| /> | ||
| </Box> | ||
| ); | ||
| }; | ||
This file contains hidden or 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,57 @@ | ||
| import Pagination from "@components/Table/Pagination"; | ||
| import { Box, Text } from "@livepeer/design-system"; | ||
| import React from "react"; | ||
|
|
||
| import { PollVoteTableProps } from "./DesktopVoteTable"; | ||
| import { MobileVoteView } from "./MobileVoteView"; | ||
|
|
||
| export const MobileVoteCards: React.FC<PollVoteTableProps> = (props) => { | ||
| const { | ||
| votes, | ||
| onSelect, | ||
| totalPages = 0, | ||
| currentPage = 1, | ||
| formatWeight, | ||
| onPageChange, | ||
| } = props; | ||
|
|
||
| return ( | ||
| <Box css={{ display: "block", "@bp2": { display: "none" } }}> | ||
| <Text | ||
| css={{ | ||
| textAlign: "center", | ||
| fontSize: "$2", | ||
| color: "$neutral11", | ||
| marginTop: "$2", | ||
| marginBottom: "$3", | ||
| }} | ||
| > | ||
| View a voter's proposal voting history by clicking the history | ||
| icon. | ||
| </Text> | ||
|
|
||
| {votes.map((vote) => { | ||
| return ( | ||
| <MobileVoteView | ||
| key={vote.transactionHash || vote.voter} | ||
| vote={vote} | ||
| formatWeight={formatWeight} | ||
| onSelect={onSelect} | ||
| /> | ||
| ); | ||
| })} | ||
|
|
||
| {/* Pagination */} | ||
| {totalPages > 1 && ( | ||
| <Pagination | ||
| currentPage={currentPage} | ||
| totalPages={totalPages} | ||
| canPrevious={currentPage > 1} | ||
| canNext={currentPage < totalPages} | ||
| onPrevious={() => onPageChange?.(currentPage - 1)} | ||
| onNext={() => onPageChange?.(currentPage + 1)} | ||
| /> | ||
| )} | ||
| </Box> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.