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

[TASK] Trust: Filter out and hide insignificant trustlines (RT-3373) #2511

Merged
merged 1 commit into from
May 8, 2015
Merged
Show file tree
Hide file tree
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
24 changes: 14 additions & 10 deletions src/js/controllers/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function AppCtrl ($scope, id, net, keychain, txQueue, appManager, rpTracker,
}
}


function handleRippleLines(data)
{
$scope.$apply(function () {
Expand All @@ -165,7 +166,7 @@ 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];

if (isSignificantLine(line)) {
if ($scope.isSignificantLine(line)) {
// XXX: This reinterpretation of the server response should be in the
// library upstream.
line = $.extend({}, line, {
Expand Down Expand Up @@ -446,15 +447,6 @@ 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;
Expand Down Expand Up @@ -574,6 +566,18 @@ 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)
$scope.isSignificantLine = function(line) {
var DefaultRipple = $scope.account.Flags & ripple.Remote.flags.account_root.DefaultRipple;

if (typeof line.balance === 'object') {
return !line.balance.is_zero() || !line.limit.is_zero() || !line.limit_peer.is_zero()
|| $scope.acctDefaultRippleFlag === line.no_ripple;
}
return line.balance !== 0 || line.limit !== 0 || line.limit_peer !== 0
|| DefaultRipple === line.no_ripple;
}

/**
* Integrations
Expand Down
13 changes: 8 additions & 5 deletions src/js/tabs/trust.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TrustTab.prototype.angular = function (module)
// User should not even be able to try granting a trust if the reserve is insufficient
$scope.$watch('account', function() {
// Check if account has DefaultRipple flag set
$scope.acctDefaultRippleFlag = ($scope.account.Flags & ripple.Remote.flags.account_root.DefaultRipple)
$scope.acctDefaultRippleFlag = ($scope.account.Flags & ripple.Remote.flags.account_root.DefaultRipple);

$scope.can_add_trust = false;
if ($scope.account.Balance && $scope.account.reserve_to_add_trust) {
Expand Down Expand Up @@ -325,11 +325,14 @@ TrustTab.prototype.angular = function (module)
var obj = {};

_.each($scope.lines, function(line){
if (!obj[line.currency]) {
obj[line.currency] = { components: [] };
}

obj[line.currency].components.push(line);
if ($scope.isSignificantLine(line)) {
if (!obj[line.currency]) {
obj[line.currency] = { components: [] };
}

obj[line.currency].components.push(line);
}
});

$scope.accountLines = obj;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/trust.jade
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ section.col-xs-12.content(ng-controller="TrustCtrl")
| to add a new trust line.&#32;
a(href="https://ripple.com/wiki/Reserves", target="_blank") More information
.row(ng-show='connected')
.col-sm-9.trust-menu
.trust-menu
.row.row-padding-small.head(ng-hide='true')
.col-sm-5(l10n) Name / Address
.col-sm-2
Expand Down