2022-08-17 12:53:26 +02:00
import { ChangeDetectionStrategy , Component , Input , OnInit } from '@angular/core' ;
import { map , Observable } from 'rxjs' ;
2022-09-21 17:23:45 +02:00
import { INodesRanking , ITopNodesPerChannels } from '../../../interfaces/node-api.interface' ;
2023-07-12 12:24:45 +09:00
import { SeoService } from '../../../services/seo.service' ;
2023-03-03 16:28:05 +09:00
import { StateService } from '../../../services/state.service' ;
2022-09-21 17:23:45 +02:00
import { GeolocationData } from '../../../shared/components/geolocation/geolocation.component' ;
2022-08-17 16:19:01 +02:00
import { LightningApiService } from '../../lightning-api.service' ;
2022-08-17 12:53:26 +02:00
@Component ( {
selector : 'app-top-nodes-per-channels' ,
templateUrl : './top-nodes-per-channels.component.html' ,
styleUrls : [ './top-nodes-per-channels.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
export class TopNodesPerChannels implements OnInit {
@Input ( ) nodes$ : Observable < INodesRanking > ;
@Input ( ) widget : boolean = false ;
topNodesPerChannels$ : Observable < ITopNodesPerChannels [ ] > ;
skeletonRows : number [ ] = [ ] ;
2023-02-23 18:36:13 +09:00
currency$ : Observable < string > ;
2022-08-17 12:53:26 +02:00
2022-09-07 10:05:22 +02:00
constructor (
private apiService : LightningApiService ,
2023-02-23 18:36:13 +09:00
private stateService : StateService ,
2023-07-12 12:24:45 +09:00
private seoService : SeoService ,
2022-09-07 10:05:22 +02:00
) { }
2022-08-17 16:19:01 +02:00
2022-08-17 12:53:26 +02:00
ngOnInit ( ) : void {
2023-02-23 18:36:13 +09:00
this . currency $ = this . stateService . fiatCurrency $ ;
2023-02-23 18:57:55 +09:00
for ( let i = 1 ; i <= ( this . widget ? 6 : 100 ) ; ++ i ) {
2022-08-17 12:53:26 +02:00
this . skeletonRows . push ( i ) ;
}
2022-08-17 16:19:01 +02:00
if ( this . widget === false ) {
2023-07-12 12:24:45 +09:00
this . seoService . setTitle ( $localize ` :@@c50bf442cf99f6fc5f8b687c460f33234b879869:Connectivity Ranking ` ) ;
2023-08-30 20:26:07 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.lightning.ranking.channels:See Lightning nodes with the most channels open along with high-level stats like total node capacity, node age, and more. ` ) ;
2023-07-12 12:24:45 +09:00
2022-09-02 10:08:25 +02:00
this . topNodesPerChannels $ = this . apiService . getTopNodesByChannels $ ( ) . pipe (
map ( ( ranking ) = > {
for ( const i in ranking ) {
ranking [ i ] . geolocation = < GeolocationData > {
country : ranking [ i ] . country ? . en ,
city : ranking [ i ] . city ? . en ,
subdivision : ranking [ i ] . subdivision ? . en ,
iso : ranking [ i ] . iso_code ,
} ;
}
return ranking ;
} )
) ;
2022-08-17 16:19:01 +02:00
} else {
this . topNodesPerChannels $ = this . nodes $ . pipe (
map ( ( ranking ) = > {
2023-02-23 18:57:55 +09:00
for ( const i in ranking . topByChannels ) {
ranking . topByChannels [ i ] . geolocation = < GeolocationData > {
country : ranking.topByChannels [ i ] . country ? . en ,
city : ranking.topByChannels [ i ] . city ? . en ,
subdivision : ranking.topByChannels [ i ] . subdivision ? . en ,
iso : ranking.topByChannels [ i ] . iso_code ,
} ;
}
2023-02-24 20:25:28 +09:00
return ranking . topByChannels . slice ( 0 , 6 ) ;
2022-08-17 16:19:01 +02:00
} )
) ;
}
2022-08-17 12:53:26 +02:00
}
}