Skip to content

Commit

Permalink
Merge pull request #2316 from gibbsfromncis/1503-scaled-orders
Browse files Browse the repository at this point in the history
#1503 Scaled Orders
  • Loading branch information
Stefan Schießl committed Feb 26, 2019
2 parents 3109f53 + 7d1971f commit e09cb82
Show file tree
Hide file tree
Showing 11 changed files with 1,731 additions and 107 deletions.
14 changes: 11 additions & 3 deletions app/actions/MarketsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,25 @@ class MarketsActions {
};
}

createLimitOrder2(order) {
createLimitOrder2(orderOrOrders) {
var tr = WalletApi.new_transaction();

let orders = [];

// let feeAsset = ChainStore.getAsset(fee_asset_id);
// if( feeAsset.getIn(["options", "core_exchange_rate", "base", "asset_id"]) === "1.3.0" && feeAsset.getIn(["options", "core_exchange_rate", "quote", "asset_id"]) === "1.3.0" ) {
// fee_asset_id = "1.3.0";
// }

order = order.toObject();
if (Array.isArray(orderOrOrders)) {
orders = orderOrOrders.map(order => order.toObject());
} else {
orders.push(orderOrOrders.toObject());
}

tr.add_type_operation("limit_order_create", order);
orders.forEach(order => {
tr.add_type_operation("limit_order_create", order);
});

return WalletDb.process_transaction(tr, null, true)
.then(result => {
Expand Down
71 changes: 71 additions & 0 deletions app/assets/locales/locale-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,53 @@
"withdraw": "Withdraw"
}
},
"validation": {
"messages": {
"required": "The field is required",
"requiredNamed": "%(name)s is required",
"types": {
"array": "The field should be array",
"arrayNamed": "%(name)s should be array",
"regexp": "The field should be regexp",
"regexpNamed": "%(name)s should be regexp",
"date": "The field should be date",
"dateNamed": "%(name)s should be date",
"object": "The field should be object",
"objectNamed": "%(name)s should be object",
"method": "The field should be method",
"methodNamed": "%(name)s should be method",
"hex": "The field should be hex",
"hexNamed": "%(name)s should be hex",
"string": "The field should be string",
"stringNamed": "%(name)s should be string",
"boolean": "The field should be boolean",
"booleanNamed": "%(name)s should be boolean",
"enum": "The field should be one of %(list)s",
"enumNamed": "%(name)s should be one of %(list)s"
},
"range": "The field should be in range from %(min)s to %(max)s",
"rangeNamed": "%(name)s should in range from %(min)s to %(max)s",
"max": "The field should be less than %(max)s",
"maxNamed": "%(name)s should be less than %(max)s",
"min": "The field should higher than %(min)s",
"minNamed": "%(name)s should be higher than %(min)s",
"number": "The field should be number",
"numberNamed": "%(name)s should be number",
"integer": "The field should be integer",
"integerNamed": "%(name)s should be integer",
"float": "The field should be float",
"floatNamed": "%(name)s should be float",
"email": "The field should be email",
"emailNamed": "%(name)s should be email",
"url": "The field should be url",
"urlNamed": "%(name)s should be url",
"oneOf": "The field should be one of: %(list)s",
"oneOfNamed": "%(name)s should be one of: %(list)s",
"balance": "Insufficient balance. Available only: %(balance)s",

"test": ""
}
},
"news": {
"author": "Author",
"errors": {
Expand All @@ -1413,6 +1460,29 @@
"news": "News",
"subject": "Subject"
},
"scaled_orders": {
"please_log_in": "You need to login before use Scaled Orders",
"title": "Scaled Order",
"price_lower": "Price Lower",
"price_upper": "Price Upper",
"quantity": "Quantity",
"distribution": {
"title": "Distribution",
"flat": "Flat"
},
"order_count": "Order Count",
"action": {
"title": "Action",
"buy": "Buy",
"sell": "Sell"
},
"total": "Total",
"fee": "Fee",
"market_fee": "Market Fee",
"preview_table": {
"price": "Price"
}
},
"notifications": {
"account_create_failure": "Failed to create account: %(account_name)s - %(error_msg)s",
"account_permissions_update_warning": "Setting your owner permissions like this will render your account permanently unusable. Please make sure you know what you're doing before modifying account authorities!",
Expand All @@ -1422,6 +1492,7 @@
"balance_claim_error": "Error claiming balance: %(error_msg)s",
"exchange_enter_valid_values": "Please enter a valid amount and price",
"exchange_insufficient_funds_for_fees": "Insufficient funds to pay fees",
"exchange_unknown_error_place_scaled_order": "Unknown error. Failed to place Scaled Order",
"exchange_insufficient_funds_to_place_order": "Insufficient funds to place order, you need at least %(amount)s $(symbol)s",
"exchange_unknown_error_place_order": "Unknown error. Failed to place order for %(amount)s %(symbol)s",
"import_keys_already_imported": "This wallet has already been imported",
Expand Down
33 changes: 33 additions & 0 deletions app/components/Exchange/BuySell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Icon from "../Icon/Icon";
import SettleModal from "../Modal/SettleModal";
import {Button, Select, Popover, Tooltip} from "bitshares-ui-style-guide";
import ReactTooltip from "react-tooltip";
import AccountStore from "../../stores/AccountStore";

class BuySell extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -960,6 +961,8 @@ class BuySell extends React.Component {
const isGloballySettled =
isBitAsset && otherAsset.get("bitasset").get("settlement_fund") > 0;

const currentAccount = AccountStore.getState().currentAccount;

return (
<div
className={cnames(this.props.className)}
Expand Down Expand Up @@ -995,6 +998,36 @@ class BuySell extends React.Component {
]}
/>
</span>
<span style={{float: "right"}}>
{currentAccount ? (
<a
href="javascript:void(0);"
onClick={
this.props.showScaledOrderModal
}
style={{textTransform: "none"}}
>
{counterpart.translate(
"scaled_orders.title"
)}
</a>
) : (
<Tooltip
title={counterpart.translate(
"scaled_orders.please_log_in"
)}
>
<a
href="javascript:void(0);"
style={{textTransform: "none"}}
>
{counterpart.translate(
"scaled_orders.title"
)}
</a>
</Tooltip>
)}
</span>
{/* <span>{buttonText} <AssetName dataPlace="top" name={quote.get("symbol")} /></span> */}
{this.props.onFlip &&
!this.props.hideFunctionButtons ? (
Expand Down
60 changes: 60 additions & 0 deletions app/components/Exchange/Exchange.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import SimpleDepositWithdraw from "../Dashboard/SimpleDepositWithdraw";
import SimpleDepositBlocktradesBridge from "../Dashboard/SimpleDepositBlocktradesBridge";
import {Notification} from "bitshares-ui-style-guide";
import PriceAlert from "./PriceAlert";
import ScaledOrder from "./ScaledOrder";
import counterpart from "counterpart";

class Exchange extends React.Component {
Expand Down Expand Up @@ -114,7 +115,11 @@ class Exchange extends React.Component {
this.showPriceAlertModal = this.showPriceAlertModal.bind(this);
this.hidePriceAlertModal = this.hidePriceAlertModal.bind(this);

this.showScaledOrderModal = this.showScaledOrderModal.bind(this);
this.hideScaledOrderModal = this.hideScaledOrderModal.bind(this);

this.handlePriceAlertSave = this.handlePriceAlertSave.bind(this);
this._createScaledOrder = this._createScaledOrder.bind(this);

this.psInit = true;
}
Expand Down Expand Up @@ -311,6 +316,7 @@ class Exchange extends React.Component {
isConfirmBuyOrderModalLoaded: false,
isConfirmSellOrderModalVisible: false,
isPriceAlertModalVisible: false,
isScaledOrderModalVisible: false,
isConfirmSellOrderModalLoaded: false,
tabVerticalPanel: ws.get("tabVerticalPanel", "my-market"),
tabBuySell: ws.get("tabBuySell", "buy"),
Expand Down Expand Up @@ -397,6 +403,18 @@ class Exchange extends React.Component {
});
}

showScaledOrderModal() {
this.setState({
isScaledOrderModalVisible: true
});
}

hideScaledOrderModal() {
this.setState({
isScaledOrderModalVisible: false
});
}

showBorrowQuoteModal() {
this.setState({
isBorrowQuoteModalVisible: true,
Expand Down Expand Up @@ -938,6 +956,38 @@ class Exchange extends React.Component {
this._createLimitOrder(type, feeID);
}

_createScaledOrder(orders, feeID) {
const limitOrders = orders.map(
order =>
new LimitOrderCreate({
for_sale: order.for_sale,
expiration: new Date(order.expirationTime || false),
to_receive: order.to_receive,
seller: this.props.currentAccount.get("id"),
fee: {
asset_id: feeID,
amount: 0
}
})
);

return MarketsActions.createLimitOrder2(limitOrders)
.then(result => {
if (result.error) {
if (result.error.message !== "wallet locked")
Notification.error({
message: counterpart.translate(
"notifications.exchange_unknown_error_place_scaled_order"
)
});
}
console.log("order success");
})
.catch(e => {
console.log("order failed:", e);
});
}

_createLimitOrder(type, feeID) {
let actionType = type === "sell" ? "ask" : "bid";

Expand Down Expand Up @@ -1981,6 +2031,7 @@ class Exchange extends React.Component {
let buyForm = isFrozen ? null : tinyScreen &&
!this.state.mobileKey.includes("buySellTab") ? null : (
<BuySell
showScaledOrderModal={this.showScaledOrderModal}
key={`actionCard_${actionCardIndex++}`}
onBorrow={baseIsBitAsset ? this._borrowBase.bind(this) : null}
onBuy={this._onBuy.bind(this, "bid")}
Expand Down Expand Up @@ -2088,6 +2139,7 @@ class Exchange extends React.Component {
let sellForm = isFrozen ? null : tinyScreen &&
!this.state.mobileKey.includes("buySellTab") ? null : (
<BuySell
showScaledOrderModal={this.showScaledOrderModal}
key={`actionCard_${actionCardIndex++}`}
onBorrow={quoteIsBitAsset ? this._borrowQuote.bind(this) : null}
onBuy={this._onBuy.bind(this, "ask")}
Expand Down Expand Up @@ -3436,6 +3488,14 @@ class Exchange extends React.Component {
showModal={this.showPriceAlertModal}
hideModal={this.hidePriceAlertModal}
/>

<ScaledOrder
createScaledOrder={this._createScaledOrder}
visible={this.state.isScaledOrderModalVisible}
hideModal={this.hideScaledOrderModal}
quoteAsset={this.props.quoteAsset.get("id")}
baseAsset={this.props.baseAsset.get("id")}
/>
</div>
);
}
Expand Down
Loading

0 comments on commit e09cb82

Please sign in to comment.