Skip to content

Commit

Permalink
Merge pull request #442 from ourzora/add-proposal-disabled-check
Browse files Browse the repository at this point in the history
Add checks for delayed governance
  • Loading branch information
neokry authored Mar 1, 2024
2 parents 928a1b4 + baa6571 commit fe2abac
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/web/src/data/subgraph/fragments/Dao.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ fragment DAO on DAO {
name
tokenAddress
auctionAddress
governorAddress
}
13 changes: 11 additions & 2 deletions apps/web/src/data/subgraph/sdk.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2220,6 +2220,7 @@ export type DaoFragment = {
name: string
tokenAddress: any
auctionAddress: any
governorAddress: any
}

export type ExploreDaoFragment = {
Expand Down Expand Up @@ -2433,7 +2434,13 @@ export type DaoTokenOwnersQuery = {
__typename?: 'Query'
daotokenOwners: Array<{
__typename?: 'DAOTokenOwner'
dao: { __typename?: 'DAO'; name: string; tokenAddress: any; auctionAddress: any }
dao: {
__typename?: 'DAO'
name: string
tokenAddress: any
auctionAddress: any
governorAddress: any
}
}>
}

Expand All @@ -2453,6 +2460,7 @@ export type DashboardQuery = {
name: string
tokenAddress: any
auctionAddress: any
governorAddress: any
auctionConfig: {
__typename?: 'AuctionConfig'
minimumBidIncrement: any
Expand Down Expand Up @@ -2763,6 +2771,7 @@ export const DaoFragmentDoc = gql`
name
tokenAddress
auctionAddress
governorAddress
}
`
export const ExploreDaoFragmentDoc = gql`
Expand Down Expand Up @@ -2909,7 +2918,7 @@ export const DaoMembersListDocument = gql`
id
owner
daoTokenCount
daoTokens {
daoTokens(first: $first) {
tokenId
mintedAt
}
Expand Down
25 changes: 25 additions & 0 deletions apps/web/src/hooks/useDelayedGovernance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useContractRead } from 'wagmi'

import { governorAbi } from 'src/data/contract/abis'
import { AddressType, CHAIN_ID } from 'src/typings'

export const useDelayedGovernance = ({
governorAddress,
chainId,
}: {
governorAddress?: AddressType
chainId: CHAIN_ID
}) => {
const { data: delayedUntilTimestamp } = useContractRead({
abi: governorAbi,
address: governorAddress,
chainId,
functionName: 'delayedGovernanceExpirationTimestamp',
})

const isGovernanceDelayed = delayedUntilTimestamp
? new Date().getTime() < Number(delayedUntilTimestamp) * 1000
: false

return { delayedUntilTimestamp, isGovernanceDelayed }
}
55 changes: 53 additions & 2 deletions apps/web/src/modules/dao/components/Activity/Activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useSWR from 'swr'
import { useAccount } from 'wagmi'

import { ContractButton } from 'src/components/ContractButton'
import { Countdown } from 'src/components/Countdown'
import AnimatedModal from 'src/components/Modal/AnimatedModal'
import { SuccessModalContent } from 'src/components/Modal/SuccessModalContent'
import Pagination from 'src/components/Pagination'
Expand All @@ -15,6 +16,7 @@ import {
getProposals,
} from 'src/data/subgraph/requests/proposalsQuery'
import { useVotes } from 'src/hooks'
import { useDelayedGovernance } from 'src/hooks/useDelayedGovernance'
import { usePagination } from 'src/hooks/usePagination'
import { Upgrade, useProposalStore } from 'src/modules/create-proposal'
import { ProposalCard } from 'src/modules/proposal'
Expand Down Expand Up @@ -62,6 +64,11 @@ export const Activity: React.FC = () => {
collectionAddress: query?.token as AddressType,
})

const { isGovernanceDelayed, delayedUntilTimestamp } = useDelayedGovernance({
governorAddress: addresses?.governor,
chainId: chain.id,
})

const [
{ viewCurrentDelegate, viewDelegateForm, viewSuccessfulDelegate, newDelegate },
{ view, edit, update, close },
Expand Down Expand Up @@ -150,7 +157,7 @@ export const Activity: React.FC = () => {
<Button
className={submitProposalBtn}
onClick={address ? handleProposalCreation : openConnectModal}
disabled={address ? !hasThreshold : false}
disabled={isGovernanceDelayed ? true : address ? !hasThreshold : false}
color={'tertiary'}
>
Submit {!isMobile ? 'proposal' : null}
Expand All @@ -166,7 +173,51 @@ export const Activity: React.FC = () => {
/>
)}
<Flex direction={'column'} mt={'x6'}>
{data?.proposals?.length ? (
{isGovernanceDelayed ? (
<Flex
width={'100%'}
mt={'x4'}
p={'x4'}
justify={'center'}
align={'center'}
borderColor={'border'}
borderStyle={'solid'}
borderRadius={'curved'}
borderWidth={'normal'}
>
<Flex textAlign={'center'} align={'center'}>
<Text
color={'text3'}
variant={'paragraph-md'}
ml={{ '@initial': 'x0', '@768': 'x3' }}
>
Time remaining before proposals can be submitted:
</Text>
</Flex>
<Flex
w={{ '@initial': '100%', '@768': 'auto' }}
justify={'center'}
align={'center'}
px={'x2'}
py={'x4'}
>
<Text
fontWeight={'display'}
ml="x1"
style={{
fontVariantNumeric: 'tabular-nums',
fontFeatureSettings: 'tnum',
}}
>
<Countdown
end={Number(delayedUntilTimestamp)}
onEnd={() => {}}
style={{ fontWeight: 'bold' }}
/>
</Text>
</Flex>
</Flex>
) : data?.proposals?.length ? (
data?.proposals?.map((proposal, index: number) => (
<ProposalCard
key={index}
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/modules/dashboard/DaoProposals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react'

import { Avatar } from 'src/components/Avatar'
import { PUBLIC_ALL_CHAINS } from 'src/constants/defaultChains'
import { useDelayedGovernance } from 'src/hooks/useDelayedGovernance'
import { AddressType } from 'src/typings'

import { DaoProposalCard } from './DaoProposalCard'
Expand All @@ -16,6 +17,7 @@ import { daoName } from './dashboard.css'
export const DaoProposals = ({
daoImage,
tokenAddress,
governorAddress,
name,
proposals,
chainId,
Expand All @@ -25,6 +27,11 @@ export const DaoProposals = ({
return daoImage ? getFetchableUrl(daoImage) : null
}, [daoImage])

const { isGovernanceDelayed } = useDelayedGovernance({
governorAddress: governorAddress,
chainId,
})

const router = useRouter()

const currentChainSlug = PUBLIC_ALL_CHAINS.find((chain) => chain.id === chainId)?.slug
Expand Down Expand Up @@ -61,6 +68,7 @@ export const DaoProposals = ({
variant="outline"
borderRadius="curved"
size={'sm'}
disabled={isGovernanceDelayed}
onClick={() =>
router.push(`/dao/${currentChainSlug}/${tokenAddress}/proposal/create`)
}
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/pages/dao/[network]/[token]/proposal/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { auctionAbi } from 'src/data/contract/abis'
import { L1_CHAINS } from 'src/data/contract/chains'
import getDAOAddresses from 'src/data/contract/requests/getDAOAddresses'
import { useVotes } from 'src/hooks'
import { useDelayedGovernance } from 'src/hooks/useDelayedGovernance'
import { getDaoLayout } from 'src/layouts/DaoLayout'
import {
CreateProposalHeading,
Expand Down Expand Up @@ -65,6 +66,11 @@ const CreateProposalPage: NextPageWithLayout = () => {
collectionAddress: query?.token as AddressType,
})

const { isGovernanceDelayed } = useDelayedGovernance({
chainId: chain.id,
governorAddress: addresses?.governor,
})

const createSelectOption = (type: TransactionFormType) => ({
value: type,
label: TRANSACTION_TYPES[type].title,
Expand Down Expand Up @@ -92,7 +98,7 @@ const CreateProposalPage: NextPageWithLayout = () => {

if (isLoading) return null

if (!hasThreshold) {
if (!hasThreshold || isGovernanceDelayed) {
return <Flex className={notFoundWrap}>403 - Access Denied</Flex>
}

Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/pages/dao/[network]/[token]/proposal/review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CACHE_TIMES } from 'src/constants/cacheTimes'
import { PUBLIC_DEFAULT_CHAINS } from 'src/constants/defaultChains'
import getDAOAddresses from 'src/data/contract/requests/getDAOAddresses'
import { useVotes } from 'src/hooks'
import { useDelayedGovernance } from 'src/hooks/useDelayedGovernance'
import { getDaoLayout } from 'src/layouts/DaoLayout'
import {
CreateProposalHeading,
Expand Down Expand Up @@ -38,14 +39,19 @@ const ReviewProposalPage: NextPageWithLayout = () => {
collectionAddress: query?.token as AddressType,
})

const { isGovernanceDelayed } = useDelayedGovernance({
chainId: chain.id,
governorAddress: addresses?.governor,
})

const transactions = useProposalStore((state) => state.transactions)
const disabled = useProposalStore((state) => state.disabled)
const title = useProposalStore((state) => state.title)
const summary = useProposalStore((state) => state.summary)

if (isLoading) return null

if (!hasThreshold) {
if (!hasThreshold || isGovernanceDelayed) {
return <Flex className={notFoundWrap}>403 - Access Denied</Flex>
}

Expand Down

0 comments on commit fe2abac

Please sign in to comment.