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 #2533 from darkdarkdragon/develop-RT-3343-2
Browse files Browse the repository at this point in the history
[FIX] Fix trade pairs edit (RT-3343)
  • Loading branch information
yongsoo committed Jun 2, 2015
2 parents deec00f + d2406e5 commit 740f942
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"spin.js": "~2.0.1",
"snapjs": "~1.9.3",
"angular-bootstrap": "~0.12.1",
"ng-sortable": "~1.1.9",
"ng-sortable": "~1.2.2",
"d3": "~3.5.3"
},
"resolutions": {
Expand Down
36 changes: 20 additions & 16 deletions src/js/services/id.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,27 @@ module.factory('rpId', ['$rootScope', '$location', '$route', '$routeParams', '$t

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;
// clean tradeCurrencyPairs one by one
// we can't set whole array, because it can be too big and don't
// fit into blob 1k patch size limit
_.find(tradeCurrencyPairs, function(v, i) {
if (!v || !v.name) {
$scope.userBlob.unset('/clients/rippletradecom/trade_currency_pairs/' + i);
return true;
}
if (_.has(v, '$$hashKey')) {
// clear $$hashKey
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs/' + i, angular.fromJson(angular.toJson(v)));
return true;
}
var count = _.reduce(tradeCurrencyPairs, function(c, b) {
return c + (v.name === b.name ? 1 : 0);
}, 0);
if (count > 1) {
$scope.userBlob.unset('/clients/rippletradecom/trade_currency_pairs/' + i);
return true;
}
});
if (tradeCurrencyPairsUniq.length !== tradeCurrencyPairs.length) {
tradeCurrencyPairs = tradeCurrencyPairsUniq;
changed = true;
}

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

if (_.has(d, 'txQueue')) {
Expand Down
21 changes: 13 additions & 8 deletions src/js/tabs/settingstrade.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,37 @@ SettingsTradeTab.prototype.angular = function(module) {

function SettingsTradeCtrl($scope, $timeout) {
if ($scope.userBlob.data && $scope.userCredentials.username) {
$scope.pairs = settings.getSetting($scope.userBlob, 'trade_currency_pairs');
$scope.pairs = _.clone(settings.getSetting($scope.userBlob, 'trade_currency_pairs'));
} else {
var removeWatcher = $scope.$on('$blobUpdate', function() {
if (!$scope.userCredentials.username)
return;
$scope.pairs = settings.getSetting($scope.userBlob, 'trade_currency_pairs');
$scope.pairs = _.clone(settings.getSetting($scope.userBlob, 'trade_currency_pairs'));
removeWatcher();
});
}

$scope.deletePair = function(index){
for (var i = 0; i < $scope.pairs.length; i++) {
if ($scope.pairs[i].name === this.entry.name) {
$scope.pairs.splice(i, 1);
$scope.userBlob.unset('/clients/rippletradecom/trade_currency_pairs/' + index);
return;
}
}
}

$scope.dragControlListeners = {
orderChanged: function(event) {
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);
}
orderChanged: function(event) {
var direction = event.dest.index < event.source.index ? 1 : -1;
var p = event.dest.index;
var end = event.source.index + direction;
do {
var obj = $scope.pairs[p];
$scope.userBlob.set('/clients/rippletradecom/trade_currency_pairs/' + p, obj);
p += direction;
} while (p != end);
}
};
}
};
Expand Down

0 comments on commit 740f942

Please sign in to comment.