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

58 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-05-01 03:01:27 +04:00
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { ActivatedRoute, ParamMap } from '@angular/router';
2022-06-29 23:06:13 +02:00
import { Observable, of } from 'rxjs';
import { catchError, switchMap, tap } from 'rxjs/operators';
2022-05-15 19:22:14 +04:00
import { SeoService } from 'src/app/services/seo.service';
2022-05-01 03:01:27 +04:00
import { LightningApiService } from '../lightning-api.service';
@Component({
selector: 'app-channel',
templateUrl: './channel.component.html',
styleUrls: ['./channel.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ChannelComponent implements OnInit {
channel$: Observable<any>;
2022-06-29 23:06:13 +02:00
error: any = null;
channelGeo: number[] = [];
2022-05-01 03:01:27 +04:00
constructor(
private lightningApiService: LightningApiService,
private activatedRoute: ActivatedRoute,
2022-05-15 19:22:14 +04:00
private seoService: SeoService,
2022-05-01 03:01:27 +04:00
) { }
ngOnInit(): void {
this.channel$ = this.activatedRoute.paramMap
.pipe(
switchMap((params: ParamMap) => {
2022-06-29 23:06:13 +02:00
this.error = null;
2022-05-15 19:22:14 +04:00
this.seoService.setTitle(`Channel: ${params.get('short_id')}`);
2022-06-29 23:06:13 +02:00
return this.lightningApiService.getChannel$(params.get('short_id'))
.pipe(
tap((data) => {
if (!data.node_left.longitude || !data.node_left.latitude ||
!data.node_right.longitude || !data.node_right.latitude) {
this.channelGeo = [];
} else {
this.channelGeo = [
data.node_left.public_key,
data.node_left.alias,
data.node_left.longitude, data.node_left.latitude,
data.node_right.public_key,
data.node_right.alias,
data.node_right.longitude, data.node_right.latitude,
];
}
}),
2022-06-29 23:06:13 +02:00
catchError((err) => {
this.error = err;
return of(null);
})
);
2022-05-01 03:01:27 +04:00
})
);
}
}