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

develop > master #424

Merged
merged 17 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cypress/integration/polling/poll-detail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion modules/address/components/AddressDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ export function AddressDetail({ address }: PropTypes): React.ReactElement {
<AddressIconBox address={address} showExternalLink />

<Box sx={{ pt: [2, 0] }}>
<LastVoted expired={false} date={statsData?.lastVote?.blockTimestamp || ''} />
<LastVoted
expired={false}
date={statsData ? (statsData.lastVote ? statsData.lastVote.blockTimestamp : null) : undefined}
/>
</Box>
</Flex>

Expand Down
29 changes: 15 additions & 14 deletions modules/comments/components/ExecutiveComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,33 +45,37 @@ export default function ExecutiveComments({
<Text variant="microHeading">Comments ({comments ? comments.length : '0'})</Text>
<Box>
<FilterButton
name={() => `Sort by ${commentSortBy !== 'Latest' ? commentSortBy : 'latest'}`}
name={() =>
`Sort by ${
commentSortBy !== CommentSortOption.LATEST ? commentSortBy : CommentSortOption.LATEST
}`
}
listVariant="menubuttons.default.list"
{...props}
>
<MenuItem
onSelect={() => setCommentSortBy('Latest')}
onSelect={() => setCommentSortBy(CommentSortOption.LATEST)}
sx={{
variant: 'menubuttons.default.item',
fontWeight: commentSortBy === 'Latest' ? 'bold' : undefined
fontWeight: commentSortBy === CommentSortOption.LATEST ? 'bold' : undefined
}}
>
Latest
</MenuItem>
<MenuItem
onSelect={() => setCommentSortBy('Oldest')}
onSelect={() => setCommentSortBy(CommentSortOption.OLDEST)}
sx={{
variant: 'menubuttons.default.item',
fontWeight: commentSortBy === 'Oldest' ? 'bold' : undefined
fontWeight: commentSortBy === CommentSortOption.OLDEST ? 'bold' : undefined
}}
>
Oldest
</MenuItem>
<MenuItem
onSelect={() => 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
Expand Down
21 changes: 11 additions & 10 deletions modules/comments/components/PollComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -103,28 +104,28 @@ export default function PollComments({
<Box>
<FilterButton name={() => `Sort by ${commentSortBy}`} listVariant="menubuttons.default.list">
<MenuItem
onSelect={() => setCommentSortBy('latest')}
onSelect={() => setCommentSortBy(CommentSortOption.LATEST)}
sx={{
variant: 'menubuttons.default.item',
fontWeight: commentSortBy === 'latest' ? 'bold' : undefined
fontWeight: commentSortBy === CommentSortOption.LATEST ? 'bold' : undefined
}}
>
Latest
</MenuItem>
<MenuItem
onSelect={() => setCommentSortBy('oldest')}
onSelect={() => setCommentSortBy(CommentSortOption.OLDEST)}
sx={{
variant: 'menubuttons.default.item',
fontWeight: commentSortBy === 'oldest' ? 'bold' : undefined
fontWeight: commentSortBy === CommentSortOption.OLDEST ? 'bold' : undefined
}}
>
Oldest
</MenuItem>
<MenuItem
onSelect={() => 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -85,3 +84,9 @@ export type PollCommentWithWeight = PollComment & {
};

export type CommentFromDB = PollCommentFromDB | ExecutiveCommentFromDB;

export enum CommentSortOption {
LATEST = 'latest',
OLDEST = 'oldest',
MKR_AMOUNT = 'MKR amount'
}
2 changes: 1 addition & 1 deletion modules/delegates/components/DelegateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function DelegateCard({ delegate }: PropTypes): React.ReactElement {
<Flex sx={{ mb: 3, justifyContent: 'space-between', alignItems: 'center' }}>
<LastVoted
expired={delegate.expired}
date={delegate.lastVoteDate ? delegate.lastVoteDate : ''}
date={delegate ? (delegate.lastVoteDate ? delegate.lastVoteDate : null) : undefined}
left
/>
{delegate.cuMember && <CoreUnitButton handleInfoClick={handleInfoClick} />}
Expand Down
2 changes: 1 addition & 1 deletion modules/delegates/components/DelegateDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export function DelegateDetail({ delegate }: PropTypes): React.ReactElement {
{delegate.cuMember && <CoreUnitButton handleInfoClick={handleInfoClick} />}
<LastVoted
expired={delegate.expired}
date={statsData?.lastVote?.blockTimestamp || ''}
date={statsData ? (statsData.lastVote ? statsData.lastVote.blockTimestamp : null) : undefined}
styles={{ my: 1 }}
/>
<DelegateContractExpiration delegate={delegate} />
Expand Down
27 changes: 0 additions & 27 deletions modules/delegates/hooks/useLastVote.ts

This file was deleted.

2 changes: 1 addition & 1 deletion modules/executive/api/fetchExecutives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion modules/gql/queries/uniswapV3MkrSupply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const uniswapV3MkrSupply = gql`
query uniswapV3MkrSupply($argMkrAddress: String!) {
token(id: $argMkrAddress) {
symbol
totalSupply
totalValueLocked
}
}
`;
4 changes: 3 additions & 1 deletion modules/mkr/components/MkrLiquiditySidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions modules/polling/api/fetchAllCurrentVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PollVote[]> {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/polling/api/fetchLastPollvote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,20 @@
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<RawPollTally> {
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);
} else {
tally = await fetchTallyRankedChoice(pollId, network);
}

if (config.USE_FS_CACHE && useCache) {
fsCacheSet(cacheKey, JSON.stringify(tally), network);
}

return tally;
}
6 changes: 3 additions & 3 deletions modules/polling/api/fetchVotesByAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading