Skip to content

Commit

Permalink
Very basic proposals loading per-account
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Dec 14, 2024
1 parent 786adc8 commit 863b76f
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/lib/state/client/account.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const defaultDataSources = {
get_account: undefined,
light_account: [],
delegated: [],
proposals: [],
rex: undefined,
rexfund: undefined
};
Expand Down Expand Up @@ -77,6 +78,7 @@ export class AccountState {
public net = $derived.by(() => (this.account ? this.account.resource('net') : undefined));
public ram = $derived.by(() => (this.account ? this.account.resource('ram') : undefined));
public permissions = $derived.by(() => (this.account ? this.account.permissions : undefined));
public proposals = $derived.by(() => this.sources.proposals);
public value = $derived.by(() => {
return this.network && this.balance && this.ram
? getAccountValue(this.network, this.balance, this.ram)
Expand Down Expand Up @@ -108,6 +110,7 @@ export class AccountState {
get_account: json.account_data,
light_account: json.balances,
delegated: json.delegated,
proposals: json.proposals,
rex: json.rex,
rexfund: json.rexfund
};
Expand Down
2 changes: 2 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Asset
} from '@wharfkit/antelope';

import * as MsigContract from '$lib/wharf/contracts/msig';
import * as SystemContract from '$lib/wharf/contracts/system';

export interface Activity {
Expand Down Expand Up @@ -50,6 +51,7 @@ export interface DataSources {
get_account?: API.v1.AccountObject | undefined;
light_account: LightAPIBalanceRow[];
delegated: SystemContract.Types.delegated_bandwidth[];
proposals: MsigContract.Types.proposal[];
rex?: SystemContract.Types.rex_balance;
rexfund?: SystemContract.Types.rex_fund;
}
Expand Down
4 changes: 4 additions & 0 deletions src/routes/[network]/(explorer)/account/[name]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
if (context.settings.data.advancedMode) {
items.push({ href: `/${network}/account/${account}/permissions`, text: 'Permissions' });
items.push({ href: `/${network}/account/${account}/votes`, text: 'Votes' });
if (data.account.proposals.length > 0) {
items.push({ href: `/${network}/account/${account}/proposals`, text: 'Proposals' });
}
}
if (context.settings.data.debugMode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script lang="ts">
import Card from '$lib/components/layout/box/card.svelte';
const { data } = $props();
</script>

{#each data.proposals as proposal}
<Card>
<h2>
<a href={`/${data.network}/msig/${data.name}/${proposal.proposal_name}`}
>{proposal.proposal_name}</a
>
</h2>
</Card>
{/each}
21 changes: 21 additions & 0 deletions src/routes/[network]/(explorer)/account/[name]/proposals/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load: PageLoad = async ({ fetch, params, parent }) => {
const { network } = await parent();
const response = await fetch(`/${params.network}/api/msig/${params.name}`);
const json = await response.json();

if ('error' in json) {
error(404, json.error);
}

return {
proposals: json.proposals,
subtitle: `Multisig proposals by ${params.name} on the ${network.chain.name} Network.`,
pageMetaTags: {
title: `Multisig Proposals | ${params.name} | ${network.chain.name} Network`,
description: `Multisig proposals by ${params.name} on the ${network.chain.name} Network.`
}
};
};
8 changes: 5 additions & 3 deletions src/routes/[network]/api/account/[[name]]/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ export const GET: RequestHandler = async ({ fetch, params }) => {
}

const network = getBackendNetwork(chain, fetch);
const { system: systemContract } = network.contracts;
const { system: systemContract, msig: msigContract } = network.contracts;

try {
const headers = getCacheHeaders(5);

const [account_data, delegated] = await Promise.all([
const [account_data, delegated, proposals] = await Promise.all([
network.client.v1.chain.get_account(params.name),
systemContract.table('delband').all({ scope: params.name })
systemContract.table('delband').all({ scope: params.name }),
msigContract.table('proposal', params.name).all()
]);

let rexbal, rexfund;
Expand Down Expand Up @@ -57,6 +58,7 @@ export const GET: RequestHandler = async ({ fetch, params }) => {
account_data,
balances,
delegated,
proposals,
rex: rexbal,
rexfund: rexfund
},
Expand Down
34 changes: 34 additions & 0 deletions src/routes/[network]/api/msig/[proposer]/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { json, type RequestEvent } from '@sveltejs/kit';

import { getChainDefinitionFromParams } from '$lib/state/network.svelte';
import { Name } from '@wharfkit/antelope';
import { getCacheHeaders } from '$lib/utils';
import { getBackendNetwork } from '$lib/wharf/client/ssr.js';

export async function GET({ fetch, params }: RequestEvent) {
const chain = getChainDefinitionFromParams(String(params.network));
if (!chain) {
return json({ error: 'Invalid chain specified' }, { status: 400 });
}
if (!params.proposer) {
return json({ error: 'Proposer must be specified' }, { status: 400 });
}

const network = getBackendNetwork(chain, fetch);

const scope = Name.from(params.proposer);

const proposals = await network.contracts.msig.table('proposal', scope).all();

return json(
{
ts: new Date(),
proposer: params.proposer,
name: params.proposal,
proposals
},
{
headers: getCacheHeaders(5)
}
);
}

0 comments on commit 863b76f

Please sign in to comment.