-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding polling comments & Removing votes from ballot (#272)
* Adding polling comments * Multistep sign comments * Working on removing ballot * Prettier * Link to the commenter page * Refactor comments into it's own module, bring address data from the comments API call, include correct address balance , fix executive contract deposit refresh UI * fix build * Refactor vote modal * Default view fixes * small fixes * prettier * fix tests * Document poll tally api * updated swaggers * Add transaction hash to comment * prettier * Reuse same comment box with limit at 250 characters and limit to 1 comment per address. Show polling comment option * comment count on executives * comments on polls * fix build
- Loading branch information
1 parent
095b31e
commit c5e911a
Showing
61 changed files
with
2,296 additions
and
1,044 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { SupportedNetworks } from 'lib/constants'; | ||
import getMaker from 'lib/maker'; | ||
import { fetchDelegate } from 'modules/delegates/api/fetchDelegates'; | ||
import { AddressApiResponse } from '../types/addressApiResponse'; | ||
import voteProxyFactoryAbi from 'lib/abis/voteProxyAbi.json'; | ||
|
||
export async function getAddressInfo( | ||
address: string, | ||
network: SupportedNetworks | ||
): Promise<AddressApiResponse> { | ||
const maker = await getMaker(network); | ||
const voteProxyContract = maker | ||
.service('smartContract') | ||
.getContractByAddressAndAbi(address, voteProxyFactoryAbi); | ||
|
||
// TODO: should we check cold for history? | ||
let hot; | ||
let cold; | ||
let voteProxyAddress; | ||
try { | ||
hot = await voteProxyContract.hot(); | ||
cold = await voteProxyContract.cold(); | ||
voteProxyAddress = address; | ||
} catch (err) { | ||
// console.log(err); | ||
} | ||
|
||
const voteProxyInfo = | ||
hot && cold && voteProxyAddress | ||
? { | ||
voteProxyAddress, | ||
hot, | ||
cold | ||
} | ||
: undefined; | ||
|
||
const delegate = await fetchDelegate(address, network); | ||
|
||
const response: AddressApiResponse = { | ||
isDelegate: !!delegate, | ||
isProxyContract: !!hot, | ||
voteProxyInfo, | ||
delegateInfo: delegate, | ||
address | ||
}; | ||
|
||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react'; | ||
import AddressIcon from './AddressIcon'; | ||
import { Box, Text, Link as ExternalLink, Flex } from 'theme-ui'; | ||
import { Icon } from '@makerdao/dai-ui-icons'; | ||
import { getNetwork } from 'lib/maker'; | ||
import { getEtherscanLink } from 'lib/utils'; | ||
import { Address } from './Address'; | ||
import Tooltip from 'modules/app/components/Tooltip'; | ||
import { VoteProxyInfo } from '../types/addressApiResponse'; | ||
|
||
type PropTypes = { | ||
address: string; | ||
voteProxyInfo?: VoteProxyInfo; | ||
showExternalLink: boolean; | ||
}; | ||
|
||
export default function AddressIconBox({ | ||
address, | ||
voteProxyInfo, | ||
showExternalLink | ||
}: PropTypes): React.ReactElement { | ||
const tooltipLabel = voteProxyInfo ? ( | ||
<Box sx={{ p: 2 }}> | ||
<Text as="p"> | ||
<Text sx={{ fontWeight: 'bold' }}>Contract:</Text> {voteProxyInfo.voteProxyAddress} | ||
</Text> | ||
<Text as="p"> | ||
<Text sx={{ fontWeight: 'bold' }}>Hot:</Text> {voteProxyInfo.hot} | ||
</Text> | ||
<Text as="p"> | ||
<Text sx={{ fontWeight: 'bold' }}>Cold:</Text> {voteProxyInfo.cold} | ||
</Text> | ||
</Box> | ||
) : null; | ||
|
||
return ( | ||
<Flex> | ||
<Box sx={{ width: '41px', mr: 2 }}> | ||
<AddressIcon address={address} width="41px" /> | ||
</Box> | ||
<Flex | ||
sx={{ | ||
ml: 2, | ||
width: '100%', | ||
flexDirection: 'column', | ||
justifyContent: 'center' | ||
}} | ||
> | ||
<Flex> | ||
<Text> | ||
<Address address={address} /> | ||
</Text> | ||
{showExternalLink && ( | ||
<ExternalLink | ||
title="View on etherscan" | ||
href={getEtherscanLink(getNetwork(), address, 'address')} | ||
target="_blank" | ||
> | ||
<Text as="p" sx={{ fontSize: [1, 3], ml: 1 }}> | ||
<Icon ml={2} name="arrowTopRight" size={2} /> | ||
</Text> | ||
</ExternalLink> | ||
)} | ||
</Flex> | ||
{voteProxyInfo && ( | ||
<Flex> | ||
<Text sx={{ color: 'textSecondary', ml: 2, fontSize: [1, 2] }}>Proxy Contract</Text>{' '} | ||
<Tooltip label={tooltipLabel}> | ||
<Box> | ||
<Icon name="question" ml={2} mt={['2px', '4px']} /> | ||
</Box> | ||
</Tooltip>{' '} | ||
</Flex> | ||
)} | ||
</Flex> | ||
</Flex> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { connectToDatabase } from 'lib/api/utils'; | ||
import { SupportedNetworks } from 'lib/constants'; | ||
import invariant from 'tiny-invariant'; | ||
|
||
import uniqBy from 'lodash/uniqBy'; | ||
import { ExecutiveComment, ExecutiveCommentFromDB } from '../types/executiveComment'; | ||
import { getAddressInfo } from 'modules/address/api/getAddressInfo'; | ||
import { ExecutiveCommentsAPIResponseItem } from '../types/comments'; | ||
|
||
export async function getExecutiveComments( | ||
spellAddress: string, | ||
network: SupportedNetworks | ||
): Promise<ExecutiveCommentsAPIResponseItem[]> { | ||
const { db, client } = await connectToDatabase(); | ||
|
||
invariant(await client.isConnected(), 'mongo client failed to connect'); | ||
|
||
const collection = db.collection('executiveComments'); | ||
// decending sort | ||
const commentsFromDB: ExecutiveCommentFromDB[] = await collection | ||
.find({ spellAddress, network }) | ||
.sort({ date: -1 }) | ||
.toArray(); | ||
|
||
const comments: ExecutiveComment[] = commentsFromDB.map(comment => { | ||
const { _id, ...rest } = comment; | ||
return rest; | ||
}); | ||
|
||
// only return the latest comment from each address | ||
const uniqueComments = uniqBy(comments, 'voterAddress'); | ||
|
||
const promises = uniqueComments.map(async comment => { | ||
return { | ||
comment, | ||
address: await getAddressInfo( | ||
comment.delegateAddress ? comment.delegateAddress : comment.voterAddress, | ||
network | ||
) | ||
}; | ||
}); | ||
|
||
const response = await Promise.all(promises); | ||
|
||
return response as ExecutiveCommentsAPIResponseItem[]; | ||
} |
Oops, something went wrong.