-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from valory-xyz/tanya/proposals
(govern) feat: add proposals
- Loading branch information
Showing
21 changed files
with
2,073 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// approx time when Ethereum blockchain produces a new block | ||
export const SECONDS_PER_BLOCK = 12; |
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
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,36 @@ | ||
import { gql, request } from 'graphql-request'; | ||
|
||
import { Proposals } from './types'; | ||
|
||
const GOVERNOR_SUBGRAPH_URL = process.env.NEXT_PUBLIC_GOVERNOR_SUBGRAPH_URL; | ||
|
||
const getProposalsQuery = gql` | ||
query GetProposalCreateds { | ||
proposalCreateds(first: 1000, orderBy: blockTimestamp, orderDirection: desc) { | ||
id | ||
blockNumber | ||
blockTimestamp | ||
proposalId | ||
startBlock | ||
endBlock | ||
isQueued | ||
isExecuted | ||
isCancelled | ||
description | ||
votesFor | ||
votesAgainst | ||
quorum | ||
proposer | ||
transactionHash | ||
voteCasts { | ||
id | ||
weight | ||
support | ||
voter | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const getProposals = async () => | ||
request<Proposals>(GOVERNOR_SUBGRAPH_URL as string, getProposalsQuery); |
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,29 @@ | ||
import { Address } from 'viem'; | ||
|
||
export type Proposal = { | ||
id: string; | ||
proposer: Address; | ||
blockNumber: string; | ||
blockTimestamp: string; | ||
proposalId: string; | ||
startBlock: string; | ||
endBlock: string; | ||
isQueued: boolean; | ||
isExecuted: boolean; | ||
isCancelled: boolean; | ||
description: string; | ||
votesFor: string; | ||
votesAgainst: string; | ||
quorum: string; | ||
transactionHash: string; | ||
voteCasts: { | ||
id: string; | ||
weight: string; | ||
support: number; | ||
voter: Address; | ||
}[]; | ||
}; | ||
|
||
export type Proposals = { | ||
proposalCreateds: Proposal[]; | ||
}; |
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,90 @@ | ||
import { Col, Flex, Row, Skeleton, Typography } from 'antd'; | ||
import { Block } from 'viem'; | ||
import { mainnet } from 'viem/chains'; | ||
import { useAccount, useBlock } from 'wagmi'; | ||
|
||
import { Caption } from 'libs/ui-components/src'; | ||
import { areAddressesEqual } from 'libs/util-functions/src'; | ||
import { AddressLink } from 'libs/ui-components/src'; | ||
|
||
import { estimateFutureBlockTimestamp, getFullFormattedDate } from 'common-util/functions'; | ||
import { Proposal } from 'common-util/graphql/types'; | ||
|
||
import { VOTES_SUPPORT, formatWeiToEth } from './utils'; | ||
import { NA } from 'libs/util-constants/src'; | ||
|
||
const { Paragraph, Text } = Typography; | ||
|
||
const useBlockTimestamp = (currentBlock: Block | undefined, block: bigint) => { | ||
// we can't get block data in the future, can only estimate instead | ||
const canLoadBlockData = | ||
currentBlock && currentBlock.number ? currentBlock.number > BigInt(block) : false; | ||
|
||
const blockData = useBlock({ | ||
blockNumber: BigInt(block), | ||
chainId: mainnet.id, | ||
query: { | ||
enabled: canLoadBlockData, | ||
}, | ||
}); | ||
|
||
return { | ||
timestamp: | ||
canLoadBlockData && blockData.data | ||
? blockData.data.timestamp | ||
: estimateFutureBlockTimestamp(currentBlock, block), | ||
isLoading: canLoadBlockData ? blockData.isLoading : false, | ||
}; | ||
}; | ||
|
||
export const ProposalDetails = ({ | ||
item, | ||
currentBlock, | ||
}: { | ||
item: Proposal; | ||
currentBlock?: Block | undefined; | ||
}) => { | ||
const { address } = useAccount(); | ||
|
||
const startDateBlock = useBlockTimestamp(currentBlock, BigInt(item.startBlock)); | ||
const endDateBlock = useBlockTimestamp(currentBlock, BigInt(item.endBlock)); | ||
|
||
return ( | ||
<Flex vertical> | ||
<Caption>Proposal description</Caption> | ||
<Paragraph className="mb-16">{item.description}</Paragraph> | ||
<Caption>Owner</Caption> | ||
<AddressLink address={item.proposer} chainId={mainnet.id} className="mb-16" /> | ||
<Flex gap={24} className="mb-16"> | ||
<Flex vertical> | ||
<Caption>Start Date</Caption> | ||
{startDateBlock.isLoading && <Skeleton.Input active />} | ||
{startDateBlock.timestamp !== null && ( | ||
<Text>{getFullFormattedDate(Number(startDateBlock.timestamp) * 1000)}</Text> | ||
)} | ||
{!startDateBlock.isLoading && startDateBlock.timestamp === null && NA} | ||
</Flex> | ||
<Flex vertical> | ||
<Caption>End Date</Caption> | ||
{endDateBlock.isLoading && <Skeleton.Input active />} | ||
{endDateBlock.timestamp !== null && ( | ||
<Text>{getFullFormattedDate(Number(endDateBlock.timestamp) * 1000)}</Text> | ||
)} | ||
</Flex> | ||
</Flex> | ||
<Flex vertical gap={8}> | ||
<Caption>Voters ({item.voteCasts?.length})</Caption> | ||
{item.voteCasts.map((vote, index) => ( | ||
<Row key={vote.id} gutter={[0, 8]}> | ||
<Col span={5}> | ||
<AddressLink address={vote.voter} chainId={mainnet.id} /> | ||
{address && areAddressesEqual(vote.voter, address) && ' (you)'} | ||
</Col> | ||
<Col span={2}>{formatWeiToEth(vote.weight)}</Col> | ||
<Col>({VOTES_SUPPORT[vote.support]})</Col> | ||
</Row> | ||
))} | ||
</Flex> | ||
</Flex> | ||
); | ||
}; |
Oops, something went wrong.