diff --git a/web-ui/src/app/components/transaction-details/transaction-details.component.html b/web-ui/src/app/components/transaction-details/transaction-details.component.html index b5248e7..66aedfe 100644 --- a/web-ui/src/app/components/transaction-details/transaction-details.component.html +++ b/web-ui/src/app/components/transaction-details/transaction-details.component.html @@ -43,15 +43,15 @@
-
+
- + - + @@ -61,8 +61,11 @@ - - + + @@ -77,8 +80,11 @@ - - + + diff --git a/web-ui/src/app/components/transaction-details/transaction-details.component.ts b/web-ui/src/app/components/transaction-details/transaction-details.component.ts index 0a49433..3a8890e 100644 --- a/web-ui/src/app/components/transaction-details/transaction-details.component.ts +++ b/web-ui/src/app/components/transaction-details/transaction-details.component.ts @@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { TranslateService } from '@ngx-translate/core'; -import { Transaction } from '../../models/transaction'; +import { Transaction, TransactionValue } from '../../models/transaction'; import { ErrorService } from '../../services/error.service'; import { NavigatorService } from '../../services/navigator.service'; @@ -17,6 +17,8 @@ import { TransactionsService } from '../../services/transactions.service'; export class TransactionDetailsComponent implements OnInit { transaction: Transaction; + collapsedInput: TransactionValue[]; + collapsedOutput: TransactionValue[]; constructor( private route: ActivatedRoute, @@ -38,12 +40,39 @@ export class TransactionDetailsComponent implements OnInit { private onTransactionRetrieved(response: Transaction) { this.transaction = response; + this.collapsedInput = this.collapseRepeatedRows(this.transaction.input); + this.collapsedOutput = this.collapseRepeatedRows(this.transaction.output); } private onError(response: any) { this.errorService.renderServerErrors(null, response); } + private collapseRepeatedRows(rows: TransactionValue[]): TransactionValue[] { + const addresses = new Set(rows.map(r => r.address)); + const collapsedRows = Array.from(addresses) + .map(address => { + const sum = rows + .filter(r => r.address === address) + .map(r => r.value) + .reduce((a, b) => a + b); + + const newValue = new TransactionValue(); + newValue.address = address; + newValue.value = sum; + + return newValue; + }); + + return collapsedRows; + } + + count(address: string, rows: TransactionValue[]): number { + return rows + .filter(r => r.address === address) + .length; + } + getFee(tx: Transaction): number { const vout = tx.output.map(t => t.value).reduce((a, b) => a + b, 0); return Math.max(0, this.getVIN(tx) - vout); diff --git a/web-ui/src/app/models/transaction.ts b/web-ui/src/app/models/transaction.ts index 1f7bf67..2049457 100644 --- a/web-ui/src/app/models/transaction.ts +++ b/web-ui/src/app/models/transaction.ts @@ -12,7 +12,7 @@ export class Transaction { received: number; } -class TransactionValue { +export class TransactionValue { address: string; value: number; }
{{'label.noInput' | translate}}{{'label.noInput' | translate}}
{{'label.from' | translate}}{{'label.from' | translate}}
{{'label.coinbase' | translate}}
+
+ {{item.address}} ({{count(item.address, transaction.input)}}) + {{item.address}} {{item.value}} {{'label.coinName' | translate}}{{'label.output' | translate}}
+
+ {{item.address}} ({{count(item.address, transaction.output)}}) + {{item.address}} {{item.value}} {{'label.coinName' | translate}}