This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add governance pages (proposal, votes)
- Loading branch information
Showing
9 changed files
with
515 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' } | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}>< 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 ></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}>< 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 ></a> | ||
</div> | ||
</section> |
31 changes: 31 additions & 0 deletions
31
src/routes/governance/govactions/[actionid]/+page.server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' } | ||
}; | ||
} |
Oops, something went wrong.