Cleanup bids on new auction (#4840)
* Cleanup bids on new auction * s/campaign/fund/
This commit is contained in:
parent
f6e522e8d9
commit
0708d43840
@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/app-crowdloan authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AuctionIndex, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
|
||||
import type { AuctionIndex, BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { Winning } from './types';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
@ -12,13 +12,13 @@ import { useTranslation } from '../translate';
|
||||
import WinBlock from './WinBlock';
|
||||
|
||||
interface Props {
|
||||
auctionInfo: [LeasePeriodOf, BlockNumber] | null;
|
||||
className?: string;
|
||||
endBlock: BlockNumber | null;
|
||||
numAuctions: AuctionIndex | null;
|
||||
winningData: Winning[] | null;
|
||||
}
|
||||
|
||||
function Auction ({ auctionInfo, className, numAuctions, winningData }: Props): React.ReactElement<Props> {
|
||||
function Auction ({ className, endBlock, numAuctions, winningData }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
@ -31,18 +31,18 @@ function Auction ({ auctionInfo, className, numAuctions, winningData }: Props):
|
||||
<Table
|
||||
className={className}
|
||||
empty={numAuctions && winningData && (
|
||||
auctionInfo && !winningData.length
|
||||
endBlock && !winningData.length
|
||||
? t<string>('No winners in this auction')
|
||||
: t<string>('No ongoing auction')
|
||||
)}
|
||||
header={headerRef.current}
|
||||
>
|
||||
{auctionInfo && winningData?.map((value, count) => (
|
||||
{endBlock && winningData?.map((value, count) => (
|
||||
<WinBlock
|
||||
endBlock={endBlock}
|
||||
isEven={!!(count % 2)}
|
||||
isLatest={count === 0}
|
||||
key={`${count}:${value.blockNumber.toString()}`}
|
||||
startBlock={auctionInfo[1]}
|
||||
key={value.blockNumber.toString()}
|
||||
value={value}
|
||||
/>
|
||||
))}
|
||||
|
||||
@ -45,7 +45,7 @@ function Bid ({ className, id }: Props): React.ReactElement<Props> {
|
||||
size='large'
|
||||
>
|
||||
<Modal.Content>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('This account will be associated with the bid. This should match the registrar for the parachain.')}>
|
||||
<Modal.Column>
|
||||
<InputAddress
|
||||
label={t<string>('bid from')}
|
||||
@ -54,11 +54,8 @@ function Bid ({ className, id }: Props): React.ReactElement<Props> {
|
||||
value={accountId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('This account will be associated with the bid. This should match the registrar for the parachain.')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The parachain id this bid is placed for')}>
|
||||
<Modal.Column>
|
||||
<InputNumber
|
||||
autoFocus
|
||||
@ -68,11 +65,8 @@ function Bid ({ className, id }: Props): React.ReactElement<Props> {
|
||||
onChange={setParaId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('The parachain id this bid is placed for')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The amount to to bid for this parachain slot')}>
|
||||
<Modal.Column>
|
||||
<InputBalance
|
||||
isZeroable={false}
|
||||
@ -80,11 +74,8 @@ function Bid ({ className, id }: Props): React.ReactElement<Props> {
|
||||
onChange={setAmount}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('The amount to to bid for this parachain slot')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<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')}>
|
||||
<Modal.Column>
|
||||
<InputNumber
|
||||
defaultValue={firstSlot?.toString()}
|
||||
@ -98,9 +89,6 @@ function Bid ({ className, id }: Props): React.ReactElement<Props> {
|
||||
onChange={setLastSlot}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{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')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={toggleOpen}>
|
||||
|
||||
@ -10,23 +10,23 @@ import WinRange from './WinRange';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
endBlock: BlockNumber;
|
||||
isEven: boolean;
|
||||
isLatest: boolean;
|
||||
startBlock: BlockNumber;
|
||||
value: Winning;
|
||||
}
|
||||
|
||||
function WinBlock ({ className = '', isEven, isLatest, startBlock, value: { blockNumber, winners } }: Props): React.ReactElement<Props> {
|
||||
function WinBlock ({ className = '', endBlock, isEven, isLatest, value: { blockNumber, winners } }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<>
|
||||
{winners.map((value, index) => (
|
||||
<WinRange
|
||||
blockNumber={blockNumber}
|
||||
className={`${className} ${isEven ? 'isEven' : 'isOdd'} ${index === (winners.length - 1) ? '' : 'noBorder'}`}
|
||||
endBlock={endBlock}
|
||||
isFirst={index === 0}
|
||||
isLatest={isLatest}
|
||||
key={index}
|
||||
startBlock={startBlock}
|
||||
value={value}
|
||||
/>
|
||||
))}
|
||||
|
||||
@ -16,13 +16,13 @@ import { useTranslation } from '../translate';
|
||||
interface Props {
|
||||
blockNumber: BN;
|
||||
className?: string;
|
||||
endBlock: BlockNumber;
|
||||
isFirst: boolean;
|
||||
isLatest: boolean;
|
||||
startBlock: BlockNumber;
|
||||
value: WinnerData;
|
||||
}
|
||||
|
||||
function WinRanges ({ blockNumber, className = '', isFirst, isLatest, startBlock, value: { accountId, paraId, range, value } }: Props): React.ReactElement<Props> {
|
||||
function WinRanges ({ blockNumber, className = '', endBlock, isFirst, isLatest, value: { accountId, paraId, range, value } }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
@ -31,7 +31,7 @@ function WinRanges ({ blockNumber, className = '', isFirst, isLatest, startBlock
|
||||
{isFirst && (
|
||||
<h1>{isLatest
|
||||
? t<string>('latest')
|
||||
: <>#{formatNumber(blockNumber.isZero() ? startBlock : blockNumber)}</>
|
||||
: <>#{formatNumber(blockNumber.isZero() ? endBlock : blockNumber)}</>
|
||||
}</h1>
|
||||
)}
|
||||
</td>
|
||||
|
||||
@ -41,7 +41,8 @@ function Auctions ({ className }: Props): React.ReactElement<Props> {
|
||||
api.query.auctions.auctionCounter,
|
||||
api.query.auctions.auctionInfo
|
||||
], optionsMulti);
|
||||
const winningData = useWinningData(auctionInfo && auctionInfo[1]);
|
||||
const endBlock = auctionInfo && auctionInfo[1];
|
||||
const winningData = useWinningData(endBlock);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@ -54,7 +55,7 @@ function Auctions ({ className }: Props): React.ReactElement<Props> {
|
||||
<Bid id={auctionInfo && numAuctions} />
|
||||
</Button.Group>
|
||||
<Auction
|
||||
auctionInfo={auctionInfo}
|
||||
endBlock={endBlock}
|
||||
numAuctions={numAuctions}
|
||||
winningData={winningData}
|
||||
/>
|
||||
|
||||
@ -96,41 +96,46 @@ function mergeFirst (prev: Winning[] | null, optFirstData: Option<WinningData>):
|
||||
|
||||
export default function useWinningData (endBlock: BlockNumber | null): Winning[] | null {
|
||||
const { api } = useApi();
|
||||
const [winning, setWinning] = useState<Winning[] | null>(null);
|
||||
const [result, setResult] = useState<Winning[] | null>(null);
|
||||
const bestNumber = useCall<BlockNumber>(api.derive.chain.bestNumber);
|
||||
const trigger = useEventTrigger([api.events.auctions?.BidAccepted]);
|
||||
const triggerRef = useRef(trigger);
|
||||
const allEntries = 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 => {
|
||||
allEntries && setWinning(
|
||||
allEntries && setResult(
|
||||
extractData(endBlock, allEntries)
|
||||
);
|
||||
}, [allEntries, endBlock]);
|
||||
|
||||
// when block 0 changes, update (typically in non-ending-period, static otherwise)
|
||||
useEffect((): void => {
|
||||
optFirstData && setWinning((prev) =>
|
||||
optFirstData && setResult((prev) =>
|
||||
mergeFirst(prev, optFirstData)
|
||||
);
|
||||
}, [optFirstData]);
|
||||
|
||||
// on a bid event, get the new entry (assuming the event really triggered, i.e. not just a block)
|
||||
// and add it to the list when not duplicated. Additionally we cleanup after ourselves when endBlock
|
||||
// gets cleared
|
||||
useEffect((): void => {
|
||||
if (endBlock && bestNumber && triggerRef.current !== trigger) {
|
||||
const blockOffset = bestNumber.gt(endBlock)
|
||||
? bestNumber.sub(endBlock).add(BN_ONE)
|
||||
: BN_ZERO;
|
||||
if (!endBlock) {
|
||||
setResult(null);
|
||||
} else if (bestNumber && bestNumber.gt(endBlock) && triggerRef.current !== trigger) {
|
||||
const blockOffset = bestNumber.sub(endBlock).iadd(BN_ONE);
|
||||
|
||||
triggerRef.current = trigger;
|
||||
|
||||
api.query.auctions
|
||||
?.winning<Option<WinningData>>(blockOffset)
|
||||
.then((optCurrent) => setWinning((prev) =>
|
||||
.then((optCurrent) => setResult((prev) =>
|
||||
mergeCurrent(prev, optCurrent, endBlock, blockOffset)
|
||||
))
|
||||
.catch(console.error);
|
||||
}
|
||||
}, [api, bestNumber, endBlock, trigger, triggerRef]);
|
||||
|
||||
return winning;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
<Button
|
||||
icon='plus'
|
||||
isDisabled={!hasAccounts}
|
||||
label={t<string>('Add campaign')}
|
||||
label={t<string>('Add fund')}
|
||||
onClick={toggleOpen}
|
||||
/>
|
||||
{isOpen && (
|
||||
@ -48,7 +48,7 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
size='large'
|
||||
>
|
||||
<Modal.Content>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('This account will be associated with the fund and pay the deposit. This should match the registrar for the parachain.')}>
|
||||
<Modal.Column>
|
||||
<InputAddress
|
||||
label={t<string>('propose from')}
|
||||
@ -57,11 +57,8 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
value={accountId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('This account will be associated with the fund and pay the deposit. This should match the registrar for the parachain.')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The parachain id this fund applies to')}>
|
||||
<Modal.Column>
|
||||
<InputNumber
|
||||
autoFocus
|
||||
@ -70,11 +67,8 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
onChange={setParaId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('The parachain id this campaign refers to')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The amount to be raised in this funding campaign')}>
|
||||
<Modal.Column>
|
||||
<InputBalance
|
||||
isZeroable={false}
|
||||
@ -82,11 +76,8 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
onChange={setCap}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('The amount to be raised in this funding campaign')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The block until which this fund is active for')}>
|
||||
<Modal.Column>
|
||||
<InputNumber
|
||||
isError={isEndError}
|
||||
@ -94,11 +85,8 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
onChange={setEndBlock}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('The block until which this campaign is active for')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<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.Column>
|
||||
<InputNumber
|
||||
label={t<string>('first slot')}
|
||||
@ -110,9 +98,6 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
|
||||
onChange={setLastSlot}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{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.Column>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={toggleOpen}>
|
||||
|
||||
@ -47,11 +47,11 @@ function FundContribute ({ cap, className, paraId, raised }: Props): React.React
|
||||
{isOpen && (
|
||||
<Modal
|
||||
className={className}
|
||||
header={t<string>('Contribute to campaign')}
|
||||
header={t<string>('Contribute to fund')}
|
||||
size='large'
|
||||
>
|
||||
<Modal.Content>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('This account will contribute to the crowdloan.')}>
|
||||
<Modal.Column>
|
||||
<InputAddress
|
||||
label={t<string>('contribute from')}
|
||||
@ -60,11 +60,8 @@ function FundContribute ({ cap, className, paraId, raised }: Props): React.React
|
||||
value={accountId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('This account will contribute to the crowdloan.')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The amount to contribute. Should be less than the remaining value and more than the minimum contribution amount.')}>
|
||||
<Modal.Column>
|
||||
<InputBalance
|
||||
autoFocus
|
||||
@ -80,9 +77,6 @@ function FundContribute ({ cap, className, paraId, raised }: Props): React.React
|
||||
<MarkWarning content={t<string>('The amount is more than the remaining contribution needed {{value}}', { replace: { value: formatBalance(remaining) } })} />
|
||||
)}
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
{t<string>('The amount to contribute. Should be less than the remaining value and more than the minimum contribution amount.')}
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={toggleOpen}>
|
||||
|
||||
@ -31,7 +31,7 @@ function Funds ({ bestNumber, className, paraIds }: Props): React.ReactElement<P
|
||||
const [funds, setFunds] = useState<Fund[] | undefined>();
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('campaigns'), 'start', 3],
|
||||
[t('funds'), 'start', 3],
|
||||
[t('cap'), 'number'],
|
||||
[t('raised'), 'number'],
|
||||
[t('end'), 'number'],
|
||||
|
||||
@ -46,7 +46,7 @@ function RegisterThread ({ className, onClose }: Props): React.ReactElement<Prop
|
||||
size='large'
|
||||
>
|
||||
<Modal.Content>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('This account will be associated with the parachain and pay the deposit.')}>
|
||||
<Modal.Column>
|
||||
<InputAddress
|
||||
label={t<string>('register from')}
|
||||
@ -55,11 +55,8 @@ function RegisterThread ({ className, onClose }: Props): React.ReactElement<Prop
|
||||
value={accountId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('This account will be associated with the parachain and pay the deposit.')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The id of this parachain as known on the network')}>
|
||||
<Modal.Column>
|
||||
<InputNumber
|
||||
autoFocus
|
||||
@ -68,11 +65,8 @@ function RegisterThread ({ className, onClose }: Props): React.ReactElement<Prop
|
||||
onChange={setParaId}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('The id of this parachain as known on the network')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The WASM validation function for this parachain.')}>
|
||||
<Modal.Column>
|
||||
<InputWasm
|
||||
help={t<string>('The compiled runtime WASM for the parachain you wish to register.')}
|
||||
@ -82,11 +76,8 @@ function RegisterThread ({ className, onClose }: Props): React.ReactElement<Prop
|
||||
placeholder={wasm && !isWasmValid && t<string>('The code is not recognized as being in valid WASM format')}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('The WASM validation function for this parachain.')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
<Modal.Columns>
|
||||
<Modal.Columns hint={t<string>('The genesis state for this parachain.')}>
|
||||
<Modal.Column>
|
||||
<InputFile
|
||||
help={t<string>('The genesis state for the parachain.')}
|
||||
@ -95,9 +86,6 @@ function RegisterThread ({ className, onClose }: Props): React.ReactElement<Prop
|
||||
onChange={_setGenesisState}
|
||||
/>
|
||||
</Modal.Column>
|
||||
<Modal.Column>
|
||||
<p>{t<string>('The genesis state for this parachain.')}</p>
|
||||
</Modal.Column>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={onClose}>
|
||||
|
||||
@ -6,9 +6,15 @@ import type { ColumnProps } from './types';
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
function Columns ({ children, className = '' }: ColumnProps): React.ReactElement<ColumnProps> {
|
||||
import Column from './Column';
|
||||
|
||||
function Columns ({ children, className = '', hint }: ColumnProps): React.ReactElement<ColumnProps> {
|
||||
return (
|
||||
<div className={`ui--Modal-Columns ${className}`}>{children}</div>
|
||||
<div className={`ui--Modal-Columns ${className}`}>
|
||||
{children}{hint && (
|
||||
<Column>{hint}</Column>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import React from 'react';
|
||||
export interface ColumnProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
hint?: React.ReactNode;
|
||||
}
|
||||
|
||||
export interface ModalProps {
|
||||
|
||||
@ -211,6 +211,7 @@ export default React.memo(styled(Body)`
|
||||
|
||||
&.noBorder td {
|
||||
border-bottom: 1px solid transparent;
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.ui--Button-Group {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user