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 #2306 from vhpoet/release
Browse files Browse the repository at this point in the history
[TASK] Trust: Don't show insignificant trustlines
  • Loading branch information
Anna Tong committed Mar 12, 2015
2 parents 0e203d6 + e814bc0 commit 25195f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
42 changes: 28 additions & 14 deletions src/js/controllers/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
});
Expand Down
11 changes: 1 addition & 10 deletions src/js/tabs/trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,9 @@ TrustTab.prototype.angular = function (module)
}

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

});

$scope.accountLines = obj;
return;
};

$scope.$on('$balancesUpdate', function(){
Expand Down Expand Up @@ -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');
}
Expand All @@ -440,7 +433,6 @@ TrustTab.prototype.angular = function (module)
});
});


keychain.requestSecret(id.account, id.username, function (err, secret) {
if (err) {
$scope.mode = 'error';
Expand All @@ -449,7 +441,6 @@ TrustTab.prototype.angular = function (module)
console.log('Error on requestSecret: ', err);

$scope.reset();

return;
}

Expand Down

0 comments on commit 25195f1

Please sign in to comment.