2019-03-19 00:13:01 +00:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2019-12-26 01:13:21 +00:00
|
|
|
import { Router } from '@angular/router';
|
2019-12-04 02:14:39 +00:00
|
|
|
import { Subject } from 'rxjs';
|
2019-12-04 23:14:34 +00:00
|
|
|
import { takeUntil, filter } from 'rxjs/operators';
|
2019-11-06 00:26:40 +00:00
|
|
|
import { Store } from '@ngrx/store';
|
2019-12-04 23:14:34 +00:00
|
|
|
import { Actions } from '@ngrx/effects';
|
2019-12-12 00:58:20 +00:00
|
|
|
import { faSmile, faFrown } from '@fortawesome/free-regular-svg-icons';
|
2019-12-26 09:15:55 +00:00
|
|
|
import { faAngleDoubleDown, faAngleDoubleUp, faChartPie, faBolt, faServer, faNetworkWired } from '@fortawesome/free-solid-svg-icons';
|
2019-03-19 00:13:01 +00:00
|
|
|
|
|
|
|
import { LoggerService } from '../../shared/services/logger.service';
|
2019-12-11 22:39:39 +00:00
|
|
|
import { CommonService } from '../../shared/services/common.service';
|
2019-12-13 04:01:04 +00:00
|
|
|
import { UserPersonaEnum, ScreenSizeEnum } from '../../shared/services/consts-enums-functions';
|
2019-12-10 16:15:35 +00:00
|
|
|
import { ChannelsStatus, GetInfo, Fees, Channel } from '../../shared/models/lndModels';
|
2019-09-01 19:55:52 +00:00
|
|
|
import { SelNodeChild } from '../../shared/models/RTLconfig';
|
2019-08-31 02:05:27 +00:00
|
|
|
import * as fromRTLReducer from '../../store/rtl.reducers';
|
2019-12-04 23:14:34 +00:00
|
|
|
import * as RTLActions from '../../store/rtl.actions';
|
2019-03-19 00:13:01 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'rtl-home',
|
|
|
|
templateUrl: './home.component.html',
|
|
|
|
styleUrls: ['./home.component.scss']
|
|
|
|
})
|
|
|
|
export class HomeComponent implements OnInit, OnDestroy {
|
2019-12-03 20:44:07 +00:00
|
|
|
public faSmile = faSmile;
|
2019-12-12 00:58:20 +00:00
|
|
|
public faFrown = faFrown;
|
2019-12-26 01:13:21 +00:00
|
|
|
public faAngleDoubleDown = faAngleDoubleDown;
|
|
|
|
public faAngleDoubleUp = faAngleDoubleUp;
|
2019-12-25 08:27:54 +00:00
|
|
|
public faChartPie = faChartPie;
|
|
|
|
public faBolt = faBolt;
|
2019-12-26 09:15:55 +00:00
|
|
|
public faServer = faServer;
|
2019-12-25 08:27:54 +00:00
|
|
|
public faNetworkWired = faNetworkWired;
|
2019-12-04 23:14:34 +00:00
|
|
|
public flgChildInfoUpdated = false;
|
2019-12-10 16:15:35 +00:00
|
|
|
public userPersonaEnum = UserPersonaEnum;
|
2019-12-04 02:14:39 +00:00
|
|
|
public activeChannels = 0;
|
|
|
|
public inactiveChannels = 0;
|
2019-12-26 03:24:31 +00:00
|
|
|
public channelBalances = {localBalance: 0, remoteBalance: 0, balancedness: '0'};
|
2019-09-01 19:55:52 +00:00
|
|
|
public selNode: SelNodeChild = {};
|
2020-03-16 15:57:57 +00:00
|
|
|
public showLoop = false;
|
2019-03-19 00:13:01 +00:00
|
|
|
public fees: Fees;
|
|
|
|
public information: GetInfo = {};
|
2019-12-25 08:27:54 +00:00
|
|
|
public balances = { onchain: -1, lightning: -1, total: 0 };
|
2019-12-10 16:15:35 +00:00
|
|
|
public allChannels: Channel[] = [];
|
|
|
|
public channelsStatus: ChannelsStatus = {};
|
2019-12-11 22:39:39 +00:00
|
|
|
public allChannelsCapacity: Channel[] = [];
|
2019-12-10 16:15:35 +00:00
|
|
|
public allInboundChannels: Channel[] = [];
|
|
|
|
public allOutboundChannels: Channel[] = [];
|
|
|
|
public totalInboundLiquidity = 0;
|
|
|
|
public totalOutboundLiquidity = 0;
|
2019-12-13 04:01:04 +00:00
|
|
|
public operatorCards = [];
|
|
|
|
public merchantCards = [];
|
|
|
|
public screenSize = '';
|
2019-12-15 00:55:50 +00:00
|
|
|
public operatorCardHeight = '330px';
|
|
|
|
public merchantCardHeight = '65px';
|
2019-12-26 03:24:31 +00:00
|
|
|
public sortField = 'Balance Score';
|
2019-08-24 20:35:31 +00:00
|
|
|
public flgLoading: Array<Boolean | 'error'> = [true, true, true, true, true, true, true, true]; // 0: Info, 1: Fee, 2: Wallet, 3: Channel, 4: Network
|
2019-12-04 02:14:39 +00:00
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject()];
|
2019-12-03 20:44:07 +00:00
|
|
|
|
2019-12-26 01:13:21 +00:00
|
|
|
constructor(private logger: LoggerService, private store: Store<fromRTLReducer.RTLState>, private actions$: Actions, private commonService: CommonService, private router: Router) {
|
2019-12-13 04:01:04 +00:00
|
|
|
this.screenSize = this.commonService.getScreenSize();
|
|
|
|
if(this.screenSize === ScreenSizeEnum.XS) {
|
|
|
|
this.operatorCards = [
|
2019-12-26 09:15:55 +00:00
|
|
|
{ id: 'node', icon: this.faServer, title: 'Node Information', cols: 10, rows: 1 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'balance', goTo: 'On-Chain', link: '/lnd/onchain', icon: this.faChartPie, title: 'Balances', cols: 10, rows: 1 },
|
2020-01-04 20:24:17 +00:00
|
|
|
{ id: 'fee', goTo: 'Routing', link: '/lnd/routing', icon: this.faBolt, title: 'Routing Fee', cols: 10, rows: 1 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'status', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faNetworkWired, title: 'Channels', cols: 10, rows: 1 },
|
|
|
|
{ id: 'capacity', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faNetworkWired, title: 'Channels Capacity', cols: 10, rows: 2 }
|
2019-12-13 04:01:04 +00:00
|
|
|
];
|
|
|
|
this.merchantCards = [
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'balance', goTo: 'On-Chain', link: '/lnd/onchain', icon: this.faChartPie, title: 'Balances', cols: 6, rows: 4 },
|
2020-05-03 19:52:38 +00:00
|
|
|
{ id: 'transactions', goTo: 'Transactions', link: '/lnd/transactions', title: '', cols: 6, rows: 6 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'inboundLiq', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faAngleDoubleDown, title: 'In-Bound Liquidity', cols: 6, rows: 8 },
|
|
|
|
{ id: 'outboundLiq', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faAngleDoubleUp, title: 'Out-Bound Liquidity', cols: 6, rows: 8 }
|
2019-12-13 04:01:04 +00:00
|
|
|
];
|
|
|
|
} else if(this.screenSize === ScreenSizeEnum.SM || this.screenSize === ScreenSizeEnum.MD) {
|
|
|
|
this.operatorCards = [
|
2019-12-26 09:15:55 +00:00
|
|
|
{ id: 'node', icon: this.faServer, title: 'Node Information', cols: 5, rows: 1 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'balance', goTo: 'On-Chain', link: '/lnd/onchain', icon: this.faChartPie, title: 'Balances', cols: 5, rows: 1 },
|
2020-01-04 20:24:17 +00:00
|
|
|
{ id: 'fee', goTo: 'Routing', link: '/lnd/routing', icon: this.faBolt, title: 'Routing Fee', cols: 5, rows: 1 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'status', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faNetworkWired, title: 'Channels', cols: 5, rows: 1 },
|
|
|
|
{ id: 'capacity', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faNetworkWired, title: 'Channels Capacity', cols: 10, rows: 2 }
|
2019-12-13 04:01:04 +00:00
|
|
|
];
|
|
|
|
this.merchantCards = [
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'balance', goTo: 'On-Chain', link: '/lnd/onchain', icon: this.faChartPie, title: 'Balances', cols: 3, rows: 4 },
|
|
|
|
{ id: 'transactions', goTo: 'Transactions', link: '/lnd/transactions', title: '', cols: 3, rows: 4 },
|
|
|
|
{ id: 'inboundLiq', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faAngleDoubleDown, title: 'In-Bound Liquidity', cols: 3, rows: 8 },
|
|
|
|
{ id: 'outboundLiq', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faAngleDoubleUp, title: 'Out-Bound Liquidity', cols: 3, rows: 8 }
|
2019-12-13 04:01:04 +00:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
this.operatorCards = [
|
2019-12-26 09:15:55 +00:00
|
|
|
{ id: 'node', icon: this.faServer, title: 'Node Information', cols: 3, rows: 1 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'balance', goTo: 'On-Chain', link: '/lnd/onchain', icon: this.faChartPie, title: 'Balances', cols: 3, rows: 1 },
|
|
|
|
{ id: 'capacity', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faNetworkWired, title: 'Channels Capacity', cols: 4, rows: 2 },
|
2020-01-04 20:24:17 +00:00
|
|
|
{ id: 'fee', goTo: 'Routing', link: '/lnd/routing', icon: this.faBolt, title: 'Routing Fee', cols: 3, rows: 1 },
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'status', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faNetworkWired, title: 'Channels', cols: 3, rows: 1 }
|
2019-12-03 20:44:07 +00:00
|
|
|
];
|
2019-12-13 04:01:04 +00:00
|
|
|
this.merchantCards = [
|
2019-12-26 01:13:21 +00:00
|
|
|
{ id: 'balance', goTo: 'On-Chain', link: '/lnd/onchain', icon: this.faChartPie, title: 'Balances', cols: 2, rows: 5 },
|
|
|
|
{ id: 'inboundLiq', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faAngleDoubleDown, title: 'In-Bound Liquidity', cols: 2, rows: 10 },
|
|
|
|
{ id: 'outboundLiq', goTo: 'Channels', link: '/lnd/peerschannels', icon: this.faAngleDoubleUp, title: 'Out-Bound Liquidity', cols: 2, rows: 10 },
|
|
|
|
{ id: 'transactions', goTo: 'Transactions', link: '/lnd/transactions', title: '', cols: 2, rows: 5 }
|
2019-12-10 16:15:35 +00:00
|
|
|
];
|
2019-12-13 04:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-19 00:13:01 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2019-09-01 19:55:52 +00:00
|
|
|
this.store.select('lnd')
|
2019-12-04 02:14:39 +00:00
|
|
|
.pipe(takeUntil(this.unSubs[1]))
|
2019-08-31 02:05:27 +00:00
|
|
|
.subscribe((rtlStore) => {
|
2019-12-14 01:23:46 +00:00
|
|
|
this.flgLoading = [true, true, true, true, true, true, true, true];
|
2019-09-01 19:55:52 +00:00
|
|
|
rtlStore.effectErrorsLnd.forEach(effectsErr => {
|
2019-03-19 00:13:01 +00:00
|
|
|
if (effectsErr.action === 'FetchInfo') {
|
|
|
|
this.flgLoading[0] = 'error';
|
|
|
|
}
|
|
|
|
if (effectsErr.action === 'FetchFees') {
|
|
|
|
this.flgLoading[1] = 'error';
|
|
|
|
}
|
|
|
|
if (effectsErr.action === 'FetchBalance/blockchain') {
|
|
|
|
this.flgLoading[2] = 'error';
|
|
|
|
}
|
|
|
|
if (effectsErr.action === 'FetchBalance/channels') {
|
|
|
|
this.flgLoading[3] = 'error';
|
|
|
|
}
|
|
|
|
if (effectsErr.action === 'FetchChannels/all') {
|
|
|
|
this.flgLoading[5] = 'error';
|
2019-12-04 23:14:34 +00:00
|
|
|
}
|
|
|
|
if (effectsErr.action === 'FetchChannels/pending') {
|
2019-03-19 00:13:01 +00:00
|
|
|
this.flgLoading[6] = 'error';
|
|
|
|
}
|
|
|
|
});
|
2019-09-01 19:55:52 +00:00
|
|
|
this.selNode = rtlStore.nodeSettings;
|
2020-03-16 15:57:57 +00:00
|
|
|
this.showLoop = (this.selNode.swapServerUrl && this.selNode.swapServerUrl.trim() !== '') ? true : false;
|
2019-08-24 20:35:31 +00:00
|
|
|
this.information = rtlStore.information;
|
|
|
|
if (this.flgLoading[0] !== 'error') {
|
2020-03-10 17:25:52 +00:00
|
|
|
this.flgLoading[0] = ( this.information.identity_pubkey) ? false : true;
|
2019-08-24 20:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.fees = rtlStore.fees;
|
|
|
|
if (this.flgLoading[1] !== 'error') {
|
2020-03-10 17:25:52 +00:00
|
|
|
this.flgLoading[1] = ( this.fees.day_fee_sum) ? false : true;
|
2019-08-24 20:35:31 +00:00
|
|
|
}
|
2019-12-04 23:14:34 +00:00
|
|
|
this.balances.onchain = (+rtlStore.blockchainBalance.total_balance >= 0) ? +rtlStore.blockchainBalance.total_balance : 0;
|
2019-08-24 20:35:31 +00:00
|
|
|
if (this.flgLoading[2] !== 'error') {
|
2019-12-04 23:14:34 +00:00
|
|
|
this.flgLoading[2] = false;
|
2019-08-24 20:35:31 +00:00
|
|
|
}
|
2019-12-26 03:24:31 +00:00
|
|
|
let local = (rtlStore.totalLocalBalance) ? +rtlStore.totalLocalBalance : 0;
|
|
|
|
let remote = (rtlStore.totalRemoteBalance) ? +rtlStore.totalRemoteBalance : 0;
|
|
|
|
let total = local + remote;
|
|
|
|
this.channelBalances = { localBalance: local, remoteBalance: remote, balancedness: (1 - Math.abs((local-remote)/total)).toFixed(3) };
|
2019-08-24 20:35:31 +00:00
|
|
|
|
2019-12-04 23:14:34 +00:00
|
|
|
this.balances.lightning = rtlStore.totalLocalBalance;
|
|
|
|
if (this.flgLoading[5] !== 'error') {
|
|
|
|
this.flgLoading[5] = false;
|
2019-08-24 20:35:31 +00:00
|
|
|
}
|
2019-12-25 08:27:54 +00:00
|
|
|
this.balances.total = this.balances.lightning + this.balances.onchain;
|
2019-12-04 23:14:34 +00:00
|
|
|
this.balances = Object.assign({}, this.balances);
|
|
|
|
|
2019-08-24 20:35:31 +00:00
|
|
|
this.activeChannels = rtlStore.numberOfActiveChannels;
|
|
|
|
this.inactiveChannels = rtlStore.numberOfInactiveChannels;
|
2019-12-03 20:44:07 +00:00
|
|
|
this.channelsStatus = {
|
|
|
|
active: { channels: rtlStore.numberOfActiveChannels, capacity: rtlStore.totalCapacityActive },
|
|
|
|
inactive: { channels: rtlStore.numberOfInactiveChannels, capacity: rtlStore.totalCapacityInactive },
|
2019-12-25 08:27:54 +00:00
|
|
|
pending: { channels: rtlStore.numberOfPendingChannels.open.num_channels, capacity: rtlStore.numberOfPendingChannels.open.limbo_balance },
|
|
|
|
closing: {
|
|
|
|
channels: rtlStore.numberOfPendingChannels.closing.num_channels + rtlStore.numberOfPendingChannels.force_closing.num_channels + rtlStore.numberOfPendingChannels.waiting_close.num_channels,
|
2019-12-26 01:13:21 +00:00
|
|
|
capacity: rtlStore.numberOfPendingChannels.total_limbo_balance
|
2019-12-25 08:27:54 +00:00
|
|
|
}
|
2019-12-03 20:44:07 +00:00
|
|
|
};
|
2019-12-04 23:14:34 +00:00
|
|
|
if (rtlStore.totalLocalBalance >= 0 && rtlStore.totalRemoteBalance >= 0 && this.flgLoading[5] !== 'error') {
|
|
|
|
this.flgLoading[5] = false;
|
2019-08-24 20:35:31 +00:00
|
|
|
}
|
2019-12-26 09:15:55 +00:00
|
|
|
if (rtlStore.numberOfPendingChannels && this.flgLoading[6] !== 'error') {
|
|
|
|
this.flgLoading[6] = false;
|
|
|
|
}
|
2019-12-10 16:15:35 +00:00
|
|
|
this.totalInboundLiquidity = 0;
|
|
|
|
this.totalOutboundLiquidity = 0;
|
2019-12-04 02:14:39 +00:00
|
|
|
this.allChannels = rtlStore.allChannels.filter(channel => channel.active === true);
|
2019-12-11 22:39:39 +00:00
|
|
|
this.allChannelsCapacity = JSON.parse(JSON.stringify(this.commonService.sortDescByKey(this.allChannels, 'balancedness')));
|
2019-12-20 23:24:31 +00:00
|
|
|
this.allInboundChannels = JSON.parse(JSON.stringify(this.commonService.sortDescByKey(this.allChannels.filter(channel => channel.remote_balance > 0), 'remote_balance')));
|
|
|
|
this.allOutboundChannels = JSON.parse(JSON.stringify(this.commonService.sortDescByKey(this.allChannels.filter(channel => channel.local_balance > 0), 'local_balance')));
|
2019-12-10 16:15:35 +00:00
|
|
|
this.allChannels.forEach(channel => {
|
|
|
|
this.totalInboundLiquidity = this.totalInboundLiquidity + +channel.remote_balance;
|
|
|
|
this.totalOutboundLiquidity = this.totalOutboundLiquidity + +channel.local_balance;
|
|
|
|
});
|
2020-01-12 19:21:04 +00:00
|
|
|
|
2019-12-05 20:16:41 +00:00
|
|
|
if (this.balances.lightning >= 0 && this.balances.onchain >= 0 && this.fees.month_fee_sum >= 0) {
|
|
|
|
this.flgChildInfoUpdated = true;
|
|
|
|
} else {
|
|
|
|
this.flgChildInfoUpdated = false;
|
|
|
|
}
|
2019-03-19 00:13:01 +00:00
|
|
|
this.logger.info(rtlStore);
|
|
|
|
});
|
2019-12-04 23:14:34 +00:00
|
|
|
this.actions$.pipe(takeUntil(this.unSubs[2]),
|
|
|
|
filter((action) => action.type === RTLActions.FETCH_FEES || action.type === RTLActions.SET_FEES))
|
|
|
|
.subscribe(action => {
|
|
|
|
if(action.type === RTLActions.FETCH_FEES) {
|
|
|
|
this.flgChildInfoUpdated = false;
|
|
|
|
}
|
|
|
|
if(action.type === RTLActions.SET_FEES) {
|
|
|
|
this.flgChildInfoUpdated = true;
|
|
|
|
}
|
|
|
|
});
|
2019-03-19 00:13:01 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 01:13:21 +00:00
|
|
|
onNavigateTo(link: string) {
|
|
|
|
this.router.navigateByUrl(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
onsortChannelsBy() {
|
2019-12-26 03:24:31 +00:00
|
|
|
if (this.sortField === 'Balance Score') {
|
2019-12-26 01:13:21 +00:00
|
|
|
this.sortField = 'Capacity';
|
|
|
|
this.allChannelsCapacity = this.allChannels.sort(function (a, b) {
|
|
|
|
const x = +a.local_balance + +a.remote_balance;
|
|
|
|
const y = +b.local_balance + +b.remote_balance;
|
|
|
|
return ((x > y) ? -1 : ((x < y) ? 1 : 0));
|
|
|
|
});
|
|
|
|
} else {
|
2019-12-26 03:24:31 +00:00
|
|
|
this.sortField = 'Balance Score';
|
2019-12-26 01:13:21 +00:00
|
|
|
this.allChannelsCapacity = JSON.parse(JSON.stringify(this.commonService.sortDescByKey(this.allChannels, 'balancedness')));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 00:13:01 +00:00
|
|
|
ngOnDestroy() {
|
2019-12-04 02:14:39 +00:00
|
|
|
this.unSubs.forEach(completeSub => {
|
2019-03-19 00:13:01 +00:00
|
|
|
completeSub.next();
|
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|