diff --git a/cypress/integration/polling/poll-detail.spec.ts b/cypress/integration/polling/poll-detail.spec.ts index 21600b230..085381b88 100644 --- a/cypress/integration/polling/poll-detail.spec.ts +++ b/cypress/integration/polling/poll-detail.spec.ts @@ -41,7 +41,7 @@ describe('/polling detail page', async () => { setAccount(TEST_ACCOUNTS.normal, () => { // Checks that the leading option is visible - cy.contains(/Leading option: Yes with/).should('be.visible'); + cy.contains(/Leading option: No with/).should('be.visible'); // Clicks on the vote breakdown tab cy.get('[data-testid="tab-Vote Breakdown"]').click(); diff --git a/modules/address/components/AddressDetail.tsx b/modules/address/components/AddressDetail.tsx index 68815e13c..03038e507 100644 --- a/modules/address/components/AddressDetail.tsx +++ b/modules/address/components/AddressDetail.tsx @@ -129,7 +129,10 @@ export function AddressDetail({ address }: PropTypes): React.ReactElement { - + diff --git a/modules/comments/components/ExecutiveComments.tsx b/modules/comments/components/ExecutiveComments.tsx index ffd272e1c..3ff89c831 100644 --- a/modules/comments/components/ExecutiveComments.tsx +++ b/modules/comments/components/ExecutiveComments.tsx @@ -3,28 +3,25 @@ import { useMemo, useState } from 'react'; import BigNumber from 'bignumber.js'; import Stack from 'modules/app/components/layout/layouts/Stack'; -import { Proposal } from '../../executive/types'; import FilterButton from 'modules/app/components/FilterButton'; import { MenuItem } from '@reach/menu-button'; -import { ParsedExecutiveComments } from '../types/comments'; +import { ParsedExecutiveComments, CommentSortOption } from '../types/comments'; import CommentItem from './CommentItem'; export default function ExecutiveComments({ - proposal, comments, ...props }: { - proposal: Proposal; comments: ParsedExecutiveComments[] | undefined; }): JSX.Element { - const [commentSortBy, setCommentSortBy] = useState('latest'); + const [commentSortBy, setCommentSortBy] = useState(CommentSortOption.MKR_AMOUNT); const sortedComments = useMemo(() => { return (comments || []).sort((a, b) => { - if (commentSortBy === 'Latest') { + if (commentSortBy === CommentSortOption.LATEST) { const aDate = a.comment.date || 0; const bDate = b.comment.date || 0; return aDate < bDate ? 1 : aDate === bDate ? 0 : -1; - } else if (commentSortBy === 'MKR Amount') { + } else if (commentSortBy === CommentSortOption.MKR_AMOUNT) { const aWeight = new BigNumber(a.comment.voterWeight || 0); const bWeight = new BigNumber(b.comment.voterWeight || 0); return aWeight.lt(bWeight) ? 1 : aWeight.eq(bWeight) ? 0 : -1; @@ -48,33 +45,37 @@ export default function ExecutiveComments({ Comments ({comments ? comments.length : '0'}) `Sort by ${commentSortBy !== 'Latest' ? commentSortBy : 'latest'}`} + name={() => + `Sort by ${ + commentSortBy !== CommentSortOption.LATEST ? commentSortBy : CommentSortOption.LATEST + }` + } listVariant="menubuttons.default.list" {...props} > setCommentSortBy('Latest')} + onSelect={() => setCommentSortBy(CommentSortOption.LATEST)} sx={{ variant: 'menubuttons.default.item', - fontWeight: commentSortBy === 'Latest' ? 'bold' : undefined + fontWeight: commentSortBy === CommentSortOption.LATEST ? 'bold' : undefined }} > Latest setCommentSortBy('Oldest')} + onSelect={() => setCommentSortBy(CommentSortOption.OLDEST)} sx={{ variant: 'menubuttons.default.item', - fontWeight: commentSortBy === 'Oldest' ? 'bold' : undefined + fontWeight: commentSortBy === CommentSortOption.OLDEST ? 'bold' : undefined }} > Oldest setCommentSortBy('MKR Amount')} + onSelect={() => setCommentSortBy(CommentSortOption.MKR_AMOUNT)} sx={{ variant: 'menubuttons.default.item', - fontWeight: commentSortBy === 'MKR Amount' ? 'bold' : undefined + fontWeight: commentSortBy === CommentSortOption.MKR_AMOUNT ? 'bold' : undefined }} > MKR Amount diff --git a/modules/comments/components/PollComments.tsx b/modules/comments/components/PollComments.tsx index 1c50d5f03..299667bfb 100644 --- a/modules/comments/components/PollComments.tsx +++ b/modules/comments/components/PollComments.tsx @@ -9,7 +9,8 @@ import { Poll, PollTally, PollTallyVote } from '../../polling/types'; import PollCommentItem from './PollCommentItem'; import { PollCommentsAPIResponseItem, - PollCommentsAPIResponseItemWithWeight + PollCommentsAPIResponseItemWithWeight, + CommentSortOption } from 'modules/comments/types/comments'; export default function PollComments({ @@ -21,7 +22,7 @@ export default function PollComments({ tally?: PollTally; poll: Poll; }): JSX.Element { - const [commentSortBy, setCommentSortBy] = useState('latest'); + const [commentSortBy, setCommentSortBy] = useState(CommentSortOption.MKR_AMOUNT); const getCommentVote = (item: PollCommentsAPIResponseItem): PollTallyVote | undefined => { const tallyVote = tally?.votesByAddress?.find(i => { @@ -64,11 +65,11 @@ export default function PollComments({ const sortedComments = useMemo(() => { return mergedComments.sort((a, b) => { - if (commentSortBy === 'latest') { + if (commentSortBy === CommentSortOption.LATEST) { const aDate = new Date(a.comment.date).getTime() || 0; const bDate = new Date(b.comment.date).getTime() || 0; return aDate < bDate ? 1 : aDate === bDate ? 0 : -1; - } else if (commentSortBy === 'MKR Amount') { + } else if (commentSortBy === CommentSortOption.MKR_AMOUNT) { return a.comment.voterWeight.lt(b.comment.voterWeight) ? 1 : a.comment.voterWeight.eq(b.comment.voterWeight) @@ -103,28 +104,28 @@ export default function PollComments({ `Sort by ${commentSortBy}`} listVariant="menubuttons.default.list"> setCommentSortBy('latest')} + onSelect={() => setCommentSortBy(CommentSortOption.LATEST)} sx={{ variant: 'menubuttons.default.item', - fontWeight: commentSortBy === 'latest' ? 'bold' : undefined + fontWeight: commentSortBy === CommentSortOption.LATEST ? 'bold' : undefined }} > Latest setCommentSortBy('oldest')} + onSelect={() => setCommentSortBy(CommentSortOption.OLDEST)} sx={{ variant: 'menubuttons.default.item', - fontWeight: commentSortBy === 'oldest' ? 'bold' : undefined + fontWeight: commentSortBy === CommentSortOption.OLDEST ? 'bold' : undefined }} > Oldest setCommentSortBy('MKR Amount')} + onSelect={() => setCommentSortBy(CommentSortOption.MKR_AMOUNT)} sx={{ variant: 'menubuttons.default.item', - fontWeight: commentSortBy === 'MKR Amount' ? 'bold' : undefined + fontWeight: commentSortBy === CommentSortOption.MKR_AMOUNT ? 'bold' : undefined }} > MKR Amount diff --git a/modules/comments/types/comments.d.ts b/modules/comments/types/comments.ts similarity index 91% rename from modules/comments/types/comments.d.ts rename to modules/comments/types/comments.ts index 0df2a6bac..cca7f8cf1 100644 --- a/modules/comments/types/comments.d.ts +++ b/modules/comments/types/comments.ts @@ -1,7 +1,6 @@ import BigNumber from 'bignumber.js'; import { AddressApiResponse } from 'modules/address/types/addressApiResponse'; -import { ExecutiveComment } from './executiveComment'; -import { PollComment, PollCommentWithWeight } from './pollComments'; +import { SupportedNetworks } from 'modules/web3/constants/networks'; export type PollCommentsAPIResponseItem = { comment: PollComment; @@ -85,3 +84,9 @@ export type PollCommentWithWeight = PollComment & { }; export type CommentFromDB = PollCommentFromDB | ExecutiveCommentFromDB; + +export enum CommentSortOption { + LATEST = 'latest', + OLDEST = 'oldest', + MKR_AMOUNT = 'MKR amount' +} diff --git a/modules/delegates/components/DelegateCard.tsx b/modules/delegates/components/DelegateCard.tsx index 9da351dde..074e2391a 100644 --- a/modules/delegates/components/DelegateCard.tsx +++ b/modules/delegates/components/DelegateCard.tsx @@ -57,7 +57,7 @@ export function DelegateCard({ delegate }: PropTypes): React.ReactElement { {delegate.cuMember && } diff --git a/modules/delegates/components/DelegateDetail.tsx b/modules/delegates/components/DelegateDetail.tsx index a4a6a6c49..cad812068 100644 --- a/modules/delegates/components/DelegateDetail.tsx +++ b/modules/delegates/components/DelegateDetail.tsx @@ -181,7 +181,7 @@ export function DelegateDetail({ delegate }: PropTypes): React.ReactElement { {delegate.cuMember && } diff --git a/modules/delegates/hooks/useLastVote.ts b/modules/delegates/hooks/useLastVote.ts deleted file mode 100644 index 5b554cd38..000000000 --- a/modules/delegates/hooks/useLastVote.ts +++ /dev/null @@ -1,27 +0,0 @@ -import useSWR from 'swr'; -import { PollVoteHistory } from 'modules/polling/types/pollVoteHistory'; -import { fetchJson } from 'lib/fetchJson'; -import { SupportedNetworks } from 'modules/web3/constants/networks'; - -type LastVoteResponse = { - data?: Record; - loading: boolean; - error?: any; -}; - -export const useLastVote = (voteDelegateAddress: string, network: SupportedNetworks): LastVoteResponse => { - const { data, error } = useSWR<{ lastVote: PollVoteHistory }>( - `/api/address/${voteDelegateAddress}/last-vote?network=${network}`, - fetchJson, - { - revalidateOnFocus: false, - refreshInterval: 0 - } - ); - - return { - data, - loading: !data && !error, - error - }; -}; diff --git a/modules/executive/api/fetchExecutives.ts b/modules/executive/api/fetchExecutives.ts index 5fc052c7a..b643eebb7 100644 --- a/modules/executive/api/fetchExecutives.ts +++ b/modules/executive/api/fetchExecutives.ts @@ -151,7 +151,7 @@ export async function getExecutiveProposal( // Use goerli as a Key for Goerli fork. In order to pick the the current executives const currentNetwork = net === SupportedNetworks.GOERLIFORK ? SupportedNetworks.GOERLI : net; - const proposals = await getGithubExecutivesWithMKR(currentNetwork); + const proposals = await getGithubExecutives(currentNetwork); const proposal = proposals.find(proposal => proposal.key === proposalId || proposal.address === proposalId); if (!proposal) return null; diff --git a/modules/gql/queries/uniswapV3MkrSupply.ts b/modules/gql/queries/uniswapV3MkrSupply.ts index 62ee8fdaf..ec896370e 100644 --- a/modules/gql/queries/uniswapV3MkrSupply.ts +++ b/modules/gql/queries/uniswapV3MkrSupply.ts @@ -4,7 +4,7 @@ export const uniswapV3MkrSupply = gql` query uniswapV3MkrSupply($argMkrAddress: String!) { token(id: $argMkrAddress) { symbol - totalSupply + totalValueLocked } } `; diff --git a/modules/mkr/components/MkrLiquiditySidebar.tsx b/modules/mkr/components/MkrLiquiditySidebar.tsx index 5f3156918..92ff00d28 100644 --- a/modules/mkr/components/MkrLiquiditySidebar.tsx +++ b/modules/mkr/components/MkrLiquiditySidebar.tsx @@ -50,7 +50,9 @@ async function getUniswapV3Mkr(mkrAddress: string) { uniswapV3MkrSupply, { argMkrAddress: mkrAddress } ); - return resp?.token?.totalSupply ? BigNumber.from(resp.token.totalSupply).mul(WAD) : BigNumber.from(0); + return resp?.token?.totalValueLocked + ? parseUnits(parseInt(resp.token.totalValueLocked).toString()) + : BigNumber.from(0); } async function getCompoundMkr(network) { diff --git a/modules/polling/api/fetchAllCurrentVotes.ts b/modules/polling/api/fetchAllCurrentVotes.ts index ed5dd072b..7a3b8ceb2 100644 --- a/modules/polling/api/fetchAllCurrentVotes.ts +++ b/modules/polling/api/fetchAllCurrentVotes.ts @@ -2,7 +2,7 @@ import { gqlRequest } from 'modules/gql/gqlRequest'; import { allCurrentVotes } from 'modules/gql/queries/allCurrentVotes'; import { SupportedNetworks } from 'modules/web3/constants/networks'; import { networkNameToChainId } from 'modules/web3/helpers/chain'; -import { parseRawOptinIdRankedChoiceOption } from '../helpers/parseRawOptionIdRankedChoiceOption'; +import { parseRankedChoiceRawOptionId } from '../helpers/parseRankedChoiceRawOptionId'; import { PollVote } from '../types'; export async function fetchAllCurrentVotes(address: string, network: SupportedNetworks): Promise { @@ -14,7 +14,7 @@ export async function fetchAllCurrentVotes(address: string, network: SupportedNe // Parse the rankedChoice option const res: PollVote[] = data.allCurrentVotes.nodes.map(o => { - const rankedChoiceOption = parseRawOptinIdRankedChoiceOption(o.optionIdRaw); + const rankedChoiceOption = parseRankedChoiceRawOptionId(o.optionIdRaw); return { ...o, rankedChoiceOption diff --git a/modules/polling/api/fetchLastPollvote.ts b/modules/polling/api/fetchLastPollvote.ts index 210df517d..00b762b55 100644 --- a/modules/polling/api/fetchLastPollvote.ts +++ b/modules/polling/api/fetchLastPollvote.ts @@ -2,7 +2,7 @@ import { gqlRequest } from 'modules/gql/gqlRequest'; import { lastPollVote } from 'modules/gql/queries/lastPollVote'; import { SupportedNetworks } from 'modules/web3/constants/networks'; import { networkNameToChainId } from 'modules/web3/helpers/chain'; -import { parseRawOptinIdRankedChoiceOption } from '../helpers/parseRawOptionIdRankedChoiceOption'; +import { parseRankedChoiceRawOptionId } from '../helpers/parseRankedChoiceRawOptionId'; import { PollVote } from '../types'; export async function fetchLastPollVote( @@ -17,7 +17,7 @@ export async function fetchLastPollVote( // Parse the rankedChoice option const res: PollVote[] = data.allCurrentVotes.nodes.map(o => { - const rankedChoiceOption = parseRawOptinIdRankedChoiceOption(o.optionIdRaw); + const rankedChoiceOption = parseRankedChoiceRawOptionId(o.optionIdRaw); return { ...o, rankedChoiceOption diff --git a/modules/polling/api/fetchPollTally.ts b/modules/polling/api/fetchRawPollTally.ts similarity index 58% rename from modules/polling/api/fetchPollTally.ts rename to modules/polling/api/fetchRawPollTally.ts index 1e5f82644..4967c195a 100644 --- a/modules/polling/api/fetchPollTally.ts +++ b/modules/polling/api/fetchRawPollTally.ts @@ -1,25 +1,14 @@ import { SupportedNetworks } from 'modules/web3/constants/networks'; -import { config } from 'lib/config'; -import { fsCacheGet, fsCacheSet } from 'lib/fscache'; import { PollVoteType, RawPollTally } from 'modules/polling/types'; import { POLL_VOTE_TYPE } from 'modules/polling/polling.constants'; import { fetchTallyPlurality } from './fetchTallyPlurality'; import { fetchTallyRankedChoice } from './fetchTallyRankedChoice'; -export async function fetchPollTally( +export async function fetchRawPollTally( pollId: number, voteType: PollVoteType, - useCache: boolean, network: SupportedNetworks ): Promise { - const cacheKey = `tally-${pollId}`; - if (config.USE_FS_CACHE && useCache) { - const cachedTally = fsCacheGet(cacheKey, network); - if (cachedTally) { - return JSON.parse(cachedTally); - } - } - let tally; if (voteType === POLL_VOTE_TYPE.PLURALITY_VOTE) { tally = await fetchTallyPlurality(pollId, network); @@ -27,9 +16,5 @@ export async function fetchPollTally( tally = await fetchTallyRankedChoice(pollId, network); } - if (config.USE_FS_CACHE && useCache) { - fsCacheSet(cacheKey, JSON.stringify(tally), network); - } - return tally; } diff --git a/modules/polling/api/fetchVotesByAddress.ts b/modules/polling/api/fetchVotesByAddress.ts index 5aa90666b..e75a55f20 100644 --- a/modules/polling/api/fetchVotesByAddress.ts +++ b/modules/polling/api/fetchVotesByAddress.ts @@ -4,9 +4,9 @@ import { PollTallyVote } from '../types'; import { gqlRequest } from 'modules/gql/gqlRequest'; import { voteAddressMkrWeightsAtTime } from 'modules/gql/queries/voteAddressMkrWeightsAtTime'; import { networkNameToChainId } from 'modules/web3/helpers/chain'; -import { parseRawOptinIdRankedChoiceOption } from '../helpers/parseRawOptionIdRankedChoiceOption'; +import { parseRankedChoiceRawOptionId } from '../helpers/parseRankedChoiceRawOptionId'; -export async function fetchVotesByAddresForPoll( +export async function fetchVotesByAddressForPoll( pollId: number, endUnix: number, network: SupportedNetworks @@ -22,7 +22,7 @@ export async function fetchVotesByAddresForPoll( if (!results) return []; const votes = results.map(vote => { - const rankedChoiceOption = parseRawOptinIdRankedChoiceOption(vote.optionIdRaw); + const rankedChoiceOption = parseRankedChoiceRawOptionId(vote.optionIdRaw); return { ...vote, diff --git a/modules/polling/components/LastVoted.tsx b/modules/polling/components/LastVoted.tsx index 69201ae4d..fa9d6367e 100644 --- a/modules/polling/components/LastVoted.tsx +++ b/modules/polling/components/LastVoted.tsx @@ -1,7 +1,8 @@ -import { Text, Flex, ThemeUIStyleObject } from 'theme-ui'; +import { Box, Text, Flex, ThemeUIStyleObject } from 'theme-ui'; import React from 'react'; import { formatDateWithTime, formatTimeAgo } from 'lib/datetime'; import Icon from 'modules/app/components/Icon'; +import Skeleton from 'modules/app/components/SkeletonThemed'; export default function LastVoted({ expired, @@ -10,7 +11,7 @@ export default function LastVoted({ styles }: { expired: boolean; - date?: string | number; + date?: string | null; left?: boolean; styles?: ThemeUIStyleObject; }): React.ReactElement { @@ -37,12 +38,22 @@ export default function LastVoted({ } }; + const loading = typeof date === 'undefined'; + + if (loading) { + return ( + + + + ); + } + const isLongerThan14Days = date && Date.now() - new Date(date).getTime() > 14 * 24 * 60 * 60 * 1000; const isLongerThan21Days = date && Date.now() - new Date(date).getTime() > 21 * 24 * 60 * 60 * 1000; const isLongerThan28Days = date && Date.now() - new Date(date).getTime() > 28 * 24 * 60 * 60 * 1000; const lastVoteDate = date - ? `LAST VOTED ${isLongerThan14Days ? formatTimeAgo(date) : formatDateWithTime(date)}` + ? `LAST VOTED ${isLongerThan14Days ? formatTimeAgo(date ?? '') : formatDateWithTime(date ?? '')}` : 'NO VOTE HISTORY'; return ( @@ -51,6 +62,7 @@ export default function LastVoted({ flexDirection: left ? 'row-reverse' : ['row-reverse', 'row'], justifyContent: left ? 'flex-end' : 'flex-start', alignItems: 'center', + height: '18px', ...styles }} > diff --git a/modules/polling/helpers/__tests__/getPollTally.spec.ts b/modules/polling/helpers/__tests__/getPollTally.spec.ts index 09ac60f57..73923897b 100644 --- a/modules/polling/helpers/__tests__/getPollTally.spec.ts +++ b/modules/polling/helpers/__tests__/getPollTally.spec.ts @@ -1,11 +1,12 @@ import { getPollTally } from '../getPollTally'; -import { fetchPollTally } from '../../api/fetchPollTally'; -import { fetchVotesByAddresForPoll } from '../../api/fetchVotesByAddress'; +import { fetchRawPollTally } from '../../api/fetchRawPollTally'; +import { fetchVotesByAddressForPoll } from '../../api/fetchVotesByAddress'; import { PluralityResult, Poll } from '../../types'; import BigNumber from 'bignumber.js'; import * as PRT from '../parseRawTally'; +import { SupportedNetworks } from 'modules/web3/constants/networks'; -jest.mock('../../api/fetchPollTally'); +jest.mock('../../api/fetchRawPollTally'); jest.mock('../../api/fetchVotesByAddress'); const mockPoll: Poll = { @@ -49,7 +50,7 @@ const expectedPRTArg = { describe('getPollTally', () => { // We add this test to check that we always return a non-empty options object to the FE so the components that rely on populated data won't crash it('Returns a correct tally for plurality votes even when the options are empty', async () => { - (fetchPollTally as jest.Mock).mockReturnValue( + (fetchRawPollTally as jest.Mock).mockReturnValue( Promise.resolve({ totalMkrParticipation: new BigNumber(0), winner: '0', @@ -57,11 +58,11 @@ describe('getPollTally', () => { options: {} }) ); - (fetchVotesByAddresForPoll as jest.Mock).mockReturnValue(Promise.resolve([])); + (fetchVotesByAddressForPoll as jest.Mock).mockReturnValue(Promise.resolve([])); jest.spyOn(PRT, 'parseRawPollTally'); const poll = mockPoll; - const tally = await getPollTally(poll); + const tally = await getPollTally(poll, SupportedNetworks.GOERLIFORK); const results = tally.results as PluralityResult[]; // When no options returned with tally, we manually add them in 'getPollTally' diff --git a/modules/polling/helpers/getPollTally.ts b/modules/polling/helpers/getPollTally.ts index c6339f61c..ba7c7a722 100644 --- a/modules/polling/helpers/getPollTally.ts +++ b/modules/polling/helpers/getPollTally.ts @@ -1,29 +1,38 @@ import { SupportedNetworks } from 'modules/web3/constants/networks'; import { backoffRetry } from 'lib/utils'; -import { fetchPollTally } from '../api/fetchPollTally'; -import { fetchVotesByAddresForPoll } from '../api/fetchVotesByAddress'; -import { POLL_VOTE_TYPE } from '../polling.constants'; -import { Poll, PollTally, PollVoteType, RawPollTally, RawPollTallyRankedChoice } from '../types'; -import { parseRawPollTally } from './parseRawTally'; import BigNumber from 'bignumber.js'; +import { config } from 'lib/config'; +import { fsCacheGet, fsCacheSet } from 'lib/fscache'; +import { fetchRawPollTally } from 'modules/polling/api/fetchRawPollTally'; +import { fetchVotesByAddressForPoll } from 'modules/polling/api/fetchVotesByAddress'; +import { POLL_VOTE_TYPE } from 'modules/polling/polling.constants'; +import { Poll, PollTally, PollVoteType, RawPollTally, RawPollTallyRankedChoice } from 'modules/polling/types'; +import { parseRawPollTally } from 'modules/polling/helpers/parseRawTally'; +import { isActivePoll } from 'modules/polling/helpers/utils'; export async function getPollTally(poll: Poll, network: SupportedNetworks): Promise { + const cacheKey = `${network}-parsed-tally-${poll.pollId}`; + if (config.USE_FS_CACHE) { + const cachedTally = fsCacheGet(cacheKey, network); + if (cachedTally) { + return JSON.parse(cachedTally); + } + } + // if poll vote type is unknown, treat as ranked choice const voteType: PollVoteType = poll.voteType || POLL_VOTE_TYPE.RANKED_VOTE; // Builds raw poll tally - const tally: RawPollTally = await backoffRetry(3, () => - fetchPollTally(poll.pollId, voteType, false, network) - ); + const tally: RawPollTally = await backoffRetry(3, () => fetchRawPollTally(poll.pollId, voteType, network)); const endUnix = new Date(poll.endDate).getTime() / 1000; - const votesByAddress = await fetchVotesByAddresForPoll(poll.pollId, endUnix, network); + const votesByAddress = await fetchVotesByAddressForPoll(poll.pollId, endUnix, network); const totalMkrParticipation = tally.totalMkrParticipation; const winner: string = tally.winner || ''; const numVoters = tally.numVoters; - const parsedTally = { + const tallyObject = { pollVoteType: voteType, options: Object.keys(tally.options).length > 0 @@ -48,8 +57,13 @@ export async function getPollTally(poll: Poll, network: SupportedNetworks): Prom votesByAddress } as RawPollTally; - if ('rounds' in tally) (parsedTally as RawPollTallyRankedChoice).rounds = tally.rounds; + if ('rounds' in tally) (tallyObject as RawPollTallyRankedChoice).rounds = tally.rounds; + + const parsedTally = parseRawPollTally(tallyObject, poll); + + if (config.USE_FS_CACHE && !isActivePoll(poll)) { + fsCacheSet(cacheKey, JSON.stringify(parsedTally), network); + } - // Return parsed tally - return parseRawPollTally(parsedTally, poll); + return parsedTally; } diff --git a/modules/polling/helpers/parseRawOptionIdRankedChoiceOption.ts b/modules/polling/helpers/parseRankedChoiceRawOptionId.ts similarity index 81% rename from modules/polling/helpers/parseRawOptionIdRankedChoiceOption.ts rename to modules/polling/helpers/parseRankedChoiceRawOptionId.ts index 67e659a4e..8418276a9 100644 --- a/modules/polling/helpers/parseRawOptionIdRankedChoiceOption.ts +++ b/modules/polling/helpers/parseRankedChoiceRawOptionId.ts @@ -1,6 +1,6 @@ import { paddedArray, toBuffer } from 'lib/utils'; -export function parseRawOptinIdRankedChoiceOption(rawValue?: string): number[] { +export function parseRankedChoiceRawOptionId(rawValue?: string): number[] { let rankedChoiceOption: number[] = []; if (rawValue) { const ballotBuffer = toBuffer(rawValue, { endian: 'little' }); diff --git a/package.json b/package.json index e21918747..8df5d2122 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "governance-portal-v2", "license": "AGPL-3.0-only", - "version": "0.4.0", + "version": "0.4.1", "jest": { "testTimeout": 7000 }, diff --git a/pages/api/address/[address]/last-vote.ts b/pages/api/address/[address]/last-vote.ts deleted file mode 100644 index ce75dd865..000000000 --- a/pages/api/address/[address]/last-vote.ts +++ /dev/null @@ -1,48 +0,0 @@ -import invariant from 'tiny-invariant'; -import { NextApiRequest, NextApiResponse } from 'next'; -import { isSupportedNetwork } from 'modules/web3/helpers/networks'; -import { fetchAddressPollVoteHistory } from 'modules/polling/api/fetchAddressPollVoteHistory'; -import { PollVoteHistory } from 'modules/polling/types/pollVoteHistory'; -import withApiHandler from 'modules/app/api/withApiHandler'; -import { DEFAULT_NETWORK } from 'modules/web3/constants/networks'; -import { resolveENS } from 'modules/web3/helpers/ens'; -import { getContracts } from 'modules/web3/helpers/getContracts'; -import { networkNameToChainId } from 'modules/web3/helpers/chain'; -import { getVoteProxyAddresses } from 'modules/app/helpers/getVoteProxyAddresses'; - -/* - Returns the last vote for a given address -*/ -export default withApiHandler( - async ( - req: NextApiRequest, - res: NextApiResponse<{ - lastVote: PollVoteHistory; - }> - ) => { - const network = (req.query.network as string) || DEFAULT_NETWORK.network; - const tempAddress = req.query.address as string; - invariant(isSupportedNetwork(network), `unsupported network ${network}`); - - const address = tempAddress.indexOf('.eth') !== -1 ? await resolveENS(tempAddress) : tempAddress; - - const contracts = getContracts(networkNameToChainId(network)); - - const voteProxyAddress = await getVoteProxyAddresses( - contracts.voteProxyFactory, - address as string, - network - ); - - const pollVoteHistory = await fetchAddressPollVoteHistory( - voteProxyAddress.hotAddress ? voteProxyAddress.hotAddress : (address as string), - network - ); - const lastVote = pollVoteHistory.sort((a, b) => (a.blockTimestamp > b.blockTimestamp ? -1 : 1))[0]; - - res.setHeader('Cache-Control', 's-maxage=15, stale-while-revalidate'); - res.status(200).json({ - lastVote - }); - } -); diff --git a/pages/executive/[proposal-id].tsx b/pages/executive/[proposal-id].tsx index b292de2c1..a1f1b7492 100644 --- a/pages/executive/[proposal-id].tsx +++ b/pages/executive/[proposal-id].tsx @@ -242,7 +242,7 @@ const ProposalView = ({ proposal, spellDiffs }: Props): JSX.Element => { ,
{comments ? ( - + ) : ( {commentsError ? (