Skip to content

Commit 7467bdc

Browse files
JonSalazarAlexITC
authored andcommitted
web-ui: collapse similar inputs while displaying a transaction (#49)
1 parent 7241bf5 commit 7467bdc

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

web-ui/src/app/components/transaction-details/transaction-details.component.html

+13-7
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343

4444
<div class="row">
4545
<!-- Input -->
46-
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
46+
<div class="col-xs-12 col-sm-12 col-md-5 col-lg-5">
4747
<table class="table table-condensed table-bordered table-striped table-hover">
4848
<thead>
4949
<tr *ngIf="transaction.input == null">
50-
<th class="col-xs-3 col-sm-3 col-md-2 col-lg-2">{{'label.noInput' | translate}}</th>
50+
<th class="col-xs-4 col-sm-4 col-md-3 col-lg-3">{{'label.noInput' | translate}}</th>
5151
<th class="col-xs-5 col-sm-5 col-md-4 col-lg-4"></th>
5252
</tr>
5353
<tr *ngIf="transaction.input != null">
54-
<th class="col-xs-3 col-sm-3 col-md-2 col-lg-2">{{'label.from' | translate}}</th>
54+
<th class="col-xs-4 col-sm-4 col-md-3 col-lg-3">{{'label.from' | translate}}</th>
5555
<th class="col-xs-5 col-sm-5 col-md-4 col-lg-4"></th>
5656
</tr>
5757
</thead>
@@ -61,8 +61,11 @@
6161
<td>{{'label.coinbase' | translate}}</td>
6262
<td></td>
6363
</tr>
64-
<tr *ngFor="let item of transaction.input">
65-
<td>
64+
<tr *ngFor="let item of collapsedInput">
65+
<td *ngIf="count(item.address, transaction.input) != 1">
66+
<a routerLink="/addresses/{{item.address}}">{{item.address}}</a> ({{count(item.address, transaction.input)}})
67+
</td>
68+
<td *ngIf="count(item.address, transaction.input) == 1">
6669
<a routerLink="/addresses/{{item.address}}">{{item.address}}</a>
6770
</td>
6871
<td>{{item.value}} {{'label.coinName' | translate}}</td>
@@ -77,8 +80,11 @@
7780
<td><strong>{{'label.output' | translate}}</strong></td>
7881
<td></td>
7982
</tr>
80-
<tr *ngFor="let item of transaction.output">
81-
<td>
83+
<tr *ngFor="let item of collapsedOutput">
84+
<td *ngIf="count(item.address, transaction.output) != 1">
85+
<a routerLink="/addresses/{{item.address}}">{{item.address}}</a> ({{count(item.address, transaction.output)}})
86+
</td>
87+
<td *ngIf="count(item.address, transaction.output) == 1">
8288
<a routerLink="/addresses/{{item.address}}">{{item.address}}</a>
8389
</td>
8490
<td>{{item.value}} {{'label.coinName' | translate}}</td>

web-ui/src/app/components/transaction-details/transaction-details.component.ts

+30-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router';
33

44
import { TranslateService } from '@ngx-translate/core';
55

6-
import { Transaction } from '../../models/transaction';
6+
import { Transaction, TransactionValue } from '../../models/transaction';
77

88
import { ErrorService } from '../../services/error.service';
99
import { NavigatorService } from '../../services/navigator.service';
@@ -17,6 +17,8 @@ import { TransactionsService } from '../../services/transactions.service';
1717
export class TransactionDetailsComponent implements OnInit {
1818

1919
transaction: Transaction;
20+
collapsedInput: TransactionValue[];
21+
collapsedOutput: TransactionValue[];
2022

2123
constructor(
2224
private route: ActivatedRoute,
@@ -38,12 +40,39 @@ export class TransactionDetailsComponent implements OnInit {
3840

3941
private onTransactionRetrieved(response: Transaction) {
4042
this.transaction = response;
43+
this.collapsedInput = this.collapseRepeatedRows(this.transaction.input);
44+
this.collapsedOutput = this.collapseRepeatedRows(this.transaction.output);
4145
}
4246

4347
private onError(response: any) {
4448
this.errorService.renderServerErrors(null, response);
4549
}
4650

51+
private collapseRepeatedRows(rows: TransactionValue[]): TransactionValue[] {
52+
const addresses = new Set(rows.map(r => r.address));
53+
const collapsedRows = Array.from(addresses)
54+
.map(address => {
55+
const sum = rows
56+
.filter(r => r.address === address)
57+
.map(r => r.value)
58+
.reduce((a, b) => a + b);
59+
60+
const newValue = new TransactionValue();
61+
newValue.address = address;
62+
newValue.value = sum;
63+
64+
return newValue;
65+
});
66+
67+
return collapsedRows;
68+
}
69+
70+
count(address: string, rows: TransactionValue[]): number {
71+
return rows
72+
.filter(r => r.address === address)
73+
.length;
74+
}
75+
4776
getFee(tx: Transaction): number {
4877
const vout = tx.output.map(t => t.value).reduce((a, b) => a + b, 0);
4978
return Math.max(0, this.getVIN(tx) - vout);

web-ui/src/app/models/transaction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Transaction {
1212
received: number;
1313
}
1414

15-
class TransactionValue {
15+
export class TransactionValue {
1616
address: string;
1717
value: number;
1818
}

0 commit comments

Comments
 (0)