Skip to content
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

Votes grouping #832

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"svg.preview.background": "black"
}
"svg.preview.background": "black",
"cSpell.words": [
"Tezos"
]
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
"devDependencies": {
"@types/jest": "^26.0.21",
"@types/node": "^14.14.35",
"@types/react": "^17.0.3",
"@types/react-dom": "^17.0.2",
"@types/react": "^17.0.44",
"@types/react-dom": "^18.2.25",
"@types/react-html-parser": "^2.0.2",
"@types/react-router-dom": "^5.1.6",
"@types/yup": "^0.29.11",
Expand All @@ -104,7 +104,7 @@
"lint-staged": "15.2.2",
"prettier": "^2.2.0",
"source-map-explorer": "2.5.2",
"typescript": "^5.0.4"
"typescript": "5.4.0-beta"
fabiolalombardim marked this conversation as resolved.
Show resolved Hide resolved
},
"resolutions": {
"@types/react": "~17.0.3",
Expand Down
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react/no-deprecated */

import React from "react"
import ReactDOM from "react-dom"
import App from "App"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/explorer/components/ProposalActionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const OptionContainer = styled(Grid)(({ theme }) => ({
"padding": "35px 42px",
"marginBottom": 16,
"cursor": "pointer",
"height": 110,
"height": 80,
"&:hover:enabled": {
background: theme.palette.secondary.dark,
scale: 1.01,
Expand Down
15 changes: 0 additions & 15 deletions src/modules/explorer/pages/Config/components/DAOInfoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Typography,
useMediaQuery,
Expand All @@ -28,14 +27,6 @@ const RowValue = styled(Typography)(({ theme }) => ({
}
}))

const TableTitle = styled(Typography)(({ theme }) => ({
fontWeight: 500,
fontSize: 18,
[theme.breakpoints.down("sm")]: {
fontSize: 16
}
}))

const CustomTableContainer = styled(TableContainer)(({ theme }) => ({
width: "inherit",
[theme.breakpoints.down("sm")]: {}
Expand All @@ -49,12 +40,6 @@ const CustomTableCell = styled(TableCell)(({ theme }) => ({
}
}))

const CustomTableCellTitle = styled(TableCell)(({ theme }) => ({
[theme.breakpoints.down("sm")]: {
paddingLeft: "16px !important"
}
}))

const CustomTableCellValue = styled(TableCell)(({ theme }) => ({
[theme.breakpoints.down("sm")]: {
paddingTop: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const OptionContainer = styled(Grid)(({ theme }) => ({
"padding": "35px 42px",
"marginBottom": 16,
"cursor": "pointer",
"height": 110,
"height": 80,
"&:hover:enabled": {
background: theme.palette.secondary.dark,
scale: 1.01,
Expand Down
57 changes: 37 additions & 20 deletions src/modules/lite/explorer/components/DownloadCsvFile.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
import React, { useEffect, useState } from "react"
import { Button, Typography } from "@material-ui/core"
import { ReactComponent as DownloadCSVIcon } from "assets/img/download_csv.svg"
import { Choice, WalletAddress } from "models/Choice"
import { mkConfig, generateCsv, download, asString } from "export-to-csv"
import { writeFile } from "node:fs"
import { mkConfig, generateCsv, download } from "export-to-csv"
import { useNotification } from "modules/lite/components/hooks/useNotification"
import BigNumber from "bignumber.js"
import { bytes2Char } from "@taquito/utils"
import dayjs from "dayjs"

interface GroupedVotes {
address: string
options: any[]
}

type DownloadCsvFileProps = {
data: Choice[]
data: GroupedVotes[]
pollId: string | undefined
symbol: string
decimals: string
isXTZ: boolean
}

export const DownloadCsvFile: React.FC<DownloadCsvFileProps> = ({ data, pollId, symbol }) => {
export const DownloadCsvFile: React.FC<DownloadCsvFileProps> = ({ data, pollId, symbol, decimals, isXTZ }) => {
const [votesDetails, setVotesDetails] = useState<any>()
const openNotification = useNotification()

useEffect(() => {
const getTotal = (options: any) => {
let total = new BigNumber(0)
if (options) {
options.map((item: any) => {
total = total.plus(new BigNumber(item.balance))
})
}
const formatted = total.div(new BigNumber(10).pow(isXTZ ? 6 : decimals))
return formatted
}
const arr: any = []

data.map(item => {
item.walletAddresses.map(vote => {
const formattedVote = {
address: vote.address,
choice: item.name,
balance: vote.balanceAtReferenceBlock,
signature: vote.signature,
ipfsStorage: vote.cidLink
}
return arr.push(formattedVote)
})
const formattedVote = {
address: item.address,
choices: item.options.map(item => item.name),
balance: getTotal(item.options),
signature: item.options[0].signature,
ipfsStorage: item.options[0].cidLink,
timestamp: bytes2Char(item.options[0].payloadBytes).split(" ")[4]
}
return arr.push(formattedVote)
})
setVotesDetails(arr)
}, [data])
}, [data, decimals, isXTZ])

const downloadCvs = () => {
console.log(votesDetails)
const csvConfig = mkConfig({
useKeysAsHeaders: true,
filename: `proposal-${pollId}`,
Expand All @@ -44,11 +60,12 @@ export const DownloadCsvFile: React.FC<DownloadCsvFileProps> = ({ data, pollId,
const votesData = votesDetails.map((row: any) => {
return {
"Address": row.address,
"Choice": row.choice,
"Choice": row.choices.toLocaleString().replace(",", ", "),
"Token": symbol,
"Vote Weight": row.balance,
"Signature": row.signature,
"IPFS Storage Link": row.ipfsStorage
"IPFS Storage Link": row.ipfsStorage,
"Timestamp": dayjs(row.timestamp).format("LLL").toString()
}
})
try {
Expand Down
9 changes: 7 additions & 2 deletions src/modules/lite/explorer/components/VoteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
calculateWeight,
calculateWeightXTZ,
calculateXTZTotal,
getGroupedVotes,
getTotalVoters,
getTreasuryPercentage,
nFormatter
Expand Down Expand Up @@ -70,6 +71,7 @@ export const VoteDetails: React.FC<{
const tokenData = useCommunityToken(communityId)
const { data: isTokenDelegationSupported } = useTokenDelegationSupported(tokenData?.tokenAddress)
const totalXTZ = calculateXTZTotal(choices)
const groupedVotes = getGroupedVotes(choices)

const handleClickOpen = () => {
setVotes(choices.filter(elem => elem.walletAddresses.length > 0))
Expand Down Expand Up @@ -218,8 +220,10 @@ export const VoteDetails: React.FC<{
)}
{getTotalVoters(choices) > 0 ? (
<DownloadCsvFile
data={choices}
data={groupedVotes}
pollId={poll?._id}
decimals={tokenData?.decimals ? tokenData?.decimals : ""}
fabiolalombardim marked this conversation as resolved.
Show resolved Hide resolved
isXTZ={isXTZ}
symbol={isXTZ ? "XTZ" : tokenData?.symbol ? tokenData?.symbol : ""}
/>
) : null}
Expand All @@ -228,7 +232,8 @@ export const VoteDetails: React.FC<{
<VotesDialog
decimals={tokenData?.decimals ? tokenData?.decimals : ""}
fabiolalombardim marked this conversation as resolved.
Show resolved Hide resolved
symbol={isXTZ ? "XTZ" : tokenData?.symbol ? tokenData?.symbol : ""}
choices={votes}
choices={choices}
groupedVotes={groupedVotes}
open={open}
isXTZ={isXTZ}
handleClose={handleClose}
Expand Down
Loading
Loading