From baa657186b8165689a7fa3406a1a721a871c990d Mon Sep 17 00:00:00 2001 From: neokry Date: Thu, 29 Feb 2024 15:51:52 -0600 Subject: [PATCH] Add checks for delayed governance --- .../src/data/subgraph/fragments/Dao.graphql | 1 + apps/web/src/data/subgraph/sdk.generated.ts | 13 ++++- apps/web/src/hooks/useDelayedGovernance.ts | 25 +++++++++ .../dao/components/Activity/Activity.tsx | 55 ++++++++++++++++++- .../src/modules/dashboard/DaoProposals.tsx | 8 +++ .../dao/[network]/[token]/proposal/create.tsx | 8 ++- .../dao/[network]/[token]/proposal/review.tsx | 8 ++- 7 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 apps/web/src/hooks/useDelayedGovernance.ts diff --git a/apps/web/src/data/subgraph/fragments/Dao.graphql b/apps/web/src/data/subgraph/fragments/Dao.graphql index a3e8bd234..14aeff3f1 100644 --- a/apps/web/src/data/subgraph/fragments/Dao.graphql +++ b/apps/web/src/data/subgraph/fragments/Dao.graphql @@ -2,4 +2,5 @@ fragment DAO on DAO { name tokenAddress auctionAddress + governorAddress } diff --git a/apps/web/src/data/subgraph/sdk.generated.ts b/apps/web/src/data/subgraph/sdk.generated.ts index 041e8cbb6..8b9197c47 100644 --- a/apps/web/src/data/subgraph/sdk.generated.ts +++ b/apps/web/src/data/subgraph/sdk.generated.ts @@ -2220,6 +2220,7 @@ export type DaoFragment = { name: string tokenAddress: any auctionAddress: any + governorAddress: any } export type ExploreDaoFragment = { @@ -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 + } }> } @@ -2453,6 +2460,7 @@ export type DashboardQuery = { name: string tokenAddress: any auctionAddress: any + governorAddress: any auctionConfig: { __typename?: 'AuctionConfig' minimumBidIncrement: any @@ -2763,6 +2771,7 @@ export const DaoFragmentDoc = gql` name tokenAddress auctionAddress + governorAddress } ` export const ExploreDaoFragmentDoc = gql` @@ -2909,7 +2918,7 @@ export const DaoMembersListDocument = gql` id owner daoTokenCount - daoTokens { + daoTokens(first: $first) { tokenId mintedAt } diff --git a/apps/web/src/hooks/useDelayedGovernance.ts b/apps/web/src/hooks/useDelayedGovernance.ts new file mode 100644 index 000000000..496d6f668 --- /dev/null +++ b/apps/web/src/hooks/useDelayedGovernance.ts @@ -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 } +} diff --git a/apps/web/src/modules/dao/components/Activity/Activity.tsx b/apps/web/src/modules/dao/components/Activity/Activity.tsx index 2dcfbbf58..e237ec37b 100644 --- a/apps/web/src/modules/dao/components/Activity/Activity.tsx +++ b/apps/web/src/modules/dao/components/Activity/Activity.tsx @@ -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' @@ -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' @@ -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 }, @@ -150,7 +157,7 @@ export const Activity: React.FC = () => {