From f0e0f9b64bf887beece4f738fb258567935c7c82 Mon Sep 17 00:00:00 2001 From: brightiron Date: Sun, 18 Dec 2022 19:16:49 -0600 Subject: [PATCH 1/2] update seconds on page refresh. fix page title --- src/hooks/useProposal.ts | 2 ++ src/hooks/useProposals.ts | 1 + src/views/Governance/Governance.tsx | 2 ++ .../Governance/components/ProposalPage/ProposalPage.tsx | 6 ++++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/hooks/useProposal.ts b/src/hooks/useProposal.ts index 54d0f7617d..9e33f7a128 100644 --- a/src/hooks/useProposal.ts +++ b/src/hooks/useProposal.ts @@ -47,6 +47,7 @@ export const useProposal = (instructionsIndex: number) => { const { data: metadata, isFetched: metadataIsFetched } = useQuery( ["GetProposalMetadata", instructionsIndex], async () => { + console.log("GetProposalMetadata", instructionsIndex); return await contract.getProposalMetadata(instructionsIndex); }, ); @@ -106,6 +107,7 @@ export const useProposal = (instructionsIndex: number) => { noVotes, uri: discussionURL, content, + now: new Date(), }; return currentProposal; diff --git a/src/hooks/useProposals.ts b/src/hooks/useProposals.ts index a5af533457..52b7f443e5 100644 --- a/src/hooks/useProposals.ts +++ b/src/hooks/useProposals.ts @@ -42,6 +42,7 @@ export interface IAnyProposal extends Omit { nextDeadline: number; collateralClaimableAt: number; isActive: boolean | undefined; + now: Date; } export interface IActiveProposal { diff --git a/src/views/Governance/Governance.tsx b/src/views/Governance/Governance.tsx index 8ee715965f..b7db5f878a 100644 --- a/src/views/Governance/Governance.tsx +++ b/src/views/Governance/Governance.tsx @@ -1,6 +1,7 @@ import { Box } from "@mui/material"; import { Paper } from "@olympusdao/component-library"; import { Route, Routes } from "react-router-dom"; +import PageTitle from "src/components/PageTitle"; import { CreateProposal } from "src/views/Governance/components/CreateProposal"; import { ProposalPage } from "src/views/Governance/components/ProposalPage"; import { VotingPower, VotingPowerMetrics } from "src/views/Governance/components/ProposalPage/components/VotingPower"; @@ -9,6 +10,7 @@ import { ProposalsDashboard } from "src/views/Governance/ProposalsDashboard"; export const Governance = () => { return ( <> + diff --git a/src/views/Governance/components/ProposalPage/ProposalPage.tsx b/src/views/Governance/components/ProposalPage/ProposalPage.tsx index 689989ad29..442cb33ba5 100644 --- a/src/views/Governance/components/ProposalPage/ProposalPage.tsx +++ b/src/views/Governance/components/ProposalPage/ProposalPage.tsx @@ -64,8 +64,10 @@ const TimeRemaining = ({ proposal }: { proposal: IAnyProposal }) => { // const now = 1668456906000; // must be activated within 1 minute // const now = 1668456816000; // can be activated in 3 minutes const now = Date.now(); - if (proposal.timeRemaining && proposal.timeRemaining > 0) { - boundedTimeRemaining = proposal.timeRemaining / 1000; + const timeRemainingDate = proposal.now.getTime() + proposal.timeRemaining; + if (proposal.timeRemaining && timeRemainingDate - now > 0) { + const timeRemainingDate = proposal.now.getTime() + proposal.timeRemaining; + boundedTimeRemaining = (timeRemainingDate - now) / 1000; } console.log( From 5140da63d56bb73301732fa8b2c9b48e4f233c37 Mon Sep 17 00:00:00 2001 From: brightiron Date: Sun, 18 Dec 2022 19:52:30 -0600 Subject: [PATCH 2/2] pending state. on success redirect to main governance page. refresh submittedevents query --- src/hooks/useProposal.ts | 32 +++++++++++++------ .../CreateProposal/CreateProposal.tsx | 13 ++++++-- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/hooks/useProposal.ts b/src/hooks/useProposal.ts index 9e33f7a128..0dcf219815 100644 --- a/src/hooks/useProposal.ts +++ b/src/hooks/useProposal.ts @@ -1,5 +1,6 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import { ethers } from "ethers"; +import toast from "react-hot-toast"; import { GOV_INSTRUCTIONS_CONTRACT, GOVERNANCE_CONTRACT } from "src/constants/contracts"; import { parseBigNumber, stringToBytes32String } from "src/helpers"; import { DecimalBigNumber } from "src/helpers/DecimalBigNumber/DecimalBigNumber"; @@ -16,6 +17,7 @@ import { useGetProposalURIFromEvent, } from "src/hooks/useProposals"; import { useVotingCollateralMinimum, useVotingCollateralRequirement, useVotingSupply } from "src/hooks/useVoting"; +import { queryClient } from "src/lib/react-query"; import { InstructionStructOutput } from "src/typechain/OlympusGovInstructions"; import { useNetwork, useSigner } from "wagmi"; @@ -167,17 +169,27 @@ export const useSubmitProposal = () => { const { data: signer } = useSigner(); // TODO(appleseed): update ANY types below - return useMutation(async ({ proposal }: { proposal: ISubmitProposal }) => { - if (!signer) throw new Error(`Signer is not set`); + return useMutation( + async ({ proposal }: { proposal: ISubmitProposal }) => { + if (!signer) throw new Error(`Signer is not set`); - // NOTE(appleseed): proposal.name is limited 31 characters, but full proposal name is uploaded in metadata via useIPFSUpload - await contract.connect(signer).submitProposal( - proposal.instructions, - ethers.utils.formatBytes32String(stringToBytes32String(proposal.name)), - // TODO(appleseed): add back in name after contract update - proposal.proposalURI, - ); - }); + // NOTE(appleseed): proposal.name is limited 31 characters, but full proposal name is uploaded in metadata via useIPFSUpload + const transaction = await contract.connect(signer).submitProposal( + proposal.instructions, + ethers.utils.formatBytes32String(stringToBytes32String(proposal.name)), + // TODO(appleseed): add back in name after contract update + proposal.proposalURI, + ); + const response = await transaction.wait(); + return response; + }, + { + onSuccess: () => { + toast("Successfully Submitted Proposal"); + queryClient.invalidateQueries({ queryKey: ["GetProposalSubmittedEvents", chain.id] }); + }, + }, + ); }; export const useIPFSUpload = () => { diff --git a/src/views/Governance/components/CreateProposal/CreateProposal.tsx b/src/views/Governance/components/CreateProposal/CreateProposal.tsx index cea2a65631..f94ae9477d 100644 --- a/src/views/Governance/components/CreateProposal/CreateProposal.tsx +++ b/src/views/Governance/components/CreateProposal/CreateProposal.tsx @@ -3,6 +3,7 @@ import { Paper, PrimaryButton } from "@olympusdao/component-library"; import MDEditor from "@uiw/react-md-editor"; import { ethers } from "ethers"; import { FC, useState } from "react"; +import { useNavigate } from "react-router-dom"; import rehypeSanitize from "rehype-sanitize"; import { TokenAllowanceGuard } from "src/components/TokenAllowanceGuard/TokenAllowanceGuard"; import { GOVERNANCE_ADDRESSES, VOTE_TOKEN_ADDRESSES } from "src/constants/addresses"; @@ -28,6 +29,7 @@ export const CreateProposal = () => { // TODO(appleseed): need to allow multiple instructions const [proposalAction, setProposalAction] = useState(ProposalAction.InstallModule); const [proposalContract, setProposalContract] = useState(); + const navigate = useNavigate(); const StyledInputLabel = styled(InputLabel)(() => ({ lineHeight: "24px", @@ -91,7 +93,14 @@ export const CreateProposal = () => { const proposalURI = `ipfs://${fileData.path}`; // TODO(appleseed): need to allow multiple instructions const instructions = [{ action: proposalAction as ProposalAction, target: proposalContract as string }]; - submitProposal.mutate({ proposal: { name: proposal.name, instructions, proposalURI } }); + submitProposal.mutate( + { proposal: { name: proposal.name, instructions, proposalURI } }, + { + onSuccess: () => { + navigate("/governance"); + }, + }, + ); } else { // TODO(appleseed): there was a problem uploading your proposal to IPFS } @@ -143,7 +152,7 @@ export const CreateProposal = () => { approvalPendingText={"Confirming Approval in your wallet"} isVertical > - + {submitProposal.isLoading ? "Submitting..." : "Continue"}