-
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.
- Loading branch information
1 parent
b316a1e
commit 7e98392
Showing
19 changed files
with
2,067 additions
and
78 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, 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,103 @@ | ||
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 { EXPLORER_URLS, UNICODE_SYMBOLS } from 'libs/util-constants/src'; | ||
import { areAddressesEqual } from 'libs/util-functions/src'; | ||
|
||
import { | ||
estimateFutureBlockTimestamp, | ||
getFullFormattedDate, | ||
truncateAddress, | ||
} from 'common-util/functions'; | ||
import { Proposal } from 'common-util/graphql/types'; | ||
|
||
import { VOTES_SUPPORT, getFormattedValue } from './utils'; | ||
|
||
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, | ||
}; | ||
}; | ||
|
||
const AddressLink = ({ address, className }: { address: string; className?: string }) => ( | ||
<a | ||
href={`${EXPLORER_URLS[mainnet.id]}/address/${address}`} | ||
target="_blank" | ||
rel="noreferrer" | ||
className={className} | ||
> | ||
{`${truncateAddress(address)} ${UNICODE_SYMBOLS.EXTERNAL_LINK}`} | ||
</a> | ||
); | ||
|
||
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} 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> | ||
)} | ||
</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} /> | ||
{address && areAddressesEqual(vote.voter, address) && ' (you)'} | ||
</Col> | ||
<Col span={2}>{getFormattedValue(vote.weight)}</Col> | ||
<Col>({VOTES_SUPPORT[vote.support]})</Col> | ||
</Row> | ||
))} | ||
</Flex> | ||
</Flex> | ||
); | ||
}; |
Oops, something went wrong.