Skip to content

Commit

Permalink
Fix bitshares#529: Withrawal modal inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Oct 11, 2017
1 parent 77901c2 commit c7b6e43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
16 changes: 13 additions & 3 deletions app/components/Dashboard/SimpleDepositWithdraw.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import { checkFeeStatusAsync, checkBalance } from "common/trxHelper";
import AssetName from "../Utility/AssetName";
import { ChainStore } from "bitsharesjs/es";
import { debounce } from "lodash";
import {DecimalChecker} from "../Exchange/ExchangeInput";

// import DepositFiatOpenLedger from "components/DepositWithdraw/openledger/DepositFiatOpenLedger";
// import WithdrawFiatOpenLedger from "components/DepositWithdraw/openledger/WithdrawFiatOpenLedger";

class DepositWithdrawContent extends React.Component {
class DepositWithdrawContent extends DecimalChecker {

static propTypes = {
sender: ChainTypes.ChainAccount.isRequired,
Expand Down Expand Up @@ -315,6 +316,7 @@ class DepositWithdrawContent extends React.Component {
}

_renderWithdraw() {
const {amountError} = this.state;
const {name: assetName} = utils.replaceName(this.props.asset.get("symbol"), !!this.props.asset.get("bitasset"));
let tabIndex = 1;
const {supportsMemos} = this.props;
Expand Down Expand Up @@ -346,20 +348,28 @@ class DepositWithdrawContent extends React.Component {
<div className="SimpleTrade__withdraw-row">
<label className="left-label">{counterpart.translate("modal.withdraw.amount")}</label>
<div className="inline-label input-wrapper">
<input tabIndex={tabIndex++} type="text" value={this.state.withdrawValue} onChange={this._onInputAmount.bind(this)} />
<input
tabIndex={tabIndex++}
type="number"
min="0"
onKeyPress={this.onKeyPress.bind(this)}
value={this.state.withdrawValue}
onChange={this._onInputAmount.bind(this)}
/>
<div className="form-label select floating-dropdown">
<div className="dropdown-wrapper inactive">
<div>{assetName}</div>
</div>
</div>
</div>
{amountError ? <p className="has-error no-margin" style={{paddingTop: 10}}><Translate content={amountError} /></p>:null}
{this.state.balanceError ? <p className="has-error no-margin" style={{paddingTop: 10}}><Translate content="transfer.errors.insufficient" /></p>:null}
</div>

<div className="SimpleTrade__withdraw-row">
<label className="left-label">{counterpart.translate("transfer.fee")}</label>
<div className="inline-label input-wrapper">
<input type="text" value={currentFee.getAmount({real: true})} />
<input type="text" disabled value={currentFee.getAmount({real: true})} />

<div className="form-label select floating-dropdown">
<div className="dropdown-wrapper inactive">
Expand Down
16 changes: 9 additions & 7 deletions app/components/Exchange/ExchangeInput.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React from "react";

class ExchangeInput extends React.Component {
constructor(){
super();
}

export class DecimalChecker extends React.Component {
onKeyPress(e){
var nextValue = e.target.value + e.key;
var decimal = nextValue.match(/\./g);
var decimalCount = decimal ? decimal.length : 0;
if(e.key === '.' && decimalCount > 1) e.preventDefault();
if(e.key === "." && decimalCount > 1) e.preventDefault();

if(this.props.onKeyPress) this.props.onKeyPress(e);
}
}

class ExchangeInput extends DecimalChecker {
constructor(){
super();
}

render(){
return <input type="number" {...this.props} onKeyPress={this.onKeyPress.bind(this)} />
return <input type="number" {...this.props} onKeyPress={this.onKeyPress.bind(this)} />;
}
}

Expand Down
3 changes: 1 addition & 2 deletions app/lib/common/MarketClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class Asset {
if (typeof sats !== "number" && typeof real !== "number") {
throw new Error("Invalid arguments for setAmount");
}
if (real && typeof real !== "undefined") {
if (typeof real !== "number" || isNaN(real)) throw new Error("Invalid argument 'real' for setAmount");
if (typeof real === "number") {
this.amount = this.toSats(real);
this._clearCache();
} else if(typeof sats === "number") {
Expand Down

0 comments on commit c7b6e43

Please sign in to comment.