mempool/frontend/src/app/components/address-labels/address-labels.component.ts

77 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-05-07 11:32:15 +04:00
import { Component, ChangeDetectionStrategy, Input, OnChanges } from '@angular/core';
import { Vin, Vout } from '@app/interfaces/electrs.interface';
import { StateService } from '@app/services/state.service';
import { AddressType, AddressTypeInfo } from '@app/shared/address-utils';
@Component({
selector: 'app-address-labels',
templateUrl: './address-labels.component.html',
styleUrls: ['./address-labels.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
2022-05-07 11:32:15 +04:00
export class AddressLabelsComponent implements OnChanges {
network = '';
2024-06-12 04:16:58 +00:00
@Input() address: AddressTypeInfo;
@Input() vin: Vin;
@Input() vout: Vout;
2022-05-07 11:32:15 +04:00
@Input() channel: any;
2024-06-10 23:04:37 +00:00
@Input() class: string = '';
label?: string;
2020-02-25 20:05:34 +07:00
constructor(
stateService: StateService,
) {
this.network = stateService.network;
}
2022-05-07 11:32:15 +04:00
ngOnChanges() {
if (this.channel) {
this.handleChannel();
2024-06-12 04:16:58 +00:00
} else if (this.address) {
this.handleAddress();
2022-05-07 11:32:15 +04:00
} else if (this.vin) {
this.handleVin();
2024-07-01 07:21:37 +02:00
} else if (this.vout) {
this.handleVout();
}
}
2022-05-07 11:32:15 +04:00
handleChannel() {
2022-06-30 00:35:27 +02:00
const type = this.vout ? 'open' : 'close';
const leftNodeName = this.channel.node_left.alias || this.channel.node_left.public_key.substring(0, 10);
const rightNodeName = this.channel.node_right.alias || this.channel.node_right.public_key.substring(0, 10);
this.label = `Channel ${type}: ${leftNodeName} <> ${rightNodeName}`;
2022-05-07 11:32:15 +04:00
}
2024-06-12 04:16:58 +00:00
handleAddress() {
if (this.address?.scripts.size) {
const script = this.address?.scripts.values().next().value;
if (script.template?.label) {
this.label = script.template.label;
}
}
}
2024-06-12 04:16:58 +00:00
handleVin() {
2024-08-30 21:39:22 +00:00
const address = new AddressTypeInfo(this.network || 'mainnet', this.vin.prevout?.scriptpubkey_address, this.vin.prevout?.scriptpubkey_type as AddressType, [this.vin]);
2024-06-12 04:16:58 +00:00
if (address?.scripts.size) {
const script = address?.scripts.values().next().value;
if (script.template?.label) {
this.label = script.template.label;
}
}
}
2024-07-01 07:21:37 +02:00
handleVout() {
const address = new AddressTypeInfo(this.network || 'mainnet', this.vout.scriptpubkey_address, this.vout.scriptpubkey_type as AddressType, undefined, this.vout);
if (address?.scripts.size) {
const script = address?.scripts.values().next().value;
if (script.template?.label) {
this.label = script.template.label;
}
}
}
}