Skip to content

Commit

Permalink
chore: add proposal status and update batched proposal query
Browse files Browse the repository at this point in the history
  • Loading branch information
devpavan04 committed Aug 10, 2023
1 parent 087f14c commit 11a476c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ import { fuzzyFilter } from '@webb-tools/webb-ui-components/components/Filter/ut
import { ChainIcon, Spinner } from '@webb-tools/icons';
import React, { useEffect, useMemo, useState } from 'react';
import { Link } from 'react-router-dom';
import { ProposalBatchStatus, ProposalType } from '../../generated/graphql';
import {
ProposalBatchStatus,
ProposalType,
ProposalBatchesOrderBy,
} from '../../generated/graphql';
import {
ProposalBatch,
BatchedProposalsQuery,
Expand Down Expand Up @@ -155,6 +159,7 @@ export const ProposalsTable = () => {
() => ({
offset: pagination.pageIndex * pageSize,
perPage: pagination.pageSize,
orderBy: ProposalBatchesOrderBy.IdDesc,
filter: null,
}),
[
Expand Down
4 changes: 2 additions & 2 deletions apps/stats-dapp/src/gql/proposals.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query ProposalBatches($perPage: Int!, $offset: Int!) {
proposalBatches(offset: $offset, first: $perPage) {
query ProposalBatches($perPage: Int!, $offset: Int!, $orderBy: [ProposalBatchesOrderBy!]) {
proposalBatches(offset: $offset, first: $perPage, orderBy: $orderBy) {
totalCount

nodes {
Expand Down
47 changes: 34 additions & 13 deletions apps/stats-dapp/src/pages/Proposals.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,44 @@
import { Card, Stats, TitleWithInfo } from '@webb-tools/webb-ui-components';
import { ProposalsTable } from '../containers';
import { useBatchedProposal, useBatchedProposals } from '../provider';
import { useMemo } from 'react';
import { useStatsContext } from '../provider';

const Proposals = () => {
// All Batched Proposals
const batchedProposals = useBatchedProposals({
offset: 0,
perPage: 10,
filter: null,
});
const {
dkgDataFromPolkadotAPI: { proposerCount, proposerThreshold },
} = useStatsContext();

// Single Batched Proposal
const batchedProposal = useBatchedProposal('10');

// console.log('Batched Proposals', batchedProposals);

// console.log('Batched Proposal', batchedProposal);
const statsItems = useMemo(() => {
return [
{
titleProps: {
title: 'Proposal Threshold',
info: 'Proposal Threshold',
},
value: proposerThreshold,
},
{
titleProps: {
title: 'Proposers',
info: 'Proposers',
},
value: proposerCount,
},
];
}, [proposerCount, proposerThreshold]);

return (
<div className="flex flex-col space-y-4">
<Card>
<TitleWithInfo
title="Proposals Status"
variant="h5"
info="Proposals Status"
/>

<Stats items={statsItems} />
</Card>

<ProposalsTable />
</div>
);
Expand Down
8 changes: 6 additions & 2 deletions apps/stats-dapp/src/provider/hooks/useProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Loadable, Page, PageInfoQuery } from './types';
import {
useProposalBatchesLazyQuery,
useProposalBatchQuery,
ProposalBatchesOrderBy,
} from '../../generated/graphql';

export type Proposal = {
Expand All @@ -18,7 +19,9 @@ export type ProposalBatch = {
chain: string;
};

export type BatchedProposalsQuery = PageInfoQuery;
export type BatchedProposalsQuery = PageInfoQuery & {
orderBy?: ProposalBatchesOrderBy;
};

export type BatchedProposals = Loadable<Page<ProposalBatch>>;

Expand All @@ -30,7 +33,7 @@ export type BatchedProposal = Loadable<ProposalBatch>;
export const useBatchedProposals = (
batchedProposalsQuery: BatchedProposalsQuery
): BatchedProposals => {
const { offset, perPage } = batchedProposalsQuery;
const { offset, perPage, orderBy } = batchedProposalsQuery;

const [call, query] = useProposalBatchesLazyQuery();

Expand All @@ -52,6 +55,7 @@ export const useBatchedProposals = (
variables: {
offset,
perPage,
orderBy,
},
});
}, [offset, perPage]);
Expand Down
11 changes: 11 additions & 0 deletions apps/stats-dapp/src/provider/stats-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type StatsProvidervalue = {
currentKey: string;
nextSessionNumber: number;
nextKey: string;
proposerCount: number;
proposerThreshold: number;
};
};

Expand Down Expand Up @@ -119,6 +121,8 @@ const statsContext: React.Context<StatsProvidervalue> =
currentKey: '',
nextSessionNumber: 0,
nextKey: '',
proposerCount: 0,
proposerThreshold: 0,
},
});

Expand Down Expand Up @@ -178,6 +182,8 @@ export const StatsProvider: React.FC<
currentKey: '',
nextSessionNumber: 0,
nextKey: '',
proposerCount: 0,
proposerThreshold: 0,
});

useEffect(() => {
Expand Down Expand Up @@ -258,11 +264,16 @@ export const StatsProvider: React.FC<
nextSessionNumber = nextDKGPublicKey[0];
nextKey = nextDKGPublicKey[1];
}
const proposerCount = await apiPromise.query.dkgProposals.proposerCount();
const proposerThreshold =
await apiPromise.query.dkgProposals.proposerThreshold();
setDkgDataFromPolkadotAPI({
currentSessionNumber,
currentKey,
nextSessionNumber,
nextKey,
proposerCount: Number(proposerCount.toString()),
proposerThreshold: Number(proposerThreshold.toString()),
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, useMemo } from 'react';
import { forwardRef } from 'react';
import { twMerge } from 'tailwind-merge';
import { ProposalsBadgeGroupProps } from './types';
import ProposalBadge from '@webb-tools/icons/ProposalBadge/ProposalBadge';
Expand Down

0 comments on commit 11a476c

Please sign in to comment.