From e814bc0f5bc9bef483c7f9453f097382be262801 Mon Sep 17 00:00:00 2001 From: Vahe Hovhannisyan Date: Wed, 11 Mar 2015 18:27:36 -0700 Subject: [PATCH] [TASK] Trust: Don't show insignificant trustlines Logged in user doesn't care about the lines where he/she's in a default state, limits are zero but the counterparty is not in a default state (has a non default flag) --- src/js/controllers/app.js | 42 ++++++++++++++++++++++++++------------- src/js/tabs/trust.js | 11 +--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/js/controllers/app.js b/src/js/controllers/app.js index e81f591ae..398988240 100644 --- a/src/js/controllers/app.js +++ b/src/js/controllers/app.js @@ -164,16 +164,18 @@ function AppCtrl ($scope, id, net, keychain, txQueue, appManager, rpTracker, for (var n = 0, l = data.lines.length; n < l; n++) { var line = data.lines[n]; - // XXX: This reinterpretation of the server response should be in the - // library upstream. - line = $.extend({}, line, { - limit: ripple.Amount.from_json({value: line.limit, currency: line.currency, issuer: line.account}), - limit_peer: ripple.Amount.from_json({value: line.limit_peer, currency: line.currency, issuer: account}), - balance: ripple.Amount.from_json({value: line.balance, currency: line.currency, issuer: account}) - }); + if (isSignificantLine(line)) { + // XXX: This reinterpretation of the server response should be in the + // library upstream. + line = $.extend({}, line, { + limit: ripple.Amount.from_json({value: line.limit, currency: line.currency, issuer: line.account}), + limit_peer: ripple.Amount.from_json({value: line.limit_peer, currency: line.currency, issuer: account}), + balance: ripple.Amount.from_json({value: line.balance, currency: line.currency, issuer: account}) + }); - $scope.lines[line.account + line.currency] = line; - updateRippleBalance(line.currency, line.account, line.balance); + $scope.lines[line.account + line.currency] = line; + updateRippleBalance(line.currency, line.account, line.balance); + } } console.log('lines updated:', $scope.lines); if (data.lines.length > 200) { @@ -427,6 +429,15 @@ function AppCtrl ($scope, id, net, keychain, txQueue, appManager, rpTracker, } } + // Current user doesn't care about a line where he/she's in a default state, + // limits are zero but the counterparty is not in a default state (has a non default flag) + function isSignificantLine(line) { + var DefaultRipple = $scope.account.Flags & ripple.Remote.flags.account_root.DefaultRipple; + + return line.balance != 0 || line.limit != 0 || line.limit_peer != 0 + || DefaultRipple === line.no_ripple; + } + function updateLines(effects) { if (!$.isArray(effects)) return; @@ -459,11 +470,6 @@ function AppCtrl ($scope, id, net, keychain, txQueue, appManager, rpTracker, balancesUpdated = true; } - if (effect.deleted) { - delete $scope.lines[index]; - return; - } - if (effect.limit) { line.limit = effect.limit; } @@ -472,6 +478,14 @@ function AppCtrl ($scope, id, net, keychain, txQueue, appManager, rpTracker, line.limit_peer = effect.limit_peer; } + if (effect.deleted || !isSignificantLine({ + balance: line.balance.to_number(), + limit: line.limit.to_number(), + limit_peer: line.limit_peer.to_number(), + no_ripple: line.no_ripple})) { + return delete $scope.lines[index]; + } + $scope.lines[index] = $.extend($scope.lines[index], line); } }); diff --git a/src/js/tabs/trust.js b/src/js/tabs/trust.js index ba7578f0a..7ee61dc50 100644 --- a/src/js/tabs/trust.js +++ b/src/js/tabs/trust.js @@ -332,11 +332,9 @@ TrustTab.prototype.angular = function (module) } obj[line.currency].components.push(line); - }); $scope.accountLines = obj; - return; }; $scope.$on('$balancesUpdate', function(){ @@ -408,26 +406,21 @@ TrustTab.prototype.angular = function (module) $scope.load_notification('remove_gateway'); var setSecretAndSubmit = function(tx) { - tx .on('proposed', function(res){ $scope.$apply(function () { - setEngineStatus(res, false); + setEngineStatus(res, false); }); }) .on('success', function(res){ $scope.$apply(function () { setEngineStatus(res, true); - - $scope.trust.loading = false; - $scope.editing = false; }); }) .on('error', function(res){ console.log('error', res); setImmediate(function () { $scope.$apply(function () { - if (res.result === 'tejMaxFeeExceeded') { $scope.load_notification('max_fee'); } @@ -440,7 +433,6 @@ TrustTab.prototype.angular = function (module) }); }); - keychain.requestSecret(id.account, id.username, function (err, secret) { if (err) { $scope.mode = 'error'; @@ -449,7 +441,6 @@ TrustTab.prototype.angular = function (module) console.log('Error on requestSecret: ', err); $scope.reset(); - return; }