From 1e5cef4a620ad4f4644de7f02de16caf468d651d Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 16 Sep 2022 20:50:12 +0000 Subject: [PATCH] Add sankey diagram to main tx page --- .../transaction/transaction.component.html | 48 +++++++++++++++++++ .../transaction/transaction.component.scss | 18 +++++++ .../transaction/transaction.component.ts | 35 +++++++++++++- 3 files changed, 99 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/components/transaction/transaction.component.html b/frontend/src/app/components/transaction/transaction.component.html index 0ff82899f..9fceec58e 100644 --- a/frontend/src/app/components/transaction/transaction.component.html +++ b/frontend/src/app/components/transaction/transaction.component.html @@ -190,6 +190,24 @@
+
+

Diagram

+
+ +
+
+ +
+
+ + + + +
+
+ +
+

Inputs & Outputs

@@ -283,6 +301,36 @@
+
+

Diagram

+
+ +
+ +
+
+ + + + + + +
+
+
+ + + + + + +
+
+
+
+ +
+

Inputs & Outputs

diff --git a/frontend/src/app/components/transaction/transaction.component.scss b/frontend/src/app/components/transaction/transaction.component.scss index 4628c35f9..ec514369f 100644 --- a/frontend/src/app/components/transaction/transaction.component.scss +++ b/frontend/src/app/components/transaction/transaction.component.scss @@ -73,6 +73,24 @@ } } +.graph-container { + position: relative; + width: 100%; + background: #181b2d; + padding: 10px; + padding-bottom: 0; +} + +.toggle-wrapper { + width: 100%; + text-align: center; + margin: 1.25em 0 0; +} + +.graph-toggle { + margin: auto; +} + @media (max-width: 767.98px) { .mobile-bottomcol { margin-top: 15px; diff --git a/frontend/src/app/components/transaction/transaction.component.ts b/frontend/src/app/components/transaction/transaction.component.ts index 9a2629f08..01090f8fe 100644 --- a/frontend/src/app/components/transaction/transaction.component.ts +++ b/frontend/src/app/components/transaction/transaction.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy } from '@angular/core'; +import { Component, OnInit, AfterViewInit, OnDestroy, HostListener, ViewChild, ElementRef } from '@angular/core'; import { ElectrsApiService } from '../../services/electrs-api.service'; import { ActivatedRoute, ParamMap } from '@angular/router'; import { @@ -24,7 +24,7 @@ import { LiquidUnblinding } from './liquid-ublinding'; templateUrl: './transaction.component.html', styleUrls: ['./transaction.component.scss'], }) -export class TransactionComponent implements OnInit, OnDestroy { +export class TransactionComponent implements OnInit, AfterViewInit, OnDestroy { network = ''; tx: Transaction; txId: string; @@ -47,6 +47,12 @@ export class TransactionComponent implements OnInit, OnDestroy { timeAvg$: Observable; liquidUnblinding = new LiquidUnblinding(); outputIndex: number; + graphExpanded: boolean = false; + graphWidth: number = 1000; + maxInOut: number = 0; + + @ViewChild('graphContainer') + graphContainer: ElementRef; constructor( private route: ActivatedRoute, @@ -167,6 +173,7 @@ export class TransactionComponent implements OnInit, OnDestroy { this.waitingForTransaction = false; this.setMempoolBlocksSubscription(); this.websocketService.startTrackTransaction(tx.txid); + this.setupGraph(); if (!tx.status.confirmed && tx.firstSeen) { this.transactionTime = tx.firstSeen; @@ -222,6 +229,10 @@ export class TransactionComponent implements OnInit, OnDestroy { }); } + ngAfterViewInit(): void { + this.setGraphSize(); + } + handleLoadElectrsTransactionError(error: any): Observable { if (error.status === 404 && /^[a-fA-F0-9]{64}$/.test(this.txId)) { this.websocketService.startMultiTrackTransaction(this.txId); @@ -284,6 +295,26 @@ export class TransactionComponent implements OnInit, OnDestroy { return +(cpfpTx.fee / (cpfpTx.weight / 4)).toFixed(1); } + setupGraph() { + this.maxInOut = Math.min(250, Math.max(this.tx?.vin?.length || 1, this.tx?.vout?.length || 1)); + } + + expandGraph() { + this.graphExpanded = true; + } + + collapseGraph() { + this.graphExpanded = false; + } + + @HostListener('window:resize', ['$event']) + setGraphSize(): void { + console.log('resize', this.graphContainer); + if (this.graphContainer) { + this.graphWidth = this.graphContainer.nativeElement.clientWidth - 24; + } + } + ngOnDestroy() { this.subscription.unsubscribe(); this.fetchCpfpSubscription.unsubscribe();