2022-05-18 20:52:16 +00:00
|
|
|
import { Component, OnInit, Inject, OnDestroy, ViewChild } from '@angular/core';
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { takeUntil, filter } from 'rxjs/operators';
|
|
|
|
import { Actions } from '@ngrx/effects';
|
|
|
|
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
|
|
import { LookupNode } from '../../../shared/models/clnModels';
|
|
|
|
import { CLNOpenLiquidityChannelAlert } from '../../../shared/models/alertData';
|
|
|
|
import { APICallStatusEnum, CLNActions } from '../../../shared/services/consts-enums-functions';
|
|
|
|
|
|
|
|
import { RTLState } from '../../../store/rtl.state';
|
|
|
|
import { saveNewChannel } from '../../store/cln.actions';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'rtl-cln-open-liquidity-channel',
|
|
|
|
templateUrl: './open-liquidity-channel-modal.component.html',
|
|
|
|
styleUrls: ['./open-liquidity-channel-modal.component.scss']
|
|
|
|
})
|
|
|
|
export class CLNOpenLiquidityChannelComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
public faExclamationTriangle = faExclamationTriangle;
|
|
|
|
@ViewChild('form', { static: true }) form: any;
|
|
|
|
public alertTitle: string;
|
|
|
|
public totalBalance = 0;
|
2022-08-08 03:18:23 +00:00
|
|
|
public node: LookupNode = {};
|
2022-05-18 20:52:16 +00:00
|
|
|
public requestedAmount = 0;
|
|
|
|
public feeRate = 0;
|
|
|
|
public localAmount = 0;
|
|
|
|
public channelConnectionError = '';
|
|
|
|
public displayedColumns = ['type', 'address', 'port'];
|
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject()];
|
|
|
|
|
|
|
|
constructor(public dialogRef: MatDialogRef<CLNOpenLiquidityChannelComponent>, @Inject(MAT_DIALOG_DATA) public data: CLNOpenLiquidityChannelAlert, private actions: Actions, private store: Store<RTLState>) { }
|
|
|
|
|
|
|
|
ngOnInit() {
|
2022-08-08 03:18:23 +00:00
|
|
|
this.alertTitle = this.data.alertTitle || '';
|
|
|
|
this.totalBalance = this.data.message?.balance || 0;
|
|
|
|
this.node = this.data.message?.node || {};
|
|
|
|
this.requestedAmount = this.data.message?.requestedAmount || 0;
|
|
|
|
this.feeRate = this.data.message?.feeRate || 0;
|
|
|
|
this.localAmount = this.data.message?.localAmount || 0;
|
2022-05-18 20:52:16 +00:00
|
|
|
this.actions.pipe(
|
|
|
|
takeUntil(this.unSubs[0]),
|
|
|
|
filter((action) => action.type === CLNActions.UPDATE_API_CALL_STATUS_CLN || action.type === CLNActions.FETCH_CHANNELS_CLN)).
|
|
|
|
subscribe((action: any) => {
|
|
|
|
if (action.type === CLNActions.UPDATE_API_CALL_STATUS_CLN && action.payload.status === APICallStatusEnum.ERROR && action.payload.action === 'SaveNewChannel') {
|
|
|
|
this.channelConnectionError = action.payload.message;
|
|
|
|
}
|
|
|
|
if (action.type === CLNActions.FETCH_CHANNELS_CLN) {
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onClose() {
|
|
|
|
this.dialogRef.close(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetData() {
|
|
|
|
this.form.resetForm();
|
2022-08-08 03:18:23 +00:00
|
|
|
this.form.controls.ramount.setValue(this.data.message?.requestedAmount);
|
|
|
|
this.form.controls.feerate.setValue(this.data.message?.feeRate);
|
|
|
|
this.form.controls.lamount.setValue(this.data.message?.localAmount);
|
2022-05-19 19:47:41 +00:00
|
|
|
this.calculateFee();
|
2022-05-18 20:52:16 +00:00
|
|
|
this.channelConnectionError = '';
|
|
|
|
}
|
|
|
|
|
2022-05-19 19:47:41 +00:00
|
|
|
calculateFee() {
|
2022-10-19 00:58:09 +00:00
|
|
|
this.node.channel_opening_fee = (+(this.node.option_will_fund?.lease_fee_base_msat || 0) / 1000) + (this.requestedAmount * (+(this.node.option_will_fund?.lease_fee_basis || 0)) / 10000) + ((+(this.node.option_will_fund?.funding_weight || 0) / 4) * this.feeRate);
|
2022-05-19 19:47:41 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 20:52:16 +00:00
|
|
|
onOpenChannel(): boolean | void {
|
2022-08-08 03:18:23 +00:00
|
|
|
if (!this.node || !this.node.option_will_fund || !this.requestedAmount || !this.feeRate || !this.localAmount || this.localAmount < 20000) {
|
2022-05-18 20:52:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-12-06 04:32:05 +00:00
|
|
|
const newChannel = { peerId: this.node.nodeid || '', amount: this.localAmount.toString(), feeRate: this.feeRate + 'perkb', requestAmount: this.requestedAmount.toString(), compactLease: this.node.option_will_fund.compact_lease, announce: true };
|
2022-05-18 20:52:16 +00:00
|
|
|
this.store.dispatch(saveNewChannel({ payload: newChannel }));
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.unSubs.forEach((completeSub) => {
|
2022-08-08 03:18:23 +00:00
|
|
|
completeSub.next(<any>null);
|
2022-05-18 20:52:16 +00:00
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|