From d6800ba2c13432115b313088a4cb60b627802a17 Mon Sep 17 00:00:00 2001 From: svk31 Date: Thu, 3 Mar 2016 23:21:00 +0100 Subject: [PATCH] Fix #758, sort My Open Orders by price --- web/app/assets/locales/locale-en.js | 6 ++-- web/app/components/Exchange/Exchange.jsx | 34 ++++++++++++++------ web/app/components/Exchange/MyOpenOrders.jsx | 8 +++-- web/app/components/Exchange/OrderBook.jsx | 34 ++++++++++++++++---- 4 files changed, 61 insertions(+), 21 deletions(-) diff --git a/web/app/assets/locales/locale-en.js b/web/app/assets/locales/locale-en.js index e1a76acec..2ca93ee4f 100644 --- a/web/app/assets/locales/locale-en.js +++ b/web/app/assets/locales/locale-en.js @@ -646,8 +646,8 @@ market: "Market", price_history: "Price Chart", order_depth: "Market Depth", - history: "All History", - my_history: "My History", + history: "Market trades", + my_history: "My trades", balance: "Balance", lowest_ask: "Lowest ask", highest_bid: "Highest bid", @@ -690,7 +690,7 @@ index: "Index", my_bids: "My bids", my_asks: "My asks", - my_orders: "My orders", + my_orders: "My open orders", settle_orders: "Settle orders", asks: "Sell orders", bids: "Buy orders", diff --git a/web/app/components/Exchange/Exchange.jsx b/web/app/components/Exchange/Exchange.jsx index 0a721ad1c..a1e424c7c 100644 --- a/web/app/components/Exchange/Exchange.jsx +++ b/web/app/components/Exchange/Exchange.jsx @@ -658,9 +658,11 @@ class Exchange extends React.Component { return ((satAmount / price.quote.amount) * price.base.amount) / totalPrecision; } - getBuyAmount(price, total = 0) { + getBuyAmount(price, total = 0, satAmount) { let amountPrecision = utils.get_asset_precision(this.props.quoteAsset.get("precision")); - let satAmount = utils.get_satoshi_amount(total, this.props.baseAsset); + if (!satAmount) { + satAmount = utils.get_satoshi_amount(total, this.props.baseAsset); + } return ((satAmount / price.quote.amount) * price.base.amount) / amountPrecision; } @@ -739,27 +741,41 @@ class Exchange extends React.Component { if (type === "bid") { let displaySellPrice = this._getDisplayPrice("ask", order.sell_price); - let sellAmount = this.getSellAmount(order.sell_price, null, order.for_sale); + let sellAmount = market_utils.limitByPrecision(this.getSellAmount(order.sell_price, null, order.totalForSale), quote); this.setState({ displaySellPrice: displaySellPrice, sellPrice: order.sell_price, - sellAmount: value, - sellTotal: utils.get_asset_amount(order.for_sale, base) + sellAmount: sellAmount, + sellTotal: utils.get_asset_amount(order.totalForSale, base), + displayBuyPrice: displaySellPrice, + buyPrice: { + quote: order.sell_price.base, + base: order.sell_price.quote + }, + buyAmount: null, + buyTotal: null }); } else if (type === "ask") { let displayBuyPrice = this._getDisplayPrice("bid", order.sell_price); - // Calculate total - let total = this.getBuyTotal(order.sell_price, null, order.for_sale); + // let total = this.getBuyTotal(order.sell_price, null, order.totalForSale); + let buyAmount = market_utils.limitByPrecision(this.getBuyAmount(order.sell_price, null, order.totalValue), quote); this.setState({ displayBuyPrice: displayBuyPrice, buyPrice: order.sell_price, - buyAmount: utils.get_asset_amount(order.for_sale, quote), - buyTotal: market_utils.limitByPrecision(total, base) + buyAmount: buyAmount, + buyTotal: utils.get_asset_amount(order.totalValue, base), + displaySellPrice: displayBuyPrice, + sellPrice: { + quote: order.sell_price.base, + base: order.sell_price.quote + }, + sellAmount: null, + sellTotal: null }); } } diff --git a/web/app/components/Exchange/MyOpenOrders.jsx b/web/app/components/Exchange/MyOpenOrders.jsx index f92bbb975..1174eb6fb 100644 --- a/web/app/components/Exchange/MyOpenOrders.jsx +++ b/web/app/components/Exchange/MyOpenOrders.jsx @@ -126,7 +126,8 @@ class MyOpenOrders extends React.Component { return b_price.full - a_price.full; }).map((order, index) => { - return ; + let {price} = market_utils.parseOrder(order, base, quote); + return ; }).toArray(); asks = orders.filter(a => { @@ -137,7 +138,8 @@ class MyOpenOrders extends React.Component { return a_price.full - b_price.full; }).map(order => { - return ; + let {price} = market_utils.parseOrder(order, base, quote); + return ; }).toArray(); } else { @@ -169,7 +171,7 @@ class MyOpenOrders extends React.Component { } rows.sort((a, b) => { - return b.props.date - a.props.date; + return a.props.price - b.props.price; }) // if (bids.length === 0 && asks.length ===0) { diff --git a/web/app/components/Exchange/OrderBook.jsx b/web/app/components/Exchange/OrderBook.jsx index 3facf649f..603498f0d 100644 --- a/web/app/components/Exchange/OrderBook.jsx +++ b/web/app/components/Exchange/OrderBook.jsx @@ -51,14 +51,29 @@ class OrderBookRowHorizontal extends React.Component { let {order, quote, base, type} = this.props; let integerClass = type === "bid" ? "orderHistoryBid" : type === "ask" ? "orderHistoryAsk" : "orderHistoryCall" ; + return ( - {utils.format_number(order.amount, quote.get("precision"))} - {utils.format_number(order.value, base.get("precision"))} - {utils.format_number(order.totalValue, base.get("precision"))} + {type === "bid" ? + utils.format_number(order.amount, quote.get("precision")) : + utils.format_asset(order.for_sale, quote, true) + } + + {type === "bid" ? + utils.format_asset(order.for_sale, base, true) : + utils.format_number(order.value, base.get("precision")) + } + + {type === "bid" ? + utils.format_asset(order.totalForSale, base, true) : + utils.format_asset(order.totalValue, base, true) + + } + + ) @@ -226,7 +241,7 @@ class OrderBook extends React.Component { let totalBidValue = 0; let totalAskAmount = 0; - let totalAsks = 0, totalBids = 0; + let totalAsks = 0, totalBids = 0, totalBidForSale = 0; if(base && quote) { let totalBidAmount = 0; @@ -250,8 +265,11 @@ class OrderBook extends React.Component { totalBidAmount = market_utils.limitByPrecision(totalBidAmount + order.amount, base); totalBidValue += order.value; + totalBidForSale += order.for_sale; + order.totalValue = totalBidValue; order.totalAmount = totalBidAmount; + order.totalForSale = totalBidForSale; return (horizontal ? a.price_full ? a.price_full : total; }, null) : 0; - let totalAskValue = 0; + let totalAskValue = 0, totalAskForSale = 0; askRows = combinedAsks.sort((a, b) => { return a.price_full - b.price_full; @@ -299,9 +317,13 @@ class OrderBook extends React.Component { }).map((order, index) => { totalAskAmount = market_utils.limitByPrecision(totalAskAmount + order.amount, base); // totalAskAmount += order.amount; - totalAskValue += order.value; + totalAskValue += (order.sell_price.quote.amount * order.for_sale / order.sell_price.base.amount); + totalAskForSale += order.for_sale; + // console.log("order:", order); + // console.log(order.sell_price.quote.amount * order.for_sale / order.sell_price.base.amount); order.totalValue = totalAskValue; order.totalAmount = totalAskAmount; + order.totalForSale = totalAskForSale; return (horizontal ?