diff --git a/src/modules/lite/explorer/components/VoteDetails.tsx b/src/modules/lite/explorer/components/VoteDetails.tsx index 24ae4903..ad03a3d0 100644 --- a/src/modules/lite/explorer/components/VoteDetails.tsx +++ b/src/modules/lite/explorer/components/VoteDetails.tsx @@ -10,6 +10,7 @@ import { calculateChoiceTotal, calculateProposalTotal, calculateWeight, + calculateWeightXTZ, calculateXTZTotal, getTotalVoters, getTreasuryPercentage, @@ -74,13 +75,6 @@ export const VoteDetails: React.FC<{ setOpen(true) } - const calculateWeightXTZ = (choice: Choice) => { - if (choice && choice.walletAddresses.length > 0) { - return (choice.walletAddresses.length / totalVoters) * 100 - } - return 0 - } - const handleClose = () => { setOpen(false) } @@ -152,7 +146,7 @@ export const VoteDetails: React.FC<{ ) .dp(2, 1) .toNumber() - : calculateWeightXTZ(choice) + : calculateWeightXTZ(choice, totalVoters) } variant="determinate" /> @@ -167,7 +161,7 @@ export const VoteDetails: React.FC<{ ) .dp(2, 1) .toString() - : numbro(calculateWeightXTZ(choice)).format(formatConfig)} + : numbro(calculateWeightXTZ(choice, totalVoters)).format(formatConfig)} % @@ -227,6 +221,7 @@ export const VoteDetails: React.FC<{ symbol={isXTZ ? "XTZ" : tokenData?.symbol ? tokenData?.symbol : ""} choices={votes} open={open} + isXTZ={isXTZ} handleClose={handleClose} /> diff --git a/src/modules/lite/explorer/components/VotesDialog.tsx b/src/modules/lite/explorer/components/VotesDialog.tsx index d756a796..56d843f6 100644 --- a/src/modules/lite/explorer/components/VotesDialog.tsx +++ b/src/modules/lite/explorer/components/VotesDialog.tsx @@ -1,10 +1,7 @@ -import React, { useEffect, useState } from "react" +import React from "react" import { - Dialog, DialogActions, DialogContent, - DialogContentText, - DialogTitle, styled, Typography, Button, @@ -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, @@ -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(null) const openNotification = useNotification() @@ -143,7 +147,10 @@ export const VotesDialog: React.FC<{ > {" "} - {formatByDecimals(choice.balanceAtReferenceBlock, decimals)} {symbol}{" "} + {!isXTZ + ? formatByDecimals(choice.balanceAtReferenceBlock, decimals) + : numbro(formatByDecimals(choice.balanceAtReferenceBlock, "6")).format(formatConfig)}{" "} + {symbol}{" "} diff --git a/src/services/lite/utils.ts b/src/services/lite/utils.ts index 6bd525e1..0959b4ad 100644 --- a/src/services/lite/utils.ts +++ b/src/services/lite/utils.ts @@ -103,6 +103,13 @@ export const calculateChoiceTotal = (choice_voters: any[], decimals: any) => { return result } +export const calculateWeightXTZ = (choice: Choice, totalVoters: number) => { + if (choice && choice.walletAddresses.length > 0) { + return (choice.walletAddresses.length / totalVoters) * 100 + } + return 0 +} + export const calculateXTZTotal = (choices: Choice[] | undefined) => { let totalVoters = 0 if (choices) {