Skip to content

Commit

Permalink
#24 exchanges empty source coin balance handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pbca26 committed Mar 4, 2019
1 parent 23a4a4e commit ba7a75d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
12 changes: 8 additions & 4 deletions imports/ui/components/Exchanges/Exchanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,11 @@ class Exchanges extends React.Component {

if (Number(amount) > Number(this.state.currentBalanceSrc)) {
const _maxBuy = this.state.buyFixedDestCoin ? Number(Number((this.state.currentBalanceSrc - fromSats(fees[srcCoinSym]))).toFixed(8)) : Number(Number((this.state.currentBalanceSrc - fromSats(fees[srcCoinSym])) * exchangeRate.data.rate).toFixed(8));

valid = false;

this.setState({
processing: false,
maxBuyError: _maxBuy,
maxBuyError: Number(_maxBuy) > 0 ? _maxBuy : 'noBalance',
});
}

Expand All @@ -404,7 +403,7 @@ class Exchanges extends React.Component {
step: 1,
exchangeRate: exchangeRate.data,
amount,
maxBuyError: false,
maxBuyError: null,
orderPlaceError: null,
});
}
Expand Down Expand Up @@ -909,13 +908,18 @@ class Exchanges extends React.Component {
value={ this.state.amount || '' } />
</div>
</div>
{ this.state.maxBuyError &&
{ (this.state.maxBuyError && this.state.maxBuyError !== 'noBalance') &&
<div
onClick={ this.setMaxBuyAmount }
className="error margin-top-15 sz350 text-center">
<i className="fa fa-warning"></i> { translate('EXCHANGES.' + (!this.state.buyFixedDestCoin ? 'INSUFFICIENT_FUNDS_SRC' : 'INSUFFICIENT_FUNDS_DESC'), `${this.state.maxBuyError} ${this.state.buyFixedDestCoin ? this.state.coinSrc.split('|')[0].toUpperCase() : this.state.coinDest.split('|')[0].toUpperCase()}`) }.
</div>
}
{ (this.state.maxBuyError && this.state.maxBuyError === 'noBalance') &&
<div className="error margin-top-15 sz350 text-center">
<i className="fa fa-warning"></i> { translate('EXCHANGES.INSUFFICIENT_FUNDS', `${!this.state.buyFixedDestCoin ? this.state.coinSrc.split('|')[0].toUpperCase() : this.state.coinDest.split('|')[0].toUpperCase()}`) }.
</div>
}
{ this.state.orderPlaceError &&
<div className="error margin-top-15 sz350 text-center">
<i className="fa fa-warning"></i> { translate('EXCHANGES.ERROR') }: { this.state.orderPlaceError }.
Expand Down
1 change: 1 addition & 0 deletions imports/ui/translate/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const lang = {
BUY: 'Buy',
ENTER_AN_AMOUNT: 'Enter an amount',
INSUFFICIENT_FUNDS_SRC: 'Insufficient funds, you can buy up to @template@ max',
INSUFFICIENT_FUNDS: 'Insufficient funds, your @template@ balance is empty',
INSUFFICIENT_FUNDS_DESC: 'Insufficient funds, you can sell up to @template@ max',
ERROR: 'Error',
PLEASE_WAIT: 'Please wait',
Expand Down

0 comments on commit ba7a75d

Please sign in to comment.