2022-05-07 11:32:15 +04:00
|
|
|
import { Component, ChangeDetectionStrategy, Input, OnChanges } from '@angular/core';
|
2020-02-16 22:15:07 +07:00
|
|
|
import { Vin, Vout } from '../../interfaces/electrs.interface';
|
2022-09-21 17:23:45 +02:00
|
|
|
import { StateService } from '../../services/state.service';
|
2024-06-12 04:16:58 +00:00
|
|
|
import { AddressType, AddressTypeInfo } from '../../shared/address-utils';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
|
|
|
@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 {
|
2020-06-10 23:52:14 +07:00
|
|
|
network = '';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
2024-06-12 04:16:58 +00:00
|
|
|
@Input() address: AddressTypeInfo;
|
2020-02-16 22:15:07 +07:00
|
|
|
@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 = '';
|
2020-02-16 22:15:07 +07:00
|
|
|
|
2022-03-29 15:47:48 +02:00
|
|
|
label?: string;
|
2020-02-25 20:05:34 +07:00
|
|
|
|
2020-06-10 23:52:14 +07:00
|
|
|
constructor(
|
|
|
|
stateService: StateService,
|
|
|
|
) {
|
|
|
|
this.network = stateService.network;
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
|
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) {
|
2020-02-16 22:15:07 +07:00
|
|
|
this.handleVin();
|
2024-07-01 07:21:37 +02:00
|
|
|
} else if (this.vout) {
|
|
|
|
this.handleVout();
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-07 11:32:15 +04:00
|
|
|
handleChannel() {
|
2022-06-30 00:35:27 +02:00
|
|
|
const type = this.vout ? 'open' : 'close';
|
2023-01-10 21:27:26 +04:00
|
|
|
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;
|
2021-02-03 19:03:59 +07:00
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2020-02-16 22:15:07 +07:00
|
|
|
}
|
2022-07-24 00:08:53 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-24 00:08:53 +02:00
|
|
|
}
|