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

[FIX] fix parsing incoming trust lines #2154

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/js/entry/web.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var types = require('../util/types');
var types = require('../util/types'),
rewriter = require('../util/jsonrewriter');

// Load app modules
require('../controllers/app');
Expand Down Expand Up @@ -136,6 +137,8 @@ var app = angular
var rippleclient = window.rippleclient = {};
rippleclient.app = app;
rippleclient.types = types;
// for unit tests
rippleclient.rewriter = rewriter;

// Install basic page template
angular.element('body').prepend(require('../../jade/client/index.jade')());
Expand Down
5 changes: 4 additions & 1 deletion src/js/tabs/trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ TrustTab.prototype.angular = function (module)
}

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

// correctly show "Rippling" flag for incoming trust lines
if (_.has(line, 'no_ripple_peer')) {
line.no_ripple = line.no_ripple_peer;
}
});

$scope.accountLines = obj;
Expand Down
17 changes: 7 additions & 10 deletions src/js/util/jsonrewriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,20 +397,17 @@ var JsonRewriter = module.exports = {

var high = node.fields.HighLimit;
var low = node.fields.LowLimit;
var viewHigh = high.issuer === account;

var which = high.issuer === account ? 'HighNoRipple' : 'LowNoRipple';
var which = obj.transaction.type === 'trusting' ? (viewHigh ? 'HighNoRipple' : 'LowNoRipple') :
(viewHigh ? 'LowNoRipple' : 'HighNoRipple');

// New trust line
if (node.diffType === 'CreatedNode') {
effect.limit = ripple.Amount.from_json(high.value > 0 ? high : low);
effect.limit_peer = ripple.Amount.from_json(high.value > 0 ? low : high);

if ((high.value > 0 && high.issuer === account)
|| (low.value > 0 && low.issuer === account)) {
effect.type = 'trust_create_local';
} else {
effect.type = 'trust_create_remote';
}
effect.limit = ripple.Amount.from_json(viewHigh ? high : low);
effect.limit_peer = ripple.Amount.from_json(viewHigh ? low : high);

effect.type = obj.transaction.type === 'trusting' ? 'trust_create_local' : 'trust_create_remote';
}

// Modified trust line
Expand Down
25 changes: 25 additions & 0 deletions test/unit/utilities/jsonRewriterSpec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.