aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/inputs/balance_bounded_input.tsx
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-05-17 08:06:57 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-05-18 04:04:39 +0800
commitea0067d99976a572dcd4a4d988f4d33ca083f230 (patch)
treece750f48028c76a152f260c84c1dbeb9333a3171 /packages/website/ts/components/inputs/balance_bounded_input.tsx
parentec49ca648027cd82c4488f388e4917a879a71364 (diff)
downloaddexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.tar
dexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.tar.gz
dexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.tar.bz2
dexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.tar.lz
dexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.tar.xz
dexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.tar.zst
dexon-sol-tools-ea0067d99976a572dcd4a4d988f4d33ca083f230.zip
Show error messages in the wrapped ether item
Diffstat (limited to 'packages/website/ts/components/inputs/balance_bounded_input.tsx')
-rw-r--r--packages/website/ts/components/inputs/balance_bounded_input.tsx32
1 files changed, 17 insertions, 15 deletions
diff --git a/packages/website/ts/components/inputs/balance_bounded_input.tsx b/packages/website/ts/components/inputs/balance_bounded_input.tsx
index 68b77cfc3..72a246280 100644
--- a/packages/website/ts/components/inputs/balance_bounded_input.tsx
+++ b/packages/website/ts/components/inputs/balance_bounded_input.tsx
@@ -14,6 +14,7 @@ interface BalanceBoundedInputProps {
amount?: BigNumber;
hintText?: string;
onChange: ValidatedBigNumberCallback;
+ onErrorMsgChange?: (errorMsg: React.ReactNode) => void;
shouldShowIncompleteErrs?: boolean;
shouldCheckBalance: boolean;
validate?: (amount: BigNumber) => InputErrMsg;
@@ -36,6 +37,7 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
isDisabled: false,
shouldShowErrs: true,
hintText: 'amount',
+ onErrorMsgChange: utils.noop,
shouldShowUnderline: true,
};
constructor(props: BalanceBoundedInputProps) {
@@ -63,17 +65,11 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
}
if (shouldResetState) {
const amountString = nextProps.amount.toString();
- this.setState({
- errMsg: this._validate(amountString, nextProps.balance),
- amountString,
- });
+ this._setAmountState(amountString, nextProps.balance);
}
} else if (isCurrentAmountNumeric) {
const amountString = '';
- this.setState({
- errMsg: this._validate(amountString, nextProps.balance),
- amountString,
- });
+ this._setAmountState(amountString, nextProps.balance);
}
}
public render(): React.ReactNode {
@@ -105,14 +101,11 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
);
}
private _onValueChange(e: any, amountString: string): void {
- const errMsg = this._validate(amountString, this.props.balance);
- this.setState(
- {
- amountString,
- errMsg,
- },
+ this._setAmountState(
+ amountString,
+ this.props.balance,
() => {
- const isValid = _.isUndefined(errMsg);
+ const isValid = _.isUndefined(this._validate(amountString, this.props.balance));
if (utils.isNumeric(amountString) && !_.includes(amountString, '-')) {
this.props.onChange(isValid, new BigNumber(amountString));
} else {
@@ -161,4 +154,13 @@ export class BalanceBoundedInput extends React.Component<BalanceBoundedInputProp
);
}
}
+
+ private _setAmountState(amount: string, balance: BigNumber, callback: () => void = utils.noop): void {
+ const errorMsg = this._validate(amount, balance);
+ this.props.onErrorMsgChange(errorMsg);
+ this.setState({
+ amountString: amount,
+ errMsg: this._validate(amount, balance),
+ }, callback);
+ }
}