Ensure bitLength is passed to number inputs (#3918)
This commit is contained in:
parent
16c64ac30e
commit
c36e4ddb97
@ -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}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user