Commit b7636597 authored by Noah Zinsmeister's avatar Noah Zinsmeister

restrict governance UI to mainnet only

fix governor name bug

revert useContract change

add governorIndex to vote page

only fetch latest useLatestProposalCount

fix useDataFromEventLogs

hardcode proposalIndexes for old governors
parent d9bd392e
...@@ -18,13 +18,19 @@ export const V2_ROUTER_ADDRESS: AddressMap = constructSameAddressMap( ...@@ -18,13 +18,19 @@ export const V2_ROUTER_ADDRESS: AddressMap = constructSameAddressMap(
) )
// most current governance contract address should always be the 0 index // most current governance contract address should always be the 0 index
// only support governance on mainnet
export const GOVERNANCE_ADDRESSES: AddressMap[] = [ export const GOVERNANCE_ADDRESSES: AddressMap[] = [
{ {
[SupportedChainId.MAINNET]: '0xC4e172459f1E7939D522503B81AFAaC1014CE6F6', [SupportedChainId.MAINNET]: '0xC4e172459f1E7939D522503B81AFAaC1014CE6F6',
}, },
constructSameAddressMap('0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F', false), {
[SupportedChainId.MAINNET]: '0x5e4be8Bc9637f0EAA1A755019e06A68ce081D58F',
},
] ]
export const TIMELOCK_ADDRESS: AddressMap = constructSameAddressMap('0x1a9C8182C09F50C8318d769245beA52c32BE35BC', false) export const TIMELOCK_ADDRESS: AddressMap = {
[SupportedChainId.MAINNET]: '0x1a9C8182C09F50C8318d769245beA52c32BE35BC',
}
export const MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = { export const MERKLE_DISTRIBUTOR_ADDRESS: AddressMap = {
[SupportedChainId.MAINNET]: '0x090D4613473dEE047c3f2706764f49E0821D256e', [SupportedChainId.MAINNET]: '0x090D4613473dEE047c3f2706764f49E0821D256e',
} }
......
...@@ -6,7 +6,9 @@ const governanceContracts = (): Record<string, string> => ...@@ -6,7 +6,9 @@ const governanceContracts = (): Record<string, string> =>
GOVERNANCE_ADDRESSES.reduce( GOVERNANCE_ADDRESSES.reduce(
(acc, addressMap, i) => ({ (acc, addressMap, i) => ({
...acc, ...acc,
[addressMap[SupportedChainId.MAINNET]]: `Governance${i === GOVERNANCE_ADDRESSES.length - 1 ? '' : ` (V${i})`}`, [addressMap[SupportedChainId.MAINNET]]: `Governance${
i === 0 ? '' : ` (V${GOVERNANCE_ADDRESSES.length - 1 - i})`
}`,
}), }),
{} {}
) )
......
export const UNISWAP_GRANTS_START_BLOCK = 11473815 export const UNISWAP_GRANTS_START_BLOCK = 11473815
export const EDUCATION_FUND_1_START_BLOCK = 12620175
...@@ -46,34 +46,19 @@ import { useActiveWeb3React } from './web3' ...@@ -46,34 +46,19 @@ import { useActiveWeb3React } from './web3'
// returns null on errors // returns null on errors
export function useContract<T extends Contract = Contract>( export function useContract<T extends Contract = Contract>(
addressOrAddressMap: string | { [chainId: number]: string } | { [chainId: number]: string }[] | undefined, addressOrAddressMap: string | { [chainId: number]: string } | undefined,
ABI: any, ABI: any,
withSignerIfPossible = true withSignerIfPossible = true
): T | null { ): T | null {
const { library, account, chainId } = useActiveWeb3React() const { library, account, chainId } = useActiveWeb3React()
return useMemo(() => { return useMemo(() => {
if (!addressOrAddressMap || !ABI || !library || !chainId) { if (!addressOrAddressMap || !ABI || !library || !chainId) return null
return null
}
let address: string | undefined let address: string | undefined
if (typeof addressOrAddressMap === 'string') { if (typeof addressOrAddressMap === 'string') address = addressOrAddressMap
address = addressOrAddressMap else address = addressOrAddressMap[chainId]
} else if (!Array.isArray(addressOrAddressMap)) { if (!address) return null
address = addressOrAddressMap[chainId]
}
if (!address && !Array.isArray(addressOrAddressMap)) {
return null
}
try { try {
if (Array.isArray(addressOrAddressMap)) {
return addressOrAddressMap.map((addressMap) =>
getContract(addressMap[chainId], ABI, library, withSignerIfPossible && account ? account : undefined)
)
}
if (!address) {
return null
}
return getContract(address, ABI, library, withSignerIfPossible && account ? account : undefined) return getContract(address, ABI, library, withSignerIfPossible && account ? account : undefined)
} catch (error) { } catch (error) {
console.error('Failed to get contract', error) console.error('Failed to get contract', error)
...@@ -131,21 +116,22 @@ export function useMerkleDistributorContract() { ...@@ -131,21 +116,22 @@ export function useMerkleDistributorContract() {
return useContract(MERKLE_DISTRIBUTOR_ADDRESS, MERKLE_DISTRIBUTOR_ABI, true) return useContract(MERKLE_DISTRIBUTOR_ADDRESS, MERKLE_DISTRIBUTOR_ABI, true)
} }
export function useGovernanceContracts(): Contract[] | null { export function useGovernanceContracts(): (Contract | null)[] {
const { library, account, chainId } = useActiveWeb3React() const { library, account, chainId } = useActiveWeb3React()
return useMemo(() => { return useMemo(() => {
if (!library || !chainId) { if (!library || !chainId) {
return null return []
}
try {
return GOVERNANCE_ADDRESSES.filter((addressMap) => Boolean(addressMap[chainId])).map((addressMap) =>
getContract(addressMap[chainId], GOVERNANCE_ABI, library, account ? account : undefined)
)
} catch (error) {
console.error('Failed to get contract', error)
return null
} }
return GOVERNANCE_ADDRESSES.filter((addressMap) => Boolean(addressMap[chainId])).map((addressMap) => {
try {
return getContract(addressMap[chainId], GOVERNANCE_ABI, library, account ? account : undefined)
} catch (error) {
console.error('Failed to get contract', error)
return null
}
})
}, [library, chainId, account]) }, [library, chainId, account])
} }
......
...@@ -87,7 +87,7 @@ export default function App() { ...@@ -87,7 +87,7 @@ export default function App() {
<Web3ReactManager> <Web3ReactManager>
<Switch> <Switch>
<Route exact strict path="/vote" component={Vote} /> <Route exact strict path="/vote" component={Vote} />
<Route exact strict path="/vote/:id" component={VotePage} /> <Route exact strict path="/vote/:governorIndex/:id" component={VotePage} />
<Route exact strict path="/claim" component={OpenClaimAddressModalAndRedirectToSwap} /> <Route exact strict path="/claim" component={OpenClaimAddressModalAndRedirectToSwap} />
<Route exact strict path="/uni" component={Earn} /> <Route exact strict path="/uni" component={Earn} />
<Route exact strict path="/uni/:currencyIdA/:currencyIdB" component={Manage} /> <Route exact strict path="/uni/:currencyIdA/:currencyIdB" component={Manage} />
......
...@@ -121,13 +121,13 @@ const ProposerAddressLink = styled(ExternalLink)` ...@@ -121,13 +121,13 @@ const ProposerAddressLink = styled(ExternalLink)`
export default function VotePage({ export default function VotePage({
match: { match: {
params: { id }, params: { governorIndex, id },
}, },
}: RouteComponentProps<{ id: string }>) { }: RouteComponentProps<{ governorIndex: string; id: string }>) {
const { chainId, account } = useActiveWeb3React() const { chainId, account } = useActiveWeb3React()
// get data for this specific proposal // get data for this specific proposal
const proposalData: ProposalData | undefined = useProposalData(id) const proposalData: ProposalData | undefined = useProposalData(Number.parseInt(governorIndex), id)
// update support based on button interactions // update support based on button interactions
const [support, setSupport] = useState<boolean>(true) const [support, setSupport] = useState<boolean>(true)
......
...@@ -248,9 +248,9 @@ export default function Vote() { ...@@ -248,9 +248,9 @@ export default function Vote() {
</TYPE.subHeader> </TYPE.subHeader>
</EmptyProposals> </EmptyProposals>
)} )}
{allProposals?.reverse().map((p: ProposalData, i) => { {allProposals?.reverse()?.map((p: ProposalData) => {
return ( return (
<Proposal as={Link} to={'/vote/' + p.id} key={i}> <Proposal as={Link} to={`/vote/${p.governorIndex}/${p.id}`} key={`${p.governorIndex}${p.id}`}>
<ProposalNumber>{p.id}</ProposalNumber> <ProposalNumber>{p.id}</ProposalNumber>
<ProposalTitle>{p.title}</ProposalTitle> <ProposalTitle>{p.title}</ProposalTitle>
<ProposalStatus status={p.status}>{ProposalState[p.status]}</ProposalStatus> <ProposalStatus status={p.status}>{ProposalState[p.status]}</ProposalStatus>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment