Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

[FIX] Advanced trade: fix values calculations #2417

Merged
merged 1 commit into from
Apr 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/js/tabs/trade.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,15 @@ TradeTab.prototype.angular = function(module)
$scope.fill_widget = function (type, order, sum) {
$scope.reset_widget(type);

$scope.order[type].price = order.price.to_human().replace(',','');
$scope.order[type].price = order.price.to_human({group_sep: false});

if (sum) {
$scope.order[type].first = order.sum.to_human().replace(',','');
$scope.order[type].first = order.sum.to_human({group_sep: false});
$scope.calc_second(type);
}
scrollToElement('widgetGroup');
};

function scrollToElement(element) {
var el = document.getElementById(element);
var yPos = el.getClientRects()[0].top;
Expand All @@ -416,6 +417,7 @@ TradeTab.prototype.angular = function(module)
}
},5);
}

/**
* Happens when user clicks on 'Place Order' button.
*
Expand Down Expand Up @@ -814,7 +816,7 @@ TradeTab.prototype.angular = function(module)

if (type === 'buy') bestPrice = $scope.bookShow.bids[0].showPrice;
else if (type === 'sell') bestPrice = $scope.bookShow.asks[0].showPrice;
bestPrice = +bestPrice.replace(',','');
bestPrice = +bestPrice.replace(/,/g, '');

return (bestPrice &&
(price > (bestPrice * fatFingerMarginMultiplier) ||
Expand All @@ -834,7 +836,7 @@ TradeTab.prototype.angular = function(module)
if (order.price_amount && order.price_amount.is_valid() &&
order.first_amount && order.first_amount.is_valid()) {
order.second_amount = order.price_amount.product_human(order.first_amount);
order.second = +order.second_amount.to_human({group_sep: false});
order.second = order.second_amount.to_human({group_sep: false});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the + killed? It's a conversion to number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jublo That was whole point of this commit. This value goes into input field. And when it is number, chrome shows it in e-notation if it too small or too big

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Well done then.

}
};

Expand All @@ -852,15 +854,16 @@ TradeTab.prototype.angular = function(module)
order.second_amount && order.second_amount.is_valid()) {

if (!order.price_amount.is_native()) {
var price = order.price_amount.to_human();
var price = order.price_amount.to_human({group_sep: false});
var currency = order.price_amount.currency().to_json();
var issuer = order.price_amount.issuer().to_json();

order.first_amount = Amount.from_json(order.second_amount.to_text_full()).ratio_human(Amount.from_json(price + '/' + currency + '/' + issuer), {reference_date: new Date()});
// use replace(/,/g,'') until ripple lib fixed
order.first_amount = Amount.from_json(order.second_amount.to_text_full().replace(/,/g, '')).ratio_human(Amount.from_json(price + '/' + currency + '/' + issuer), {reference_date: new Date()});
} else {
order.first_amount = Amount.from_json(order.second_amount.to_text_full()).ratio_human(Amount.from_json(order.price_amount.to_text()), {reference_date: new Date()});
order.first_amount = Amount.from_json(order.second_amount.to_text_full().replace(/,/g, '')).ratio_human(Amount.from_json(order.price_amount.to_text()), {reference_date: new Date()});
}
order.first = +order.first_amount.to_human({group_sep: false});
order.first = order.first_amount.to_human({group_sep: false});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

}
};

Expand Down