diff --git a/packages/ui-app/src/InputBalance.tsx b/packages/ui-app/src/InputBalance.tsx index 71dfffba97..3aac0e0077 100644 --- a/packages/ui-app/src/InputBalance.tsx +++ b/packages/ui-app/src/InputBalance.tsx @@ -32,7 +32,7 @@ export default class InputBalance extends React.PureComponent { autoFocus={autoFocus} className={className} bitLength={DEFAULT_BITLENGTH} - defaultValue={defaultValue || '0'} + defaultValue={defaultValue} isDisabled={isDisabled} isError={isError} isSi diff --git a/packages/ui-app/src/InputNumber.tsx b/packages/ui-app/src/InputNumber.tsx index 735e876deb..b53b286eac 100644 --- a/packages/ui-app/src/InputNumber.tsx +++ b/packages/ui-app/src/InputNumber.tsx @@ -52,21 +52,25 @@ class InputNumber extends React.PureComponent { constructor (props: Props) { super(props); - const valueBN = new BN(this.props.value || 0); + const { defaultValue, value } = this.props; + let valueBN = new BN(value || 0); + const si = formatBalance.calcSi(valueBN.toString(), formatBalance.getDefaults().decimals); + + valueBN = valueBN.div(new BN(10).pow(new BN(si.power))); this.state = { - defaultValue: this.props.defaultValue || !this.props.value - ? undefined + defaultValue: defaultValue + ? defaultValue.toString() : valueBN.toString(), isPreKeyDown: false, - isValid: !isUndefined(this.props.value), + isValid: !isUndefined(value), siOptions: formatBalance.getOptions().map(({ power, text, value }) => ({ value, text: power === 0 ? InputNumber.units : text })), - siUnit: '-', + siUnit: si.value, valueBN }; } @@ -76,7 +80,7 @@ class InputNumber extends React.PureComponent { InputNumber.units = units; } - static getDerivedStateFromProps ({ isDisabled, isSi, defaultValue = '0' }: Props): Partial | null { + static getDerivedStateFromProps ({ isDisabled, isSi, defaultValue = '0' }: Props, state: State): Partial | null { if (!isDisabled || !isSi) { return null; }