Skip to content

Commit

Permalink
Temporary solution for very large numbers (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhay authored Jan 20, 2024
1 parent 4d7f356 commit f85e079
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions components/ProposalVoteCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export const ProposalVoteCard = ({
...r,
index,
percent: totalVotes?.isZero()
? 100 / proposal?.choices.length
: (r.weight.toNumber() / totalVotes.toNumber()) * 100,
? BigInt(100) / BigInt(proposal?.choices.length)
: (BigInt(r.weight.toString()) / BigInt(totalVotes.toString())) * BigInt(100),
}))
.sort((a, b) => b.percent - a.percent);
.sort((a, b) => (a.percent < b.percent) ? -1 : ((a.percent > b.percent) ? 1 : 0));
return { results, totalVotes };
}, [proposal?.choices]);

Expand Down
10 changes: 2 additions & 8 deletions pages/[network]/proposals/[proposalKey].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,16 @@ import { format } from "date-fns";
import Link from "next/link";
import { useRouter } from "next/router";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useAsync } from "react-async-hook";
import ReactMarkdown from "react-markdown";
import ContentSection from "../../../components/ContentSection";
import CopyableText from "../../../components/CopyableText";
import MetaTags from "../../../components/MetaTags";
import Page from "../../../components/Page";
import VoteOptionsSection from "../../../components/VoteOptionsSection";
import VoteResults from "../../../components/VoteResults";
import { useNetwork } from "../../../hooks/useNetwork";
import { humanReadable } from "../../../utils/formatting";
import { AiFillCaretDown, AiFillCaretUp } from "react-icons/ai";
import { VoteBreakdown } from "../../../components/VoteBreakdown";
import Button, {
LinkButton,
SecondaryButton,
} from "../../../components/Button";
import { SecondaryButton } from "../../../components/Button";
import { FaArrowLeft } from "react-icons/fa6";
import { FaGithub } from "react-icons/fa";
import { FaXTwitter } from "react-icons/fa6";
Expand Down Expand Up @@ -91,7 +85,7 @@ const VoteDetailsPage = ({
index,
percent: totalVotes?.isZero()
? 100 / choices.length
: (r.weight.toNumber() / totalVotes.toNumber()) * 100,
: (BigInt(r.weight.toString()) / BigInt(totalVotes.toString()) * BigInt(100)),
}));
return { results, totalVotes };
}, [choices]);
Expand Down

0 comments on commit f85e079

Please sign in to comment.