diff --git a/src/renderer/component/walletSendTip/view.jsx b/src/renderer/component/walletSendTip/view.jsx index 05aea75d0..779ec2010 100644 --- a/src/renderer/component/walletSendTip/view.jsx +++ b/src/renderer/component/walletSendTip/view.jsx @@ -18,7 +18,7 @@ type Props = { type State = { tipAmount: number, - newTipError: string, + tipError: string, }; class WalletSendTip extends React.PureComponent { @@ -27,9 +27,8 @@ class WalletSendTip extends React.PureComponent { this.state = { tipAmount: 0, - newTipError: '', + tipError: '', }; - (this: any).handleSendButtonClicked = this.handleSendButtonClicked.bind(this); } @@ -48,26 +47,32 @@ class WalletSendTip extends React.PureComponent { handleSupportPriceChange(event: SyntheticInputEvent<*>) { const { balance } = this.props; + const regexp = RegExp(/^(\d*([.]\d{0,8})?)$/); + const validTipInput = regexp.test(event.target.value); const tipAmount = parseFloat(event.target.value); - let newTipError; - if (!String(tipAmount).match(/^(\d*([.]\d{0,8})?)$/)) { - newTipError = __('Tip must be a valid number with no more than 8 decimal places'); - } - if (tipAmount === balance) { - newTipError = __('Please decrease your tip to account for transaction fees'); + let tipError; + + if (!tipAmount) { + tipError = __('Tip must be a number'); + } else if (tipAmount <= 0) { + tipError = __('Tip must be a positive number'); + } else if (!validTipInput) { + tipError = __('Tip must have no more than 8 decimal places'); + } else if (tipAmount === balance) { + tipError = __('Please decrease your tip to account for transaction fees'); } else if (tipAmount > balance) { - newTipError = __('Not enough credits'); + tipError = __('Not enough credits'); } this.setState({ tipAmount, - newTipError, + tipError, }); } render() { const { title, isPending, uri, onCancel, balance } = this.props; - const { tipAmount, newTipError } = this.state; + const { tipAmount, tipError } = this.state; return (
@@ -78,10 +83,15 @@ class WalletSendTip extends React.PureComponent {
{