Adjust parachain hooks/info (#4929)
* Adjust parachain hooks/info * Auto-fill current lease * Combine account/id * crowdload gte * defaultSlot, non-object
This commit is contained in:
parent
d3e69b8b32
commit
10f5b5912c
@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AuctionIndex, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { AuctionInfo } from '../types';
|
||||
import type { Winning } from './types';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
@ -12,13 +12,12 @@ import { useTranslation } from '../translate';
|
||||
import WinRange from './WinRange';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: [LeasePeriodOf, BlockNumber] | null;
|
||||
auctionInfo: AuctionInfo;
|
||||
className?: string;
|
||||
numAuctions: AuctionIndex | null;
|
||||
winningData: Winning[] | null;
|
||||
}
|
||||
|
||||
function Auction ({ auctionInfo, className, numAuctions, winningData }: Props): React.ReactElement<Props> {
|
||||
function Auction ({ auctionInfo, className, winningData }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
@ -31,8 +30,8 @@ function Auction ({ auctionInfo, className, numAuctions, winningData }: Props):
|
||||
<Table
|
||||
className={className}
|
||||
empty={
|
||||
numAuctions && winningData && (
|
||||
auctionInfo && auctionInfo[1] && !winningData.length
|
||||
auctionInfo.numAuctions && winningData && (
|
||||
auctionInfo.endBlock && !winningData.length
|
||||
? t<string>('No winners in this auction')
|
||||
: t<string>('No ongoing auction')
|
||||
)
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { AuctionIndex, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { OwnedId, OwnerInfo } from '../types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { AuctionInfo, OwnedId, OwnerInfo } from '../types';
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
@ -16,9 +16,8 @@ import { useTranslation } from '../translate';
|
||||
import { RANGES } from './constants';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: [LeasePeriodOf, BlockNumber] | null;
|
||||
auctionInfo: AuctionInfo;
|
||||
className?: string;
|
||||
id: AuctionIndex | null;
|
||||
ownedIds: OwnedId[];
|
||||
}
|
||||
|
||||
@ -27,7 +26,7 @@ interface Option {
|
||||
value: number;
|
||||
}
|
||||
|
||||
function Bid ({ auctionInfo, className, id, ownedIds }: Props): React.ReactElement<Props> {
|
||||
function Bid ({ auctionInfo, className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { hasAccounts } = useAccounts();
|
||||
@ -38,26 +37,21 @@ function Bid ({ auctionInfo, className, id, ownedIds }: Props): React.ReactEleme
|
||||
const [isOpen, toggleOpen] = useToggle();
|
||||
|
||||
const rangeOpts = useMemo(
|
||||
(): Option[] => {
|
||||
const [leasePeriod] = auctionInfo || [null, null];
|
||||
|
||||
return leasePeriod
|
||||
(): Option[] =>
|
||||
auctionInfo.leasePeriod
|
||||
? RANGES.map(([first, last], value): Option => ({
|
||||
text: `${formatNumber(leasePeriod.addn(first))} - ${formatNumber(leasePeriod.addn(last))}`,
|
||||
text: `${formatNumber(auctionInfo.leasePeriod?.addn(first))} - ${formatNumber(auctionInfo.leasePeriod?.addn(last))}`,
|
||||
value
|
||||
}))
|
||||
: [];
|
||||
},
|
||||
: [],
|
||||
[auctionInfo]
|
||||
);
|
||||
|
||||
const [leasePeriod, endBlock] = auctionInfo || [null, null];
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
icon='plus'
|
||||
isDisabled={!ownedIds.length || !hasAccounts || !id || !leasePeriod || !endBlock || bestNumber?.gte(endBlock.add(api.consts.auctions.endingPeriod as BlockNumber))}
|
||||
isDisabled={!ownedIds.length || !hasAccounts || !auctionInfo.numAuctions || !auctionInfo.leasePeriod || !auctionInfo.endBlock || bestNumber?.gte(auctionInfo.endBlock.add(api.consts.auctions.endingPeriod as BlockNumber))}
|
||||
label={t<string>('Bid')}
|
||||
onClick={toggleOpen}
|
||||
/>
|
||||
@ -81,7 +75,7 @@ function Bid ({ auctionInfo, className, id, ownedIds }: Props): React.ReactEleme
|
||||
</Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The first and last slots for this bid. The last slot should be after the first and a maximum of 3 slots more than the first')}>
|
||||
<Dropdown
|
||||
label={t<string>('bid slot range (start slot, end slot)')}
|
||||
label={t<string>('bid slot range (first slot - last slot)')}
|
||||
onChange={setRange}
|
||||
options={rangeOpts}
|
||||
value={range}
|
||||
@ -92,10 +86,10 @@ function Bid ({ auctionInfo, className, id, ownedIds }: Props): React.ReactEleme
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
icon='plus'
|
||||
isDisabled={!paraId || !amount?.gt(BN_ZERO) || !leasePeriod}
|
||||
isDisabled={!paraId || !amount?.gt(BN_ZERO) || !auctionInfo.leasePeriod}
|
||||
label={t<string>('Bid')}
|
||||
onStart={toggleOpen}
|
||||
params={[paraId, id, leasePeriod?.addn(RANGES[range][0]), leasePeriod?.addn(RANGES[range][1]), amount]}
|
||||
params={[paraId, auctionInfo.numAuctions, auctionInfo.leasePeriod?.addn(RANGES[range][0]), auctionInfo.leasePeriod?.addn(RANGES[range][1]), amount]}
|
||||
tx={api.tx.auctions.bid}
|
||||
/>
|
||||
</Modal.Actions>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AuctionIndex, Balance, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { Balance, BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { AuctionInfo } from '../types';
|
||||
import type { Winning } from './types';
|
||||
|
||||
import React from 'react';
|
||||
@ -9,68 +10,68 @@ import React from 'react';
|
||||
import { CardSummary, SummaryBox } from '@polkadot/react-components';
|
||||
import { useApi, useBestNumber, useCall } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
import { BN_THREE, formatNumber } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: [LeasePeriodOf, BlockNumber] | null;
|
||||
auctionInfo: AuctionInfo;
|
||||
className?: string;
|
||||
lastWinner: Winning | null;
|
||||
numAuctions?: AuctionIndex | null;
|
||||
}
|
||||
|
||||
function Summary ({ auctionInfo, className, lastWinner, numAuctions }: Props): React.ReactElement<Props> {
|
||||
function Summary ({ auctionInfo, className, lastWinner }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const bestNumber = useBestNumber();
|
||||
const totalIssuance = useCall<Balance>(api.query.balances?.totalIssuance);
|
||||
const [period, ending] = auctionInfo || [];
|
||||
|
||||
return (
|
||||
<SummaryBox className={className}>
|
||||
<section>
|
||||
<CardSummary label={t<string>('auctions')}>
|
||||
{formatNumber(numAuctions)}
|
||||
{formatNumber(auctionInfo.numAuctions)}
|
||||
</CardSummary>
|
||||
{period && (
|
||||
<CardSummary label={t<string>('period')}>
|
||||
{formatNumber(period)}
|
||||
</CardSummary>
|
||||
)}
|
||||
</section>
|
||||
{auctionInfo && (
|
||||
{auctionInfo.endBlock && (
|
||||
<>
|
||||
{totalIssuance && lastWinner && (
|
||||
<CardSummary
|
||||
label={t<string>('total')}
|
||||
progress={{
|
||||
hideValue: true,
|
||||
total: totalIssuance,
|
||||
value: lastWinner.total,
|
||||
withTime: true
|
||||
}}
|
||||
>
|
||||
<FormatBalance
|
||||
value={lastWinner.total}
|
||||
withSi
|
||||
/>
|
||||
</CardSummary>
|
||||
)}
|
||||
<section>
|
||||
{bestNumber && ending && (
|
||||
bestNumber.lt(ending)
|
||||
{auctionInfo.leasePeriod && (
|
||||
<CardSummary label={t<string>('first - last')}>
|
||||
{formatNumber(auctionInfo.leasePeriod)} - {formatNumber(auctionInfo.leasePeriod.add(BN_THREE))}
|
||||
</CardSummary>
|
||||
)}
|
||||
{totalIssuance && lastWinner && (
|
||||
<CardSummary
|
||||
label={t<string>('total')}
|
||||
progress={{
|
||||
hideValue: true,
|
||||
total: totalIssuance,
|
||||
value: lastWinner.total,
|
||||
withTime: true
|
||||
}}
|
||||
>
|
||||
<FormatBalance
|
||||
value={lastWinner.total}
|
||||
withSi
|
||||
/>
|
||||
</CardSummary>
|
||||
)}
|
||||
</section>
|
||||
<section>
|
||||
{bestNumber && (
|
||||
bestNumber.lt(auctionInfo.endBlock)
|
||||
? (
|
||||
<CardSummary
|
||||
label={t<string>('end period at')}
|
||||
progress={{
|
||||
hideGraph: true,
|
||||
total: ending,
|
||||
total: auctionInfo.endBlock,
|
||||
value: bestNumber,
|
||||
withTime: true
|
||||
}}
|
||||
>
|
||||
#{formatNumber(ending)}
|
||||
#{formatNumber(auctionInfo.endBlock)}
|
||||
</CardSummary>
|
||||
)
|
||||
: (
|
||||
@ -78,7 +79,7 @@ function Summary ({ auctionInfo, className, lastWinner, numAuctions }: Props): R
|
||||
label={t<string>('ending period')}
|
||||
progress={{
|
||||
total: api.consts.auctions.endingPeriod as BlockNumber,
|
||||
value: bestNumber.sub(ending),
|
||||
value: bestNumber.sub(auctionInfo.endBlock),
|
||||
withTime: true
|
||||
}}
|
||||
></CardSummary>
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { AuctionInfo } from '../types';
|
||||
import type { WinnerData } from './types';
|
||||
|
||||
import React from 'react';
|
||||
@ -14,7 +14,7 @@ import { formatNumber } from '@polkadot/util';
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: [LeasePeriodOf, BlockNumber];
|
||||
auctionInfo: AuctionInfo;
|
||||
blockNumber: BN;
|
||||
className?: string;
|
||||
isFirst: boolean;
|
||||
@ -24,7 +24,6 @@ interface Props {
|
||||
|
||||
function WinRanges ({ auctionInfo, blockNumber, className = '', isFirst, isLatest, value: { accountId, paraId, range, value } }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [leasePeriod, endBlock] = auctionInfo;
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
@ -32,14 +31,16 @@ function WinRanges ({ auctionInfo, blockNumber, className = '', isFirst, isLates
|
||||
{isFirst && (
|
||||
<h1>{isLatest
|
||||
? t<string>('latest')
|
||||
: <>#{formatNumber(blockNumber.isZero() ? endBlock : blockNumber)}</>
|
||||
: <>#{formatNumber(blockNumber.isZero() ? auctionInfo.endBlock : blockNumber)}</>
|
||||
}</h1>
|
||||
)}
|
||||
</td>
|
||||
<td className='number'><h1>{formatNumber(paraId)}</h1></td>
|
||||
<td className='badge'><ParaLink id={paraId} /></td>
|
||||
<td className='address'><AddressMini value={accountId} /></td>
|
||||
<td className='all number'><Digits value={`${formatNumber(leasePeriod.addn(range[0]))} - ${formatNumber(leasePeriod.addn(range[1]))}`} /></td>
|
||||
<td className='all number'>{auctionInfo.leasePeriod && (
|
||||
<Digits value={`${formatNumber(auctionInfo.leasePeriod.addn(range[0]))} - ${formatNumber(auctionInfo.leasePeriod.addn(range[1]))}`} />
|
||||
)}</td>
|
||||
<td className='number'><FormatBalance value={value} /></td>
|
||||
</tr>
|
||||
);
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AuctionIndex, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { OwnedId } from '../types';
|
||||
import type { AuctionInfo, OwnedId } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Button } from '@polkadot/react-components';
|
||||
import { useApi, useCallMulti } from '@polkadot/react-hooks';
|
||||
|
||||
import Auction from './Auction';
|
||||
import Bid from './Bid';
|
||||
@ -17,32 +13,12 @@ import Summary from './Summary';
|
||||
import useWinningData from './useWinningData';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: AuctionInfo;
|
||||
className?: string;
|
||||
ownedIds: OwnedId[];
|
||||
}
|
||||
|
||||
interface QueryState {
|
||||
auctionInfo: [LeasePeriodOf, BlockNumber] | null;
|
||||
numAuctions: AuctionIndex | null;
|
||||
}
|
||||
|
||||
const optionsMulti = {
|
||||
defaultValue: {
|
||||
auctionInfo: null,
|
||||
numAuctions: null
|
||||
},
|
||||
transform: ([numAuctions, optInfo]: [AuctionIndex, Option<ITuple<[LeasePeriodOf, BlockNumber]>>]) => ({
|
||||
auctionInfo: optInfo.unwrapOr(null),
|
||||
numAuctions
|
||||
})
|
||||
};
|
||||
|
||||
function Auctions ({ className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const { auctionInfo, numAuctions } = useCallMulti<QueryState>([
|
||||
api.query.auctions.auctionCounter,
|
||||
api.query.auctions.auctionInfo
|
||||
], optionsMulti);
|
||||
function Auctions ({ auctionInfo, className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
const winningData = useWinningData(auctionInfo);
|
||||
|
||||
return (
|
||||
@ -50,18 +26,15 @@ function Auctions ({ className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
<Summary
|
||||
auctionInfo={auctionInfo}
|
||||
lastWinner={winningData && winningData[0]}
|
||||
numAuctions={numAuctions}
|
||||
/>
|
||||
<Button.Group>
|
||||
<Bid
|
||||
auctionInfo={auctionInfo}
|
||||
id={numAuctions}
|
||||
ownedIds={ownedIds}
|
||||
/>
|
||||
</Button.Group>
|
||||
<Auction
|
||||
auctionInfo={auctionInfo}
|
||||
numAuctions={numAuctions}
|
||||
winningData={winningData}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@ -2,7 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Option, StorageKey } from '@polkadot/types';
|
||||
import type { BlockNumber, LeasePeriodOf, WinningData } from '@polkadot/types/interfaces';
|
||||
import type { BlockNumber, WinningData } from '@polkadot/types/interfaces';
|
||||
import type { AuctionInfo } from '../types';
|
||||
import type { WinnerData, Winning } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@ -89,7 +90,7 @@ function mergeFirst (prev: Winning[] | null, optFirstData: Option<WinningData>):
|
||||
return prev;
|
||||
}
|
||||
|
||||
export default function useWinningData (auctionInfo: [LeasePeriodOf, BlockNumber] | null): Winning[] | null {
|
||||
export default function useWinningData (auctionInfo: AuctionInfo): Winning[] | null {
|
||||
const { api } = useApi();
|
||||
const [result, setResult] = useState<Winning[] | null>(null);
|
||||
const bestNumber = useBestNumber();
|
||||
@ -101,7 +102,7 @@ export default function useWinningData (auctionInfo: [LeasePeriodOf, BlockNumber
|
||||
// should be fired once, all entries as an initial round
|
||||
useEffect((): void => {
|
||||
allEntries && setResult(
|
||||
extractData(auctionInfo && auctionInfo[1], allEntries)
|
||||
extractData(auctionInfo.endBlock, allEntries)
|
||||
);
|
||||
}, [allEntries, auctionInfo]);
|
||||
|
||||
@ -116,7 +117,7 @@ export default function useWinningData (auctionInfo: [LeasePeriodOf, BlockNumber
|
||||
// and add it to the list when not duplicated. Additionally we cleanup after ourselves when endBlock
|
||||
// gets cleared
|
||||
useEffect((): void => {
|
||||
const [, endBlock] = auctionInfo || [null, null];
|
||||
const { endBlock } = auctionInfo;
|
||||
|
||||
if (!endBlock) {
|
||||
setResult((prev) => prev && prev.length ? [] : prev);
|
||||
|
||||
@ -2,24 +2,26 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import type { OwnedId, OwnerInfo } from '../types';
|
||||
import type { AuctionInfo, LeasePeriod, OwnedId, OwnerInfo } from '../types';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { Button, InputBalance, InputNumber, Modal, TxButton } from '@polkadot/react-components';
|
||||
import { useApi, useToggle } from '@polkadot/react-hooks';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
import { BN_ONE, BN_THREE, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import InputOwner from '../InputOwner';
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: AuctionInfo;
|
||||
bestNumber?: BN;
|
||||
className?: string;
|
||||
leasePeriod: LeasePeriod | null;
|
||||
ownedIds: OwnedId[];
|
||||
}
|
||||
|
||||
function FundAdd ({ bestNumber, className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
function FundAdd ({ auctionInfo, bestNumber, className, leasePeriod, ownedIds }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const [{ accountId, paraId }, setOwnerInfo] = useState<OwnerInfo>({ accountId: null, paraId: 0 });
|
||||
@ -30,7 +32,9 @@ function FundAdd ({ bestNumber, className, ownedIds }: Props): React.ReactElemen
|
||||
const [isOpen, toggleOpen] = useToggle();
|
||||
|
||||
const isEndError = !bestNumber || !endBlock || endBlock.lt(bestNumber);
|
||||
const isLastError = !lastSlot || !firstSlot || lastSlot.lt(firstSlot) || lastSlot.gt(firstSlot.addn(3));
|
||||
const isFirstError = !firstSlot || (!!leasePeriod && firstSlot.lte(leasePeriod.currentPeriod));
|
||||
const isLastError = !lastSlot || !firstSlot || lastSlot.lt(firstSlot) || lastSlot.gt(firstSlot.add(BN_THREE));
|
||||
const defaultSlot = (auctionInfo.leasePeriod || leasePeriod?.currentPeriod.add(BN_ONE) || 1).toString();
|
||||
|
||||
// TODO Add verifier
|
||||
|
||||
@ -53,26 +57,34 @@ function FundAdd ({ bestNumber, className, ownedIds }: Props): React.ReactElemen
|
||||
onChange={setOwnerInfo}
|
||||
ownedIds={ownedIds}
|
||||
/>
|
||||
<Modal.Columns hint={t<string>('The amount to be raised in this funding campaign')}>
|
||||
<Modal.Columns hint={t<string>('The amount to be raised in this funding campaign.')}>
|
||||
<InputBalance
|
||||
isZeroable={false}
|
||||
label={t<string>('crowdfund cap')}
|
||||
onChange={setCap}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The block until which this fund is active for')}>
|
||||
<Modal.Columns hint={t<string>('The end block for contributions to this fund.')}>
|
||||
<InputNumber
|
||||
isError={isEndError}
|
||||
label={t<string>('ending block')}
|
||||
onChange={setEndBlock}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The first and last slots for this funding campaign. The last slot should be after the first and a maximum of 3 slots more than the first')}>
|
||||
<Modal.Columns hint={
|
||||
<>
|
||||
<p>{t<string>('The first and last slots for this funding campaign.')}</p>
|
||||
<p>{t<string>('The last slot should be after the first and a maximum of 3 slots more than the first')}</p>
|
||||
</>
|
||||
}>
|
||||
<InputNumber
|
||||
defaultValue={defaultSlot}
|
||||
isError={isFirstError}
|
||||
label={t<string>('first slot')}
|
||||
onChange={setFirstSlot}
|
||||
/>
|
||||
<InputNumber
|
||||
defaultValue={defaultSlot}
|
||||
isError={isLastError}
|
||||
label={t<string>('last slot')}
|
||||
onChange={setLastSlot}
|
||||
@ -83,7 +95,7 @@ function FundAdd ({ bestNumber, className, ownedIds }: Props): React.ReactElemen
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
icon='plus'
|
||||
isDisabled={!paraId || !cap?.gt(BN_ZERO) || !firstSlot?.gte(BN_ZERO) || isEndError || isLastError}
|
||||
isDisabled={!paraId || !cap?.gt(BN_ZERO) || !firstSlot?.gte(BN_ZERO) || isEndError || isFirstError || isLastError}
|
||||
label={t<string>('Add')}
|
||||
onStart={toggleOpen}
|
||||
params={[paraId, cap, firstSlot, lastSlot, endBlock, null]}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { OwnedId } from '../types';
|
||||
import type { AuctionInfo, LeasePeriod, OwnedId } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@ -14,11 +14,13 @@ import Summary from './Summary';
|
||||
import useFunds from './useFunds';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: AuctionInfo;
|
||||
className?: string;
|
||||
leasePeriod: LeasePeriod | null;
|
||||
ownedIds: OwnedId[];
|
||||
}
|
||||
|
||||
function Crowdloan ({ className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
function Crowdloan ({ auctionInfo, className, leasePeriod, ownedIds }: Props): React.ReactElement<Props> {
|
||||
const bestNumber = useBestNumber();
|
||||
const { activeCap, activeRaised, funds, totalCap, totalRaised } = useFunds();
|
||||
|
||||
@ -33,7 +35,9 @@ function Crowdloan ({ className, ownedIds }: Props): React.ReactElement<Props> {
|
||||
/>
|
||||
<Button.Group>
|
||||
<FundAdd
|
||||
auctionInfo={auctionInfo}
|
||||
bestNumber={bestNumber}
|
||||
leasePeriod={leasePeriod}
|
||||
ownedIds={ownedIds}
|
||||
/>
|
||||
</Button.Group>
|
||||
|
||||
@ -36,28 +36,29 @@ function InputOwner ({ onChange, ownedIds }: Props): React.ReactElement<Props> {
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal.Columns hint={t<string>('This account that has been used to register the parachain. This will pay all associated fees.')}>
|
||||
<InputAddress
|
||||
filter={owners}
|
||||
label={t<string>('parachain owner')}
|
||||
onChange={setAccountId}
|
||||
type='account'
|
||||
value={accountId}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns hint={
|
||||
<>
|
||||
<p>{t<string>('This account that has been used to register the parachain. This will pay all associated fees.')}</p>
|
||||
<p>{t<string>('The parachain id is associated with the selected account via parathread registration.')}</p>
|
||||
</>
|
||||
}>
|
||||
<InputAddress
|
||||
filter={owners}
|
||||
label={t<string>('parachain owner')}
|
||||
onChange={setAccountId}
|
||||
type='account'
|
||||
value={accountId}
|
||||
/>
|
||||
{accountId && (
|
||||
<Modal.Columns hint={t<string>('The parachain id, as associated with the account on the registrar')}>
|
||||
<Dropdown
|
||||
defaultValue={optIds[0].value}
|
||||
key={accountId}
|
||||
label={t<string>('parachain id')}
|
||||
onChange={setParaId}
|
||||
options={optIds}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
<Dropdown
|
||||
defaultValue={optIds[0].value}
|
||||
key={accountId}
|
||||
label={t<string>('parachain id')}
|
||||
onChange={setParaId}
|
||||
options={optIds}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
</Modal.Columns>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { LeasePeriod } from './types';
|
||||
import type { LeasePeriod } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ParaId } from '@polkadot/types/interfaces';
|
||||
import type { Proposals } from '../types';
|
||||
import type { LeasePeriod, Proposals } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
@ -13,19 +13,18 @@ import Parachains from './Parachains';
|
||||
import Summary from './Summary';
|
||||
import Upcomings from './Upcomings';
|
||||
import useActionsQueue from './useActionsQueue';
|
||||
import useLeasePeriod from './useLeasePeriod';
|
||||
import useUpcomingIds from './useUpcomingIds';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
leasePeriod: LeasePeriod | null;
|
||||
proposals?: Proposals;
|
||||
}
|
||||
|
||||
function Overview ({ className, proposals }: Props): React.ReactElement<Props> {
|
||||
function Overview ({ className, leasePeriod, proposals }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const paraIds = useCall<ParaId[]>(api.query.paras?.parachains);
|
||||
const actionsQueue = useActionsQueue();
|
||||
const leasePeriod = useLeasePeriod();
|
||||
const upcomingIds = useUpcomingIds();
|
||||
|
||||
return (
|
||||
|
||||
@ -10,12 +10,6 @@ export interface LeaseInfo {
|
||||
period: number;
|
||||
}
|
||||
|
||||
export interface LeasePeriod {
|
||||
currentPeriod: BN;
|
||||
length: BN;
|
||||
remainder: BN;
|
||||
}
|
||||
|
||||
export interface QueuedAction {
|
||||
paraIds: ParaId[];
|
||||
sessionIndex: BN;
|
||||
|
||||
@ -14,6 +14,8 @@ import Crowdloan from './Crowdloan';
|
||||
import Overview from './Overview';
|
||||
import Proposals from './Proposals';
|
||||
import { useTranslation } from './translate';
|
||||
import useAuctionInfo from './useAuctionInfo';
|
||||
import useLeasePeriod from './useLeasePeriod';
|
||||
import useOwnedIds from './useOwnedIds';
|
||||
import useProposals from './useProposals';
|
||||
|
||||
@ -26,6 +28,8 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement<Prop
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { pathname } = useLocation();
|
||||
const auctionInfo = useAuctionInfo();
|
||||
const leasePeriod = useLeasePeriod();
|
||||
const ownedIds = useOwnedIds();
|
||||
const proposals = useProposals();
|
||||
|
||||
@ -57,10 +61,17 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement<Prop
|
||||
/>
|
||||
<Switch>
|
||||
<Route path={`${basePath}/auctions`}>
|
||||
<Auctions ownedIds={ownedIds} />
|
||||
<Auctions
|
||||
auctionInfo={auctionInfo}
|
||||
ownedIds={ownedIds}
|
||||
/>
|
||||
</Route>
|
||||
<Route path={`${basePath}/crowdloan`}>
|
||||
<Crowdloan ownedIds={ownedIds} />
|
||||
<Crowdloan
|
||||
auctionInfo={auctionInfo}
|
||||
leasePeriod={leasePeriod}
|
||||
ownedIds={ownedIds}
|
||||
/>
|
||||
</Route>
|
||||
<Route path={`${basePath}/proposals`}>
|
||||
<Proposals proposals={proposals} />
|
||||
@ -68,6 +79,7 @@ function ParachainsApp ({ basePath, className }: Props): React.ReactElement<Prop
|
||||
</Switch>
|
||||
<Overview
|
||||
className={basePath === pathname ? '' : 'parachains--hidden'}
|
||||
leasePeriod={leasePeriod}
|
||||
proposals={proposals}
|
||||
/>
|
||||
</main>
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ParachainProposal, ParaId, ParaInfo, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type BN from 'bn.js';
|
||||
import type { AuctionIndex, BlockNumber, LeasePeriodOf, ParachainProposal, ParaId, ParaInfo, SessionIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
export interface AuctionInfo {
|
||||
endBlock: BlockNumber | null;
|
||||
leasePeriod: LeasePeriodOf | null;
|
||||
numAuctions: AuctionIndex | null;
|
||||
}
|
||||
|
||||
export interface ProposalExt {
|
||||
id: ParaId;
|
||||
@ -15,6 +22,12 @@ export interface ScheduledProposals {
|
||||
sessionIndex: SessionIndex;
|
||||
}
|
||||
|
||||
export interface LeasePeriod {
|
||||
currentPeriod: BN;
|
||||
length: BN;
|
||||
remainder: BN;
|
||||
}
|
||||
|
||||
export interface Proposals {
|
||||
approvedIds: ParaId[];
|
||||
proposalIds: ParaId[];
|
||||
|
||||
37
packages/page-parachains/src/useAuctionInfo.tsx
Normal file
37
packages/page-parachains/src/useAuctionInfo.tsx
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2017-2021 @polkadot/app-parachains authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AuctionIndex, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { AuctionInfo } from './types';
|
||||
|
||||
import { useApi, useCallMulti } from '@polkadot/react-hooks';
|
||||
|
||||
const defaultValue: AuctionInfo = {
|
||||
endBlock: null,
|
||||
leasePeriod: null,
|
||||
numAuctions: null
|
||||
};
|
||||
|
||||
const optionsMulti = {
|
||||
defaultValue,
|
||||
transform: ([numAuctions, optInfo]: [AuctionIndex, Option<ITuple<[LeasePeriodOf, BlockNumber]>>]): AuctionInfo => {
|
||||
const [leasePeriod, endBlock] = optInfo.unwrapOr([null, null]);
|
||||
|
||||
return {
|
||||
endBlock,
|
||||
leasePeriod,
|
||||
numAuctions
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default function useAuctionInfo (): AuctionInfo {
|
||||
const { api } = useApi();
|
||||
|
||||
return useCallMulti<AuctionInfo>([
|
||||
api.query.auctions?.auctionCounter,
|
||||
api.query.auctions?.auctionInfo
|
||||
], optionsMulti);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user