Bid action (no result data displays) (#4822)

* Bid action (no rsult data displays)

* allow last === first

* Bump api
This commit is contained in:
Jaco Greeff 2021-03-11 14:21:34 +01:00 committed by GitHub
parent 9cb6a7e250
commit 71497c57f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 268 additions and 67 deletions

View File

@ -12,13 +12,13 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^4.0.4-10",
"@polkadot/api-contract": "^4.0.4-10",
"@polkadot/api": "^4.0.4-11",
"@polkadot/api-contract": "^4.0.4-11",
"@polkadot/hw-ledger": "^6.0.5",
"@polkadot/keyring": "^6.0.5",
"@polkadot/networks": "^6.0.5",
"@polkadot/phishing": "^0.6.20",
"@polkadot/types": "^4.0.4-10",
"@polkadot/types": "^4.0.4-11",
"@polkadot/util": "^6.0.5",
"@polkadot/util-crypto": "^6.0.5",
"@polkadot/wasm-crypto": "^4.0.2",

View File

@ -10,6 +10,6 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.13.10",
"@polkadot/api-contract": "^4.0.4-10"
"@polkadot/api-contract": "^4.0.4-11"
}
}

View File

@ -0,0 +1,52 @@
// Copyright 2017-2021 @polkadot/app-crowdloan authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AuctionIndex, BlockNumber, LeasePeriodOf } from '@polkadot/types/interfaces';
import React, { useRef } from 'react';
import { Table } from '@polkadot/react-components';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
import Bid from './Bid';
interface Props {
auctionInfo: [LeasePeriodOf, BlockNumber] | null;
className?: string;
numAuctions: AuctionIndex | null;
}
function Auction ({ auctionInfo, className, numAuctions }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const headerRef = useRef([
[t('auctions'), 'start', 1],
[t('duration'), 'number'],
[t('lease period'), 'number'],
[t('winning'), 'number', 3],
[]
]);
return (
<Table
className={className}
empty={numAuctions && t<string>('No ongoing auction')}
header={headerRef.current}
>
{auctionInfo && numAuctions && (
<tr>
<td className='number'><h1>{formatNumber(numAuctions)}</h1></td>
<td className='number all'>{formatNumber(auctionInfo[1])}</td>
<td className='number'>{formatNumber(auctionInfo[0])}</td>
<td colSpan={3} />
<td className='button'>
<Bid id={numAuctions} />
</td>
</tr>
)}
</Table>
);
}
export default React.memo(Auction);

View File

@ -0,0 +1,120 @@
// Copyright 2017-2021 @polkadot/app-crowdloan authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type BN from 'bn.js';
import type { AuctionIndex } from '@polkadot/types/interfaces';
import React, { useState } from 'react';
import { Button, InputAddress, InputBalance, InputNumber, Modal, TxButton } from '@polkadot/react-components';
import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks';
import { BN_ZERO } from '@polkadot/util';
import { useTranslation } from '../translate';
interface Props {
className?: string;
id: AuctionIndex;
}
function Bid ({ className, id }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const { hasAccounts } = useAccounts();
const [accountId, setAccountId] = useState<string | null>(null);
const [amount, setAmount] = useState<BN | undefined>();
const [firstSlot, setFirstSlot] = useState<BN | undefined>();
const [lastSlot, setLastSlot] = useState<BN | undefined>();
const [paraId, setParaId] = useState<BN | undefined>();
const [isOpen, toggleOpen] = useToggle();
const isLastError = !lastSlot || !firstSlot || lastSlot.lt(firstSlot) || lastSlot.gt(firstSlot.addn(3));
return (
<>
<Button
icon='plus'
isDisabled={!hasAccounts}
label={t<string>('Bid')}
onClick={toggleOpen}
/>
{isOpen && (
<Modal
className={className}
header={t<string>('Place bid')}
size='large'
>
<Modal.Content>
<Modal.Columns>
<Modal.Column>
<InputAddress
label={t<string>('bid from')}
onChange={setAccountId}
type='account'
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.Column>
<InputNumber
autoFocus
isZeroable={false}
label={t<string>('parachain id')}
onChange={setParaId}
/>
</Modal.Column>
<Modal.Column>
{t<string>('The parachain id this bid is placed for')}
</Modal.Column>
</Modal.Columns>
<Modal.Columns>
<Modal.Column>
<InputBalance
isZeroable={false}
label={t<string>('bid amount')}
onChange={setAmount}
/>
</Modal.Column>
<Modal.Column>
{t<string>('The amount to to bid for this parachain slot')}
</Modal.Column>
</Modal.Columns>
<Modal.Columns>
<Modal.Column>
<InputNumber
label={t<string>('first slot')}
onChange={setFirstSlot}
/>
<InputNumber
isError={isLastError}
label={t<string>('last slot')}
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}>
<TxButton
accountId={accountId}
icon='plus'
isDisabled={!paraId?.gt(BN_ZERO) || !amount?.gt(BN_ZERO) || !firstSlot?.gte(BN_ZERO) || isLastError}
label={t<string>('Bid')}
onStart={toggleOpen}
params={[paraId, id, firstSlot, lastSlot, amount]}
tx={api.tx.auctions.bid}
/>
</Modal.Actions>
</Modal>
)}
</>
);
}
export default React.memo(Bid);

View File

@ -6,18 +6,16 @@ import type { AuctionIndex } from '@polkadot/types/interfaces';
import React from 'react';
import { CardSummary, SummaryBox } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
import { useTranslation } from '../translate';
interface Props {
className?: string;
numAuctions?: AuctionIndex | null;
}
function Summary ({ className }: Props): React.ReactElement<Props> {
const { api } = useApi();
const numAuctions = useCall<AuctionIndex>(api.query.auctions.auctionCounter);
function Summary ({ className, numAuctions }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
return (

View File

@ -1,18 +1,51 @@
// Copyright 2017-2021 @polkadot/app-crowdloan 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 React from 'react';
import { useApi, useCallMulti } from '@polkadot/react-hooks';
import Auction from './Auction';
import Summary from './Summary';
interface Props {
className?: string;
}
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 }: Props): React.ReactElement<Props> {
const { api } = useApi();
const { auctionInfo, numAuctions } = useCallMulti<QueryState>([
api.query.auctions.auctionCounter,
api.query.auctions.auctionInfo
], optionsMulti);
return (
<div className={className}>
<Summary />
<Summary numAuctions={numAuctions} />
<Auction
auctionInfo={auctionInfo}
numAuctions={numAuctions}
/>
</div>
);
}

View File

@ -29,7 +29,7 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
const [isOpen, toggleOpen] = useToggle();
const isEndError = !bestNumber || !endBlock || endBlock.lt(bestNumber);
const isLastError = !lastSlot || !firstSlot || lastSlot.eq(BN_ZERO) || lastSlot.lte(firstSlot) || lastSlot.gt(firstSlot.addn(3));
const isLastError = !lastSlot || !firstSlot || lastSlot.lt(firstSlot) || lastSlot.gt(firstSlot.addn(3));
// TODO Add verifier
@ -101,13 +101,11 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
<Modal.Columns>
<Modal.Column>
<InputNumber
isZeroable={false}
label={t<string>('first slot')}
onChange={setFirstSlot}
/>
<InputNumber
isError={isLastError}
isZeroable={false}
label={t<string>('last slot')}
onChange={setLastSlot}
/>
@ -121,7 +119,7 @@ function FundAdd ({ bestNumber, className }: Props): React.ReactElement<Props> {
<TxButton
accountId={accountId}
icon='plus'
isDisabled={!paraId?.gt(BN_ZERO) || !cap?.gt(BN_ZERO) || !firstSlot?.gt(BN_ZERO) || isEndError || isLastError}
isDisabled={!paraId?.gt(BN_ZERO) || !cap?.gt(BN_ZERO) || !firstSlot?.gte(BN_ZERO) || isEndError || isLastError}
label={t<string>('Add')}
onStart={toggleOpen}
params={[paraId, cap, firstSlot, lastSlot, endBlock, null]}

View File

@ -15,7 +15,7 @@
"homepage": "https://github.com/polkadot-js/apps/tree/master/packages/react-api#readme",
"dependencies": {
"@babel/runtime": "^7.13.10",
"@polkadot/api": "^4.0.4-10",
"@polkadot/api": "^4.0.4-11",
"@polkadot/extension-dapp": "^0.37.3-5",
"@polkadot/x-rxjs": "^6.0.5",
"fflate": "^0.6.7"

106
yarn.lock
View File

@ -2086,54 +2086,54 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/api-contract@npm:^4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/api-contract@npm:4.0.4-10"
"@polkadot/api-contract@npm:^4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/api-contract@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/api": 4.0.4-10
"@polkadot/types": 4.0.4-10
"@polkadot/api": 4.0.4-11
"@polkadot/types": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/x-rxjs": ^6.0.5
bn.js: ^4.11.9
checksum: 2f145371eeb0d641cf86d04d4bbf392a47f4b325a5f3b0dcfb14aea0b53beae036237bbf44ea270cbe16ef977170cce9d2477dff9ea3a49f8b79b12e018061d7
checksum: 8ae5a6fa052f844b994e3100049c6b80f05e8a6a7152c6cdda1976a974cfa4beeb35da4e9f33e4c53a8a9cd96985e77ece422f28e9d89c8a939aacd94a4f96ce
languageName: node
linkType: hard
"@polkadot/api-derive@npm:4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/api-derive@npm:4.0.4-10"
"@polkadot/api-derive@npm:4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/api-derive@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/api": 4.0.4-10
"@polkadot/rpc-core": 4.0.4-10
"@polkadot/types": 4.0.4-10
"@polkadot/api": 4.0.4-11
"@polkadot/rpc-core": 4.0.4-11
"@polkadot/types": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/util-crypto": ^6.0.5
"@polkadot/x-rxjs": ^6.0.5
bn.js: ^4.11.9
checksum: 90620133a900b295b063d9756884f4f9303cd64690a3d35bf074a8a3f9afc1fd7647826fc84c15568352e49f7bc4c77f468d04197c8a30dea945da7330b0f765
checksum: d4558975216b0d960dd4b9e61522ea9e8322e328b4a64a82d217ac7bb410e44524766f0648b5e5ab534a9ab2849694abdfd301f8263716e8f3f5a3da03752f4d
languageName: node
linkType: hard
"@polkadot/api@npm:^4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/api@npm:4.0.4-10"
"@polkadot/api@npm:^4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/api@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/api-derive": 4.0.4-10
"@polkadot/api-derive": 4.0.4-11
"@polkadot/keyring": ^6.0.5
"@polkadot/metadata": 4.0.4-10
"@polkadot/rpc-core": 4.0.4-10
"@polkadot/rpc-provider": 4.0.4-10
"@polkadot/types": 4.0.4-10
"@polkadot/types-known": 4.0.4-10
"@polkadot/metadata": 4.0.4-11
"@polkadot/rpc-core": 4.0.4-11
"@polkadot/rpc-provider": 4.0.4-11
"@polkadot/types": 4.0.4-11
"@polkadot/types-known": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/util-crypto": ^6.0.5
"@polkadot/x-rxjs": ^6.0.5
bn.js: ^4.11.9
eventemitter3: ^4.0.7
checksum: 066e993e411a93deca6323a62bbdc751baafcfbeed1eb111da2594eda302c96b0f49f163c49e9d2d904615df8ae22e509e639d6b98ea5851183316a15998fb07
checksum: e3c99472396a49d043268d7058e27a7e059c4da28d5aa61775772233e4d0ebbea3b0a13ef71a7ea2efcf532713bfd940ac017d0454a2a0f501fad60f1b4c64e6
languageName: node
linkType: hard
@ -2197,7 +2197,7 @@ __metadata:
resolution: "@polkadot/app-contracts@workspace:packages/page-contracts"
dependencies:
"@babel/runtime": ^7.13.10
"@polkadot/api-contract": ^4.0.4-10
"@polkadot/api-contract": ^4.0.4-11
languageName: unknown
linkType: soft
@ -2607,17 +2607,17 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/metadata@npm:4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/metadata@npm:4.0.4-10"
"@polkadot/metadata@npm:4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/metadata@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/types": 4.0.4-10
"@polkadot/types-known": 4.0.4-10
"@polkadot/types": 4.0.4-11
"@polkadot/types-known": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/util-crypto": ^6.0.5
bn.js: ^4.11.9
checksum: b6463ad59ed0146eacf353f541a0511079c43f58e0f6c0819373ae5bd8899ea49542f8fb6fa1426c3d1a26514de018b4f7083264e502cdb4b1d61a2a83651d4b
checksum: b5808f095c0b32b37d5600083fa5628773a63e2618f96b85be25083a815f2c1d14d4f4ceca029de03370ff5f24afab74d3b495f6245ecd089cbabc41176a2c7d
languageName: node
linkType: hard
@ -2647,7 +2647,7 @@ __metadata:
resolution: "@polkadot/react-api@workspace:packages/react-api"
dependencies:
"@babel/runtime": ^7.13.10
"@polkadot/api": ^4.0.4-10
"@polkadot/api": ^4.0.4-11
"@polkadot/extension-dapp": ^0.37.3-5
"@polkadot/x-rxjs": ^6.0.5
fflate: ^0.6.7
@ -2778,26 +2778,26 @@ __metadata:
languageName: unknown
linkType: soft
"@polkadot/rpc-core@npm:4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/rpc-core@npm:4.0.4-10"
"@polkadot/rpc-core@npm:4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/rpc-core@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/metadata": 4.0.4-10
"@polkadot/rpc-provider": 4.0.4-10
"@polkadot/types": 4.0.4-10
"@polkadot/metadata": 4.0.4-11
"@polkadot/rpc-provider": 4.0.4-11
"@polkadot/types": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/x-rxjs": ^6.0.5
checksum: 046d1e09602e78665d1312f7be681dcb002b660c7d175dc55d398c02824154fcfd3d830cee0066e8eb29372c93dc15527b4ed001bd9c9151f8428cb4106e49a2
checksum: 55c3892e8c2427b6b6c73affdcaf3ad43f1653549e3b48c7093e6a833dfed193d106f03e541ff39cc12d1a95a26075ba5b24a443bf57abd0881aaf825e5ce6d1
languageName: node
linkType: hard
"@polkadot/rpc-provider@npm:4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/rpc-provider@npm:4.0.4-10"
"@polkadot/rpc-provider@npm:4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/rpc-provider@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/types": 4.0.4-10
"@polkadot/types": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/util-crypto": ^6.0.5
"@polkadot/x-fetch": ^6.0.5
@ -2805,7 +2805,7 @@ __metadata:
"@polkadot/x-ws": ^6.0.5
bn.js: ^4.11.9
eventemitter3: ^4.0.7
checksum: f082d0d327719d6f2ee13561b9a0926b35bd42ebf3d621ce01d054fd133046467034e7cb0e0256759d5a9172582b499b76b09fa39aa501fe81ea92180bde1fd8
checksum: 3f6ed2981ddbc4c3e56da3170f9cc85c502818054b4ac06786ec3b7b828abe1b19b9c69c76261c7b12ac889c4db09d8463a399a8459e36753983309220c478a2
languageName: node
linkType: hard
@ -2830,31 +2830,31 @@ __metadata:
languageName: node
linkType: hard
"@polkadot/types-known@npm:4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/types-known@npm:4.0.4-10"
"@polkadot/types-known@npm:4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/types-known@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/networks": ^6.0.5
"@polkadot/types": 4.0.4-10
"@polkadot/types": 4.0.4-11
"@polkadot/util": ^6.0.5
bn.js: ^4.11.9
checksum: 7009c5dc0d4e18261047c7b48acccce6b34fa22099c1e9afe9c53a7c9ca248e668c8173f73e14c09c046e79b473d8f7badc47d8d6ee8bd5d80c626005b7f3897
checksum: 552366ab183d97548d17cc3ed46016554ffc5b69f809194824bcbcf6216cba9df9f51ac0ee8d02dfea443ecdb1a7693db9e3524ea70bbe96b996647a7f10dc1e
languageName: node
linkType: hard
"@polkadot/types@npm:^4.0.4-10":
version: 4.0.4-10
resolution: "@polkadot/types@npm:4.0.4-10"
"@polkadot/types@npm:^4.0.4-11":
version: 4.0.4-11
resolution: "@polkadot/types@npm:4.0.4-11"
dependencies:
"@babel/runtime": ^7.13.9
"@polkadot/metadata": 4.0.4-10
"@polkadot/metadata": 4.0.4-11
"@polkadot/util": ^6.0.5
"@polkadot/util-crypto": ^6.0.5
"@polkadot/x-rxjs": ^6.0.5
"@types/bn.js": ^4.11.6
bn.js: ^4.11.9
checksum: fe70830657ea95cf5e35f33f53754aa5d1a1ecded91d3b6d3316ce6d4849d4a3bf3e078690b78a79c3d30582d088e25765bed97a24145101dd89195aa053df8d
checksum: e3f313ee7f8b0eab6d7f0d8c4fa62ba2b5420595e545662f8ac4a11f77de228854ef6014f3c5a25d5ecc4aa5f6099701a00eb71a7e390b34081361d004a68e0a
languageName: node
linkType: hard