From e136e4846196257b4a90cb4699beb976e79ef772 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 2 Sep 2017 12:43:10 +0300 Subject: [PATCH] send amount validation fix --- .../components/dashboard/sendCoin/sendCoin.js | 14 ++++----- .../walletsNativeSend/walletsNativeSend.js | 30 +++++++++++-------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/react/src/components/dashboard/sendCoin/sendCoin.js b/react/src/components/dashboard/sendCoin/sendCoin.js index 231ae13..ede761e 100644 --- a/react/src/components/dashboard/sendCoin/sendCoin.js +++ b/react/src/components/dashboard/sendCoin/sendCoin.js @@ -757,7 +757,7 @@ class SendCoin extends React.Component { } // TODO same as in walletsNav and receiveCoin, find a way to reuse it? - checkTotalBalance() { + checkBalance() { let _balance = '0'; const _mode = this.props.ActiveCoin.mode; @@ -777,21 +777,16 @@ class SendCoin extends React.Component { (_cache[_coin][_address].getbalance.data.balance || _cache[_coin][_address].getbalance.data.interest)) { const _regBalance = _cache[_coin][_address].getbalance.data.balance ? _cache[_coin][_address].getbalance.data.balance : 0; - const _regInterest = _cache[_coin][_address].getbalance.data.interest ? _cache[_coin][_address].getbalance.data.interest : 0; - _balance = _regBalance + _regInterest; + _balance = _regBalance; } } - } else if (_mode === 'native') { - if (this.props.ActiveCoin.balance && - this.props.ActiveCoin.balance.total) { - _balance = this.props.ActiveCoin.balance.total; - } } return _balance; } + // TODO: reduce to a single toast validateSendFormData() { let valid = true; if (!this.state.sendTo || this.state.sendTo.length < 34) { @@ -838,7 +833,8 @@ class SendCoin extends React.Component { valid = false; } - if (this.state.amount > this.checkTotalBalance()) { + if ((this.props.ActiveCoin.mode === 'basilisk' && Number(this.state.amount) > Number(this.state.sendFromAmount)) || + (this.props.ActiveCoin.mode === 'full' && Number(this.state.amount) > Number(this.checkBalance()))) { Store.dispatch( triggerToaster( translate('SEND.INSUFFICIENT_FUNDS'), diff --git a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js index a1ee7aa..5c30dad 100644 --- a/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js +++ b/react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js @@ -367,17 +367,7 @@ 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; - } - + // TODO: reduce to a single toast validateSendFormData() { let valid = true; @@ -404,7 +394,20 @@ class WalletsNativeSend extends React.Component { valid = false; } - if (this.state.amount > this.checkTotalBalance()) { + if (((!this.state.sendFrom || this.state.addressType === 'public') && + this.state.sendTo && + this.state.sendTo.length === 34 && + this.props.ActiveCoin.balance && + this.props.ActiveCoin.balance.transparent && + Number(this.state.amount) > Number(this.props.ActiveCoin.balance.transparent)) || + (this.state.addressType === 'public' && + this.state.sendTo && + this.state.sendTo.length > 34 && + Number(this.state.amount) > Number(this.state.sendFromAmount)) || + (this.state.addressType === 'private' && + this.state.sendTo && + this.state.sendTo.length >= 34 && + Number(this.state.amount) > Number(this.state.sendFromAmount))) { Store.dispatch( triggerToaster( translate('SEND.INSUFFICIENT_FUNDS'), @@ -427,6 +430,8 @@ class WalletsNativeSend extends React.Component { valid = false; } + valid = false; + return valid; } @@ -457,6 +462,7 @@ const mapStateToProps = (state) => { coin: state.ActiveCoin.coin, mode: state.ActiveCoin.mode, opids: state.ActiveCoin.opids, + balance: state.ActiveCoin.balance, activeSection: state.ActiveCoin.activeSection, }, };