2022-12-14 16:51:53 -06:00
import { Component , OnInit , ChangeDetectionStrategy , OnDestroy } from '@angular/core' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { BehaviorSubject , EMPTY , merge , Observable , Subscription } from 'rxjs' ;
import { catchError , switchMap , tap } from 'rxjs/operators' ;
2023-05-03 13:16:27 -06:00
import { WebsocketService } from '../../services/websocket.service' ;
2022-12-17 09:39:06 -06:00
import { RbfTree } from '../../interfaces/node-api.interface' ;
2022-12-14 16:51:53 -06:00
import { ApiService } from '../../services/api.service' ;
import { StateService } from '../../services/state.service' ;
2023-08-30 23:59:51 +09:00
import { SeoService } from '../../services/seo.service' ;
import { seoDescriptionNetwork } from '../../shared/common.utils' ;
2022-12-14 16:51:53 -06:00
@Component ( {
selector : 'app-rbf-list' ,
templateUrl : './rbf-list.component.html' ,
styleUrls : [ './rbf-list.component.scss' ] ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
export class RbfList implements OnInit , OnDestroy {
2022-12-17 09:39:06 -06:00
rbfTrees$ : Observable < RbfTree [ ] > ;
nextRbfSubject = new BehaviorSubject ( null ) ;
2022-12-14 16:51:53 -06:00
urlFragmentSubscription : Subscription ;
fullRbf : boolean ;
isLoading = true ;
constructor (
private route : ActivatedRoute ,
private router : Router ,
private apiService : ApiService ,
public stateService : StateService ,
private websocketService : WebsocketService ,
2023-08-30 23:59:51 +09:00
private seoService : SeoService ,
2023-07-18 11:01:35 +09:00
) { }
2022-12-14 16:51:53 -06:00
ngOnInit ( ) : void {
this . urlFragmentSubscription = this . route . fragment . subscribe ( ( fragment ) = > {
this . fullRbf = ( fragment === 'fullrbf' ) ;
this . websocketService . startTrackRbf ( this . fullRbf ? 'fullRbf' : 'all' ) ;
2022-12-17 09:39:06 -06:00
this . nextRbfSubject . next ( null ) ;
2022-12-14 16:51:53 -06:00
} ) ;
2022-12-17 09:39:06 -06:00
this . rbfTrees $ = merge (
this . nextRbfSubject . pipe (
switchMap ( ( ) = > {
return this . apiService . getRbfList $ ( this . fullRbf ) ;
2022-12-14 16:51:53 -06:00
} ) ,
catchError ( ( e ) = > {
return EMPTY ;
} )
) ,
this . stateService . rbfLatest $
)
. pipe (
2022-12-17 09:39:06 -06:00
tap ( ( ) = > {
2022-12-14 16:51:53 -06:00
this . isLoading = false ;
} )
) ;
2023-08-30 23:59:51 +09:00
2023-11-25 20:31:29 +09:00
this . seoService . setTitle ( $localize ` :@@5e3d5a82750902f159122fcca487b07f1af3141f:RBF Replacements ` ) ;
2023-08-30 23:59:51 +09:00
this . seoService . setDescription ( $localize ` :@@meta.description.rbf-list:See the most recent RBF replacements on the Bitcoin ${ seoDescriptionNetwork ( this . stateService . network ) } network, updated in real-time. ` ) ;
2022-12-14 16:51:53 -06:00
}
ngOnDestroy ( ) : void {
this . websocketService . stopTrackRbf ( ) ;
}
2023-08-30 23:59:51 +09:00
}