From 17b2256936608e997ec3adfbeced02ce872978b4 Mon Sep 17 00:00:00 2001 From: petitPapillon Date: Tue, 22 Aug 2017 23:21:38 +0200 Subject: [PATCH] Native send form - add validation --- .../walletsNativeSend/walletsNativeSend.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js index 0c89e11..646d42c 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js @@ -16,6 +16,7 @@ import { WalletsNativeSendFormRender, _WalletsNativeSendFormRender } from './walletsNativeSend.render'; +import { isPositiveNumber } from "../../../util/number"; class WalletsNativeSend extends React.Component { constructor(props) { @@ -269,6 +270,10 @@ class WalletsNativeSend extends React.Component { } handleSubmit() { + if (!this.validateSendFormData()) { + return; + } + Store.dispatch( sendNativeTx( this.props.ActiveCoin.coin, @@ -348,6 +353,55 @@ class WalletsNativeSend extends React.Component { return null; } + checkTotalBalance() { + let _balance = 0; + if (this.props.ActiveCoin.balance && + this.props.ActiveCoin.balance.total) { + _balance = this.props.ActiveCoin.balance.total; + } + + return _balance; + } + + validateSendFormData() { + let valid = true; + if (!this.state.sendTo || this.state.sendTo.length < 34) { + Store.dispatch( + triggerToaster( + translate('SEND.SEND_TO_ADDRESS_MIN_LENGTH'), + '', + 'error' + ) + ); + valid = false; + } + + if (!isPositiveNumber(this.state.amount)) { + Store.dispatch( + triggerToaster( + translate('SEND.AMOUNT_POSITIVE_NUMBER'), + '', + 'error' + ) + ); + valid = false; + } + + if (this.state.amount > this.checkTotalBalance()) { + Store.dispatch( + triggerToaster( + translate('SEND.INSUFFICIENT_FUNDS'), + '', + 'error' + ) + ); + valid = false; + } + + return valid; + } + + render() { if (this.props && this.props.ActiveCoin &&