2
0
mirror of https://github.com/Ride-The-Lightning/RTL synced 2024-10-31 09:20:27 +00:00
RTL/src/app/lnd/home/channel-liquidity-info/channel-liquidity-info.component.ts

74 lines
2.6 KiB
TypeScript
Raw Normal View History

import { Component, Input, OnInit, OnDestroy } from '@angular/core';
2020-01-08 23:57:51 +00:00
import { Router } from '@angular/router';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { ScreenSizeEnum, LoopTypeEnum } from '../../../shared/services/consts-enums-functions';
import { Channel } from '../../../shared/models/lndModels';
import { LoopModalComponent } from '../../../shared/components/services/loop/loop-modal/loop-modal.component';
import { LoopService } from '../../../shared/services/loop.service';
import { CommonService } from '../../../shared/services/common.service';
2021-12-29 23:08:41 +00:00
import { RTLState } from '../../../store/rtl.state';
import { openAlert } from '../../../store/rtl.actions';
import { SelNodeChild } from '../../../shared/models/RTLconfig';
import { lndNodeSettings } from '../../store/lnd.selector';
@Component({
selector: 'rtl-channel-liquidity-info',
templateUrl: './channel-liquidity-info.component.html',
styleUrls: ['./channel-liquidity-info.component.scss']
})
export class ChannelLiquidityInfoComponent implements OnInit, OnDestroy {
2021-08-28 21:03:18 +00:00
@Input() direction: string;
@Input() totalLiquidity: number;
@Input() allChannels: Channel[];
2021-08-28 21:03:18 +00:00
@Input() errorMessage: string;
public showLoop: boolean;
private targetConf = 6;
public screenSize = '';
public screenSizeEnum = ScreenSizeEnum;
private unSubs: Array<Subject<void>> = [new Subject(), new Subject()];
2021-12-29 23:08:41 +00:00
constructor(private router: Router, private loopService: LoopService, private commonService: CommonService, private store: Store<RTLState>) { }
ngOnInit() {
this.screenSize = this.commonService.getScreenSize();
this.store.select(lndNodeSettings).pipe(takeUntil(this.unSubs[0])).subscribe((nodeSettings: SelNodeChild | null) => {
this.showLoop = !!((nodeSettings?.swapServerUrl && nodeSettings.swapServerUrl.trim() !== ''));
2021-12-29 23:08:41 +00:00
});
}
2020-01-08 23:57:51 +00:00
goToChannels() {
this.router.navigateByUrl('/lnd/connections');
2020-01-08 23:57:51 +00:00
}
onLoopOut(channel: Channel) {
2021-08-28 21:03:18 +00:00
this.loopService.getLoopOutTermsAndQuotes(this.targetConf).
pipe(takeUntil(this.unSubs[1])).
subscribe((response) => {
2021-12-29 23:08:41 +00:00
this.store.dispatch(openAlert({
payload: {
minHeight: '56rem', data: {
channel: channel,
minQuote: response[0],
maxQuote: response[1],
direction: LoopTypeEnum.LOOP_OUT,
component: LoopModalComponent
}
2021-08-28 21:03:18 +00:00
}
}));
});
}
ngOnDestroy() {
2021-08-28 21:03:18 +00:00
this.unSubs.forEach((completeSub) => {
completeSub.next(<any>null);
completeSub.complete();
});
}
}