diff --git a/src/pages/governance/[proposalId]/index.page.tsx b/src/pages/governance/[proposalId]/index.page.tsx index c3924c934..7bf208e5f 100644 --- a/src/pages/governance/[proposalId]/index.page.tsx +++ b/src/pages/governance/[proposalId]/index.page.tsx @@ -72,6 +72,8 @@ export default function ProposalDetailPage({ } }, [isChangeVoteClicked]); + console.log(proposal); + return ( <> @@ -320,7 +322,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { id: proposalId, masternode: MasternodeType.ALL, cycle: proposal.currentCycle, - size: 10, + size: 1, next: next, }); const pages = CursorPagination.getPages( diff --git a/src/pages/governance/_components/ProposalTable.tsx b/src/pages/governance/_components/ProposalTable.tsx index 875a539b5..c9a461cfe 100644 --- a/src/pages/governance/_components/ProposalTable.tsx +++ b/src/pages/governance/_components/ProposalTable.tsx @@ -15,6 +15,9 @@ import { isValidOCGGithubUrl, isValidOCGRedditUrl, } from "utils/commons/LinkValidator"; +import { PlaygroundRpcClient } from "@defichain/playground-api-client"; +import { newPlaygroundClient } from "@contexts/WhaleContext"; +import { isPlayground } from "@waveshq/walletkit-core"; import { ProposalDisplayName } from "./ProposalCard"; import { VoteModal } from "./VoteModal"; import { useCycleEndDate } from "../shared/useCycleEndTime"; @@ -27,14 +30,36 @@ export function ProposalTable({ currentBlockHeight, currentBlockMedianTime, userQueryProposalStatus, + masternodeId, }: { proposals: GovernanceProposal[]; currentBlockHeight: number; currentBlockMedianTime: number; userQueryProposalStatus: ListProposalsStatus; + masternodeId: string; }) { const [displayVoteModal, setDisplayVoteModal] = useState(false); + // TODO: remove testing code + const connection = useNetwork().connection; + async function voteDummyProposals( + proposalId: string, + masternodeId: string, + vote: string + ): Promise { + const playgroundRPC = new PlaygroundRpcClient( + newPlaygroundClient(connection) + ); + console.log( + `Voted proposal: ${proposalId} with ${vote}, tx hash:`, + await playgroundRPC.call( + "votegov", + [proposalId, masternodeId, vote], + "number" + ) + ); + } + return (
+ voteDummyProposals(proposal.proposalId, masternodeId, vote) + } /> {displayVoteModal && ( void; }) { const router = useRouter(); const { connection } = useNetwork(); @@ -212,7 +242,6 @@ function ProposalRow({
- {(userQueryProposalStatus === ListProposalsStatus.COMPLETED || userQueryProposalStatus === ListProposalsStatus.REJECTED) && ( @@ -230,6 +259,43 @@ function ProposalRow({ )} + {isPlayground(connection) && ( + + + + + + )} ); } diff --git a/src/pages/governance/index.page.tsx b/src/pages/governance/index.page.tsx index 9935c5d0a..9dae63dd1 100644 --- a/src/pages/governance/index.page.tsx +++ b/src/pages/governance/index.page.tsx @@ -1,11 +1,16 @@ -import React from "react"; +import React, { useState } from "react"; +import { isPlayground } from "@waveshq/walletkit-core"; import { Container } from "@components/commons/Container"; import { ApiPagedResponse } from "@defichain/whale-api-client"; import { CursorPage, CursorPagination, } from "@components/commons/CursorPagination"; -import { getWhaleApiClient, getWhaleRpcClient } from "@contexts/WhaleContext"; +import { + getWhaleApiClient, + getWhaleRpcClient, + newPlaygroundClient, +} from "@contexts/WhaleContext"; import { GetServerSidePropsContext } from "next"; import { ListProposalsType, @@ -15,11 +20,18 @@ import { GovernanceProposal, GovernanceProposalStatus, } from "@defichain/whale-api-client/dist/api/governance"; +import { useNetwork } from "@contexts/NetworkContext"; +import { PlaygroundRpcClient } from "@defichain/playground-api-client"; import classNames from "classnames"; import { Link } from "@components/commons/link/Link"; import { EmptySection } from "@components/commons/sections/EmptySection"; import { ProposalCards } from "./_components/ProposalCard"; import { ProposalTable } from "./_components/ProposalTable"; +import { Button } from "./_components/Button"; +import { + getLocalStorageItem, + setLocalStorage, +} from "./shared/localStorageHelper"; import { OnChainGovernanceTitles } from "./enum/onChainGovernanceTitles"; interface OCGProps { @@ -43,11 +55,48 @@ export default function OnChainGovernancePage({ allProposalsDetails, proposals, }: OCGProps) { + const connection = useNetwork().connection; const userQueryProposalStatus = allProposalsDetails.userQueryProposalStatus; const userQueryProposalType = allProposalsDetails.userQueryProposalType; + const [masternodeId, setMasterNodeID] = useState( + getLocalStorageItem("dummyMasternodeID") ?? "" + ); // const { currentYear, currentMonth } = getCurrentYearMonth(); + // TODO remove this before release to prod + async function createDummyProposals(): Promise { + const playgroundRPC = new PlaygroundRpcClient( + newPlaygroundClient(connection) + ); + for (let i = 0; i < 5; i += 1) { + const governanceType = ["creategovvoc", "creategovcfp"]; + const proposalType = + governanceType[Math.floor(Math.random() * governanceType.length)]; // get random governance type + const cfpData = { + title: `Title testing proposal ${new Date().getTime()}`, + amount: "100000000", + context: "https://github.com/DeFiCh/dfips/issues/238", + payoutAddress: "mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy", + cycles: i + 1, + }; + const vocData = { + title: `Title testing proposal ${new Date().getTime()}`, + context: + "https://www.reddit.com/r/defiblockchain/comments/10l6451/cfp_defichainwiki_9000_dfi/", + }; + const proposal = await playgroundRPC.call( + proposalType, + [proposalType === "creategovvoc" ? vocData : cfpData, []], + "number" + ); + console.log( + `proposal created with id:${proposal} is created with ${proposalType}` + ); + } + } + console.log(proposals); + return (
{/* TODO: uncomment to use announcement banner */ @@ -65,6 +114,33 @@ export default function OnChainGovernancePage({
*/} + + {isPlayground(connection) && ( +
+
+ )}
@@ -168,6 +244,7 @@ export default function OnChainGovernancePage({ allProposalsDetails.currentBlockMedianTime } userQueryProposalStatus={userQueryProposalStatus} + masternodeId={masternodeId} />
@@ -373,7 +450,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { .listGovProposals({ type: userQueryProposalType, status: userQueryProposalStatus, - size: 10, + size: 2, next: next, }) .catch(() => {