Interleave crowdloan for non-existing bids (#5001)

This commit is contained in:
Jaco Greeff 2021-04-01 17:54:43 +03:00 committed by GitHub
parent bcdd1c8fa8
commit 47b348d64e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ import React, { useCallback, useRef } from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { BN_THREE } from '@polkadot/util';
import { useTranslation } from '../translate';
import WinRange from './WinRange';
@ -33,24 +34,36 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re
]);
const interleave = useCallback(
(winners: WinnerData[], newRaise: ParaId[], asIs: boolean): WinnerData[] => {
if (asIs) {
(winners: WinnerData[], asIs: boolean): WinnerData[] => {
if (asIs || !newRaise || !auctionInfo?.leasePeriod) {
return winners;
}
const leasePeriod = auctionInfo.leasePeriod;
const leasePeriodEnd = leasePeriod.add(BN_THREE);
const sorted = (campaigns.funds || [])
.filter(({ paraId }) => newRaise.some((n) => n.eq(paraId)))
.filter(({ firstSlot, lastSlot, paraId }) => newRaise.some((n) => n.eq(paraId)) && firstSlot.gte(leasePeriod) && lastSlot.lte(leasePeriodEnd))
.sort((a, b) => b.value.cmp(a.value));
return winners.map((w): WinnerData =>
sorted.find(({ firstSlot, lastSlot, value }) =>
w.firstSlot.eq(firstSlot) &&
w.lastSlot.eq(lastSlot) &&
w.value.lt(value)
) || w
const excluded = sorted.filter(({ firstSlot, lastSlot }) =>
!winners.some((w) => w.firstSlot.eq(firstSlot) && w.lastSlot.eq(lastSlot))
);
return winners
.map((w): WinnerData =>
sorted.find(({ firstSlot, lastSlot, value }) =>
w.firstSlot.eq(firstSlot) &&
w.lastSlot.eq(lastSlot) &&
w.value.lt(value)
) || w
)
.concat(...excluded)
.sort((a, b) =>
a.firstSlot.eq(b.firstSlot)
? a.lastSlot.cmp(b.lastSlot)
: a.firstSlot.cmp(b.firstSlot)
);
},
[campaigns]
[auctionInfo, campaigns, newRaise]
);
return (
@ -68,7 +81,7 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re
>
{auctionInfo && newRaise && winningData?.map(({ blockNumber, winners }, round) => (
<tbody key={round}>
{interleave(winners, newRaise, round !== 0 || winningData.length !== 1).map((value, index) => (
{interleave(winners, round !== 0 || winningData.length !== 1).map((value, index) => (
<WinRange
auctionInfo={auctionInfo}
blockNumber={blockNumber}