2022-05-01 03:01:27 +04:00
import { ChangeDetectionStrategy , Component , OnInit } from '@angular/core' ;
import { ActivatedRoute , ParamMap } from '@angular/router' ;
2022-08-29 14:06:50 +02:00
import { Observable , of , zip } from 'rxjs' ;
2022-09-07 10:05:22 +02:00
import { catchError , map , shareReplay , switchMap , tap } from 'rxjs/operators' ;
2022-09-21 17:23:45 +02:00
import { IChannel } from '../../interfaces/node-api.interface' ;
import { ElectrsApiService } from '../../services/electrs-api.service' ;
import { SeoService } from '../../services/seo.service' ;
2022-05-01 03:01:27 +04:00
import { LightningApiService } from '../lightning-api.service' ;
@Component ( {
selector : 'app-channel' ,
templateUrl : './channel.component.html' ,
styleUrls : [ './channel.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
export class ChannelComponent implements OnInit {
channel$ : Observable < any > ;
2022-08-20 14:24:26 +04:00
channelGeo$ : Observable < number [ ] > ;
transactions$ : Observable < any > ;
2022-06-29 23:06:13 +02:00
error : any = null ;
2022-05-01 03:01:27 +04:00
constructor (
private lightningApiService : LightningApiService ,
private activatedRoute : ActivatedRoute ,
2022-05-15 19:22:14 +04:00
private seoService : SeoService ,
2022-08-20 14:24:26 +04:00
private electrsApiService : ElectrsApiService ,
2022-05-01 03:01:27 +04:00
) { }
ngOnInit ( ) : void {
this . channel $ = this . activatedRoute . paramMap
. pipe (
switchMap ( ( params : ParamMap ) = > {
2022-06-29 23:06:13 +02:00
this . error = null ;
return this . lightningApiService . getChannel $ ( params . get ( 'short_id' ) )
. pipe (
2022-09-07 10:05:22 +02:00
tap ( ( value ) = > {
2022-10-07 00:54:33 +04:00
this . seoService . setTitle ( $localize ` Channel: ${ value . short_id } ` ) ;
2023-08-30 20:26:07 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.lightning.channel:Overview for Lightning channel ${ value . short_id } . See channel capacity, the Lightning nodes involved, related on-chain transactions, and more. ` ) ;
2022-09-07 10:05:22 +02:00
} ) ,
2022-06-29 23:06:13 +02:00
catchError ( ( err ) = > {
this . error = err ;
2023-03-09 02:34:21 -06:00
this . seoService . logSoft404 ( ) ;
2023-02-25 13:38:09 +09:00
return [ {
short_id : params.get ( 'short_id' )
} ] ;
2022-06-29 23:06:13 +02:00
} )
) ;
2022-08-20 14:24:26 +04:00
} ) ,
shareReplay ( ) ,
2022-05-01 03:01:27 +04:00
) ;
2022-08-20 14:24:26 +04:00
this . channelGeo $ = this . channel $ . pipe (
map ( ( data ) = > {
if ( ! data . node_left . longitude || ! data . node_left . latitude ||
! data . node_right . longitude || ! data . node_right . latitude ) {
return [ ] ;
} else {
return [
data . node_left . public_key ,
data . node_left . alias ,
data . node_left . longitude , data . node_left . latitude ,
data . node_right . public_key ,
data . node_right . alias ,
data . node_right . longitude , data . node_right . latitude ,
] ;
}
} ) ,
) ;
this . transactions $ = this . channel $ . pipe (
2022-08-27 16:00:58 +02:00
switchMap ( ( channel : IChannel ) = > {
2022-08-20 14:24:26 +04:00
return zip ( [
2022-08-27 16:00:58 +02:00
channel . transaction_id ? this . electrsApiService . getTransaction $ ( channel . transaction_id ) : of ( null ) ,
channel . closing_transaction_id ? this . electrsApiService . getTransaction $ ( channel . closing_transaction_id ) . pipe (
map ( ( tx ) = > {
tx . _channels = { inputs : { 0 : channel } , outputs : { } } ;
return tx ;
} )
) : of ( null ) ,
2022-08-20 14:24:26 +04:00
] ) ;
} ) ,
) ;
2022-05-01 03:01:27 +04:00
}
2022-11-10 18:32:18 -06:00
showCloseBoxes ( channel : IChannel ) : boolean {
return ! ! ( channel . node_left . funding_balance || channel . node_left . closing_balance
|| channel . node_right . funding_balance || channel . node_right . closing_balance ) ;
}
2022-05-01 03:01:27 +04:00
}