From 71497c57f8e8a670863c0b3df23a186dbe263044 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 11 Mar 2021 14:21:34 +0100 Subject: [PATCH] Bid action (no result data displays) (#4822) * Bid action (no rsult data displays) * allow last === first * Bump api --- package.json | 6 +- packages/page-contracts/package.json | 2 +- .../page-parachains/src/Auctions/Auction.tsx | 52 ++++++++ packages/page-parachains/src/Auctions/Bid.tsx | 120 ++++++++++++++++++ .../page-parachains/src/Auctions/Summary.tsx | 6 +- .../page-parachains/src/Auctions/index.tsx | 35 ++++- .../page-parachains/src/Crowdloan/FundAdd.tsx | 6 +- packages/react-api/package.json | 2 +- yarn.lock | 106 ++++++++-------- 9 files changed, 268 insertions(+), 67 deletions(-) create mode 100644 packages/page-parachains/src/Auctions/Auction.tsx create mode 100644 packages/page-parachains/src/Auctions/Bid.tsx diff --git a/package.json b/package.json index 7223b11ace..46dee58934 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/page-contracts/package.json b/packages/page-contracts/package.json index 16952f4f7a..293099e69b 100644 --- a/packages/page-contracts/package.json +++ b/packages/page-contracts/package.json @@ -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" } } diff --git a/packages/page-parachains/src/Auctions/Auction.tsx b/packages/page-parachains/src/Auctions/Auction.tsx new file mode 100644 index 0000000000..8cc56eef5a --- /dev/null +++ b/packages/page-parachains/src/Auctions/Auction.tsx @@ -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 { + const { t } = useTranslation(); + + const headerRef = useRef([ + [t('auctions'), 'start', 1], + [t('duration'), 'number'], + [t('lease period'), 'number'], + [t('winning'), 'number', 3], + [] + ]); + + return ( + ('No ongoing auction')} + header={headerRef.current} + > + {auctionInfo && numAuctions && ( + + + + + + + )} +

{formatNumber(numAuctions)}

{formatNumber(auctionInfo[1])}{formatNumber(auctionInfo[0])} + + +
+ ); +} + +export default React.memo(Auction); diff --git a/packages/page-parachains/src/Auctions/Bid.tsx b/packages/page-parachains/src/Auctions/Bid.tsx new file mode 100644 index 0000000000..8bfd0b56ce --- /dev/null +++ b/packages/page-parachains/src/Auctions/Bid.tsx @@ -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 { + const { t } = useTranslation(); + const { api } = useApi(); + const { hasAccounts } = useAccounts(); + const [accountId, setAccountId] = useState(null); + const [amount, setAmount] = useState(); + const [firstSlot, setFirstSlot] = useState(); + const [lastSlot, setLastSlot] = useState(); + const [paraId, setParaId] = useState(); + const [isOpen, toggleOpen] = useToggle(); + + const isLastError = !lastSlot || !firstSlot || lastSlot.lt(firstSlot) || lastSlot.gt(firstSlot.addn(3)); + + return ( + <> +