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

Commit

Permalink
Merge pull request #2417 from darkdarkdragon/develop-fix-trade-input
Browse files Browse the repository at this point in the history
[FIX] Advanced trade: fix values calculations
  • Loading branch information
mrajvanshy committed Apr 29, 2015
2 parents 6d0d549 + a49edc3 commit 67fe91a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/js/tabs/trade.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,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 @@ -434,6 +435,7 @@ TradeTab.prototype.angular = function(module)
}
},5);
}

/**
* Happens when user clicks on 'Place Order' button.
*
Expand Down Expand Up @@ -858,7 +860,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 @@ -878,7 +880,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});
}
};

Expand All @@ -896,15 +898,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});
}
};

Expand Down

0 comments on commit 67fe91a

Please sign in to comment.