2022-08-17 21:20:11 +02:00
import { ChangeDetectionStrategy , Component , Input , OnInit } from '@angular/core' ;
import { map , Observable } from 'rxjs' ;
2024-10-22 21:05:01 +09:00
import { GeolocationData } from '@app/shared/components/geolocation/geolocation.component' ;
import { SeoService } from '@app/services/seo.service' ;
2024-10-23 11:09:38 +09:00
import { IOldestNodes } from '@interfaces/node-api.interface' ;
2024-10-22 21:05:01 +09:00
import { LightningApiService } from '@app/lightning/lightning-api.service' ;
2022-08-17 21:20:11 +02:00
@Component ( {
selector : 'app-oldest-nodes' ,
templateUrl : './oldest-nodes.component.html' ,
styleUrls : [ './oldest-nodes.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
export class OldestNodes implements OnInit {
@Input ( ) widget : boolean = false ;
oldestNodes$ : Observable < IOldestNodes [ ] > ;
skeletonRows : number [ ] = [ ] ;
2022-09-07 10:05:22 +02:00
constructor (
private apiService : LightningApiService ,
private seoService : SeoService
) { }
2022-08-17 21:20:11 +02:00
ngOnInit ( ) : void {
2022-09-07 10:05:22 +02:00
if ( ! this . widget ) {
this . seoService . setTitle ( $localize ` Oldest lightning nodes ` ) ;
2023-08-30 20:26:07 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.lightning.ranking.oldest:See the oldest nodes on the Lightning network along with their capacity, number of channels, location, etc. ` ) ;
2022-09-07 10:05:22 +02:00
}
2022-08-17 21:20:11 +02:00
for ( let i = 1 ; i <= ( this . widget ? 10 : 100 ) ; ++ i ) {
this . skeletonRows . push ( i ) ;
}
if ( this . widget === false ) {
2022-09-02 10:08:25 +02:00
this . oldestNodes $ = this . apiService . getOldestNodes $ ( ) . 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 21:20:11 +02:00
} else {
this . oldestNodes $ = this . apiService . getOldestNodes $ ( ) . pipe (
map ( ( nodes : IOldestNodes [ ] ) = > {
2022-09-02 10:08:25 +02:00
return nodes . slice ( 0 , 7 ) ;
2022-08-17 21:20:11 +02:00
} )
) ;
}
}
}