2022-06-15 01:40:05 +00:00
|
|
|
import { Component, ElementRef, ViewChild, Input, OnChanges, ChangeDetectionStrategy } from '@angular/core';
|
2022-09-21 17:23:45 +02:00
|
|
|
import { TransactionStripped } from '../../interfaces/websocket.interface';
|
|
|
|
import { Position } from '../../components/block-overview-graph/sprite-types.js';
|
2023-02-28 10:59:39 +09:00
|
|
|
import { Price } from '../../services/price.service';
|
2022-06-15 01:40:05 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-block-overview-tooltip',
|
|
|
|
templateUrl: './block-overview-tooltip.component.html',
|
|
|
|
styleUrls: ['./block-overview-tooltip.component.scss'],
|
|
|
|
})
|
|
|
|
export class BlockOverviewTooltipComponent implements OnChanges {
|
|
|
|
@Input() tx: TransactionStripped | void;
|
|
|
|
@Input() cursorPosition: Position;
|
|
|
|
@Input() clickable: boolean;
|
2023-01-26 19:14:40 -06:00
|
|
|
@Input() auditEnabled: boolean = false;
|
2023-02-23 13:34:48 +09:00
|
|
|
@Input() blockConversion: Price;
|
2022-06-15 01:40:05 +00:00
|
|
|
|
|
|
|
txid = '';
|
|
|
|
fee = 0;
|
|
|
|
value = 0;
|
|
|
|
vsize = 1;
|
|
|
|
feeRate = 0;
|
2023-03-14 15:39:55 +09:00
|
|
|
effectiveRate;
|
2022-06-15 01:40:05 +00:00
|
|
|
|
|
|
|
tooltipPosition: Position = { x: 0, y: 0 };
|
|
|
|
|
|
|
|
@ViewChild('tooltip') tooltipElement: ElementRef<HTMLCanvasElement>;
|
|
|
|
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
ngOnChanges(changes): void {
|
|
|
|
if (changes.cursorPosition && changes.cursorPosition.currentValue) {
|
|
|
|
let x = changes.cursorPosition.currentValue.x + 10;
|
|
|
|
let y = changes.cursorPosition.currentValue.y + 10;
|
|
|
|
if (this.tooltipElement) {
|
|
|
|
const elementBounds = this.tooltipElement.nativeElement.getBoundingClientRect();
|
|
|
|
const parentBounds = this.tooltipElement.nativeElement.offsetParent.getBoundingClientRect();
|
|
|
|
if ((parentBounds.left + x + elementBounds.width) > parentBounds.right) {
|
|
|
|
x = Math.max(0, parentBounds.width - elementBounds.width - 10);
|
|
|
|
}
|
|
|
|
if (y + elementBounds.height > parentBounds.height) {
|
|
|
|
y = y - elementBounds.height - 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.tooltipPosition = { x, y };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changes.tx) {
|
|
|
|
const tx = changes.tx.currentValue || {};
|
|
|
|
this.txid = tx.txid || '';
|
|
|
|
this.fee = tx.fee || 0;
|
|
|
|
this.value = tx.value || 0;
|
|
|
|
this.vsize = tx.vsize || 1;
|
|
|
|
this.feeRate = this.fee / this.vsize;
|
2023-03-14 15:39:55 +09:00
|
|
|
this.effectiveRate = tx.rate;
|
2022-06-15 01:40:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|