diff --git a/apps/core-app/src/components/proposalCards/BaseProposalCard.tsx b/apps/core-app/src/components/proposalCards/BaseProposalCard.tsx index ae5cc2821..51c4a535c 100644 --- a/apps/core-app/src/components/proposalCards/BaseProposalCard.tsx +++ b/apps/core-app/src/components/proposalCards/BaseProposalCard.tsx @@ -31,6 +31,8 @@ const LeftCard = styled.div` `; const RightCard = styled.div` + min-width: 30rem; + /* width: 100%; */ @media ${widthQuery.sm} { max-width: 100%; min-width: 0; diff --git a/apps/core-app/src/components/proposalCards/ReadyForProcessing.tsx b/apps/core-app/src/components/proposalCards/ReadyForProcessing.tsx index 3995012d8..98e067d2a 100644 --- a/apps/core-app/src/components/proposalCards/ReadyForProcessing.tsx +++ b/apps/core-app/src/components/proposalCards/ReadyForProcessing.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { ITransformedProposal } from '@daohaus/dao-data'; import { useToast } from '@daohaus/ui'; @@ -7,15 +7,19 @@ import { ActionTemplate, GasDisplay, Verdict } from './ActionPrimitives'; import { useParams } from 'react-router-dom'; import { useHausConnect } from '@daohaus/daohaus-connect-feature'; import { useDao } from '@daohaus/dao-context'; -import { useTxBuilder } from '@daohaus/tx-builder-feature'; +import { createContract, useTxBuilder } from '@daohaus/tx-builder-feature'; import { handleErrorMessage, + isValidNetwork, + ReactSetter, roundedPercentage, TXLego, + ValidNetwork, } from '@daohaus/common-utilities'; import { ACTION_TX } from '../../legos/tx'; import { GatedButton } from './GatedButton'; import { VotingBar } from '../VotingBar'; +import { LOCAL_ABI } from '@daohaus/abi-utilities'; // Adding to the gas limit to account for cost of processProposal export const PROCESS_PROPOSAL_GAS_LIMIT_ADDITION = 150000; @@ -29,17 +33,50 @@ const ProcessBox = styled.div` /* justify-content: space-between; */ `; +const eligibableStatuses = [0, 6, 7, 3]; + +const checkCanProcess = async ({ + daoid, + daochain, + prevProposalId, + setCanProcess, +}: { + daoid: string; + daochain: ValidNetwork; + prevProposalId: string; + setCanProcess: ReactSetter; +}) => { + try { + const state = await createContract({ + address: daoid, + abi: LOCAL_ABI.BAAL, + chainId: daochain, + })['state'](prevProposalId); + + setCanProcess( + eligibableStatuses.some((status) => status === state) + ? true + : 'Another proposal in the DAO needs to executed first.' + ); + } catch (error) { + setCanProcess('Network Error. Could not check for Proposal status'); + } +}; + export const ReadyForProcessing = ({ proposal, }: { proposal: ITransformedProposal; }) => { - const { daochain } = useParams(); + const { daochain, daoid } = useParams(); const { chainId } = useHausConnect(); const { fireTransaction } = useTxBuilder(); const { errorToast, defaultToast, successToast } = useToast(); const { refreshAll } = useDao(); + const [canProcess, setCanProcess] = React.useState( + 'Checking Process data.' + ); const [isLoading, setIsLoading] = React.useState(false); const processProposal = async () => { @@ -89,6 +126,17 @@ export const ReadyForProcessing = ({ }); }; + useEffect(() => { + if (daoid && isValidNetwork(daochain)) { + checkCanProcess({ + daochain, + daoid, + prevProposalId: proposal.prevProposalId, + setCanProcess, + }); + } + }, [proposal, daoid, daochain]); + const isConnectedToDao = chainId === daochain ? true @@ -122,7 +170,7 @@ export const ReadyForProcessing = ({ sm onClick={processProposal} className="execute" - rules={[isConnectedToDao, isNotLoading]} + rules={[isConnectedToDao, isNotLoading, canProcess]} > Execute diff --git a/apps/core-app/src/pages/ProposalDetails.tsx b/apps/core-app/src/pages/ProposalDetails.tsx index 42d864a2c..a5523fe99 100644 --- a/apps/core-app/src/pages/ProposalDetails.tsx +++ b/apps/core-app/src/pages/ProposalDetails.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import styled from 'styled-components'; import { useParams } from 'react-router-dom'; @@ -52,37 +52,25 @@ export function ProposalDetails() { >(); const [proposalLoading, setProposalLoading] = useState(false); - useEffect(() => { - let shouldUpdate = true; - if (daochain && daoid && proposalId) { - loadProposal({ - daoid, - daochain: daochain as keyof Keychain, - proposalId, - setProposal, - setProposalLoading, - shouldUpdate, - connectedAddress: address, - }); - } - return () => { - shouldUpdate = false; - }; + const fetchProposal = useCallback(() => { + const shouldUpdate = true; + if (!daochain || !daoid || !proposalId) return; + loadProposal({ + daoid, + daochain: daochain as keyof Keychain, + proposalId, + setProposal, + setProposalLoading, + shouldUpdate, + connectedAddress: address, + }); }, [daochain, daoid, proposalId, address]); - const refreshProposal = () => { + useEffect(() => { if (daochain && daoid && proposalId) { - loadProposal({ - daoid, - daochain: daochain as keyof Keychain, - proposalId, - setProposal, - setProposalLoading, - shouldUpdate: true, - connectedAddress: address, - }); + fetchProposal(); } - }; + }, [daochain, daoid, proposalId, address, fetchProposal]); if (proposalLoading) { return ( @@ -98,7 +86,7 @@ export function ProposalDetails() { subtitle={getProposalTypeLabel(proposal?.proposalType)} actions={ proposal && ( - + ) } left={