Socket selector and copy

This commit is contained in:
softsimon
2022-05-06 00:20:14 +04:00
parent d9d7f8cc66
commit 79aa4461f3
3 changed files with 46 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { map, switchMap } from 'rxjs/operators';
import { LightningApiService } from '../lightning-api.service';
@Component({
@@ -14,6 +14,7 @@ export class NodeComponent implements OnInit {
node$: Observable<any>;
statistics$: Observable<any>;
publicKey$: Observable<string>;
selectedSocketIndex = 0;
constructor(
private lightningApiService: LightningApiService,
@@ -25,7 +26,27 @@ export class NodeComponent implements OnInit {
.pipe(
switchMap((params: ParamMap) => {
return this.lightningApiService.getNode$(params.get('public_key'));
})
}),
map((node) => {
const socketsObject = [];
for (const socket of node.sockets.split(',')) {
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,
});
}
console.log(socketsObject);
node.socketsObject = socketsObject;
return node;
}),
);
this.statistics$ = this.activatedRoute.paramMap
@@ -36,4 +57,8 @@ export class NodeComponent implements OnInit {
);
}
changeSocket(index: number) {
this.selectedSocketIndex = index;
}
}