mempool/frontend/src/app/lightning/nodes-per-country/nodes-per-country.component.ts

53 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-07-16 15:56:36 +02:00
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { map, Observable } from 'rxjs';
import { ApiService } from 'src/app/services/api.service';
import { SeoService } from 'src/app/services/seo.service';
import { getFlagEmoji } from 'src/app/shared/common.utils';
import { GeolocationData } from 'src/app/shared/components/geolocation/geolocation.component';
2022-07-16 15:56:36 +02:00
@Component({
selector: 'app-nodes-per-country',
templateUrl: './nodes-per-country.component.html',
styleUrls: ['./nodes-per-country.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NodesPerCountry implements OnInit {
nodes$: Observable<any>;
2022-07-18 00:55:47 +02:00
country: {name: string, flag: string};
2022-07-16 15:56:36 +02:00
constructor(
private apiService: ApiService,
private seoService: SeoService,
2022-07-16 15:56:36 +02:00
private route: ActivatedRoute,
) { }
ngOnInit(): void {
this.nodes$ = this.apiService.getNodeForCountry$(this.route.snapshot.params.country)
.pipe(
map(response => {
2022-07-18 00:55:47 +02:00
this.country = {
name: response.country.en,
flag: getFlagEmoji(this.route.snapshot.params.country)
};
for (const i in response.nodes) {
response.nodes[i].geolocation = <GeolocationData>{
country: response.nodes[i].country?.en,
city: response.nodes[i].city?.en,
subdivision: response.nodes[i].subdivision?.en,
iso: response.nodes[i].iso_code,
};
}
2022-07-18 00:55:47 +02:00
this.seoService.setTitle($localize`Lightning nodes in ${this.country.name}`);
return response.nodes;
2022-07-16 15:56:36 +02:00
})
);
}
trackByPublicKey(index: number, node: any) {
return node.public_key;
}
}