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.
69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
5 years ago
|
import { Component, OnInit, Inject } from '@angular/core';
|
||
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||
|
import { Store } from '@ngrx/store';
|
||
|
|
||
5 years ago
|
import { Peer, GetInfo } from '../../../../shared/models/lndModels';
|
||
|
import { OpenChannelAlert } from '../../../../shared/models/alertData';
|
||
|
import { TRANS_TYPES } from '../../../../shared/services/consts-enums-functions';
|
||
5 years ago
|
|
||
|
import * as RTLActions from '../../../../store/rtl.actions';
|
||
|
import * as fromRTLReducer from '../../../../store/rtl.reducers';
|
||
|
|
||
|
@Component({
|
||
|
selector: 'rtl-open-channel',
|
||
|
templateUrl: './open-channel.component.html',
|
||
|
styleUrls: ['./open-channel.component.scss']
|
||
|
})
|
||
|
export class OpenChannelComponent implements OnInit {
|
||
5 years ago
|
public alertTitle: string;
|
||
5 years ago
|
public peer: Peer;
|
||
|
public information: GetInfo;
|
||
|
public totalBalance = 0;
|
||
|
public fundingAmount: number;
|
||
|
public isPrivate = false;
|
||
|
public selTransType = '0';
|
||
5 years ago
|
public newlyAdded = false;
|
||
5 years ago
|
public spendUnconfirmed = false;
|
||
5 years ago
|
public transTypeValue = {blocks: '', fees: ''};
|
||
|
public transTypes = TRANS_TYPES;
|
||
|
|
||
5 years ago
|
constructor(public dialogRef: MatDialogRef<OpenChannelComponent>, @Inject(MAT_DIALOG_DATA) public data: OpenChannelAlert, private store: Store<fromRTLReducer.RTLState>) { }
|
||
5 years ago
|
|
||
|
ngOnInit() {
|
||
5 years ago
|
this.peer = this.data.message.peer;
|
||
|
this.information = this.data.message.information;
|
||
|
this.totalBalance = this.data.message.balance;
|
||
5 years ago
|
this.newlyAdded = this.data.newlyAdded;
|
||
5 years ago
|
this.alertTitle = this.data.alertTitle;
|
||
5 years ago
|
}
|
||
|
|
||
|
onClose() {
|
||
|
this.dialogRef.close(false);
|
||
|
}
|
||
|
|
||
5 years ago
|
resetData() {
|
||
|
this.fundingAmount = null;
|
||
|
this.isPrivate = false;
|
||
5 years ago
|
this.spendUnconfirmed = false;
|
||
5 years ago
|
this.selTransType = '0';
|
||
|
this.transTypeValue = {blocks: '', fees: ''};
|
||
|
}
|
||
|
|
||
5 years ago
|
onOpenChannel() {
|
||
5 years ago
|
if (!this.fundingAmount || ((this.totalBalance - this.fundingAmount) < 0) || (this.selTransType === '1' && !this.transTypeValue.blocks) || (this.selTransType === '2' && !this.transTypeValue.fees)) { return true; }
|
||
5 years ago
|
let transTypeValue = '0';
|
||
|
if (this.selTransType === '1') {
|
||
|
transTypeValue = this.transTypeValue.blocks;
|
||
|
} else if (this.selTransType === '2') {
|
||
|
transTypeValue = this.transTypeValue.fees;
|
||
|
}
|
||
|
this.store.dispatch(new RTLActions.OpenSpinner('Opening Channel...'));
|
||
|
this.store.dispatch(new RTLActions.SaveNewChannel({
|
||
|
selectedPeerPubkey: this.peer.pub_key, fundingAmount: this.fundingAmount, private: this.isPrivate,
|
||
5 years ago
|
transType: this.selTransType, transTypeValue: transTypeValue, spendUnconfirmed: this.spendUnconfirmed
|
||
5 years ago
|
}));
|
||
|
this.dialogRef.close(false);
|
||
|
}
|
||
|
|
||
|
}
|