You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RTL/src/app/clightning/peers-channels/channels/channels-tables/channels-tables.component.ts

50 lines
1.4 KiB
TypeScript

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { LoggerService } from '../../../../shared/services/logger.service';
import * as fromRTLReducer from '../../../../store/rtl.reducers';
@Component({
selector: 'rtl-cl-channels-tables',
templateUrl: './channels-tables.component.html',
styleUrls: ['./channels-tables.component.scss']
})
export class CLChannelsTablesComponent implements OnInit, OnDestroy {
public openChannels = 0;
public pendingChannels = 0;
private unSubs: Array<Subject<void>> = [new Subject()];
constructor(private logger: LoggerService, private store: Store<fromRTLReducer.RTLState>) {}
ngOnInit() {
this.store.select('cl')
.pipe(takeUntil(this.unSubs[0]))
.subscribe((rtlStore) => {
if (rtlStore.allChannels && rtlStore.allChannels.length) {
this.openChannels = 0;
this.pendingChannels = 0;
rtlStore.allChannels.forEach(channel => {
if(channel.state === 'CHANNELD_NORMAL') {
this.openChannels++;
} else {
this.pendingChannels++;
}
});
} else {
this.openChannels = 0;
this.pendingChannels = 0;
}
this.logger.info(rtlStore);
});
}
ngOnDestroy() {
this.unSubs.forEach(completeSub => {
completeSub.next();
completeSub.complete();
});
}
}