diff --git a/packages/page-alliance/src/Members/Member.tsx b/packages/page-alliance/src/Members/Member.tsx index fc05747c15..44095035e9 100644 --- a/packages/page-alliance/src/Members/Member.tsx +++ b/packages/page-alliance/src/Members/Member.tsx @@ -6,9 +6,8 @@ import type { Member as MemberType } from '../types'; import React, { useCallback, useMemo } from 'react'; -import { AddressSmall, Menu, Popup, Tag } from '@polkadot/react-components'; +import { AddressSmall, Menu, Popup, Table, Tag } from '@polkadot/react-components'; import { useAccounts, useApi, useQueue } from '@polkadot/react-hooks'; -import { FormatBalance } from '@polkadot/react-query'; import { useTranslation } from '../translate'; import useMemberInfo from '../useMemberInfo'; @@ -82,11 +81,7 @@ function Member ({ bestNumber, className, info: { accountId, role }, isPrime, is /> ))} - - {info && info.deposit && ( - - )} - + {role} diff --git a/packages/page-bounties/src/Bounty.tsx b/packages/page-bounties/src/Bounty.tsx index f50561330d..9d059693e3 100644 --- a/packages/page-bounties/src/Bounty.tsx +++ b/packages/page-bounties/src/Bounty.tsx @@ -70,7 +70,7 @@ function Bounty ({ bestNumber, bounty, className = '', description, index, propo - + {curatorToRender && ( - - {deposit && ( - - )} - + diff --git a/packages/page-democracy/src/Overview/External.tsx b/packages/page-democracy/src/Overview/External.tsx index 77661cb95f..c89d27195f 100644 --- a/packages/page-democracy/src/Overview/External.tsx +++ b/packages/page-democracy/src/Overview/External.tsx @@ -5,9 +5,8 @@ import type { DeriveProposalExternal } from '@polkadot/api-derive/types'; import React from 'react'; -import { AddressMini, Button, Columar, ExpandButton, LinkExternal } from '@polkadot/react-components'; +import { AddressMini, Button, Columar, ExpandButton, LinkExternal, Table } from '@polkadot/react-components'; import { useCollectiveMembers, useToggle } from '@polkadot/react-hooks'; -import { FormatBalance } from '@polkadot/react-query'; import Fasttrack from './Fasttrack'; import PreImageButton from './PreImageButton'; @@ -34,9 +33,7 @@ function External ({ className = '', value: { image, imageHash, threshold } }: P )} - - {image && } - + {!image?.proposal && ( diff --git a/packages/page-parachains/src/Auctions/WinRange.tsx b/packages/page-parachains/src/Auctions/WinRange.tsx index 03b47b9596..f41568d74c 100644 --- a/packages/page-parachains/src/Auctions/WinRange.tsx +++ b/packages/page-parachains/src/Auctions/WinRange.tsx @@ -7,7 +7,6 @@ import type { AuctionInfo, WinnerData } from '../types'; import React from 'react'; import { AddressMini, ParaLink, Table } from '@polkadot/react-components'; -import { FormatBalance } from '@polkadot/react-query'; import { formatNumber } from '@polkadot/util'; import { useTranslation } from '../translate'; @@ -44,7 +43,7 @@ function WinRanges ({ auctionInfo, blockNumber, className = '', isFirst, isLates : `${formatNumber(firstSlot)} - ${formatNumber(lastSlot)}` } - + ); } diff --git a/packages/page-society/src/Candidates/Bid.tsx b/packages/page-society/src/Candidates/Bid.tsx index be8fd0dd63..d76a40ab8e 100644 --- a/packages/page-society/src/Candidates/Bid.tsx +++ b/packages/page-society/src/Candidates/Bid.tsx @@ -5,9 +5,8 @@ import type { PalletSocietyBid } from '@polkadot/types/lookup'; import React, { useMemo } from 'react'; -import { AddressSmall, TxButton } from '@polkadot/react-components'; +import { AddressSmall, Table, TxButton } from '@polkadot/react-components'; import { useAccounts, useApi } from '@polkadot/react-hooks'; -import { FormatBalance } from '@polkadot/react-query'; import { useTranslation } from '../translate'; import BidType from './BidType'; @@ -72,14 +71,8 @@ function BidRow ({ index, value: { kind, value, who } }: Props): React.ReactElem ) } - - - - - {tip && ( - - )} - + + ); } diff --git a/packages/page-society/src/Candidates/Candidate.tsx b/packages/page-society/src/Candidates/Candidate.tsx index a9bcfb3bad..0d9445b782 100644 --- a/packages/page-society/src/Candidates/Candidate.tsx +++ b/packages/page-society/src/Candidates/Candidate.tsx @@ -8,9 +8,8 @@ import type { VoteType } from '../types'; import React, { useMemo } from 'react'; -import { AddressSmall } from '@polkadot/react-components'; +import { AddressSmall, Table } from '@polkadot/react-components'; import { useApi, useCall } from '@polkadot/react-hooks'; -import { FormatBalance } from '@polkadot/react-query'; import Votes from '../Overview/Votes'; import BidType from './BidType'; @@ -45,9 +44,7 @@ function Candidate ({ allMembers, isMember, ownMembers, value: { accountId, kind - - - + - - {balance && ( - - )} - + ); } diff --git a/packages/page-staking/src/Bags/Bag.tsx b/packages/page-staking/src/Bags/Bag.tsx index 106807a181..9c965a685e 100644 --- a/packages/page-staking/src/Bags/Bag.tsx +++ b/packages/page-staking/src/Bags/Bag.tsx @@ -8,8 +8,7 @@ import type { ListNode, StashNode } from './types'; import React, { useEffect, useState } from 'react'; -import { AddressMini } from '@polkadot/react-components'; -import { FormatBalance } from '@polkadot/react-query'; +import { AddressMini, Table } from '@polkadot/react-components'; import { formatNumber } from '@polkadot/util'; import Rebag from './Rebag'; @@ -63,8 +62,8 @@ function Bag ({ bagLower, bagUpper, info, nodesOwn }: Props): React.ReactElement return ( - - + + {info.head.isSome && } {info.tail.isSome && } diff --git a/packages/page-staking/src/Payouts/Stash.tsx b/packages/page-staking/src/Payouts/Stash.tsx index 8cca59a6fd..f02454971d 100644 --- a/packages/page-staking/src/Payouts/Stash.tsx +++ b/packages/page-staking/src/Payouts/Stash.tsx @@ -6,8 +6,8 @@ import type { PayoutStash } from './types'; import React, { useEffect, useState } from 'react'; -import { AddressSmall } from '@polkadot/react-components'; -import { BlockToTime, FormatBalance } from '@polkadot/react-query'; +import { AddressSmall, Table } from '@polkadot/react-components'; +import { BlockToTime } from '@polkadot/react-query'; import { BN_MILLION } from '@polkadot/util'; import useEraBlocks from './useEraBlocks'; @@ -46,7 +46,7 @@ function Stash ({ className = '', historyDepth, payout: { available, rewards, st {eraStr} - + {eraStr} - + {eraBlocks && } ( - - {stashAvail && } - + ), [stashAvail]); @@ -222,9 +219,7 @@ function Payouts ({ className = '', historyDepth, isInElection, ownPools, ownVal const footerVal = useMemo(() => ( - - {valAvail && } - + ), [valAvail]); diff --git a/packages/page-staking/src/Pools/Pool.tsx b/packages/page-staking/src/Pools/Pool.tsx index 711ebedefc..fea1cef39d 100644 --- a/packages/page-staking/src/Pools/Pool.tsx +++ b/packages/page-staking/src/Pools/Pool.tsx @@ -68,12 +68,10 @@ function Pool ({ className = '', members, ownAccounts, params, poolId }: Props): ? info.bonded.state.type : Destroying} - - - + {info && !info.rewardClaimable.isZero() && } {info && info.nominating.length !== 0 && ( diff --git a/packages/page-treasury/src/Overview/Proposal.tsx b/packages/page-treasury/src/Overview/Proposal.tsx index 20964c5909..c1568efd73 100644 --- a/packages/page-treasury/src/Overview/Proposal.tsx +++ b/packages/page-treasury/src/Overview/Proposal.tsx @@ -7,7 +7,6 @@ import React, { useMemo } from 'react'; import { AddressMini, AddressSmall, Columar, LinkExternal, Table } from '@polkadot/react-components'; import { useApi, useToggle } from '@polkadot/react-hooks'; -import { FormatBalance } from '@polkadot/react-query'; import { isFunction } from '@polkadot/util'; import { useTranslation } from '../translate'; @@ -42,9 +41,7 @@ function ProposalDisplay ({ className = '', isMember, members, proposal: { counc - - - + { + return ( + + {value + ? + : withLoading && ( + + ) + } + + ); +} + +export default React.memo(Balance); diff --git a/packages/react-components/src/Table/Column/index.ts b/packages/react-components/src/Table/Column/index.ts new file mode 100644 index 0000000000..2ac85713a8 --- /dev/null +++ b/packages/react-components/src/Table/Column/index.ts @@ -0,0 +1,11 @@ +// Copyright 2017-2023 @polkadot/react-components authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { TableType } from '../types'; + +import Balance from './Balance'; +import Expand from './Expand'; +import Favorite from './Favorite'; +import Id from './Id'; + +export const Column: TableType['Column'] = { Balance, Expand, Favorite, Id }; diff --git a/packages/react-components/src/Table/index.ts b/packages/react-components/src/Table/index.ts new file mode 100644 index 0000000000..db4aa96b1f --- /dev/null +++ b/packages/react-components/src/Table/index.ts @@ -0,0 +1,13 @@ +// Copyright 2017-2023 @polkadot/react-components authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { TableType } from './types'; + +import { Column } from './Column'; +import TableBase from './Table'; + +const Table = TableBase as unknown as TableType; + +Table.Column = Column; + +export default Table; diff --git a/packages/react-components/src/Table/index.tsx b/packages/react-components/src/Table/index.tsx deleted file mode 100644 index e9928e7b6f..0000000000 --- a/packages/react-components/src/Table/index.tsx +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017-2023 @polkadot/react-components authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { ColExpandProps, ColFavoriteProps, ColIdProps, TableProps } from './types'; - -import React from 'react'; - -import Expand from './Column/Expand'; -import Favorite from './Column/Favorite'; -import Id from './Column/Id'; -import TableBase from './Table'; - -type TableType = React.ComponentType & { - Column: { - Expand: React.ComponentType; - Favorite: React.ComponentType; - Id: React.ComponentType; - } -}; - -const Table = TableBase as unknown as TableType; - -Table.Column = { Expand, Favorite, Id }; - -export default Table; diff --git a/packages/react-components/src/Table/types.ts b/packages/react-components/src/Table/types.ts index 5e4fc783ac..f4d5c504b5 100644 --- a/packages/react-components/src/Table/types.ts +++ b/packages/react-components/src/Table/types.ts @@ -3,6 +3,12 @@ import type { BN } from '@polkadot/util'; +export interface ColBalanceProps { + className?: string; + value?: BN | null; + withLoading?: boolean; +} + export interface ColExpandProps { className?: string; isExpanded: boolean; @@ -36,3 +42,12 @@ export interface TableProps { legend?: React.ReactNode; noBodyTag?: boolean; } + +export type TableType = React.ComponentType & { + Column: { + Balance: React.ComponentType; + Expand: React.ComponentType; + Favorite: React.ComponentType; + Id: React.ComponentType; + } +};