Adjust events for parachains (#5010)
This commit is contained in:
parent
97a6dc78ab
commit
35d0527013
@ -25,9 +25,8 @@ const FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {
|
||||
year: 'numeric'
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function assertUnreachable (x: never): never {
|
||||
throw new Error('We cannot get here');
|
||||
function assertUnreachable (type: string): never {
|
||||
throw new Error(`We should not get here, unhandled ${type}`);
|
||||
}
|
||||
|
||||
function exportCalendar (date: Date, description: string): void {
|
||||
@ -60,6 +59,10 @@ function exportCalendar (date: Date, description: string): void {
|
||||
window.URL.revokeObjectURL(anchor.href);
|
||||
}
|
||||
|
||||
function createLink (to: string, desc: string): React.ReactNode {
|
||||
return <div className='itemLink'><a href={`#/${to}`}>{desc}</a></div>;
|
||||
}
|
||||
|
||||
function DayItem ({ className, item: { date, info, type }, showAllEvents }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
@ -78,22 +81,26 @@ function DayItem ({ className, item: { date, info, type }, showAllEvents }: Prop
|
||||
: formatNumber(info)
|
||||
);
|
||||
const typeLink = ['councilElection'].includes(type)
|
||||
? <div className='itemLink'><a href='#/council'>{t<string>('via Council')}</a></div>
|
||||
? createLink('council', t<string>('via Council'))
|
||||
: ['councilMotion'].includes(type)
|
||||
? <div className='itemLink'><a href='#/council/motions'>{t<string>('via Council/Motions')}</a></div>
|
||||
? createLink('council/motions', t<string>('via Council/Motions'))
|
||||
: ['democracyDispatch', 'scheduler'].includes(type)
|
||||
? <div className='itemLink'><a href='#/democracy/dispatch'>{t<string>('via Democracy/Dispatch')}</a></div>
|
||||
? createLink('democracy/dispatch', t<string>('via Democracy/Dispatch'))
|
||||
: ['democracyLaunch', 'referendumDispatch', 'referendumVote'].includes(type)
|
||||
? <div className='itemLink'><a href='#/democracy'>{t<string>('via Democracy')}</a></div>
|
||||
? createLink('/democracy', t<string>('via Democracy'))
|
||||
: ['societyChallenge', 'societyRotate'].includes(type)
|
||||
? <div className='itemLink'><a href='#/society'>{t<string>('via Society')}</a></div>
|
||||
? createLink('society', t<string>('via Society'))
|
||||
: ['stakingEpoch', 'stakingEra'].includes(type)
|
||||
? <div className='itemLink'><a href='#/staking'>{t<string>('via Staking')}</a></div>
|
||||
? createLink('staking', t<string>('via Staking'))
|
||||
: ['stakingSlash'].includes(type)
|
||||
? <div className='itemLink'><a href='#/staking/slashes'>{t<string>('via Staking/Slashed')}</a></div>
|
||||
? createLink('staking/slashes', t<string>('via Staking/Slashed'))
|
||||
: ['treasurySpend'].includes(type)
|
||||
? <div className='itemLink'><a href='#/treasury'>{t<string>('via Treasury')}</a></div>
|
||||
: undefined;
|
||||
? createLink('treasury', t<string>('via Treasury'))
|
||||
: ['parachainLease'].includes(type)
|
||||
? createLink('parachains', t<string>('via Parachains'))
|
||||
: ['parachainAuction'].includes(type)
|
||||
? createLink('parachains/auction', t<string>('via Parachains/Auction'))
|
||||
: undefined;
|
||||
let s = '';
|
||||
|
||||
switch (type) {
|
||||
@ -113,6 +120,14 @@ function DayItem ({ className, item: { date, info, type }, showAllEvents }: Prop
|
||||
s = t<string>('Start of the next referendum voting period');
|
||||
break;
|
||||
|
||||
case 'parachainAuction':
|
||||
s = t<string>('End of the current parachain auction {{id}}', { replace: { id } });
|
||||
break;
|
||||
|
||||
case 'parachainLease':
|
||||
s = t<string>('Start of the next parachain lease period {{id}}', { replace: { id } });
|
||||
break;
|
||||
|
||||
case 'referendumDispatch':
|
||||
s = t<string>('Potential dispatch of referendum {{id}} (if passed)', { replace: { id } });
|
||||
break;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
import type BN from 'bn.js';
|
||||
|
||||
export type EntryType = 'councilElection' | 'councilMotion' | 'democracyDispatch' | 'democracyLaunch' | 'referendumDispatch' | 'referendumVote' | 'scheduler' | 'societyChallenge' | 'societyRotate'| 'stakingEpoch' | 'stakingEra' | 'stakingSlash' | 'treasurySpend';
|
||||
export type EntryType = 'councilElection' | 'councilMotion' | 'democracyDispatch' | 'democracyLaunch' | 'parachainAuction' | 'parachainLease' | 'referendumDispatch' | 'referendumVote' | 'scheduler' | 'societyChallenge' | 'societyRotate'| 'stakingEpoch' | 'stakingEra' | 'stakingSlash' | 'treasurySpend';
|
||||
|
||||
export interface EntryInfo {
|
||||
blockNumber: BN;
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
// Copyright 2017-2021 @polkadot/app-calendar authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { DeriveCollectiveProposal, DeriveDispatch, DeriveReferendumExt, DeriveSessionProgress } from '@polkadot/api-derive/types';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { BlockNumber, EraIndex, Scheduled, UnappliedSlash } from '@polkadot/types/interfaces';
|
||||
import type { BlockNumber, EraIndex, LeasePeriodOf, Scheduled, UnappliedSlash } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { EntryInfo, EntryInfoTyped, EntryType } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { useApi, useBestNumber, useBlockTime, useCall } from '@polkadot/react-hooks';
|
||||
import { BN_ONE } from '@polkadot/util';
|
||||
import { BN_ONE, BN_THREE } from '@polkadot/util';
|
||||
|
||||
interface DateExt {
|
||||
date: Date;
|
||||
@ -39,7 +40,7 @@ function createConstDurations (bestNumber: BlockNumber, blockTime: number, items
|
||||
...newDate(blocks, blockTime),
|
||||
blockNumber: bestNumber.add(blocks),
|
||||
blocks,
|
||||
info: null
|
||||
info: bestNumber.div(duration)
|
||||
}]];
|
||||
});
|
||||
}
|
||||
@ -168,6 +169,19 @@ function createScheduled (bestNumber: BlockNumber, blockTime: number, scheduled:
|
||||
}, [])]];
|
||||
}
|
||||
|
||||
function createAuctionInfo (bestNumber: BlockNumber, blockTime: number, [leasePeriod, endBlock]: [LeasePeriodOf, BlockNumber]): [EntryType, EntryInfo[]][] {
|
||||
const blocks = endBlock.sub(bestNumber);
|
||||
|
||||
return [
|
||||
['parachainAuction', [{
|
||||
...newDate(blocks, blockTime),
|
||||
blockNumber: endBlock,
|
||||
blocks,
|
||||
info: `${leasePeriod.toString()} - ${leasePeriod.add(BN_THREE).toString()}`
|
||||
}]]
|
||||
];
|
||||
}
|
||||
|
||||
function addFiltered (state: EntryInfoTyped[], types: [EntryType, EntryInfo[]][]): EntryInfoTyped[] {
|
||||
return types.reduce((state: EntryInfoTyped[], [typeFilter, items]): EntryInfoTyped[] => {
|
||||
return state
|
||||
@ -185,11 +199,12 @@ export default function useScheduled (): EntryInfo[] {
|
||||
const { api } = useApi();
|
||||
const [blockTime] = useBlockTime();
|
||||
const bestNumber = useBestNumber();
|
||||
const auctionInfo = useCall<Option<ITuple<[LeasePeriodOf, BlockNumber]>>>(api.query.auctions?.auctionInfo);
|
||||
const councilMotions = useCall<DeriveCollectiveProposal[]>(api.derive.council?.proposals);
|
||||
const dispatches = useCall<DeriveDispatch[]>(api.derive.democracy?.dispatchQueue);
|
||||
const referendums = useCall<DeriveReferendumExt[]>(api.derive.democracy?.referendums);
|
||||
const scheduled = useCall<ScheduleEntry[]>(api.query.scheduler?.agenda?.entries);
|
||||
const sessionInfo = useCall<DeriveSessionProgress>(api.query.staking && api.derive.session?.progress);
|
||||
const sessionInfo = useCall<DeriveSessionProgress>(api.derive.session?.progress);
|
||||
const slashes = useCall<SlashEntry[]>(api.query.staking?.unappliedSlashes.entries);
|
||||
const [state, setState] = useState<EntryInfoTyped[]>([]);
|
||||
|
||||
@ -218,16 +233,23 @@ export default function useScheduled (): EntryInfo[] {
|
||||
}, [bestNumber, blockTime, scheduled]);
|
||||
|
||||
useEffect((): void => {
|
||||
bestNumber && sessionInfo?.sessionLength.gt(BN_ONE) && slashes && setState((state) =>
|
||||
addFiltered(state, createStakingInfo(bestNumber, blockTime, sessionInfo, slashes, api.consts.staking.slashDeferDuration))
|
||||
bestNumber && sessionInfo?.sessionLength.gt(BN_ONE) && setState((state) =>
|
||||
addFiltered(state, createStakingInfo(bestNumber, blockTime, sessionInfo, slashes || [], api.consts.staking?.slashDeferDuration))
|
||||
);
|
||||
}, [api, bestNumber, blockTime, sessionInfo, slashes]);
|
||||
|
||||
useEffect((): void => {
|
||||
bestNumber && auctionInfo?.isSome && setState((state) =>
|
||||
addFiltered(state, createAuctionInfo(bestNumber, blockTime, auctionInfo.unwrap()))
|
||||
);
|
||||
}, [auctionInfo, bestNumber, blockTime]);
|
||||
|
||||
useEffect((): void => {
|
||||
bestNumber && setState((state) =>
|
||||
addFiltered(state, createConstDurations(bestNumber, blockTime, [
|
||||
['councilElection', (api.consts.elections || api.consts.electionsPhragmen)?.termDuration],
|
||||
['democracyLaunch', api.consts.democracy?.launchPeriod],
|
||||
['parachainLease', api.consts.slots?.leasePeriod as BlockNumber],
|
||||
['societyChallenge', api.consts.society?.challengePeriod],
|
||||
['societyRotate', api.consts.society?.rotationPeriod],
|
||||
['treasurySpend', api.consts.treasury?.spendPeriod]
|
||||
|
||||
@ -31,6 +31,12 @@ function Summary ({ auctionInfo, className, lastWinners }: Props): React.ReactEl
|
||||
<CardSummary label={t<string>('auctions')}>
|
||||
{formatNumber(auctionInfo?.numAuctions)}
|
||||
</CardSummary>
|
||||
<CardSummary label={t<string>('active')}>
|
||||
{auctionInfo?.leasePeriod
|
||||
? t<string>('yes')
|
||||
: t<string>('no')
|
||||
}
|
||||
</CardSummary>
|
||||
</section>
|
||||
{auctionInfo && (
|
||||
<>
|
||||
|
||||
@ -41,9 +41,9 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement<Prop
|
||||
const ownedIds = useOwnedIds();
|
||||
const winningData = useWinningData(auctionInfo);
|
||||
const proposals = useProposals();
|
||||
const paraIds = useCall<ParaId[]>(api.query.paras?.parachains);
|
||||
const actionsQueue = useActionsQueue();
|
||||
const upcomingIds = useUpcomingIds();
|
||||
const paraIds = useCall<ParaId[]>(api.query.paras?.parachains);
|
||||
|
||||
const items = useRef([
|
||||
{
|
||||
@ -67,7 +67,7 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement<Prop
|
||||
name: 'crowdloan',
|
||||
text: t<string>('Crowdloan')
|
||||
}
|
||||
].filter((q): q is { name: string; text: string } => !!q));
|
||||
].filter((q) => !!q));
|
||||
|
||||
return (
|
||||
<main className={className}>
|
||||
|
||||
@ -20,11 +20,12 @@ function isNewWinners (a: WinnerData[], b: WinnerData[]): boolean {
|
||||
}
|
||||
|
||||
function isNewOrdering (a: WinnerData[], b: WinnerData[]): boolean {
|
||||
return a.length !== b.length || a.some(({ firstSlot, lastSlot, paraId }, index) =>
|
||||
!paraId.eq(b[index].paraId) ||
|
||||
!firstSlot.eq(b[index].firstSlot) ||
|
||||
!lastSlot.eq(b[index].lastSlot)
|
||||
);
|
||||
return a.length !== b.length ||
|
||||
a.some(({ firstSlot, lastSlot, paraId }, index) =>
|
||||
!paraId.eq(b[index].paraId) ||
|
||||
!firstSlot.eq(b[index].firstSlot) ||
|
||||
!lastSlot.eq(b[index].lastSlot)
|
||||
);
|
||||
}
|
||||
|
||||
function extractWinners (auctionInfo: AuctionInfo, optData: Option<WinningData>): WinnerData[] {
|
||||
@ -124,15 +125,15 @@ export default function useWinningData (auctionInfo?: AuctionInfo): Winning[] |
|
||||
const bestNumber = useBestNumber();
|
||||
const trigger = useEventTrigger([api.events.auctions?.BidAccepted]);
|
||||
const triggerRef = useRef(trigger);
|
||||
const allEntries = useCall<[StorageKey<[BlockNumber]>, Option<WinningData>][]>(api.query.auctions?.winning.entries);
|
||||
const initialEntries = useCall<[StorageKey<[BlockNumber]>, Option<WinningData>][]>(api.query.auctions?.winning.entries);
|
||||
const optFirstData = useCall<Option<WinningData>>(api.query.auctions?.winning, FIRST_PARAM);
|
||||
|
||||
// should be fired once, all entries as an initial round
|
||||
useEffect((): void => {
|
||||
auctionInfo && allEntries && setResult(
|
||||
extractData(auctionInfo, allEntries)
|
||||
auctionInfo && initialEntries && setResult(
|
||||
extractData(auctionInfo, initialEntries)
|
||||
);
|
||||
}, [allEntries, auctionInfo]);
|
||||
}, [auctionInfo, initialEntries]);
|
||||
|
||||
// when block 0 changes, update (typically in non-ending-period, static otherwise)
|
||||
useEffect((): void => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user