Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
feat: Add governance pages (proposal, votes)
Browse files Browse the repository at this point in the history
  • Loading branch information
satran004 committed Jan 21, 2024
1 parent a1b8f9a commit 1da76d3
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 10 deletions.
23 changes: 21 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.53.1",
"svelte-check": "^2.9.2",
"svelte-feather-icons": "^4.1.0",
"svelte-preprocess": "^4.10.7",
"tailwindcss": "^3.3.2",
"tslib": "^2.4.1",
Expand Down
35 changes: 27 additions & 8 deletions src/components/Nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@
}
};
function closeDropdown() {
const detailsElement = document.querySelector("details");
function closeDropdownCertificateMenu() {
const detailsElement = document.querySelector("#certificate-menu");
if (detailsElement) {
detailsElement.removeAttribute("open");
}
}
function closeDropdownGovernanceMenu() {
const detailsElement = document.querySelector("#governance-menu");
if (detailsElement) {
detailsElement.removeAttribute("open");
}
Expand All @@ -40,21 +47,33 @@
<ul class="menu menu-horizontal px-1">
<li><a href="/">Home</a></li>
<li>
<details>
<details id="certificate-menu">
<summary>
Certificates
</summary>
<ul class="p-2 bg-base-100">
<li><a href="/certificates/stakekey-registrations" on:click={closeDropdown}>Stake Registration</a></li>
<li><a href="/certificates/stakekey-deregistrations" on:click={closeDropdown}>Stake DeRegistration</a></li>
<li><a href="/certificates/pool-registrations" on:click={closeDropdown}>Pool Registration</a></li>
<li><a href="/certificates/pool-retirements" on:click={closeDropdown}>Pool Retirements</a></li>
<li><a href="/certificates/delegations" on:click={closeDropdown}>Delegations</a></li>
<li><a href="/certificates/stakekey-registrations" on:click={closeDropdownCertificateMenu}>Stake Registration</a></li>
<li><a href="/certificates/stakekey-deregistrations" on:click={closeDropdownCertificateMenu}>Stake DeRegistration</a></li>
<li><a href="/certificates/pool-registrations" on:click={closeDropdownCertificateMenu}>Pool Registration</a></li>
<li><a href="/certificates/pool-retirements" on:click={closeDropdownCertificateMenu}>Pool Retirements</a></li>
<li><a href="/certificates/delegations" on:click={closeDropdownCertificateMenu}>Delegations</a></li>
</ul>
</details>
</li>
<li>
<details id="governance-menu">
<summary>
Governance
</summary>
<ul class="p-2 bg-base-100">
<li><a href="/governance/govactions" on:click={closeDropdownGovernanceMenu}>Proposals</a></li>
<li><a href="/governance/votes" on:click={closeDropdownGovernanceMenu}>Votes</a></li>
</ul>
</details>
</li>
<li><a href="/blocks">Blocks</a></li>
<li><a href="/transactions">Transactions</a></li>
</ul>
</div>
</div>
Expand Down
33 changes: 33 additions & 0 deletions src/routes/governance/govactions/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { PageLoad } from './$types'

export const load: PageLoad = async ({params, url}) => {
let page = url.searchParams.get('page');
if (!page) page = 0;
const count = 20;

const INDEXER_BASE_URL = import.meta.env.VITE_INDEXER_BASE_URL;
const apiUrl = `${INDEXER_BASE_URL}/gov-action-proposals?page=${page}&count=${count}`;
console.log(apiUrl);

const res = await fetch(apiUrl);
const data = await res.json();

const govactions = data;
console.log(data);

if (res.ok) {
return {
govactions,
total: 0,
total_pages: 0,
page: page,
count: count
}
}

return {
status: 404,
body: { error: 'Can not fetch Gov Action Proposals.' }
};

}
123 changes: 123 additions & 0 deletions src/routes/governance/govactions/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<script>
import {goto} from "$app/navigation";
import {page} from "$app/stores";
import {truncate, getDate} from "../../../util/util.js";
import { AirplayIcon, AtSignIcon, EyeIcon} from 'svelte-feather-icons'
export let data;
$: activeUrl = $page.url.searchParams.get('page')
let pages = [];
$:{
pages.forEach((page) => {
let splitUrl = page.href.split('?');
let queryString = splitUrl.slice(1).join('?');
const hrefParams = new URLSearchParams(queryString);
let hrefValue = hrefParams.get('page');
if (hrefValue === activeUrl) {
page.active = true
} else {
page.active = false
}
})
pages = pages
}
const previous = () => {
let currentPage = parseInt(data.page);
let prevPage = currentPage - 1;
if (prevPage <= 0)
prevPage = 1;
goto(`/governance/govactions?page=${prevPage}&count=${data.count}`)
};
const next = () => {
let currentPage = parseInt(data.page);
let nextPage = currentPage + 1;
if (data.govactions.length == 0)
nextPage = currentPage;
goto(`/governance/govactions?page=${nextPage}&count=${data.count}`)
};
console.log(data);
if (!data.govactions)
data.govactions = []
let showModal = false;
let selectedDetails = null;
function showDetails(details) {
selectedDetails = details;
showModal = true;
}
function closeModal() {
showModal = false;
}
</script>


<section class="container mx-auto text-sm">
<div class="flex flex-wrap justify-between mt-4 mb-2">
<a href="#"
class="px-4 py-2 text-blue-500 font-medium rounded-md bg-gray-100 hover:bg-gray-200 transition-colors"
role="button" on:click={previous}>&lt; Previous</a>
<h2 class="text-2xl font-bold text-center text-gray-500">Proposals</h2>
<a href="#"
class="px-4 py-2 text-blue-500 font-medium rounded-md bg-gray-100 hover:bg-gray-200 transition-colors"
role="button" on:click={next}>Next &gt;</a>
</div>
<div class="overflow-x-auto">
<table class="w-full bg-white border border-gray-300">
<thead>
<tr>
<th class="py-2 px-4 bg-gray-100 font-bold text-center">Transaction Hash</th>
<th class="py-2 px-4 bg-gray-100 font-bold text-center">Index</th>
<th class="py-2 px-4 bg-gray-100 font-bold text-center">Block</th>
<th class="py-2 px-4 bg-gray-100 font-bold text-center">Action Type</th>
<th class="py-2 px-4 bg-gray-100 font-bold text-center">Return Address</th>
<th class="py-2 px-4 bg-gray-100 font-bold text-center">Details</th>
</tr>
</thead>
<tbody>
<!-- Iterate over stake registrations data -->
{#each data.govactions as govaction, index}
<tr class="{index % 2 === 0 ? 'bg-gray-50' : 'bg-white'}">
<td class="py-2 px-4">
<a href="/transactions/{govaction.tx_hash}" class="text-blue-500">
<span class="ml-2">{truncate(govaction.tx_hash, 30, "...")}</span>
</a>
</td>
<td class="py-2 px-4 text-center">{govaction.index}</td>
<td class="py-2 px-4 text-center">
<a href="/blocks/{govaction.block_number}" class="text-blue-500">
{govaction.block_number}
</a>
</td>
<td class="py-2 px-4 text-center">{govaction.type}</td>
<td class="py-2 px-4 tex">{govaction.return_address}</td>
<td class="py-2 px-4 text-center"> <a href="/governance/govactions/{govaction.tx_hash}_{govaction.index}" target="_blank"><EyeIcon size="1.5x"/></a></td>
<!--{#if govaction.anchor_url}-->
<!-- <td class="py-2 px-4"><a href="{govaction.anchor_url}" target="_blank">{govaction.anchor_url}</a></td>-->
<!-- <td class="py-2 px-4">{govaction.anchor_hash}</td>-->
<!--{:else }-->
<!-- <td class="py-2 px-4">_</td>-->
<!-- <td class="py-2 px-4">_</td>-->
<!--{/if}-->
</tr>
{/each}
</tbody>
</table>
</div>
<div class="flex flex-wrap justify-between mt-2 mb-2">
<a href="#"
class="px-4 py-2 text-blue-500 font-medium rounded-md bg-gray-100 hover:bg-gray-200 transition-colors"
role="button" on:click={previous}>&lt; Previous</a>
<a href="#"
class="px-4 py-2 text-blue-500 font-medium rounded-md bg-gray-100 hover:bg-gray-200 transition-colors"
role="button" on:click={next}>Next &gt;</a>
</div>
</section>
31 changes: 31 additions & 0 deletions src/routes/governance/govactions/[actionid]/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { PageLoad } from './$types'

export const load: PageLoad = async ({params}) => {

let splits = params.actionid.split('_');
let index = parseInt(splits[1]);
const INDEXER_BASE_URL = import.meta.env.VITE_INDEXER_BASE_URL;
const blockApiUrl = `${INDEXER_BASE_URL}/gov-action-proposals/${splits[0]}`;

const res = await fetch(blockApiUrl);
const govActions = await res.json();

if (res.ok) {
let filterActionArr = govActions.filter((govAction) => govAction.index === index);
if (filterActionArr.length === 0) {
return {
status: 404,
body: { error: 'Can not fetch Gov Action Proposal.' }
};
} else {
return {
govAction: filterActionArr[0]
};
}
}

return {
status: 404,
body: { error: 'Can not fetch block.' }
};
}
Loading

0 comments on commit 1da76d3

Please sign in to comment.