Hrmp queue extension (#4992)
* Hrml queue extension * Column adjustments
This commit is contained in:
parent
08f3e56167
commit
19a608c4aa
@ -175,10 +175,21 @@ function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, la
|
||||
</td>
|
||||
<td className='start together hash'>{paraInfo.headHex}</td>
|
||||
<td className='start media--1100'>
|
||||
<Lifecycle
|
||||
lifecycle={paraInfo.lifecycle}
|
||||
nextAction={nextAction}
|
||||
/>
|
||||
{paraInfo.updateAt && bestNumber && paraInfo.lifecycle?.isParachain
|
||||
? (
|
||||
<>
|
||||
{t<string>('Upgrading')}
|
||||
<BlockToTime value={paraInfo.updateAt.sub(bestNumber)} />
|
||||
#{formatNumber(paraInfo.updateAt)}
|
||||
</>
|
||||
)
|
||||
: (
|
||||
<Lifecycle
|
||||
lifecycle={paraInfo.lifecycle}
|
||||
nextAction={nextAction}
|
||||
/>
|
||||
)
|
||||
}
|
||||
</td>
|
||||
<td className='all' />
|
||||
<td className='number'>{blockDelay && <BlockToTime value={blockDelay} />}</td>
|
||||
@ -199,16 +210,12 @@ function Parachain ({ bestNumber, channelDst, channelSrc, className = '', id, la
|
||||
}
|
||||
</td>
|
||||
<td className='number media--900 no-pad-left'>{paraBest && <>{formatNumber(paraBest)}</>}</td>
|
||||
<td className='number media--1200'>
|
||||
{paraInfo.updateAt && bestNumber && (
|
||||
<>
|
||||
<BlockToTime value={paraInfo.updateAt.sub(bestNumber)} />
|
||||
#{formatNumber(paraInfo.updateAt)}
|
||||
</>
|
||||
)}
|
||||
</td>
|
||||
<td className='number media--1300'>
|
||||
{formatNumber(paraInfo.qUmp)} / {formatNumber(paraInfo.qDmp)} / {formatNumber(paraInfo.qHrmpE)} / {formatNumber(paraInfo.qHrmpI)} ({formatNumber(channelCounts[0])} / {formatNumber(channelCounts[1])})
|
||||
{/* {formatNumber(paraInfo.qUmp)} / {formatNumber(paraInfo.qDmp)} / {formatNumber(paraInfo.qHrmpE)} / {formatNumber(paraInfo.qHrmpI)} ({formatNumber(channelCounts[0])} / {formatNumber(channelCounts[1])}) */}
|
||||
{formatNumber(paraInfo.qHrmpI)} ({formatNumber(channelCounts[0])})
|
||||
</td>
|
||||
<td className='number media--1300 no-pad-left'>
|
||||
{formatNumber(paraInfo.qHrmpE)} ({formatNumber(channelCounts[1])})
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
|
||||
@ -3,11 +3,10 @@
|
||||
|
||||
import type { ApiPromise } from '@polkadot/api';
|
||||
import type { SignedBlockExtended } from '@polkadot/api-derive/types';
|
||||
import type { Option, StorageKey } from '@polkadot/types';
|
||||
import type { AccountId, CandidateReceipt, Event, HrmpChannel, HrmpChannelId, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
|
||||
import type { AccountId, CandidateReceipt, Event, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
|
||||
import type { IEvent } from '@polkadot/types/types';
|
||||
import type { ScheduledProposals } from '../types';
|
||||
import type { ChannelMap, EventMapInfo, QueuedAction, ValidatorInfo } from './types';
|
||||
import type { EventMapInfo, QueuedAction, ValidatorInfo } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
@ -17,6 +16,7 @@ import { useApi, useBestNumber, useCall, useCallMulti } from '@polkadot/react-ho
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import Parachain from './Parachain';
|
||||
import useHrmp from './useHrmp';
|
||||
|
||||
interface Props {
|
||||
actionsQueue: QueuedAction[];
|
||||
@ -115,29 +115,6 @@ function extractEvents (api: ApiPromise, lastBlock: SignedBlockExtended, prev: L
|
||||
: prev;
|
||||
}
|
||||
|
||||
const optChannelKeys = {
|
||||
transform: (keys: StorageKey<[HrmpChannelId]>[]): HrmpChannelId[] =>
|
||||
keys.map(({ args: [id] }) => id)
|
||||
};
|
||||
|
||||
const optChannels = {
|
||||
transform: ([[channelIds], channels]: [[HrmpChannelId[]], Option<HrmpChannel>[]]): [ChannelMap, ChannelMap] =>
|
||||
channelIds
|
||||
.map((id, index): [HrmpChannelId, Option<HrmpChannel>] => [id, channels[index]])
|
||||
.filter(([, opt]) => opt.isSome)
|
||||
.map(([id, opt]): [HrmpChannelId, HrmpChannel] => [id, opt.unwrap()])
|
||||
.reduce(([src, dst]: [ChannelMap, ChannelMap], [id, channel]): [ChannelMap, ChannelMap] => {
|
||||
dst[id.receiver.toNumber()] ||= [];
|
||||
src[id.sender.toNumber()] ||= [];
|
||||
|
||||
dst[id.receiver.toNumber()].push([id, channel]);
|
||||
src[id.sender.toNumber()].push([id, channel]);
|
||||
|
||||
return [src, dst];
|
||||
}, [{}, {}]),
|
||||
withParamsTransform: true
|
||||
};
|
||||
|
||||
function extractActions (actionsQueue: QueuedAction[], knownIds?: [ParaId, string][]): Record<string, QueuedAction | undefined> {
|
||||
return actionsQueue && knownIds
|
||||
? knownIds.reduce((all: Record<string, QueuedAction | undefined>, [id, key]) => ({
|
||||
@ -158,8 +135,7 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
api.query.paraScheduler?.validatorGroups || api.query.scheduler?.validatorGroups,
|
||||
api.query.shared?.activeValidatorIndices
|
||||
], optionsMulti);
|
||||
const channelIds = useCall<HrmpChannelId[]>(api.query.hrmp?.hrmpChannels.keys, undefined, optChannelKeys);
|
||||
const allChannels = useCall<[ChannelMap, ChannelMap]>(channelIds && api.query.hrmp.hrmpChannels.multi, [channelIds], optChannels);
|
||||
const hrmp = useHrmp();
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('parachains'), 'start', 2],
|
||||
@ -171,8 +147,7 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
[t('backed'), 'no-pad-left'],
|
||||
[t('timeout'), 'no-pad-left'],
|
||||
[t('chain best'), 'media--900 no-pad-left'],
|
||||
[t('upgrade'), 'media--1200'],
|
||||
[t('ump/dmp/hrmp'), 'media--1300']
|
||||
[t('in/out (msg)'), 'media--1300', 2]
|
||||
]);
|
||||
|
||||
const scheduledIds = useMemo(
|
||||
@ -209,8 +184,8 @@ function Parachains ({ actionsQueue, ids, scheduled }: Props): React.ReactElemen
|
||||
{knownIds?.map(([id, key], index): React.ReactNode => (
|
||||
<Parachain
|
||||
bestNumber={bestNumber}
|
||||
channelDst={allChannels?.[1][id.toNumber()]}
|
||||
channelSrc={allChannels?.[0][id.toNumber()]}
|
||||
channelDst={hrmp?.dst[id.toString()]}
|
||||
channelSrc={hrmp?.src[id.toString()]}
|
||||
id={id}
|
||||
isScheduled={scheduledIds[key]}
|
||||
key={key}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
import type BN from 'bn.js';
|
||||
import type { AccountId, BalanceOf, HrmpChannel, HrmpChannelId, ParaId, ParaValidatorIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
export type ChannelMap = Record<number, [HrmpChannelId, HrmpChannel][]>;
|
||||
export type ChannelMap = Record<string, [HrmpChannelId, HrmpChannel][]>;
|
||||
|
||||
export interface LeaseInfo {
|
||||
accountId: AccountId;
|
||||
|
||||
50
packages/page-parachains/src/Overview/useHrmp.ts
Normal file
50
packages/page-parachains/src/Overview/useHrmp.ts
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { HrmpChannel, HrmpChannelId } from '@polkadot/types/interfaces';
|
||||
import type { ChannelMap } from './types';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { useApi, useCall, useEventTrigger } from '@polkadot/react-hooks';
|
||||
|
||||
interface Result {
|
||||
dst: ChannelMap;
|
||||
src: ChannelMap;
|
||||
}
|
||||
|
||||
const optChannels = {
|
||||
transform: ([[channelIds], channels]: [[HrmpChannelId[]], Option<HrmpChannel>[]]): Result =>
|
||||
channelIds
|
||||
.map((id, index): [HrmpChannelId, Option<HrmpChannel>] => [id, channels[index]])
|
||||
.filter(([, opt]) => opt.isSome)
|
||||
.map(([id, opt]): [HrmpChannelId, HrmpChannel] => [id, opt.unwrap()])
|
||||
.reduce((all: Result, [id, channel]): Result => {
|
||||
all.dst[id.receiver.toString()] ||= [];
|
||||
all.src[id.sender.toString()] ||= [];
|
||||
|
||||
all.dst[id.receiver.toString()].push([id, channel]);
|
||||
all.src[id.sender.toString()].push([id, channel]);
|
||||
|
||||
return all;
|
||||
}, { dst: {}, src: {} }),
|
||||
withParamsTransform: true
|
||||
};
|
||||
|
||||
export default function useHrmp (): Result | undefined {
|
||||
const { api } = useApi();
|
||||
const [channelIds, setChannelIds] = useState<HrmpChannelId[] | null>(null);
|
||||
const trigger = useEventTrigger([api.events.hrmp?.OpenChannelAccepted, api.events.hrmp?.ChannelClosed]);
|
||||
const allChannels = useCall<Result>(channelIds && api.query.hrmp?.hrmpChannels.multi, [channelIds], optChannels);
|
||||
|
||||
useEffect((): void => {
|
||||
trigger &&
|
||||
api.query.hrmp?.hrmpChannels
|
||||
.keys<[HrmpChannelId]>()
|
||||
.then((keys) => setChannelIds(keys.map(({ args: [id] }) => id)))
|
||||
.catch(console.error);
|
||||
}, [api, trigger]);
|
||||
|
||||
return allChannels;
|
||||
}
|
||||
@ -167,9 +167,9 @@ export default function useFunds (): Campaigns {
|
||||
const { api } = useApi();
|
||||
const bestNumber = useBestNumber();
|
||||
const [paraIds, setParaIds] = useState<ParaId[]>([]);
|
||||
const trigger = useEventTrigger([api.events.crowdloan.Created]);
|
||||
const campaigns = useCall<Campaign[]>(api.query.crowdloan.funds.multi, [paraIds], optFundMulti);
|
||||
const leases = useCall<ParaId[]>(api.query.slots.leases.multi, [paraIds], optLeaseMulti);
|
||||
const trigger = useEventTrigger([api.events.crowdloan?.Created]);
|
||||
const campaigns = useCall<Campaign[]>(api.query.crowdloan?.funds.multi, [paraIds], optFundMulti);
|
||||
const leases = useCall<ParaId[]>(api.query.slots?.leases.multi, [paraIds], optLeaseMulti);
|
||||
const [result, setResult] = useState<Campaigns>(EMPTY);
|
||||
|
||||
// on event triggers, update the available paraIds
|
||||
|
||||
Loading…
Reference in New Issue
Block a user