Ensure bitLength is passed to number inputs (#3918)

This commit is contained in:
Jaco Greeff 2020-10-22 21:00:38 +02:00 committed by GitHub
parent 16c64ac30e
commit c36e4ddb97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ import { bnToBn, formatNumber, isUndefined } from '@polkadot/util';
import Bare from './Bare';
function Amount ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, withLabel }: Props): React.ReactElement<Props> {
function Amount ({ className = '', defaultValue: { value }, isDisabled, isError, label, onChange, onEnter, type, withLabel }: Props): React.ReactElement<Props> {
const defaultValue = useMemo(
() => isDisabled
? value instanceof ClassOf(registry, 'AccountIndex')
@ -22,6 +22,17 @@ function Amount ({ className = '', defaultValue: { value }, isDisabled, isError,
[isDisabled, value]
);
const bitLength = useMemo(
(): number => {
try {
return registry.createType(type.type as 'u32').bitLength();
} catch (error) {
return 32;
}
},
[type]
);
const _onChange = useCallback(
(value?: BN) => onChange && onChange({
isValid: !isUndefined(value),
@ -45,6 +56,7 @@ function Amount ({ className = '', defaultValue: { value }, isDisabled, isError,
)
: (
<InputNumber
bitLength={bitLength}
className='full'
defaultValue={defaultValue}
isError={isError}