import { AutoColumn, Box, Button, Loader, Text } from '@honeycomb-finance/core'; import { useSarPositionsHook } from '@honeycomb-finance/sar'; import { ExternalLink, PNG, ZERO_ADDRESS, getEtherscanLink, isAddress, useChainId, usePangolinWeb3, useTranslation, } from '@honeycomb-finance/shared'; import { useTokenBalance } from '@honeycomb-finance/state-hooks'; import { CHAINS, GovernanceType, JSBI, TokenAmount } from '@pangolindex/sdk'; import { DateTime } from 'luxon'; import React, { useMemo, useState } from 'react'; import { ArrowLeft } from 'react-feather'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { useGetProposalDetailViaSubgraph } from 'src/hooks/common'; import { useUserDelegate, useUserVotes } from 'src/hooks/evm'; import VoteModal from './VoteModal'; import { ArrowWrapper, ButtonWrapper, CardSection, CardWrapper, DetailText, MarkDownWrapper, PageWrapper, Progress, ProgressWrapper, ProposalInfo, ProposalStatus, StyledDataCard, WrapSmall, Wrapper, } from './styleds'; export type GovernanceDetailProps = Record<'id', 'string'>; const GovernanceDetail: React.FC = ({ id }) => { const { account } = usePangolinWeb3(); const chainId = useChainId(); const { t } = useTranslation(); // get data for this specific proposal const proposalData = useGetProposalDetailViaSubgraph(id as string); // update support based on button interactions const [support, setSupport] = useState(true); // modal for casting votes const [showModal, setShowModal] = useState(false); //sar nft const useSarPositions = useSarPositionsHook[chainId]; const { positions, isLoading } = useSarPositions(); // sort by balance const filteredPositions = useMemo( () => positions ?.filter((position) => !position.balance.isZero()) .sort((a, b) => Number(b.balance.sub(a.balance).toString())), // remove zero balances and sort by balance [positions], ); // get and format date from data const startTimestamp: number | undefined = proposalData?.startTime; const endTimestamp: number | undefined = proposalData?.endTime; const startDate: DateTime | undefined = startTimestamp ? DateTime.fromSeconds(startTimestamp) : undefined; const endDate: DateTime | undefined = endTimestamp ? DateTime.fromSeconds(endTimestamp) : undefined; const now: DateTime = DateTime.local(); // get total votes and format percentages for UI const totalVotes: number | undefined = proposalData ? proposalData.forCount + proposalData.againstCount : undefined; const forPercentage: string = proposalData && totalVotes ? ((proposalData.forCount * 100) / totalVotes).toFixed(0) + '%' : '0%'; const againstPercentage: string = proposalData && totalVotes ? ((proposalData.againstCount * 100) / totalVotes).toFixed(0) + '%' : '0%'; // show delegation option if they have have a balance, have not delegated const availableVotes: TokenAmount | undefined = useUserVotes(); const uniBalance: TokenAmount | undefined = useTokenBalance(account ?? undefined, chainId ? PNG[chainId] : undefined); const userDelegatee: string | undefined = useUserDelegate(); const notAllowedToVote = CHAINS[chainId]?.contracts?.governor?.type === GovernanceType.SAR_NFT ? filteredPositions?.length === 0 : Boolean(uniBalance && JSBI.notEqual(uniBalance.raw, JSBI.BigInt(0)) && userDelegatee === ZERO_ADDRESS); const checkDateValidation = endDate && endDate > now && startDate && startDate <= now; const checkAvailableVotes = CHAINS[chainId]?.contracts?.governor?.type === GovernanceType.STANDARD && availableVotes && JSBI.greaterThan(availableVotes?.raw, JSBI.BigInt(0)); const checkForV1 = !notAllowedToVote && checkAvailableVotes && checkDateValidation; const checkForV2 = !notAllowedToVote && checkDateValidation; // show links in propsoal details if content is an address const linkIfAddress = (content: string) => { if (isAddress(content) && chainId) { return {content}; } return {content}; }; return ( setShowModal(false)} proposalId={proposalData?.id} support={support} filteredPositions={filteredPositions} nftLoading={isLoading} /> {t('votePage.backToProposals')} {proposalData && {proposalData?.status}} {proposalData?.title} {startDate && startDate <= now ? t('votePage.votingStarted') + (startDate && startDate.toLocaleString(DateTime.DATETIME_FULL)) : proposalData ? t('votePage.votingStarts') + (startDate && startDate.toLocaleString(DateTime.DATETIME_FULL)) : ''} {endDate && endDate < now ? t('votePage.votingEnded') + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL)) : proposalData ? t('votePage.votingEnds') + (endDate && endDate.toLocaleString(DateTime.DATETIME_FULL)) : ''} {checkForV1 || checkForV2 ? ( ) : ( '' )} {t('votePage.for')} {proposalData?.forCount.toLocaleString(undefined, { maximumFractionDigits: 0 })} {t('votePage.against')} {proposalData?.againstCount.toLocaleString(undefined, { maximumFractionDigits: 0 })} {t('votePage.details')} {proposalData?.details?.map((d, index) => { return ( {index + 1}: {linkIfAddress(d.target)}.{d.functionSig}( {d.callData.split(',').map((content, j) => { return ( {linkIfAddress(content)} {d.callData.split(',').length - 1 === j ? '' : ','} ); })} ) ); })} {proposalData?.description ? ( <> {t('votePage.overview')} {proposalData?.description} ) : ( )} {proposalData?.proposer && ( <> {t('votePage.proposer')} {proposalData?.proposer} )} ); }; export default GovernanceDetail;