2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-11-15 18:13:00 +00:00
RTL/src/app/cln/network-info/network-info.component.ts

163 lines
10 KiB
TypeScript
Raw Normal View History

2020-01-05 04:28:40 +00:00
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
2021-12-29 23:08:41 +00:00
import { takeUntil, withLatestFrom } from 'rxjs/operators';
2020-01-05 04:28:40 +00:00
import { Store } from '@ngrx/store';
2021-08-28 21:03:18 +00:00
import { faBolt, faServer, faNetworkWired, faLink } from '@fortawesome/free-solid-svg-icons';
2020-01-05 04:28:40 +00:00
import { SelNodeChild } from '../../shared/models/RTLconfig';
import { GetInfo, Fees, ChannelsStatus, FeeRates, LocalRemoteBalance, Channel, ListForwards } from '../../shared/models/clnModels';
2021-08-28 21:03:18 +00:00
import { APICallStatusEnum, ScreenSizeEnum, UserPersonaEnum } from '../../shared/services/consts-enums-functions';
2021-12-29 23:08:41 +00:00
import { ApiCallStatusPayload } from '../../shared/models/apiCallsPayload';
2021-08-28 21:03:18 +00:00
import { LoggerService } from '../../shared/services/logger.service';
import { CommonService } from '../../shared/services/common.service';
2020-01-05 04:28:40 +00:00
2021-12-29 23:08:41 +00:00
import { RTLState } from '../../store/rtl.state';
import { channels, feeRatesPerKB, feeRatesPerKW, fees, forwardingHistory, localRemoteBalance, nodeInfoAndNodeSettingsAndAPIsStatus } from '../store/cln.selector';
2020-01-05 04:28:40 +00:00
@Component({
selector: 'rtl-cln-network-info',
2020-01-05 04:28:40 +00:00
templateUrl: './network-info.component.html',
styleUrls: ['./network-info.component.scss']
})
export class CLNNetworkInfoComponent implements OnInit, OnDestroy {
2021-08-28 21:03:18 +00:00
2020-01-05 04:28:40 +00:00
public faBolt = faBolt;
public faServer = faServer;
2021-08-28 21:03:18 +00:00
public faNetworkWired = faNetworkWired;
public faLink = faLink;
public selNode: SelNodeChild | null = {};
public information: GetInfo = {};
public fees: Fees;
2021-12-29 23:08:41 +00:00
public channelsStatus: ChannelsStatus = { active: {}, pending: {}, inactive: {} };
2021-08-28 21:03:18 +00:00
public feeRatesPerKB: FeeRates = {};
public feeRatesPerKW: FeeRates = {};
public nodeCardsOperator: any[] = [];
public nodeCardsMerchant: any[] = [];
2020-01-05 04:28:40 +00:00
public screenSize = '';
public screenSizeEnum = ScreenSizeEnum;
public userPersonaEnum = UserPersonaEnum;
2021-08-28 21:03:18 +00:00
public errorMessages = ['', '', '', '', '', '', ''];
public apiCallStatusNodeInfo: ApiCallStatusPayload | null = null;
public apiCallStatusLRBal: ApiCallStatusPayload | null = null;
public apiCallStatusChannels: ApiCallStatusPayload | null = null;
public apiCallStatusFees: ApiCallStatusPayload | null = null;
public apiCallStatusFHistory: ApiCallStatusPayload | null = null;
public apiCallStatusPerKB: ApiCallStatusPayload | null = null;
public apiCallStatusPerKW: ApiCallStatusPayload | null = null;
2021-08-28 21:03:18 +00:00
public apiCallStatusEnum = APICallStatusEnum;
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(), new Subject()];
2020-01-05 04:28:40 +00:00
2021-12-29 23:08:41 +00:00
constructor(private logger: LoggerService, private commonService: CommonService, private store: Store<RTLState>) {
2020-01-05 04:28:40 +00:00
this.screenSize = this.commonService.getScreenSize();
2021-08-28 21:03:18 +00:00
if (this.screenSize === ScreenSizeEnum.XS) {
2020-01-05 04:28:40 +00:00
this.nodeCardsMerchant = [
{ id: 'node', icon: this.faServer, title: 'Node Information', cols: 6, rows: 3 },
{ id: 'status', icon: this.faNetworkWired, title: 'Channels', cols: 6, rows: 3 },
{ id: 'fee', icon: this.faBolt, title: 'Routing Fee', cols: 6, rows: 1 },
2021-08-28 21:03:18 +00:00
{ id: 'feeRatesKB', icon: this.faServer, title: 'Fee Rate Per KB', cols: 4, rows: 4 },
{ id: 'feeRatesKW', icon: this.faNetworkWired, title: 'Fee Rate Per KW', cols: 4, rows: 4 },
{ id: 'onChainFeeEstimates', icon: this.faLink, title: 'Onchain Fee Estimates (Sats)', cols: 4, rows: 4 }
2020-01-05 04:28:40 +00:00
];
this.nodeCardsOperator = [
2021-08-28 21:03:18 +00:00
{ id: 'feeRatesKB', icon: this.faServer, title: 'Fee Rate Per KB', cols: 4, rows: 4 },
{ id: 'feeRatesKW', icon: this.faNetworkWired, title: 'Fee Rate Per KW', cols: 4, rows: 4 },
{ id: 'onChainFeeEstimates', icon: this.faLink, title: 'Onchain Fee Estimates (Sats)', cols: 4, rows: 4 }
2020-01-05 04:28:40 +00:00
];
} else {
this.nodeCardsMerchant = [
{ id: 'node', icon: this.faServer, title: 'Node Information', cols: 2, rows: 3 },
{ id: 'status', icon: this.faNetworkWired, title: 'Channels', cols: 2, rows: 3 },
{ id: 'fee', icon: this.faBolt, title: 'Routing Fee', cols: 2, rows: 3 },
2021-08-28 21:03:18 +00:00
{ id: 'feeRatesKB', icon: this.faServer, title: 'Fee Rate Per KB', cols: 2, rows: 4 },
{ id: 'feeRatesKW', icon: this.faNetworkWired, title: 'Fee Rate Per KW', cols: 2, rows: 4 },
{ id: 'onChainFeeEstimates', icon: this.faLink, title: 'Onchain Fee Estimates (Sats)', cols: 2, rows: 4 }
2020-01-05 04:28:40 +00:00
];
this.nodeCardsOperator = [
2021-08-28 21:03:18 +00:00
{ id: 'feeRatesKB', icon: this.faServer, title: 'Fee Rate Per KB', cols: 2, rows: 4 },
{ id: 'feeRatesKW', icon: this.faNetworkWired, title: 'Fee Rate Per KW', cols: 2, rows: 4 },
{ id: 'onChainFeeEstimates', icon: this.faLink, title: 'Onchain Fee Estimates (Sats)', cols: 2, rows: 4 }
2020-01-05 04:28:40 +00:00
];
}
}
ngOnInit() {
2021-12-29 23:08:41 +00:00
this.store.select(nodeInfoAndNodeSettingsAndAPIsStatus).pipe(takeUntil(this.unSubs[0])).
subscribe((infoSettingsStatusSelector: { information: GetInfo, nodeSettings: SelNodeChild | null, apisCallStatus: ApiCallStatusPayload[] }) => {
2021-12-29 23:08:41 +00:00
this.errorMessages[0] = '';
this.apiCallStatusNodeInfo = infoSettingsStatusSelector.apisCallStatus[0];
if (this.apiCallStatusNodeInfo.status === APICallStatusEnum.ERROR) {
this.errorMessages[0] = (typeof (this.apiCallStatusNodeInfo.message) === 'object') ? JSON.stringify(this.apiCallStatusNodeInfo.message) : this.apiCallStatusNodeInfo.message ? this.apiCallStatusNodeInfo.message : '';
2020-01-05 04:28:40 +00:00
}
2021-12-29 23:08:41 +00:00
this.selNode = infoSettingsStatusSelector.nodeSettings;
this.information = infoSettingsStatusSelector.information;
this.logger.info(infoSettingsStatusSelector);
});
this.store.select(channels).pipe(takeUntil(this.unSubs[1]),
withLatestFrom(this.store.select(localRemoteBalance))).
subscribe(([channelsSeletor, lrBalanceSeletor]: [{ activeChannels: Channel[], pendingChannels: Channel[], inactiveChannels: Channel[], apiCallStatus: ApiCallStatusPayload }, { localRemoteBalance: LocalRemoteBalance, apiCallStatus: ApiCallStatusPayload }]) => {
this.errorMessages[2] = '';
this.errorMessages[3] = '';
this.apiCallStatusLRBal = channelsSeletor.apiCallStatus;
this.apiCallStatusChannels = lrBalanceSeletor.apiCallStatus;
if (this.apiCallStatusLRBal.status === APICallStatusEnum.ERROR) {
this.errorMessages[2] = (typeof (this.apiCallStatusLRBal.message) === 'object') ? JSON.stringify(this.apiCallStatusLRBal.message) : this.apiCallStatusLRBal.message ? this.apiCallStatusLRBal.message : '';
2020-01-05 04:28:40 +00:00
}
2021-12-29 23:08:41 +00:00
if (this.apiCallStatusChannels.status === APICallStatusEnum.ERROR) {
this.errorMessages[3] = (typeof (this.apiCallStatusChannels.message) === 'object') ? JSON.stringify(this.apiCallStatusChannels.message) : this.apiCallStatusChannels.message ? this.apiCallStatusChannels.message : '';
2021-08-28 21:03:18 +00:00
}
2021-12-29 23:08:41 +00:00
this.channelsStatus.active.channels = channelsSeletor.activeChannels.length || 0;
this.channelsStatus.pending.channels = channelsSeletor.pendingChannels.length || 0;
this.channelsStatus.inactive.channels = channelsSeletor.inactiveChannels.length || 0;
this.channelsStatus.active.capacity = lrBalanceSeletor.localRemoteBalance.localBalance || 0;
this.channelsStatus.pending.capacity = lrBalanceSeletor.localRemoteBalance.pendingBalance || 0;
this.channelsStatus.inactive.capacity = lrBalanceSeletor.localRemoteBalance.inactiveBalance || 0;
});
this.store.select(fees).pipe(takeUntil(this.unSubs[2])).
subscribe((feesSeletor: { fees: Fees, apiCallStatus: ApiCallStatusPayload }) => {
this.errorMessages[1] = '';
this.apiCallStatusFees = feesSeletor.apiCallStatus;
if (this.apiCallStatusFees.status === APICallStatusEnum.ERROR) {
this.errorMessages[1] = (typeof (this.apiCallStatusFees.message) === 'object') ? JSON.stringify(this.apiCallStatusFees.message) : this.apiCallStatusFees.message ? this.apiCallStatusFees.message : '';
2021-08-28 21:03:18 +00:00
}
2021-12-29 23:08:41 +00:00
this.fees = feesSeletor.fees;
});
this.store.select(forwardingHistory).pipe(takeUntil(this.unSubs[3])).
subscribe((fhSeletor: { forwardingHistory: ListForwards, apiCallStatus: ApiCallStatusPayload }) => {
2021-12-29 23:08:41 +00:00
this.errorMessages[4] = '';
this.apiCallStatusFHistory = fhSeletor.apiCallStatus;
if (this.apiCallStatusFHistory.status === APICallStatusEnum.ERROR) {
this.errorMessages[4] = (typeof (this.apiCallStatusFHistory.message) === 'object') ? JSON.stringify(this.apiCallStatusFHistory.message) : this.apiCallStatusFHistory.message ? this.apiCallStatusFHistory.message : '';
2021-08-28 21:03:18 +00:00
}
if (fhSeletor.forwardingHistory && fhSeletor.forwardingHistory.listForwards && fhSeletor.forwardingHistory.listForwards.length) {
this.fees.totalTxCount = fhSeletor.forwardingHistory.listForwards.length;
2021-08-28 21:03:18 +00:00
}
2021-12-29 23:08:41 +00:00
});
this.store.select(feeRatesPerKB).pipe(takeUntil(this.unSubs[4])).
subscribe((frbSeletor: { feeRatesPerKB: FeeRates, apiCallStatus: ApiCallStatusPayload }) => {
this.errorMessages[5] = '';
this.apiCallStatusPerKB = frbSeletor.apiCallStatus;
if (this.apiCallStatusPerKB.status === APICallStatusEnum.ERROR) {
this.errorMessages[5] = (typeof (this.apiCallStatusPerKB.message) === 'object') ? JSON.stringify(this.apiCallStatusPerKB.message) : this.apiCallStatusPerKB.message ? this.apiCallStatusPerKB.message : '';
2020-01-05 04:28:40 +00:00
}
2021-12-29 23:08:41 +00:00
this.feeRatesPerKB = frbSeletor.feeRatesPerKB;
});
this.store.select(feeRatesPerKW).pipe(takeUntil(this.unSubs[5])).
subscribe((frwSeletor: { feeRatesPerKW: FeeRates, apiCallStatus: ApiCallStatusPayload }) => {
this.errorMessages[6] = '';
this.apiCallStatusPerKW = frwSeletor.apiCallStatus;
if (this.apiCallStatusPerKW.status === APICallStatusEnum.ERROR) {
this.errorMessages[6] = (typeof (this.apiCallStatusPerKW.message) === 'object') ? JSON.stringify(this.apiCallStatusPerKW.message) : this.apiCallStatusPerKW.message ? this.apiCallStatusPerKW.message : '';
2021-08-28 21:03:18 +00:00
}
2021-12-29 23:08:41 +00:00
this.feeRatesPerKW = frwSeletor.feeRatesPerKW;
2021-08-28 21:03:18 +00:00
});
2020-01-05 04:28:40 +00:00
}
ngOnDestroy() {
2021-08-28 21:03:18 +00:00
this.unSubs.forEach((completeSub) => {
completeSub.next(<any>null);
2020-01-05 04:28:40 +00:00
completeSub.complete();
});
}
2021-08-28 21:03:18 +00:00
2020-01-05 04:28:40 +00:00
}