Skip to content

Commit

Permalink
proposal info
Browse files Browse the repository at this point in the history
  • Loading branch information
yongenaelf committed Jul 24, 2024
1 parent fa4eb26 commit 446f1f9
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 4 deletions.
15 changes: 15 additions & 0 deletions app/api/get-proposal-info/route.ts
Original file line number Diff line number Diff line change
@@ -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);
}
34 changes: 30 additions & 4 deletions components/workspace/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (
<>
<table className="mt-4">
<tr>
<td className="pr-4">TransactionId: </td>
<td className="pr-4">TransactionId:</td>
<td>{id}</td>
</tr>
<tr>
<td>Status: </td>
<td>Status:</td>
<td>{result.Status}</td>
</tr>
<tr>
<td>ProposalId: </td>
<td>ProposalId:</td>
<td>{data?.proposalId}</td>
</tr>
<tr>
<td>Proposal Status:</td>
<td>{proposalInfo?.data.proposal.status}</td>
</tr>
<tr>
<td>Contract Address:</td>
<td>
{proposalInfo?.data.proposal.status === "released"
? contractAddressData?.address
: "-"}
</td>
</tr>
</table>
</>
);
Expand Down
66 changes: 66 additions & 0 deletions data/proposal-info-types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions data/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

0 comments on commit 446f1f9

Please sign in to comment.