From 446f1f92ef6b3be6ee59a823786e22e5287e0215 Mon Sep 17 00:00:00 2001 From: "yongen.loong" Date: Wed, 24 Jul 2024 23:44:22 +0800 Subject: [PATCH] proposal info --- app/api/get-proposal-info/route.ts | 15 +++++++ components/workspace/cli.tsx | 34 +++++++++++++-- data/proposal-info-types.ts | 66 ++++++++++++++++++++++++++++++ data/wallet.ts | 8 ++++ 4 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 app/api/get-proposal-info/route.ts create mode 100644 data/proposal-info-types.ts diff --git a/app/api/get-proposal-info/route.ts b/app/api/get-proposal-info/route.ts new file mode 100644 index 0000000..111268f --- /dev/null +++ b/app/api/get-proposal-info/route.ts @@ -0,0 +1,15 @@ +export async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const id = searchParams.get("id"); + + if (!id) { + throw new Error("no id"); + } + + const res = await fetch( + `https://explorer-test-side02.aelf.io/api/proposal/proposalInfo?proposalId=${id}` + ); + const data = await res.json(); + + return Response.json(data); +} diff --git a/components/workspace/cli.tsx b/components/workspace/cli.tsx index 5cfab0b..1ef9c73 100644 --- a/components/workspace/cli.tsx +++ b/components/workspace/cli.tsx @@ -2,7 +2,12 @@ import { build } from "@/data/build"; import { db } from "@/data/db"; -import { useDeploy, useLogs, useTransactionResult } from "@/data/wallet"; +import { + getProposalInfo, + useDeploy, + useLogs, + useTransactionResult, +} from "@/data/wallet"; import { useTheme } from "next-themes"; import { useParams } from "next/navigation"; import { ReactTerminal } from "react-terminal"; @@ -64,21 +69,42 @@ export default function Cli() { const result = await getResult(id); const logs = await getLogs(id); const { data } = z.object({ proposalId: z.string() }).safeParse(logs); + const proposalInfo = await getProposalInfo(data?.proposalId); + const releasedTxId = proposalInfo?.data.proposal.releasedTxId; + const releasedTxLogs = releasedTxId + ? await getLogs(releasedTxId) + : undefined; + const { data: contractAddressData } = z + .object({ address: z.string() }) + .safeParse(releasedTxLogs); + return ( <> - + - + - + + + + + + + + +
TransactionId: TransactionId: {id}
Status: Status: {result.Status}
ProposalId: ProposalId: {data?.proposalId}
Proposal Status:{proposalInfo?.data.proposal.status}
Contract Address: + {proposalInfo?.data.proposal.status === "released" + ? contractAddressData?.address + : "-"} +
); diff --git a/data/proposal-info-types.ts b/data/proposal-info-types.ts new file mode 100644 index 0000000..8899f8d --- /dev/null +++ b/data/proposal-info-types.ts @@ -0,0 +1,66 @@ +export interface ProposalInfo { + msg: string; + code: number; + data: Data; +} + +export interface Data { + proposal: Proposal; + bpList: string[]; + organization: Organization; + parliamentProposerList: any[]; +} + +export interface Proposal { + createAt: string; + expiredTime: string; + approvals: number; + rejections: number; + abstentions: number; + leftInfo: LeftInfo; + releasedTime: string; + id: number; + orgAddress: string; + createTxId: string; + proposalId: string; + proposer: string; + contractAddress: string; + contractMethod: string; + contractParams: string; + status: string; + releasedTxId: string; + createdBy: string; + isContractDeployed: boolean; + proposalType: string; + canVote: boolean; + votedStatus: string; +} + +export interface LeftInfo { + organizationAddress: string; +} + +export interface Organization { + createdAt: string; + updatedAt: string; + releaseThreshold: ReleaseThreshold; + leftOrgInfo: LeftOrgInfo; + orgAddress: string; + orgHash: string; + txId: string; + creator: string; + proposalType: string; +} + +export interface ReleaseThreshold { + minimalApprovalThreshold: string; + maximalRejectionThreshold: string; + maximalAbstentionThreshold: string; + minimalVoteThreshold: string; +} + +export interface LeftOrgInfo { + proposerAuthorityRequired: boolean; + parliamentMemberProposingAllowed: boolean; + creationToken: any; +} diff --git a/data/wallet.ts b/data/wallet.ts index 1cafc82..2216fd1 100644 --- a/data/wallet.ts +++ b/data/wallet.ts @@ -5,6 +5,7 @@ import { db } from "./db"; // @ts-ignore import AElf from "aelf-sdk"; import BigNumber from "bignumber.js"; +import { ProposalInfo } from "./proposal-info-types"; const { deserializeLog } = AElf.pbUtils; const aelf = new AElf( @@ -162,4 +163,11 @@ export function useLogs() { return err; } }; +} + +export async function getProposalInfo(proposalId?: string) { + const res = await fetch(`/api/get-proposal-info?id=${proposalId}`); + const data: ProposalInfo = await res.json(); + + return data; } \ No newline at end of file