From 7e65066d18d23785299a27f94b2b6cd1b7d5b296 Mon Sep 17 00:00:00 2001 From: Keith Ingram Date: Tue, 12 Nov 2019 12:00:44 +0100 Subject: [PATCH] Functional InputNumber with fixed bugs (#1820) * Functional InputNumber * linting * linting * remove max button * linting * linting * version * version * combine values * fix * Re-enable SI dropdown * KSM formats * Formatting tweaks * Mini fixes * Adjust postfix opacity * Linting * More linting * Remove unneeded list override * Misc small adjustments * Vertical alignment --- packages/app-accounts/src/modals/Transfer.tsx | 2 +- packages/app-claims/src/Claim.tsx | 4 +- packages/app-claims/src/index.tsx | 4 +- packages/app-contracts/src/Contracts/Call.tsx | 1 + packages/app-contracts/src/Deploy.tsx | 6 +- .../app-council/src/Overview/VoteValue.tsx | 2 +- .../app-democracy/src/Overview/Proposal.tsx | 4 +- .../app-democracy/src/Overview/Referendum.tsx | 4 +- packages/app-generic-asset/src/Transfer.tsx | 2 +- .../src/Actions/Account/BondExtra.tsx | 2 +- packages/react-api/src/Api.tsx | 4 +- packages/react-components/src/AddressInfo.tsx | 58 ++- packages/react-components/src/AddressMini.tsx | 1 + packages/react-components/src/Balance.tsx | 40 +- packages/react-components/src/Bonded.tsx | 26 +- packages/react-components/src/Call.tsx | 4 +- .../react-components/src/InputBalance.tsx | 12 +- .../src/InputBalanceBonded.tsx | 4 +- packages/react-components/src/InputNumber.tsx | 475 ++++++++---------- packages/react-components/src/Row.tsx | 1 + .../react-components/src/TreasuryProposal.tsx | 6 +- packages/react-query/src/Available.tsx | 19 +- packages/react-query/src/Balance.tsx | 19 +- packages/react-query/src/BalanceVoting.tsx | 19 +- packages/react-query/src/Bonded.tsx | 17 +- packages/react-query/src/FormatBalance.tsx | 51 ++ packages/react-query/src/LockedVote.tsx | 18 +- packages/react-query/src/index.ts | 1 + packages/react-signer/src/Checks/Proposal.tsx | 4 +- packages/react-signer/src/Modal.tsx | 1 + 30 files changed, 420 insertions(+), 391 deletions(-) create mode 100644 packages/react-query/src/FormatBalance.tsx diff --git a/packages/app-accounts/src/modals/Transfer.tsx b/packages/app-accounts/src/modals/Transfer.tsx index b0ffc9bb47..3ce8f8bc61 100644 --- a/packages/app-accounts/src/modals/Transfer.tsx +++ b/packages/app-accounts/src/modals/Transfer.tsx @@ -84,7 +84,7 @@ function Transfer ({ className, onClose, recipientId: propRecipientId, senderId: } }, [amount, recipientId, senderId]); - const transferrable = {t('transferrable ')}; + const transferrable = {t('transferrable')}; return ( {t('has a valid claim for')} -

{formatBalance(claimValue)}

+

{button} ) diff --git a/packages/app-claims/src/index.tsx b/packages/app-claims/src/index.tsx index ff07892784..6d4fa9c6c0 100644 --- a/packages/app-claims/src/index.tsx +++ b/packages/app-claims/src/index.tsx @@ -14,7 +14,7 @@ import styled from 'styled-components'; import CopyToClipboard from 'react-copy-to-clipboard'; import { withApi, withMulti } from '@polkadot/react-api'; import { Button, Card, Columar, Column, InputAddress, Tooltip } from '@polkadot/react-components'; -import { InputNumber } from '@polkadot/react-components/InputNumber'; +import { TokenUnit } from '@polkadot/react-components/InputNumber'; import TxModal, { TxModalState, TxModalProps } from '@polkadot/react-components/TxModal'; import { u8aToHex, u8aToString } from '@polkadot/util'; import { decodeAddress } from '@polkadot/util-crypto'; @@ -112,7 +112,7 @@ class App extends TxModal {

- claim your {InputNumber.units} tokens + claim your {TokenUnit.abbr} tokens

diff --git a/packages/app-contracts/src/Contracts/Call.tsx b/packages/app-contracts/src/Contracts/Call.tsx index 09fe72e10e..794320e408 100644 --- a/packages/app-contracts/src/Contracts/Call.tsx +++ b/packages/app-contracts/src/Contracts/Call.tsx @@ -167,6 +167,7 @@ function Call (props: Props): React.ReactElement | null { help={t('The allotted value for this contract, i.e. the amount transferred to the contract as part of this call.')} isDisabled={isBusy} isError={!isEndowmentValid} + isZeroable label={t('value')} onChange={_onChangeEndowment} value={endowment} diff --git a/packages/app-contracts/src/Deploy.tsx b/packages/app-contracts/src/Deploy.tsx index 7ec70be5f2..bbee4ff42c 100644 --- a/packages/app-contracts/src/Deploy.tsx +++ b/packages/app-contracts/src/Deploy.tsx @@ -21,7 +21,7 @@ import ContractModal, { ContractModalProps, ContractModalState } from './Modal'; import Params from './Params'; import store from './store'; import translate from './translate'; -import { GAS_LIMIT } from './constants'; +import { ENDOWMENT, GAS_LIMIT } from './constants'; type ConstructOptions = { key: string; text: React.ReactNode; value: string }[]; @@ -51,7 +51,7 @@ class Deploy extends ContractModal { ...this.defaultState, constructorIndex: -1, constructOptions: [], - endowment: new BN(0), + endowment: new BN(ENDOWMENT), gasLimit: new BN(GAS_LIMIT), isHashValid: false, params: [], @@ -182,7 +182,7 @@ class Deploy extends ContractModal { } + labelExtra={{t('voting balance')}} params={accountId} />} onChange={_setVoteValue} /> ); diff --git a/packages/app-democracy/src/Overview/Proposal.tsx b/packages/app-democracy/src/Overview/Proposal.tsx index 22196daf8a..b40d6a2f4d 100644 --- a/packages/app-democracy/src/Overview/Proposal.tsx +++ b/packages/app-democracy/src/Overview/Proposal.tsx @@ -11,7 +11,7 @@ import React from 'react'; import { Option, Tuple, Vec } from '@polkadot/types'; import { ActionItem, InputAddress, Labelled, Static } from '@polkadot/react-components'; import { withCalls, withMulti } from '@polkadot/react-api'; -import { formatBalance } from '@polkadot/util'; +import { FormatBalance } from '@polkadot/react-query'; import translate from '../translate'; import Seconding from './Seconding'; @@ -42,7 +42,7 @@ function renderProposal ({ democracy_depositOf, t }: Props): React.ReactNode { ))} - {formatBalance(balance)} + ); diff --git a/packages/app-democracy/src/Overview/Referendum.tsx b/packages/app-democracy/src/Overview/Referendum.tsx index 4150c6ad61..bb07af7674 100644 --- a/packages/app-democracy/src/Overview/Referendum.tsx +++ b/packages/app-democracy/src/Overview/Referendum.tsx @@ -104,12 +104,12 @@ function Referendum ({ chain_bestNumber, className, democracy_enactmentPeriod, d values={[ { colors: COLORS_AYE, - label: `Aye, ${formatBalance(votedAye)} (${formatNumber(voteCountAye)})`, + label: `Aye, ${formatBalance(votedAye, { forceUnit: '-' })} (${formatNumber(voteCountAye)})`, value: votedAye.muln(10000).div(votedTotal).toNumber() / 100 }, { colors: COLORS_NAY, - label: `Nay, ${formatBalance(votedNay)} (${formatNumber(voteCountNay)})`, + label: `Nay, ${formatBalance(votedNay, { forceUnit: '-' })} (${formatNumber(voteCountNay)})`, value: votedNay.muln(10000).div(votedTotal).toNumber() / 100 } ]} diff --git a/packages/app-generic-asset/src/Transfer.tsx b/packages/app-generic-asset/src/Transfer.tsx index b67653a018..5c171d90a2 100644 --- a/packages/app-generic-asset/src/Transfer.tsx +++ b/packages/app-generic-asset/src/Transfer.tsx @@ -63,7 +63,7 @@ function Transfer ({ assets, className, onClose, recipientId: propRecipientId, s } }; - const transferrable = {t('transferrable ')}; + const transferrable = {t('transferrable')}; return (
diff --git a/packages/app-staking/src/Actions/Account/BondExtra.tsx b/packages/app-staking/src/Actions/Account/BondExtra.tsx index 31e5e46228..55b24ea576 100644 --- a/packages/app-staking/src/Actions/Account/BondExtra.tsx +++ b/packages/app-staking/src/Actions/Account/BondExtra.tsx @@ -100,7 +100,7 @@ class BondExtra extends TxComponent { private renderContent (): React.ReactNode { const { stashId, systemChain, t } = this.props; const { amountError, maxAdditional, maxBalance } = this.state; - const transferrable = {t('transferrable ')}; + const transferrable = {t('transferrable')}; const isUnsafeChain = detectUnsafe(systemChain); return ( diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 3a9045872a..82464f81ce 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -11,7 +11,7 @@ import ApiPromise from '@polkadot/api/promise'; import { isWeb3Injected, web3Accounts, web3Enable } from '@polkadot/extension-dapp'; import defaults from '@polkadot/rpc-provider/defaults'; import { WsProvider } from '@polkadot/rpc-provider'; -import { InputNumber } from '@polkadot/react-components/InputNumber'; +import { TokenUnit } from '@polkadot/react-components/InputNumber'; import keyring from '@polkadot/ui-keyring'; import uiSettings from '@polkadot/ui-settings'; import ApiSigner from '@polkadot/react-signer/ApiSigner'; @@ -152,7 +152,7 @@ export default class Api extends React.PureComponent { decimals: tokenDecimals, unit: tokenSymbol }); - InputNumber.setUnit(tokenSymbol); + TokenUnit.setAbbr(tokenSymbol); // finally load the keyring keyring.loadAll({ diff --git a/packages/react-components/src/AddressInfo.tsx b/packages/react-components/src/AddressInfo.tsx index 137e42d266..fa7e1def5f 100644 --- a/packages/react-components/src/AddressInfo.tsx +++ b/packages/react-components/src/AddressInfo.tsx @@ -12,6 +12,7 @@ import styled from 'styled-components'; import { formatBalance, formatNumber, isObject } from '@polkadot/util'; import { Icon, Tooltip, TxButton } from '@polkadot/react-components'; import { withCalls, withMulti } from '@polkadot/react-api'; +import { FormatBalance } from '@polkadot/react-query'; import CryptoType from './CryptoType'; import Label from './Label'; @@ -165,7 +166,7 @@ function renderUnlocking ({ stakingInfo, t }: Props): React.ReactNode { return (
- {formatBalance(total)} + @@ -211,9 +212,10 @@ function renderValidatorPrefs ({ stakingInfo, t, withValidatorPrefs = false }: P {validatorPrefsDisplay.validatorPayment && stakingInfo.validatorPrefs.validatorPayment && ( <>
@@ -73,7 +73,7 @@ export function Proposal ({ deposit, democracy_minimumDeposit = ZERO, onChange, {t('The deposit of {{deposit}} will be reserved until the proposal is completed', { replace: { - deposit: formatBalance(extraAmount) + deposit: formatBalance(extraAmount, { forceUnit: '-' }) } })}
diff --git a/packages/react-signer/src/Modal.tsx b/packages/react-signer/src/Modal.tsx index a2b1b25667..7a70c25782 100644 --- a/packages/react-signer/src/Modal.tsx +++ b/packages/react-signer/src/Modal.tsx @@ -294,6 +294,7 @@ class Signer extends React.PureComponent {