2022-07-20 11:39:51 +02:00
import { ChangeDetectionStrategy , Component , OnInit } from '@angular/core' ;
2022-07-17 22:57:29 +02:00
import { ActivatedRoute } from '@angular/router' ;
2022-09-09 14:56:18 +02:00
import { map , Observable , share } from 'rxjs' ;
2022-09-21 17:23:45 +02:00
import { ApiService } from '../../services/api.service' ;
import { SeoService } from '../../services/seo.service' ;
import { getFlagEmoji } from '../../shared/common.utils' ;
import { GeolocationData } from '../../shared/components/geolocation/geolocation.component' ;
2022-07-17 22:57:29 +02:00
@Component ( {
selector : 'app-nodes-per-isp' ,
templateUrl : './nodes-per-isp.component.html' ,
styleUrls : [ './nodes-per-isp.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
export class NodesPerISP implements OnInit {
nodes$ : Observable < any > ;
isp : { name : string , id : number } ;
2022-09-06 11:01:46 +02:00
skeletonLines : number [ ] = [ ] ;
2022-07-17 22:57:29 +02:00
constructor (
private apiService : ApiService ,
private seoService : SeoService ,
private route : ActivatedRoute ,
2022-09-06 11:01:46 +02:00
) {
for ( let i = 0 ; i < 20 ; ++ i ) {
this . skeletonLines . push ( i ) ;
}
}
2022-07-17 22:57:29 +02:00
ngOnInit ( ) : void {
this . nodes $ = this . apiService . getNodeForISP $ ( this . route . snapshot . params . isp )
. pipe (
map ( response = > {
this . isp = {
name : response.isp ,
2022-09-09 14:56:18 +02:00
id : this.route.snapshot.params.isp.split ( ',' ) . join ( ', ' )
2022-07-17 22:57:29 +02:00
} ;
this . seoService . setTitle ( $localize ` Lightning nodes on ISP: ${ response . isp } [AS ${ this . route . snapshot . params . isp } ] ` ) ;
2023-08-30 20:26:07 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.lightning.nodes-isp:Browse all Bitcoin Lightning nodes using the ${ response . isp } [AS ${ this . route . snapshot . params . isp } ] ISP and see aggregate stats like total number of nodes, total capacity, and more for the ISP. ` ) ;
2022-08-18 17:14:09 +02:00
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-09-09 14:56:18 +02:00
const sumLiquidity = response . nodes . reduce ( ( partialSum , a ) = > partialSum + a . capacity , 0 ) ;
const sumChannels = response . nodes . reduce ( ( partialSum , a ) = > partialSum + a . channels , 0 ) ;
const countries = { } ;
const topCountry = {
count : 0 ,
country : '' ,
iso : '' ,
flag : '' ,
} ;
for ( const node of response . nodes ) {
if ( ! node . geolocation . iso ) {
continue ;
}
countries [ node . geolocation . iso ] = countries [ node . geolocation . iso ] ? ? 0 + 1 ;
if ( countries [ node . geolocation . iso ] > topCountry . count ) {
topCountry . count = countries [ node . geolocation . iso ] ;
topCountry . country = node . geolocation . country ;
topCountry . iso = node . geolocation . iso ;
}
}
topCountry . flag = getFlagEmoji ( topCountry . iso ) ;
return {
nodes : response.nodes ,
sumLiquidity : sumLiquidity ,
sumChannels : sumChannels ,
topCountry : topCountry ,
} ;
} ) ,
share ( )
2022-07-17 22:57:29 +02:00
) ;
}
2022-09-09 14:56:18 +02:00
trackByPublicKey ( index : number , node : any ) : string {
2022-07-17 22:57:29 +02:00
return node . public_key ;
}
}