From bc61644ff92199fc3ea2a4f50983ba9abcd4fd82 Mon Sep 17 00:00:00 2001 From: Phil Schalm Date: Fri, 5 Jan 2018 10:59:18 -0800 Subject: [PATCH] Add "Maximize Collateral" button to Borrow Modal. (#964) * Add "Maximize Collateral" button to Borrow Modal. - Fixes #901 * Improved "Maximize Collateral" - Move button to a more logical position - Ensured that the ratio doesn't go above the maximum of 1000 - Include the initial position in the maximized collateral --- app/components/Modal/BorrowModal.jsx | 33 +++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/app/components/Modal/BorrowModal.jsx b/app/components/Modal/BorrowModal.jsx index 478395a9a..2855a0ec3 100755 --- a/app/components/Modal/BorrowModal.jsx +++ b/app/components/Modal/BorrowModal.jsx @@ -183,6 +183,23 @@ class BorrowModalContent extends React.Component { this._setUpdatedPosition(newState); } + _maximizeCollateral() { + let currentPosition = this.props ? this._getCurrentPosition(this.props) : {}; + let initialCollateral = 0; + + if (currentPosition.collateral) { + initialCollateral = utils.get_asset_amount(currentPosition.collateral, this.props.backing_asset); + } + + // Make sure we don't go over the maximum collateral ratio of + let maximizedCollateral = Math.floor(Math.min( + this.props.backing_balance.get("balance") / utils.get_asset_precision(this.props.backing_asset) + initialCollateral - 10, + (this.state.short_amount / this._getFeedPrice()) * 1000.0 + )); + + this._onCollateralChange(new Object({ amount: maximizedCollateral.toString() })); + } + _setUpdatedPosition(newState) { this.setState({ newPosition: (parseFloat(newState.short_amount) / parseFloat(newState.collateral)) @@ -418,18 +435,22 @@ class BorrowModalContent extends React.Component { {errors.collateral_balance ?
{errors.collateral_balance}
: null} {!isPredictionMarket ? ( -
- - -
{utils.format_number(collateral_ratio, 2)}
- {errors.below_maintenance || errors.close_maintenance ?
{errors.below_maintenance}{errors.close_maintenance}
: null} -
) : null} +
+
+ + +
{utils.format_number(collateral_ratio, 2)}
+ {errors.below_maintenance || errors.close_maintenance ?
{errors.below_maintenance}{errors.close_maintenance}
: null} +
+
+ ) : null}
{e.preventDefault(); this.setState(this._initialState(this.props));}} href className="button info">
{/*
*/} +
Maximize Collateral