mempool/frontend/src/app/lightning/node/node.component.ts

105 lines
3.0 KiB
TypeScript
Raw Normal View History

2022-05-01 03:01:27 +04:00
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
2022-04-29 03:57:27 +04:00
import { ActivatedRoute, ParamMap } from '@angular/router';
import { Observable } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
2022-05-15 19:22:14 +04:00
import { SeoService } from 'src/app/services/seo.service';
2022-04-29 03:57:27 +04:00
import { LightningApiService } from '../lightning-api.service';
import { isMobile } from '../../shared/common.utils';
import { GeolocationData } from 'src/app/shared/components/geolocation/geolocation.component';
2022-04-29 03:57:27 +04:00
@Component({
selector: 'app-node',
templateUrl: './node.component.html',
2022-05-01 03:01:27 +04:00
styleUrls: ['./node.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
2022-04-29 03:57:27 +04:00
})
export class NodeComponent implements OnInit {
node$: Observable<any>;
2022-05-05 23:19:24 +04:00
statistics$: Observable<any>;
2022-05-01 03:01:27 +04:00
publicKey$: Observable<string>;
2022-05-06 00:20:14 +04:00
selectedSocketIndex = 0;
2022-05-06 00:52:25 +04:00
qrCodeVisible = false;
channelsListStatus: string;
error: Error;
publicKey: string;
2022-08-29 22:25:43 +02:00
channelListLoading = false;
publicKeySize = 99;
2022-04-29 03:57:27 +04:00
constructor(
private lightningApiService: LightningApiService,
private activatedRoute: ActivatedRoute,
2022-05-15 19:22:14 +04:00
private seoService: SeoService,
) {
if (isMobile()) {
this.publicKeySize = 12;
}
}
2022-04-29 03:57:27 +04:00
ngOnInit(): void {
this.node$ = this.activatedRoute.paramMap
.pipe(
switchMap((params: ParamMap) => {
this.publicKey = params.get('public_key');
2022-05-01 03:01:27 +04:00
return this.lightningApiService.getNode$(params.get('public_key'));
2022-05-06 00:20:14 +04:00
}),
map((node) => {
2022-05-15 19:22:14 +04:00
this.seoService.setTitle(`Node: ${node.alias}`);
2022-05-06 00:20:14 +04:00
const socketsObject = [];
for (const socket of node.sockets.split(',')) {
2022-05-06 00:52:25 +04:00
if (socket === '') {
continue;
}
2022-05-06 00:20:14 +04:00
let label = '';
if (socket.match(/(?:[0-9]{1,3}\.){3}[0-9]{1,3}/)) {
label = 'IPv4';
} else if (socket.indexOf('[') > -1) {
label = 'IPv6';
} else if (socket.indexOf('onion') > -1) {
label = 'Tor';
}
socketsObject.push({
label: label,
socket: node.public_key + '@' + socket,
});
}
node.socketsObject = socketsObject;
node.avgCapacity = node.capacity / Math.max(1, node.active_channel_count);
if (!node?.country && !node?.city &&
!node?.subdivision && !node?.iso) {
node.geolocation = null;
} else {
node.geolocation = <GeolocationData>{
country: node.country?.en,
city: node.city?.en,
subdivision: node.subdivision?.en,
iso: node.iso_code,
};
}
2022-05-06 00:20:14 +04:00
return node;
}),
catchError(err => {
this.error = err;
return [{
alias: this.publicKey,
public_key: this.publicKey,
}];
})
2022-04-29 03:57:27 +04:00
);
}
2022-05-06 00:20:14 +04:00
changeSocket(index: number) {
this.selectedSocketIndex = index;
}
onChannelsListStatusChanged(e) {
this.channelsListStatus = e;
}
2022-08-29 22:25:43 +02:00
onLoadingEvent(e) {
this.channelListLoading = e;
}
2022-04-29 03:57:27 +04:00
}