2020-03-10 17:25:52 +00:00
|
|
|
import { Component, Input, OnInit, OnDestroy } from '@angular/core';
|
2020-01-08 23:57:51 +00:00
|
|
|
import { Router } from '@angular/router';
|
2020-03-10 17:25:52 +00:00
|
|
|
import { Subject } from 'rxjs';
|
2020-03-16 15:57:57 +00:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2020-03-10 17:25:52 +00:00
|
|
|
import { Store } from '@ngrx/store';
|
2019-12-11 22:39:39 +00:00
|
|
|
|
2021-02-21 19:02:31 +00:00
|
|
|
import { ScreenSizeEnum, LoopTypeEnum } from '../../../shared/services/consts-enums-functions';
|
2019-12-10 16:15:35 +00:00
|
|
|
import { Channel } from '../../../shared/models/lndModels';
|
2021-02-21 19:02:31 +00:00
|
|
|
import { LoopModalComponent } from '../../../shared/components/services/loop/loop-modal/loop-modal.component';
|
2020-03-16 15:57:57 +00:00
|
|
|
import { LoopService } from '../../../shared/services/loop.service';
|
2020-12-20 23:36:04 +00:00
|
|
|
import { CommonService } from '../../../shared/services/common.service';
|
2019-12-10 16:15:35 +00:00
|
|
|
|
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';
|
2020-03-10 17:25:52 +00:00
|
|
|
|
2019-12-10 16:15:35 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'rtl-channel-liquidity-info',
|
|
|
|
templateUrl: './channel-liquidity-info.component.html',
|
|
|
|
styleUrls: ['./channel-liquidity-info.component.scss']
|
|
|
|
})
|
2020-03-10 17:25:52 +00:00
|
|
|
export class ChannelLiquidityInfoComponent implements OnInit, OnDestroy {
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2019-12-10 16:15:35 +00:00
|
|
|
@Input() direction: string;
|
|
|
|
@Input() totalLiquidity: number;
|
|
|
|
@Input() allChannels: Channel[];
|
2021-08-28 21:03:18 +00:00
|
|
|
@Input() errorMessage: string;
|
2020-03-16 15:57:57 +00:00
|
|
|
public showLoop: boolean;
|
2020-03-10 17:25:52 +00:00
|
|
|
private targetConf = 6;
|
2020-12-20 23:36:04 +00:00
|
|
|
public screenSize = '';
|
|
|
|
public screenSizeEnum = ScreenSizeEnum;
|
2020-03-10 17:25:52 +00:00
|
|
|
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>) { }
|
2019-12-10 16:15:35 +00:00
|
|
|
|
2020-03-16 15:57:57 +00:00
|
|
|
ngOnInit() {
|
2020-12-20 23:36:04 +00:00
|
|
|
this.screenSize = this.commonService.getScreenSize();
|
2022-08-19 04:41:59 +00:00
|
|
|
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-03-16 15:57:57 +00:00
|
|
|
}
|
2020-01-08 23:57:51 +00:00
|
|
|
|
|
|
|
goToChannels() {
|
2020-12-20 23:36:04 +00:00
|
|
|
this.router.navigateByUrl('/lnd/connections');
|
2020-01-08 23:57:51 +00:00
|
|
|
}
|
2020-03-10 17:25:52 +00:00
|
|
|
|
2020-03-16 15:57:57 +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
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
2021-02-21 19:02:31 +00:00
|
|
|
}
|
2020-03-16 15:57:57 +00:00
|
|
|
|
2020-03-10 17:25:52 +00:00
|
|
|
ngOnDestroy() {
|
2021-08-28 21:03:18 +00:00
|
|
|
this.unSubs.forEach((completeSub) => {
|
2022-08-11 09:17:43 +00:00
|
|
|
completeSub.next(<any>null);
|
2020-03-10 17:25:52 +00:00
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-10 16:15:35 +00:00
|
|
|
}
|