From eb1d85eb74b5597207f5bf1e1d5774f7b79f80e0 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sun, 11 Mar 2018 14:34:55 -0600 Subject: [PATCH] web-ui: Display transaction details --- web-ui/src/app/app.component.ts | 7 ++- .../transaction-details.component.html | 52 +++++++++++++++++- .../transaction-details.component.ts | 55 ++++++++++++++++++- 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/web-ui/src/app/app.component.ts b/web-ui/src/app/app.component.ts index 06bc892..1c05f71 100644 --- a/web-ui/src/app/app.component.ts +++ b/web-ui/src/app/app.component.ts @@ -40,7 +40,12 @@ export class AppComponent { 'action.find': 'Find', // labels - 'label.transactionId': 'Transaction Id' + 'label.transactionId': 'Transaction Id', + 'label.confirmations': 'Confirmations', + 'label.blockhash': 'Block Hash', + 'label.blocktime': 'Block Time', + 'label.inputAddresses': 'Senders', + 'label.outputAddresses': 'Receivers' }; } } 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 eebae24..5adaff5 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 @@ -1,3 +1,49 @@ -

- transaction-details works! -

+
+
+ {{'message.transactionNotFound' | translate}} +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+
+ +
+
+
+ + +
+
+
+ + +
+
+ +
+
+
+ + +
+
+
+
+
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 fa1cc45..26b8588 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 @@ -1,4 +1,11 @@ import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { TranslateService } from '@ngx-translate/core'; + +import { ErrorService } from '../../services/error.service'; +import { NavigatorService } from '../../services/navigator.service'; +import { TransactionsService } from '../../services/transactions.service'; @Component({ selector: 'app-transaction-details', @@ -7,9 +14,55 @@ import { Component, OnInit } from '@angular/core'; }) export class TransactionDetailsComponent implements OnInit { - constructor() { } + transaction: object; + + constructor( + private route: ActivatedRoute, + private router: Router, + private navigatorService: NavigatorService, + private transactionsService: TransactionsService, + private errorService: ErrorService) { } ngOnInit() { + const txid = this.route.snapshot.paramMap.get('txid'); + this.transactionsService.get(txid).subscribe( + response => this.onTransactionRetrieved(response), + response => this.onError(response) + ); + } + + private onTransactionRetrieved(response: any) { + console.log(response); + this.transaction = response; + } + + private onError(response: any) { + this.errorService.renderServerErrors(null, response); + } + + inputAddresses(transaction): string[] { + // TODO: complete + // transaction.vin.keys + return []; + } + + // TODO: verify correctness + outputAddresses(transaction): string[] { + const keys: number[] = Array.from(transaction.vout.keys()); + const nestedAddresses = keys.map(k => transaction.vout[k].scriptPubKey.addresses); + return this.flatten(nestedAddresses); } + // TODO: move function to another package + private flatten = function (arr, result = []) { + for (let i = 0, length = arr.length; i < length; i++) { + const value = arr[i]; + if (Array.isArray(value)) { + this.flatten(value, result); + } else { + result.push(value); + } + } + return result; + }; }