Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolalombardim committed Feb 25, 2024
2 parents e327c09 + 4ad9483 commit a193668
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 85 deletions.
1 change: 1 addition & 0 deletions src/models/Polls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface Poll {
endTimeMinutes?: number | null
endTimeHours?: number | null
endTimeDays?: number | null
isXTZ: boolean
}

export interface Vote {
Expand Down
3 changes: 1 addition & 2 deletions src/modules/creator/deployment/steps/Config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ const CustomFormikTextField = withStyles({
"& .MuiInput-underline:after": {
borderBottom: "none !important"
}
},
disabled: {}
}
})(FormikTextField)

const CustomInputContainer = styled(Grid)(({ theme }) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/modules/explorer/components/UsersTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react"
import { TableCell, TableHead, TableRow, styled, Grid, Typography, useTheme, useMediaQuery } from "@material-ui/core"
import { styled, Grid, Typography, useTheme, useMediaQuery } from "@material-ui/core"
import dayjs from "dayjs"
import { Blockie } from "modules/common/Blockie"
import { CopyButton } from "./CopyButton"
Expand Down
3 changes: 0 additions & 3 deletions src/modules/explorer/pages/DAOList/components/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const StyledInput = withStyles((theme: Theme) => ({
"& .MuiInput-underline:after": {
borderBottomColor: "transparent"
}
},
input: {
disabled: {}
}
}))(TextField)

Expand Down
3 changes: 1 addition & 2 deletions src/modules/explorer/pages/Treasury/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useTransfers } from "../../../../services/contracts/baseDAO/hooks/useTr
import { InfoIcon } from "../../components/styled/InfoIcon"
import { useIsProposalButtonDisabled } from "../../../../services/contracts/baseDAO/hooks/useCycleInfo"
import { styled } from "@material-ui/core"
import { MainButton } from "../../../common/MainButton"
import { TabPanel } from "modules/explorer/components/TabPanel"
import { NFTs } from "../NFTs"
import TollIcon from "@mui/icons-material/Toll"
Expand Down Expand Up @@ -139,8 +138,8 @@ export const Treasury: React.FC = () => {
item
xs
container
direction="row"
justifyContent="flex-end"
direction="row"
style={isMobileSmall ? {} : { marginLeft: 30 }}
>
<CopyButton style={{ marginRight: 4 }} text={dao?.data.address} displayedText="Copy Address" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ const CustomCopyButton = withStyles({
"& .MuiBox-root": {
padding: "0px !important"
}
},
disabled: {}
}
})(Grid)

const OffChainBox = styled(Grid)(({ theme }) => ({
Expand Down Expand Up @@ -132,10 +131,12 @@ export const Delegation: React.FC<{ daoId: string }> = ({ daoId }) => {
>
<Typography color="textPrimary">Voting Weight</Typography>
<Balance color="textPrimary">
{!voteWeight || voteWeight.eq(new BigNumber(0)) ? (
{!voteWeight || voteWeight.votingWeight.eq(new BigNumber(0)) ? (
"-"
) : (
<>{`${parseUnits(voteWeight, dao.data.token.decimals).toString()} ${dao.data.token.symbol}`}</>
<>{`${parseUnits(voteWeight.votingWeight, dao.data.token.decimals).toString()} ${
dao.data.token.symbol
}`}</>
)}
</Balance>
</OffChainBox>
Expand Down
10 changes: 4 additions & 6 deletions src/modules/lite/explorer/components/Choices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
withStyles
} from "@material-ui/core"
import { theme } from "theme"

import { AddCircleOutline, RemoveCircleOutline, DeleteTwoTone } from "@material-ui/icons"
import { AddCircleOutline, DeleteTwoTone } from "@material-ui/icons"
import { FieldArray, Field } from "formik"
import { TextField as FormikTextField } from "formik-material-ui"
import { useDAOID } from "modules/explorer/pages/DAO/router"
import { useDAO } from "services/services/dao/hooks/useDAO"
import { useTokenVoteWeight } from "services/contracts/token/hooks/useTokenVoteWeight"
import { useCommunity } from "../hooks/useCommunity"
import BigNumber from "bignumber.js"

const ChoicesContainer = styled(Grid)(({ theme }) => ({
marginTop: 24,
Expand Down Expand Up @@ -104,8 +104,7 @@ const CustomFormikChoiceTextField = withStyles({
"& .MuiInput-underline:after": {
borderBottom: "none !important"
}
},
disabled: {}
}
})(FormikTextField)

const MainButton = styled(Button)(({ theme }) => ({
Expand All @@ -131,8 +130,7 @@ export const Choices: React.FC<any> = ({
const community = useCommunity(id)

const { data: userTokenVoteWeight } = useTokenVoteWeight(data?.data?.token?.contract || community?.tokenAddress)
const canCreateProposal = userTokenVoteWeight && userTokenVoteWeight.gt(0) ? true : false

const canCreateProposal = userTokenVoteWeight && userTokenVoteWeight.votingWeight.gt(0) ? true : false
const classes = useStyles()

return (
Expand Down
99 changes: 62 additions & 37 deletions src/modules/lite/explorer/components/VoteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import {
calculateChoiceTotal,
calculateProposalTotal,
calculateWeight,
calculateWeightXTZ,
calculateXTZTotal,
getTotalVoters,
getTreasuryPercentage,
nFormatter
} from "services/lite/utils"
import numbro from "numbro"
import { useTezos } from "services/beacon/hooks/useTezos"
import { useCommunityToken } from "../hooks/useCommunityToken"
import { getTurnoutValue } from "services/utils/utils"
Expand Down Expand Up @@ -49,12 +52,13 @@ const GraphicsContainer = styled(Grid)({
paddingBottom: 25
})

export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[]; token: any; communityId: any }> = ({
poll,
choices,
token,
communityId
}) => {
export const VoteDetails: React.FC<{
poll: Poll | undefined
choices: Choice[]
token: any
communityId: any
isXTZ: boolean
}> = ({ poll, choices, token, communityId, isXTZ }) => {
const theme = useTheme()
const isMobileSmall = useMediaQuery(theme.breakpoints.down("xs"))
const isMobile = useMediaQuery(theme.breakpoints.down("sm"))
Expand All @@ -64,6 +68,7 @@ export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[];
const [votes, setVotes] = useState<Choice[]>([])
const tokenData = useCommunityToken(communityId)
const { data: isTokenDelegationSupported } = useTokenDelegationSupported(tokenData?.tokenAddress)
const totalVoters = calculateXTZTotal(choices)

const handleClickOpen = () => {
setVotes(choices.filter(elem => elem.walletAddresses.length > 0))
Expand All @@ -74,6 +79,13 @@ export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[];
setOpen(false)
}

const formatConfig = {
average: true,
mantissa: 1,
thousandSeparated: true,
trimMantissa: true
}

useMemo(async () => {
if (token && tokenData) {
const value = await getTurnoutValue(
Expand Down Expand Up @@ -110,8 +122,12 @@ export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[];
{choice && choice.walletAddresses ? (
<Typography color="textPrimary" variant="body2">
{choice.walletAddresses.length} Voters -{" "}
{nFormatter(calculateChoiceTotal(choice.walletAddresses, tokenData?.decimals), 1)}{" "}
{tokenData?.symbol}
{!isMobile
? nFormatter(calculateChoiceTotal(choice.walletAddresses, isXTZ ? 6 : tokenData?.decimals), 1)
: numbro(calculateChoiceTotal(choice.walletAddresses, isXTZ ? 6 : tokenData?.decimals)).format(
formatConfig
)}{" "}
{isXTZ ? "XTZ" : tokenData?.symbol}
</Typography>
) : null}
</Grid>
Expand All @@ -121,25 +137,31 @@ export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[];
<LinearProgress
style={{ width: "100%", marginRight: "4px" }}
color="secondary"
value={calculateWeight(
poll?.totalSupplyAtReferenceBlock,
calculateChoiceTotal(choice.walletAddresses, tokenData?.decimals),
tokenData?.decimals
)
.dp(2, 1)
.toNumber()}
value={
!poll?.isXTZ
? calculateWeight(
poll?.totalSupplyAtReferenceBlock,
calculateChoiceTotal(choice.walletAddresses, tokenData?.decimals),
tokenData?.decimals
)
.dp(2, 1)
.toNumber()
: calculateWeightXTZ(choice, totalVoters)
}
variant="determinate"
/>
</Grid>
<Grid item xs={2} lg={1} sm={1} container justifyContent="flex-end">
<Typography color="textPrimary" variant="body2">
{calculateWeight(
poll?.totalSupplyAtReferenceBlock,
calculateChoiceTotal(choice.walletAddresses, tokenData?.decimals),
tokenData?.decimals
)
.dp(2, 1)
.toString()}
{!poll?.isXTZ
? calculateWeight(
poll?.totalSupplyAtReferenceBlock,
calculateChoiceTotal(choice.walletAddresses, isXTZ ? 6 : tokenData?.decimals),
isXTZ ? 6 : tokenData?.decimals
)
.dp(2, 1)
.toString()
: numbro(calculateWeightXTZ(choice, totalVoters)).format(formatConfig)}
%
</Typography>
</Grid>
Expand All @@ -155,7 +177,7 @@ export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[];
<Typography color="textPrimary" variant="body1" onClick={() => handleClickOpen()}>
Votes
</Typography>
{isTokenDelegationSupported && turnout ? (
{isTokenDelegationSupported && turnout && !poll?.isXTZ ? (
<Typography color="textPrimary" variant="body1">
({turnout.toFixed(2)} % Turnout)
</Typography>
Expand All @@ -174,29 +196,32 @@ export const VoteDetails: React.FC<{ poll: Poll | undefined; choices: Choice[];
justifyContent={isMobileSmall ? "flex-start" : "flex-end"}
>
<Typography color="textPrimary" variant="body1">
{nFormatter(calculateProposalTotal(choices, tokenData?.decimals), 1)}
</Typography>
<Typography color="textPrimary" variant="body1">
{poll?.tokenSymbol}
{numbro(calculateProposalTotal(choices, isXTZ ? 6 : tokenData?.decimals)).format(formatConfig)}
</Typography>
<Typography color="textPrimary" variant="body1">
(
{getTreasuryPercentage(
calculateProposalTotal(choices, tokenData?.decimals),
poll?.totalSupplyAtReferenceBlock,
tokenData?.decimals
)
.dp(5, 1)
.toString()}
% of Total Supply)
{isXTZ ? "XTZ" : poll?.tokenSymbol}
</Typography>
{!poll?.isXTZ && (
<Typography color="textPrimary" variant="body1">
(
{getTreasuryPercentage(
calculateProposalTotal(choices, isXTZ ? 6 : tokenData?.decimals),
poll?.totalSupplyAtReferenceBlock,
isXTZ ? 6 : tokenData?.decimals
)
.dp(5, 1)
.toString()}
% of Total Supply)
</Typography>
)}
</Grid>
</LegendContainer>
<VotesDialog
decimals={tokenData?.decimals ? tokenData?.decimals : ""}
symbol={tokenData?.symbol ? tokenData?.symbol : ""}
symbol={isXTZ ? "XTZ" : tokenData?.symbol ? tokenData?.symbol : ""}
choices={votes}
open={open}
isXTZ={isXTZ}
handleClose={handleClose}
/>
</GraphicsContainer>
Expand Down
21 changes: 14 additions & 7 deletions src/modules/lite/explorer/components/VotesDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React, { useEffect, useState } from "react"
import React from "react"
import {
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
styled,
Typography,
Button,
Expand All @@ -15,9 +12,10 @@ import {
import { toShortAddress } from "services/contracts/utils"
import { FileCopyOutlined } from "@material-ui/icons"
import { Choice } from "models/Choice"
import { formatByDecimals, getTotalVoters } from "services/lite/utils"
import { calculateWeightXTZ, formatByDecimals, getTotalVoters } from "services/lite/utils"
import { useNotification } from "modules/common/hooks/useNotification"
import { ResponsiveDialog } from "modules/explorer/components/ResponsiveDialog"
import numbro from "numbro"

const CustomContent = styled(DialogContent)(({ theme }) => ({
padding: 0,
Expand Down Expand Up @@ -60,13 +58,19 @@ const Row = styled(Grid)(({ theme }) => ({
}
}))

const formatConfig = {
mantissa: 4,
trimMantissa: true
}

export const VotesDialog: React.FC<{
open: boolean
handleClose: any
choices: Choice[]
symbol: string
decimals: string
}> = ({ open, handleClose, choices, symbol, decimals }) => {
isXTZ: boolean
}> = ({ open, handleClose, choices, symbol, decimals, isXTZ }) => {
const descriptionElementRef = React.useRef<HTMLElement>(null)
const openNotification = useNotification()

Expand Down Expand Up @@ -143,7 +147,10 @@ export const VotesDialog: React.FC<{
>
<Typography color="textPrimary" variant="body1">
{" "}
{formatByDecimals(choice.balanceAtReferenceBlock, decimals)} {symbol}{" "}
{!isXTZ
? formatByDecimals(choice.balanceAtReferenceBlock, decimals)
: numbro(formatByDecimals(choice.balanceAtReferenceBlock, "6")).format(formatConfig)}{" "}
{symbol}{" "}
</Typography>
</Grid>
</Row>
Expand Down
Loading

0 comments on commit a193668

Please sign in to comment.