From ea0067d99976a572dcd4a4d988f4d33ca083f230 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 16 May 2018 17:06:57 -0700 Subject: Show error messages in the wrapped ether item --- .../ts/components/inputs/balance_bounded_input.tsx | 32 ++++++++++---------- .../ts/components/inputs/eth_amount_input.tsx | 2 ++ .../ts/components/inputs/token_amount_input.tsx | 2 ++ .../ts/components/wallet/wrap_ether_item.tsx | 34 +++++++++++++++++----- packages/website/ts/types.ts | 2 +- packages/website/ts/utils/utils.ts | 3 ++ 6 files changed, 52 insertions(+), 23 deletions(-) (limited to 'packages/website') 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 { - 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 void = utils.noop): void { + const errorMsg = this._validate(amount, balance); + this.props.onErrorMsgChange(errorMsg); + this.setState({ + amountString: amount, + errMsg: this._validate(amount, balance), + }, callback); + } } diff --git a/packages/website/ts/components/inputs/eth_amount_input.tsx b/packages/website/ts/components/inputs/eth_amount_input.tsx index c3822a80b..862ba25f8 100644 --- a/packages/website/ts/components/inputs/eth_amount_input.tsx +++ b/packages/website/ts/components/inputs/eth_amount_input.tsx @@ -12,6 +12,7 @@ interface EthAmountInputProps { amount?: BigNumber; hintText?: string; onChange: ValidatedBigNumberCallback; + onErrorMsgChange?: (errorMsg: React.ReactNode) => void; shouldShowIncompleteErrs: boolean; onVisitBalancesPageClick?: () => void; shouldCheckBalance: boolean; @@ -40,6 +41,7 @@ export class EthAmountInput extends React.Component void; onVisitBalancesPageClick?: () => void; lastForceTokenStateRefetch: number; shouldShowErrs?: boolean; @@ -85,6 +86,7 @@ export class TokenAmountInput extends React.Component { @@ -60,8 +66,8 @@ export class WrapEtherItem extends React.Component ) : ( )} + {this._renderErrorMsg()} } secondaryTextLines={2} @@ -119,7 +128,11 @@ export class WrapEtherItem extends React.Component { @@ -144,6 +157,13 @@ export class WrapEtherItem extends React.Component ); } + private _renderErrorMsg(): React.ReactNode { + return ( +
+ {this.state.errorMsg} +
+ ); + } private async _wrapEtherConfirmationActionAsync(): Promise { this.setState({ isEthConversionHappening: true, diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index 5caf5e73c..e3901fd81 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -208,7 +208,7 @@ export interface ContractEvent { } export type InputErrMsg = React.ReactNode | string | undefined; -export type ValidatedBigNumberCallback = (isValid: boolean, amount?: BigNumber) => void; +export type ValidatedBigNumberCallback = (isValid: boolean, amount?: BigNumber, errorMessage?: React.ReactNode) => void; export enum ScreenWidths { Sm = 'SM', Md = 'MD', diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index 3c99bd2fe..5a0ab934d 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -27,6 +27,9 @@ const MD_MIN_EM = 52; const isDogfood = (): boolean => _.includes(window.location.href, configs.DOMAIN_DOGFOOD); export const utils = { + noop(): void { + return undefined; + }, assert(condition: boolean, message: string): void { if (!condition) { throw new Error(message); -- cgit