2023-02-23 18:36:13 +09:00
import { ChangeDetectionStrategy , Component , Input , OnInit } from '@angular/core' ;
2023-12-14 12:29:21 +01:00
import { combineLatest , map , Observable } from 'rxjs' ;
2023-12-14 12:22:00 +01:00
import { INodesRanking , INodesStatistics , ITopNodesPerCapacity } from '../../../interfaces/node-api.interface' ;
2022-09-21 17:23:45 +02: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:00:30 +02:00
import { LightningApiService } from '../../lightning-api.service' ;
2022-08-17 12:53:26 +02:00
@Component ( {
selector : 'app-top-nodes-per-capacity' ,
templateUrl : './top-nodes-per-capacity.component.html' ,
styleUrls : [ './top-nodes-per-capacity.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
2023-02-23 18:36:13 +09:00
export class TopNodesPerCapacity implements OnInit {
2022-08-17 12:53:26 +02:00
@Input ( ) nodes$ : Observable < INodesRanking > ;
2023-12-14 12:22:00 +01:00
@Input ( ) statistics$ : Observable < INodesStatistics > ;
2022-08-17 12:53:26 +02:00
@Input ( ) widget : boolean = false ;
2023-08-30 20:26:07 +09:00
2023-12-14 12:29:21 +01:00
topNodesPerCapacity$ : Observable < { nodes : ITopNodesPerCapacity [ ] ; statistics : { totalCapacity : number ; totalChannels? : number ; } } > ;
2022-08-17 12:53:26 +02:00
skeletonRows : number [ ] = [ ] ;
2023-02-23 18:19:47 +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:19:47 +09:00
private seoService : SeoService ,
private stateService : StateService ,
2022-09-07 10:05:22 +02:00
) { }
2022-08-17 16:00:30 +02:00
2022-08-17 12:53:26 +02:00
ngOnInit ( ) : void {
2023-02-23 18:19:47 +09:00
this . currency $ = this . stateService . fiatCurrency $ ;
2022-09-07 10:05:22 +02:00
if ( ! this . widget ) {
2022-10-13 17:40:13 +04:00
this . seoService . setTitle ( $localize ` :@@2d9883d230a47fbbb2ec969e32a186597ea27405:Liquidity Ranking ` ) ;
2023-08-30 20:26:07 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.lightning.ranking.liquidity:See Lightning nodes with the most BTC liquidity deployed along with high-level stats like number of open channels, location, node age, and more. ` ) ;
2022-09-07 10:05:22 +02:00
}
2023-02-23 18:19:47 +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:00:30 +02:00
if ( this . widget === false ) {
2023-12-14 12:29:21 +01:00
this . topNodesPerCapacity $ = combineLatest ( [
this . apiService . getTopNodesByCapacity $ ( ) ,
this . statistics $
] )
. pipe (
map ( ( [ ranking , statistics ] ) = > {
2022-09-02 10:08:25 +02:00
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 ,
} ;
}
2023-12-14 12:29:21 +01:00
return {
nodes : ranking ,
statistics : {
totalCapacity : statistics.latest.total_capacity ,
totalChannels : statistics.latest.channel_count ,
}
}
2022-09-02 10:08:25 +02:00
} )
) ;
2022-08-17 16:00:30 +02:00
} else {
2023-12-14 12:29:21 +01:00
this . topNodesPerCapacity $ = combineLatest ( [
this . nodes $ ,
this . statistics $
] )
. pipe (
map ( ( [ ranking , statistics ] ) = > {
return {
nodes : ranking.topByCapacity.slice ( 0 , 6 ) ,
statistics : {
totalCapacity : statistics.latest.total_capacity ,
}
}
2022-08-17 16:00:30 +02:00
} )
) ;
}
2022-08-17 12:53:26 +02:00
}
}