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

Commit

Permalink
[FIX] Trade: fix trade pairs order edit (RT-3343)
Browse files Browse the repository at this point in the history
Fix editing trade pairs order.
Clean trade pairs list - remove $$hashKey, remove duplicates.
Check trade pair before adding.
  • Loading branch information
darkdarkdragon committed Apr 16, 2015
1 parent 1b7888b commit ad9cdbd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
21 changes: 21 additions & 0 deletions src/js/services/id.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,27 @@ module.factory('rpId', ['$rootScope', '$location', '$route', '$routeParams', '$t
$scope.userBlob.unset('/trade_currency_pairs');
}

var tradeCurrencyPairs = settings.getSetting($scope.userBlob, 'trade_currency_pairs', []);
if (_.isArray(tradeCurrencyPairs) && tradeCurrencyPairs.length > 0) {
var changed = false;
if (_.find(tradeCurrencyPairs, _.partial(_.has, _, '$$hashKey'))) {
// clear $$hashKey
tradeCurrencyPairs = angular.fromJson(angular.toJson(tradeCurrencyPairs));
changed = true;
}
var tradeCurrencyPairsUniq = _.uniq(tradeCurrencyPairs, false, function(o) {
return o.name;
});
if (tradeCurrencyPairsUniq.length !== tradeCurrencyPairs.length) {
tradeCurrencyPairs = tradeCurrencyPairsUniq;
changed = true;
}

if (changed) {
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs', tradeCurrencyPairs);
}
}

if (_.has(d, 'txQueue')) {
$scope.userBlob.set('/clients/rippletradecom/txQueue', d.txQueue);
$scope.userBlob.unset('/txQueue');
Expand Down
31 changes: 6 additions & 25 deletions src/js/tabs/settingstrade.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var util = require('util'),
settings = require('../util/settings'),
Tab = require('../client/tab').Tab;

var SettingsTradeTab = function ()
{
var SettingsTradeTab = function() {
Tab.call(this);
};

Expand All @@ -24,9 +23,6 @@ SettingsTradeTab.prototype.angular = function(module) {
SettingsTradeCtrl.$inject = ['$scope', '$timeout'];

function SettingsTradeCtrl($scope, $timeout) {
var dirty = false,
saveTimeout;

if ($scope.userBlob.data && $scope.userCredentials.username) {
$scope.pairs = settings.getSetting($scope.userBlob, 'trade_currency_pairs');
} else {
Expand All @@ -40,8 +36,7 @@ SettingsTradeTab.prototype.angular = function(module) {

$scope.deletePair = function(index){
for (var i = 0; i < $scope.pairs.length; i++) {
if ($scope.pairs[i].$$hashKey === this.entry.$$hashKey) {
saveTradePairs();
if ($scope.pairs[i].name === this.entry.name) {
$scope.userBlob.unset('/clients/rippletradecom/trade_currency_pairs/' + index);
return;
}
Expand All @@ -50,26 +45,12 @@ SettingsTradeTab.prototype.angular = function(module) {

$scope.dragControlListeners = {
orderChanged: function(event) {
dirty = true;
if (saveTimeout) {
$timeout.cancel(saveTimeout);
}
saveTimeout = $timeout(saveTradePairs, 2000);
var sourceObj = _.clone($scope.pairs[event.source.index]);
var destObj = _.clone($scope.pairs[event.dest.index]);
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs/' + event.source.index, sourceObj);
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs/' + event.dest.index, destObj);
}
};

$scope.$on('$destroy', saveTradePairs);

function saveTradePairs() {
if (dirty) {
$timeout.cancel(saveTimeout);
saveTimeout = null;
// clear $$hashKey
var pairs = angular.fromJson(angular.toJson($scope.pairs));
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs', pairs);
dirty = false;
}
}
}
};

Expand Down
10 changes: 7 additions & 3 deletions src/js/tabs/trade.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -927,22 +927,26 @@ TradeTab.prototype.angular = function(module)
}
});

$scope.open_custom_currency_selector = function () {
$scope.open_custom_currency_selector = function() {
$scope.first_currency_selected = '';
$scope.first_issuer_selected = '';
$scope.second_currency_selected = '';
$scope.second_issuer_selected = '';
$scope.adding_pair = true;
}

$scope.add_pair = function () {
$scope.add_pair = function() {
var formattedIssuerFirst = $scope.first_currency_selected === 'XRP' ? '' : '.' + $scope.first_issuer_selected;
var formattedIssuerSecond = $scope.second_currency_selected === 'XRP' ? '' : '.' + $scope.second_issuer_selected;
if (($scope.second_currency_selected !== 'XRP' && ($scope.second_issuer_selected == null || $scope.second_issuer_selected === '')) ||
($scope.first_currency_selected !== 'XRP' && ($scope.first_issuer_selected == null || $scope.first_issuer_selected === ''))) {
// this could happen if gate is not validated
return;
}

$scope.order.currency_pair = $scope.first_currency_selected + formattedIssuerFirst + '/' + $scope.second_currency_selected + formattedIssuerSecond;

$scope.userBlob.unshift('/clients/rippletradecom/trade_currency_pairs', { name: $scope.order.currency_pair });
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs', $scope.pairs_query);

$scope.adding_pair = false;
};
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/settingstrade.jade
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ section.col-xs-12.content(ng-controller="SettingsTradeCtrl")
| section.
div(ng-if="pairs")
div(as-sortable="dragControlListeners", ng-model="pairs")
div.pair(ng-repeat="entry in pairs", as-sortable-item)
div.pair(ng-repeat="entry in pairs track by entry.name", as-sortable-item)
.col-xs-12(as-sortable-item-handle)
i.grip
span.description(ng-bind="entry.name")
Expand Down

0 comments on commit ad9cdbd

Please sign in to comment.