Browse Source

send amount validation fix

all-modes
pbca26 7 years ago
parent
commit
e136e48461
  1. 14
      react/src/components/dashboard/sendCoin/sendCoin.js
  2. 30
      react/src/components/dashboard/walletsNativeSend/walletsNativeSend.js

14
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'),

30
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,
},
};

Loading…
Cancel
Save