From 941448d65cc42870a93e0430158bfd7ab52fd2cd Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 9 Oct 2018 12:11:12 -0700 Subject: Fix empty input bug --- packages/instant/src/components/amount_input.tsx | 12 ++++++++---- .../instant/src/containers/selected_asset_amount_input.tsx | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'packages') diff --git a/packages/instant/src/components/amount_input.tsx b/packages/instant/src/components/amount_input.tsx index 2b64469f6..29d1bf161 100644 --- a/packages/instant/src/components/amount_input.tsx +++ b/packages/instant/src/components/amount_input.tsx @@ -10,7 +10,7 @@ export interface AmountInputProps { fontColor?: ColorOption; fontSize?: string; value?: BigNumber; - onChange?: (value: BigNumber) => void; + onChange?: (value?: BigNumber) => void; } export class AmountInput extends React.Component { @@ -22,7 +22,7 @@ export class AmountInput extends React.Component { fontColor={fontColor} fontSize={fontSize} onChange={this._handleChange} - value={value ? value.toString() : undefined} + value={value ? value.toString() : ''} placeholder="0.00" width="2em" /> @@ -30,9 +30,13 @@ export class AmountInput extends React.Component { ); } private readonly _handleChange = (event: React.ChangeEvent): void => { - const bigNumberValue = new BigNumber(event.target.value); + const value = event.target.value; + let bigNumberValue; + if (!_.isEmpty(value)) { + bigNumberValue = new BigNumber(event.target.value); + } if (!_.isUndefined(this.props.onChange)) { this.props.onChange(bigNumberValue); } - } + }; } diff --git a/packages/instant/src/containers/selected_asset_amount_input.tsx b/packages/instant/src/containers/selected_asset_amount_input.tsx index 818caa965..800a4c568 100644 --- a/packages/instant/src/containers/selected_asset_amount_input.tsx +++ b/packages/instant/src/containers/selected_asset_amount_input.tsx @@ -19,7 +19,7 @@ interface ConnectedState { } interface ConnectedDispatch { - onChange?: (value: BigNumber) => void; + onChange?: (value?: BigNumber) => void; } const mapStateToProps = (state: State, _ownProps: SelectedAssetAmountInputProps): ConnectedState => ({ -- cgit v1.2.3