Adjust InputBalance label positions (#8790)

* Adjust InputBalance label positions

* Allow null values

* Fix undefined params
This commit is contained in:
Jaco 2023-01-14 09:46:26 +02:00 committed by GitHub
parent eb842954db
commit 0bf67023d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 34 additions and 61 deletions

View File

@ -22,7 +22,7 @@ function Transfer ({ accountId, assetId, className, minBalance, siFormat: [siDec
const { t } = useTranslation();
const { api } = useApi();
const [isOpen, toggleOpen] = useToggle();
const [amount, setAmount] = useState<BN | null>(null);
const [amount, setAmount] = useState<BN | undefined>();
const [recipientId, setRecipientId] = useState<string | null>(null);
const [isProtected, setIsProtected] = useState(true);

View File

@ -26,11 +26,11 @@ function Info ({ assetIds, className = '', defaultValue, onChange, openId }: Pro
const [initial] = useState(() => defaultValue);
const [initialId] = useState(() => openId);
const [accountId, setAccountId] = useState<string | null>(null);
const [assetId, setAssetId] = useState<BN | null>(null);
const [assetDecimals, setAssetDecimals] = useState<BN | null>(null);
const [assetId, setAssetId] = useState<BN | undefined>();
const [assetDecimals, setAssetDecimals] = useState<BN | undefined>();
const [assetName, setAssetName] = useState<string | null | undefined>(() => defaultValue?.assetName);
const [assetSymbol, setAssetSymbol] = useState<string | null | undefined>(() => defaultValue?.assetSymbol);
const [minBalance, setMinBalance] = useState<BN | null>(null);
const [minBalance, setMinBalance] = useState<BN | undefined>();
const [siDecimals, siSymbol] = useMemo(
() => assetDecimals && assetSymbol

View File

@ -22,7 +22,7 @@ interface Props {
function Mint ({ className, details: { issuer, minBalance }, id, metadata, onClose }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [amount, setAmount] = useState<BN | null>(null);
const [amount, setAmount] = useState<BN | undefined>();
const [recipientId, setRecipientId] = useState<string | null>(null);
const isAmountValid = useMemo(

View File

@ -9,7 +9,7 @@ import React, { useEffect, useMemo, useState } from 'react';
import { getTreasuryProposalThreshold } from '@polkadot/apps-config';
import { Button, InputAddress, InputBalance, MarkError, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useCollectiveInstance, useCollectiveMembers, useToggle } from '@polkadot/react-hooks';
import { BN, BN_ZERO } from '@polkadot/util';
import { BN } from '@polkadot/util';
import { truncateTitle } from '../helpers';
import { useBounties } from '../hooks';
@ -34,7 +34,7 @@ function ProposeCuratorAction ({ description, index, proposals, value }: Props):
const [accountId, setAccountId] = useState<string | null>(null);
const [curatorId, setCuratorId] = useState<string | null>(null);
const [threshold, setThreshold] = useState<BN>();
const [fee, setFee] = useState<BN>(BN_ZERO);
const [fee, setFee] = useState<BN | null>();
const [isFeeValid, setIsFeeValid] = useState(false);
useEffect((): void => {
@ -56,7 +56,7 @@ function ProposeCuratorAction ({ description, index, proposals, value }: Props):
);
useEffect(() => {
setIsFeeValid(!!value?.gt(fee));
setIsFeeValid(!!fee && !!value?.gt(fee));
}, [value, fee]);
return isMember && !isVotingInitiated && councilMod

View File

@ -1,6 +1,7 @@
// Copyright 2017-2023 @polkadot/app-council authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { u128 } from '@polkadot/types';
import type { ComponentProps as Props } from './types';
import React, { useState } from 'react';
@ -41,7 +42,7 @@ function SubmitCandidacy ({ electionsInfo }: Props): React.ReactElement<Props> |
{api.consts[modLocation] && (
<Modal.Columns hint={t('The bond will be reserved for the duration of your candidacy and membership.')}>
<InputBalance
defaultValue={api.consts[modLocation].candidacyBond}
defaultValue={api.consts[modLocation as 'council']?.candidacyBond as u128}
isDisabled
label={t<string>('candidacy bond')}
/>

View File

@ -80,14 +80,14 @@ function Bid ({ className, isDisabled, proxies }: Props): React.ReactElement<Pro
<Modal.Columns hint={t<string>('The amount you wish to lock for the duration. It needs to be more than the gilt minimum.')}>
<InputBalance
autoFocus
defaultValue={api.consts.gilt.minFreeze}
defaultValue={api.consts.gilt.minFreeze as u128}
isError={isAmountError}
isZeroable={false}
label={t<string>('bid amount')}
onChange={setAmount}
/>
<InputBalance
defaultValue={api.consts.gilt.minFreeze}
defaultValue={api.consts.gilt.minFreeze as u128}
isDisabled
label={t<string>('minimum freeze amount')}
/>

View File

@ -1,6 +1,7 @@
// Copyright 2017-2023 @polkadot/app-parachains authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { u128 } from '@polkadot/types';
import type { BN } from '@polkadot/util';
import React, { useState } from 'react';
@ -46,7 +47,7 @@ function RegisterId ({ className, nextParaId, onClose }: Props): React.ReactElem
</Modal.Columns>
<Modal.Columns hint={t<string>('The reservation fee for this Id')}>
<InputBalance
defaultValue={api.consts.registrar.paraDeposit}
defaultValue={api.consts.registrar.paraDeposit as u128}
isDisabled
label={t<string>('reserved deposit')}
/>

View File

@ -49,7 +49,7 @@ function Propose ({ className, onClose }: Props): React.ReactElement<Props> {
const [accountId, setAccountId] = useState<string | null>(null);
const [name, setName] = useState('');
const [paraId, setParaId] = useState<BN | undefined>();
const [balance, setBalance] = useState(() => BN_THOUSAND.mul(BN_TEN.pow(new BN(api.registry.chainDecimals[0]))));
const [balance, setBalance] = useState<BN | undefined>(() => BN_THOUSAND.mul(BN_TEN.pow(new BN(api.registry.chainDecimals[0]))));
const [validators, setValidators] = useState<string[]>(['']);
const [{ isWasmValid, wasm }, setWasm] = useState<CodeState>({ isWasmValid: false, wasm: null });
const [genesisState, setGenesisState] = useState<Uint8Array | null>(null);

View File

@ -26,7 +26,7 @@ function Unbond ({ controllerId, onClose, stakingLedger, stashId }: Props): Reac
const { api } = useApi();
const bondedBlocks = useUnbondDuration();
const [maxBalance] = useState<BN | null>(() => stakingLedger?.active?.unwrap() || null);
const [maxUnbond, setMaxUnbond] = useState<BN | null>(null);
const [maxUnbond, setMaxUnbond] = useState<BN | undefined>();
const [withMax, setWithMax] = useState(false);
return (

View File

@ -27,7 +27,7 @@ function BondExtra ({ className, controllerId, onClose, poolId }: Props): React.
const { t } = useTranslation();
const { api } = useApi();
const [type, setType] = useState(DEFAULT_TYPE);
const [amount, setAmount] = useState(BN_ZERO);
const [amount, setAmount] = useState<BN | undefined>();
const isAmountError = useAmountError(controllerId, amount, BN_ZERO);
const typeRef = useRef([

View File

@ -8,7 +8,6 @@ import React, { useState } from 'react';
import { InputBalance, Modal, Static, Toggle, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
import { BN_ZERO } from '@polkadot/util';
import { useTranslation } from '../../translate';
import PoolInfo from '../partials/PoolInfo';
@ -25,7 +24,7 @@ interface Props {
function Unbond ({ className, controllerId, maxUnbond, onClose, poolId }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const { api } = useApi();
const [amount, setAmount] = useState(BN_ZERO);
const [amount, setAmount] = useState<BN | undefined>();
const [withMax, setWithMax] = useState(false);
const bondedBlocks = useUnbondDuration();

View File

@ -8,7 +8,7 @@ import React, { useMemo, useState } from 'react';
import { Button, Input, InputAddress, InputBalance, InputNumber, Modal, TxButton } from '@polkadot/react-components';
import { useApi, useToggle } from '@polkadot/react-hooks';
import { BN_ZERO, bnMax } from '@polkadot/util';
import { bnMax } from '@polkadot/util';
import { useTranslation } from '../translate';
import useAmountError from './useAmountError';
@ -28,7 +28,7 @@ function Create ({ className, isDisabled, ownAccounts, params: { minCreateBond,
const { api } = useApi();
const [isOpen, toggleOpen] = useToggle();
const [accountId, setAccount] = useState<string | null>(null);
const [amount, setAmount] = useState<BN>(BN_ZERO);
const [amount, setAmount] = useState<BN | undefined>();
const [metadata, setMetadata] = useState('');
const minValue = useMemo(

View File

@ -4,7 +4,6 @@
import type { SiDef } from '@polkadot/util/types';
import React, { useMemo } from 'react';
import styled from 'styled-components';
import { BN, formatBalance, isUndefined } from '@polkadot/util';
@ -14,7 +13,7 @@ interface Props {
autoFocus?: boolean;
children?: React.ReactNode;
className?: string;
defaultValue?: BN | string;
defaultValue?: BN | string | null;
isDisabled?: boolean;
isError?: boolean;
isFull?: boolean;
@ -23,14 +22,14 @@ interface Props {
isZeroable?: boolean;
label?: React.ReactNode;
labelExtra?: React.ReactNode;
maxValue?: BN;
maxValue?: BN | null;
onChange?: (value?: BN) => void;
onEnter?: () => void;
onEscape?: () => void;
placeholder?: string;
siDecimals?: number;
siSymbol?: string;
value?: BN;
value?: BN | null;
withEllipsis?: boolean;
withLabel?: boolean;
withMax?: boolean;
@ -38,7 +37,7 @@ interface Props {
const DEFAULT_BITLENGTH = 128;
function reformat (value?: string | BN, isDisabled = false, siDecimals?: number): { defaultValue?: string; siDefault?: SiDef } {
function reformat (value?: string | BN | null, isDisabled = false, siDecimals?: number): { defaultValue?: string; siDefault?: SiDef } {
if (!value) {
return {};
}
@ -102,28 +101,4 @@ function InputBalance ({ autoFocus, children, className = '', defaultValue: inDe
);
}
export default React.memo(styled(InputBalance)`
&&:not(.isSmall) .labelExtra {
right: 6.5rem;
}
.ui.action.input.ui--Input > .buttons {
align-items: stretch;
.ui--SiDropdown.ui.button.compact.floating.selection.dropdown {
&.disabled {
border-style: solid;
opacity: 1 !important;
}
> div.text:first-child {
font-size: var(--font-size-small);
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 0.5rem;
width: 3rem;
}
}
}
`);
export default React.memo(InputBalance);

View File

@ -277,16 +277,12 @@ function InputNumber ({ autoFocus, bitLength = DEFAULT_BITLENGTH, children, clas
export default React.memo(styled(InputNumber)`
.siUnit {
bottom: 0.85rem;
color: var(--color-label);
font-size: var(--font-size-tiny);
font-weight: var(--font-weight-label);
position: absolute;
top: 50%;
transform: translateY(-50%);
font-weight: var(--font-weight-bold);
right: 1.25rem;
}
.ui.buttons+.ui--Toggle.isOverlay {
bottom: 1.1rem;
right: 6.5rem;
}
`);

View File

@ -108,7 +108,7 @@ export default React.memo(styled(Labelled)`
color: var(--color-label);
font-size: var(--font-size-label);
font-weight: var(--font-weight-label);
right: 1.75rem;
right: 1.25rem;
text-align: right;
text-transform: var(--text-transform-label);
}

View File

@ -12,12 +12,12 @@ import { useTranslation } from './translate';
interface Props {
className?: string;
onChange: (tip: BN) => void;
onChange: (tip?: BN) => void;
}
function Tip ({ className, onChange }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const [tip, setTip] = useState(BN_ZERO);
const [tip, setTip] = useState<BN | undefined>();
const [showTip, setShowTip] = useState(false);
useEffect((): void => {

View File

@ -8,6 +8,7 @@ import type { KeyringPair } from '@polkadot/keyring/types';
import type { QueueTx, QueueTxMessageSetStatus } from '@polkadot/react-components/Status/types';
import type { Option } from '@polkadot/types';
import type { Multisig, Timepoint } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';
import type { HexString } from '@polkadot/util/types';
import type { AddressFlags, AddressProxy, QrState } from './types';
@ -19,7 +20,7 @@ import { web3FromSource } from '@polkadot/extension-dapp';
import { Button, ErrorBoundary, Modal, Output, Toggle } from '@polkadot/react-components';
import { useApi, useLedger, useQueue, useToggle } from '@polkadot/react-hooks';
import { keyring } from '@polkadot/ui-keyring';
import { assert, BN_ZERO, nextTick } from '@polkadot/util';
import { assert, nextTick } from '@polkadot/util';
import { addressEq } from '@polkadot/util-crypto';
import Address from './Address';
@ -204,7 +205,7 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea
const [signedOptions, setSignedOptions] = useState<Partial<SignerOptions>>({});
const [signedTx, setSignedTx] = useState<string | null>(null);
const [{ innerHash, innerTx }, setCallInfo] = useState<InnerTx>(EMPTY_INNER);
const [tip, setTip] = useState(BN_ZERO);
const [tip, setTip] = useState<BN | undefined>();
useEffect((): void => {
setFlags(tryExtract(senderInfo.signAddress));