import { Box, Loader, Text } from '@honeycomb-finance/core'; import { PNG, ZERO_ADDRESS, getEtherscanLink, shortenAddress, useChain, useChainId, usePangolinWeb3, usePngSymbol, useTranslation, } from '@honeycomb-finance/shared'; import { ApplicationModal, useModalOpen, useToggleDelegateModal, useTokenBalance, } from '@honeycomb-finance/state-hooks'; import { GovernanceType, JSBI, TokenAmount } from '@pangolindex/sdk'; import React from 'react'; import { useGetProposalsViaSubgraph } from 'src/hooks/common'; import { useUserDelegate, useUserVotes } from 'src/hooks/evm'; import { ProposalData } from 'src/hooks/types'; import DelegateModal from './DelegateModal'; import FormattedCurrencyAmount from './FormattedCurrencyAmount'; import GovernanceCard, { ProposalStates } from './GovernanceCard'; import { About, AddressButton, ContentWrapper, DefaultButton, DelegatInfo, DelegateWarpper, PageTitle, PageWrapper, StyledExternalLink, TextButton, WrapSmall, } from './styleds'; const GovernanceList = () => { const { account } = usePangolinWeb3(); const chainId = useChainId(); const chain = useChain(chainId); const { t } = useTranslation(); const pngSymbol = usePngSymbol(); // toggle for showing delegation modal const showDelegateModal = useModalOpen(ApplicationModal.DELEGATE); const toggleDelegateModal = useToggleDelegateModal(); // get data to list all proposals const allProposals = useGetProposalsViaSubgraph(); // user data const availableVotes: TokenAmount | undefined = useUserVotes(); const pngBalance: TokenAmount | undefined = useTokenBalance(account ?? undefined, PNG[chainId]); const userDelegatee: string | undefined = useUserDelegate(); // show delegation option if they have have a balance, but have not delegated const showUnlockVoting = Boolean( pngBalance && JSBI.notEqual(pngBalance.raw, JSBI.BigInt(0)) && userDelegatee === ZERO_ADDRESS && chain.contracts?.governor?.type === GovernanceType.STANDARD, ); function getAddress() { if (userDelegatee === account) { return 'Self'; } return userDelegatee ? shortenAddress(userDelegatee, chainId) : ''; } return ( {t('votePage.pangolinGovernance')} {t('votePage.about')} {t('votePage.earnedPngTokens', { pngSymbol: pngSymbol })} {t('votePage.eligibleToVote', { pngSymbol: pngSymbol })} {t('votePage.governanceVotes')} {chain?.contracts?.governor ? ( <> {showUnlockVoting ? ( {t('votePage.unlockVoting')} ) : availableVotes && JSBI.notEqual(JSBI.BigInt(0), availableVotes?.raw) ? ( {t('votePage.votes')} ) : pngBalance && userDelegatee && userDelegatee !== ZERO_ADDRESS && JSBI.notEqual(JSBI.BigInt(0), pngBalance?.raw) ? ( {t('votePage.votes')} ) : ( '' )} {!showUnlockVoting && (
{userDelegatee && userDelegatee !== ZERO_ADDRESS ? ( {t('votePage.delegatedTo')} {getAddress()} ({t('votePage.edit')}) ) : ( '' )} )} {(!allProposals || allProposals.length === 0) && (
)} {allProposals?.map((p: ProposalData) => { return ( ); })} ) : ( {t('votePage.notSupported')} )} ); }; export default GovernanceList;