From c7b6e4373212fdc7bc17d2cbfe94103aa089c372 Mon Sep 17 00:00:00 2001 From: Sigve Kvalsvik Date: Wed, 11 Oct 2017 13:26:51 +0200 Subject: [PATCH] Fix #529: Withrawal modal inputs --- .../Dashboard/SimpleDepositWithdraw.jsx | 16 +++++++++++++--- app/components/Exchange/ExchangeInput.jsx | 16 +++++++++------- app/lib/common/MarketClasses.js | 3 +-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/components/Dashboard/SimpleDepositWithdraw.jsx b/app/components/Dashboard/SimpleDepositWithdraw.jsx index a9d0838393..aad36e5da8 100644 --- a/app/components/Dashboard/SimpleDepositWithdraw.jsx +++ b/app/components/Dashboard/SimpleDepositWithdraw.jsx @@ -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, @@ -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; @@ -346,20 +348,28 @@ class DepositWithdrawContent extends React.Component {
- +
{assetName}
+ {amountError ?

:null} {this.state.balanceError ?

:null}
- +
diff --git a/app/components/Exchange/ExchangeInput.jsx b/app/components/Exchange/ExchangeInput.jsx index 3e75c708b4..49834cc7ff 100644 --- a/app/components/Exchange/ExchangeInput.jsx +++ b/app/components/Exchange/ExchangeInput.jsx @@ -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 + return ; } } diff --git a/app/lib/common/MarketClasses.js b/app/lib/common/MarketClasses.js index 2fd2ddc6aa..7043e0016c 100644 --- a/app/lib/common/MarketClasses.js +++ b/app/lib/common/MarketClasses.js @@ -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") {