2020-07-07 17:57:15 +00:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2022-05-17 02:53:13 +00:00
|
|
|
import { Router, ResolveEnd, Event } from '@angular/router';
|
2020-07-07 17:57:15 +00:00
|
|
|
import { Subject } from 'rxjs';
|
2020-12-20 23:36:04 +00:00
|
|
|
import { takeUntil, filter } from 'rxjs/operators';
|
2020-07-07 17:57:15 +00:00
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
2020-12-20 23:36:04 +00:00
|
|
|
import { ECLOpenChannelComponent } from '../open-channel-modal/open-channel.component';
|
2020-07-07 17:57:15 +00:00
|
|
|
import { LoggerService } from '../../../../shared/services/logger.service';
|
2021-12-29 23:08:41 +00:00
|
|
|
import { Channel, ChannelsStatus, GetInfo, LightningBalance, OnChainBalance, Peer } from '../../../../shared/models/eclModels';
|
2020-12-20 23:36:04 +00:00
|
|
|
import { SelNodeChild } from '../../../../shared/models/RTLconfig';
|
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
import { RTLState } from '../../../../store/rtl.state';
|
|
|
|
import { openAlert } from '../../../../store/rtl.actions';
|
2022-05-01 17:35:20 +00:00
|
|
|
import { allChannelsInfo, eclNodeInformation, eclnNodeSettings, onchainBalance, peers } from '../../../store/ecl.selector';
|
2021-12-29 23:08:41 +00:00
|
|
|
import { ApiCallStatusPayload } from '../../../../shared/models/apiCallsPayload';
|
2020-07-07 17:57:15 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'rtl-ecl-channels-tables',
|
|
|
|
templateUrl: './channels-tables.component.html',
|
|
|
|
styleUrls: ['./channels-tables.component.scss']
|
|
|
|
})
|
|
|
|
export class ECLChannelsTablesComponent implements OnInit, OnDestroy {
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2020-07-07 17:57:15 +00:00
|
|
|
public numOfOpenChannels = 0;
|
|
|
|
public numOfPendingChannels = 0;
|
|
|
|
public numOfInactiveChannels = 0;
|
2022-08-19 04:41:59 +00:00
|
|
|
public selNode: SelNodeChild | null = {};
|
2020-12-20 23:36:04 +00:00
|
|
|
public information: GetInfo = {};
|
|
|
|
public peers: Peer[] = [];
|
|
|
|
public totalBalance = 0;
|
2021-08-28 21:03:18 +00:00
|
|
|
public links = [{ link: 'open', name: 'Open' }, { link: 'pending', name: 'Pending' }, { link: 'inactive', name: 'Inactive' }];
|
2020-12-20 23:36:04 +00:00
|
|
|
public activeLink = 0;
|
2021-12-29 23:08:41 +00:00
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject()];
|
2020-07-07 17:57:15 +00:00
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
constructor(private logger: LoggerService, private store: Store<RTLState>, private router: Router) { }
|
2020-07-07 17:57:15 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2021-08-28 21:03:18 +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)).
|
2022-05-17 02:53:13 +00:00
|
|
|
subscribe({
|
|
|
|
next: (value: ResolveEnd | Event) => {
|
|
|
|
this.activeLink = this.links.findIndex((link) => link.link === (<ResolveEnd>value).urlAfterRedirects.substring((<ResolveEnd>value).urlAfterRedirects.lastIndexOf('/') + 1));
|
|
|
|
}
|
2021-08-28 21:03:18 +00:00
|
|
|
});
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.select(allChannelsInfo).pipe(takeUntil(this.unSubs[1])).
|
|
|
|
subscribe((allChannelsSelector: ({ activeChannels: Channel[], pendingChannels: Channel[], inactiveChannels: Channel[], lightningBalance: LightningBalance, channelsStatus: ChannelsStatus, apiCallStatus: ApiCallStatusPayload })) => {
|
|
|
|
this.numOfOpenChannels = (allChannelsSelector.channelsStatus && allChannelsSelector.channelsStatus.active && allChannelsSelector.channelsStatus.active.channels) ? allChannelsSelector.channelsStatus.active.channels : 0;
|
|
|
|
this.numOfPendingChannels = (allChannelsSelector.channelsStatus && allChannelsSelector.channelsStatus.pending && allChannelsSelector.channelsStatus.pending.channels) ? allChannelsSelector.channelsStatus.pending.channels : 0;
|
|
|
|
this.numOfInactiveChannels = (allChannelsSelector.channelsStatus && allChannelsSelector.channelsStatus.inactive && allChannelsSelector.channelsStatus.inactive.channels) ? allChannelsSelector.channelsStatus.inactive.channels : 0;
|
|
|
|
this.logger.info(allChannelsSelector);
|
|
|
|
});
|
2022-05-01 17:35:20 +00:00
|
|
|
this.store.select(eclnNodeSettings).pipe(takeUntil(this.unSubs[2])).
|
2022-08-19 04:41:59 +00:00
|
|
|
subscribe((nodeSettings: SelNodeChild | null) => {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.selNode = nodeSettings;
|
|
|
|
});
|
|
|
|
this.store.select(eclNodeInformation).pipe(takeUntil(this.unSubs[3])).
|
|
|
|
subscribe((nodeInfo: GetInfo) => {
|
|
|
|
this.information = nodeInfo;
|
|
|
|
});
|
|
|
|
this.store.select(peers).pipe(takeUntil(this.unSubs[4])).
|
|
|
|
subscribe((peersSelector: { peers: Peer[], apiCallStatus: ApiCallStatusPayload }) => {
|
|
|
|
this.peers = peersSelector.peers;
|
|
|
|
});
|
|
|
|
this.store.select(onchainBalance).pipe(takeUntil(this.unSubs[5])).
|
|
|
|
subscribe((oCBalanceSelector: { onchainBalance: OnChainBalance, apiCallStatus: ApiCallStatusPayload }) => {
|
2022-08-19 04:41:59 +00:00
|
|
|
this.totalBalance = oCBalanceSelector.onchainBalance.total || 0;
|
2021-08-28 21:03:18 +00:00
|
|
|
});
|
2020-07-07 17:57:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-20 23:36:04 +00:00
|
|
|
onOpenChannel() {
|
|
|
|
const peerToAddChannelMessage = {
|
2021-08-28 21:03:18 +00:00
|
|
|
peers: this.peers,
|
2020-12-20 23:36:04 +00:00
|
|
|
information: this.information,
|
|
|
|
balance: this.totalBalance
|
|
|
|
};
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(openAlert({
|
|
|
|
payload: {
|
|
|
|
data: {
|
|
|
|
alertTitle: 'Open Channel',
|
|
|
|
message: peerToAddChannelMessage,
|
|
|
|
component: ECLOpenChannelComponent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
2020-12-20 23:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedTabChange(event) {
|
|
|
|
this.router.navigateByUrl('/ecl/connections/channels/' + this.links[event.index].link);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-07 17:57:15 +00:00
|
|
|
ngOnDestroy() {
|
2021-08-28 21:03:18 +00:00
|
|
|
this.unSubs.forEach((completeSub) => {
|
2022-08-11 09:17:43 +00:00
|
|
|
completeSub.next(<any>null);
|
2020-07-07 17:57:15 +00:00
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2020-07-07 17:57:15 +00:00
|
|
|
}
|