InputNumber fix (#2669)
* InputNumber workaround for edit bug * defaultValue robustness checks
This commit is contained in:
parent
e2aeb50921
commit
8cdb813255
@ -5,7 +5,7 @@
|
||||
import { BareProps, BitLength } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { BitLengthOption } from '@polkadot/react-components/constants';
|
||||
import { formatBalance, isBn } from '@polkadot/util';
|
||||
@ -36,11 +36,15 @@ const DEFAULT_BITLENGTH = BitLengthOption.CHAIN_SPEC as BitLength;
|
||||
const TEN = new BN(10);
|
||||
|
||||
function InputBalance ({ autoFocus, className, defaultValue: inDefault, help, isDisabled, isError, isFull, isZeroable, label, labelExtra, maxValue, onChange, onEnter, onEscape, placeholder, style, value, withEllipsis, withLabel, withMax }: Props): React.ReactElement<Props> {
|
||||
const defaultValue = inDefault
|
||||
? isBn(inDefault)
|
||||
? inDefault.div(TEN.pow(new BN(formatBalance.getDefaults().decimals))).toString()
|
||||
: formatBalance(inDefault, { forceUnit: '-', withSi: false }).replace(',', isDisabled ? ',' : '')
|
||||
: inDefault;
|
||||
const [defaultValue, setDefaultValue] = useState<string | undefined>();
|
||||
|
||||
useEffect((): void => {
|
||||
inDefault && setDefaultValue(
|
||||
isBn(inDefault)
|
||||
? inDefault.div(TEN.pow(new BN(formatBalance.getDefaults().decimals))).toString()
|
||||
: formatBalance(inDefault, { forceUnit: '-', withSi: false }).replace(',', isDisabled ? ',' : '')
|
||||
);
|
||||
}, [inDefault, isDisabled]);
|
||||
|
||||
return (
|
||||
<InputNumber
|
||||
|
||||
@ -5,13 +5,14 @@
|
||||
import { Props } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useCallback } from 'react';
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import { InputBalance } from '@polkadot/react-components';
|
||||
|
||||
import Bare from './Bare';
|
||||
|
||||
function Balance ({ className, defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, onEscape, style, withLabel }: Props): React.ReactElement<Props> {
|
||||
const defaultValue = new BN((value as BN || '0').toString()).toString(10);
|
||||
const [defaultValue] = useState(new BN((value as BN || '0').toString()).toString(10));
|
||||
|
||||
const _onChange = useCallback(
|
||||
(value?: BN): void =>
|
||||
onChange && onChange({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user