@@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router';
3
3
4
4
import { TranslateService } from '@ngx-translate/core' ;
5
5
6
- import { Transaction } from '../../models/transaction' ;
6
+ import { Transaction , TransactionValue } from '../../models/transaction' ;
7
7
8
8
import { ErrorService } from '../../services/error.service' ;
9
9
import { NavigatorService } from '../../services/navigator.service' ;
@@ -17,6 +17,8 @@ import { TransactionsService } from '../../services/transactions.service';
17
17
export class TransactionDetailsComponent implements OnInit {
18
18
19
19
transaction : Transaction ;
20
+ collapsedInput : TransactionValue [ ] ;
21
+ collapsedOutput : TransactionValue [ ] ;
20
22
21
23
constructor (
22
24
private route : ActivatedRoute ,
@@ -38,12 +40,39 @@ export class TransactionDetailsComponent implements OnInit {
38
40
39
41
private onTransactionRetrieved ( response : Transaction ) {
40
42
this . transaction = response ;
43
+ this . collapsedInput = this . collapseRepeatedRows ( this . transaction . input ) ;
44
+ this . collapsedOutput = this . collapseRepeatedRows ( this . transaction . output ) ;
41
45
}
42
46
43
47
private onError ( response : any ) {
44
48
this . errorService . renderServerErrors ( null , response ) ;
45
49
}
46
50
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
+
47
76
getFee ( tx : Transaction ) : number {
48
77
const vout = tx . output . map ( t => t . value ) . reduce ( ( a , b ) => a + b , 0 ) ;
49
78
return Math . max ( 0 , this . getVIN ( tx ) - vout ) ;
0 commit comments