2019-11-21 00:14:37 +00:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2020-12-20 23:36:04 +00:00
|
|
|
import { Router, ResolveEnd } from '@angular/router';
|
2019-11-21 00:14:37 +00:00
|
|
|
import { Subject } from 'rxjs';
|
2020-12-20 23:36:04 +00:00
|
|
|
import { takeUntil, filter } from 'rxjs/operators';
|
2019-11-21 00:14:37 +00:00
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
import { faUsers, faChartPie } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
|
|
import { SelNodeChild } from '../../shared/models/RTLconfig';
|
2020-05-03 19:52:38 +00:00
|
|
|
import { LoggerService } from '../../shared/services/logger.service';
|
|
|
|
|
2019-11-21 00:14:37 +00:00
|
|
|
import * as fromRTLReducer from '../../store/rtl.reducers';
|
|
|
|
|
|
|
|
@Component({
|
2020-12-20 23:36:04 +00:00
|
|
|
selector: 'rtl-connections',
|
|
|
|
templateUrl: './connections.component.html',
|
|
|
|
styleUrls: ['./connections.component.scss']
|
2019-11-21 00:14:37 +00:00
|
|
|
})
|
2020-12-20 23:36:04 +00:00
|
|
|
export class ConnectionsComponent implements OnInit, OnDestroy {
|
2019-11-21 00:14:37 +00:00
|
|
|
public selNode: SelNodeChild = {};
|
|
|
|
public activePeers = 0;
|
|
|
|
public activeChannels = 0;
|
|
|
|
public faUsers = faUsers;
|
|
|
|
public faChartPie = faChartPie;
|
|
|
|
public balances = [{title: 'Total Balance', dataValue: 0}, {title: 'Confirmed', dataValue: 0}, {title: 'Unconfirmed', dataValue: 0}];
|
2020-12-20 23:36:04 +00:00
|
|
|
public links = [{link: 'channels', name: 'Channels'}, {link: 'peers', name: 'Peers'}];
|
|
|
|
public activeLink = 0;
|
2019-11-21 00:14:37 +00:00
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject()];
|
|
|
|
|
2020-12-20 23:36:04 +00:00
|
|
|
constructor(private store: Store<fromRTLReducer.RTLState>, private logger: LoggerService, private router: Router) {}
|
2019-11-21 00:14:37 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-20 23:36:04 +00:00
|
|
|
this.activeLink = this.links.findIndex(link => link.link === this.router.url.substring(this.router.url.lastIndexOf('/') + 1));
|
|
|
|
this.router.events.pipe(takeUntil(this.unSubs[0]), filter(e => e instanceof ResolveEnd))
|
|
|
|
.subscribe((value: ResolveEnd) => {
|
|
|
|
this.activeLink = this.links.findIndex(link => link.link === value.urlAfterRedirects.substring(value.urlAfterRedirects.lastIndexOf('/') + 1));
|
|
|
|
});
|
2019-11-21 00:14:37 +00:00
|
|
|
this.store.select('lnd')
|
|
|
|
.pipe(takeUntil(this.unSubs[1]))
|
|
|
|
.subscribe((rtlStore) => {
|
|
|
|
this.selNode = rtlStore.nodeSettings;
|
|
|
|
this.activePeers = (rtlStore.peers && rtlStore.peers.length) ? rtlStore.peers.length : 0;
|
|
|
|
this.activeChannels = rtlStore.numberOfActiveChannels;
|
|
|
|
this.balances = [{title: 'Total Balance', dataValue: rtlStore.blockchainBalance.total_balance || 0}, {title: 'Confirmed', dataValue: rtlStore.blockchainBalance.confirmed_balance}, {title: 'Unconfirmed', dataValue: rtlStore.blockchainBalance.unconfirmed_balance}];
|
2020-05-03 19:52:38 +00:00
|
|
|
this.logger.info(rtlStore);
|
2019-11-21 00:14:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-20 23:36:04 +00:00
|
|
|
onSelectedTabChange(event) {
|
|
|
|
this.router.navigateByUrl('/lnd/connections/' + this.links[event.index].link);
|
2020-05-03 19:52:38 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 00:14:37 +00:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.unSubs.forEach(completeSub => {
|
2021-06-20 20:27:08 +00:00
|
|
|
completeSub.next(null);
|
2019-11-21 00:14:37 +00:00
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|