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
|
|
|
|
2020-12-20 23:36:04 +00:00
|
|
|
import { ScreenSizeEnum, SwapTypeEnum } from '../../../shared/services/consts-enums-functions';
|
2019-12-10 16:15:35 +00:00
|
|
|
import { Channel } from '../../../shared/models/lndModels';
|
2020-03-16 15:57:57 +00:00
|
|
|
import { LoopModalComponent } from '../../loop/loop-modal/loop-modal.component';
|
|
|
|
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
|
|
|
|
2020-03-10 17:25:52 +00:00
|
|
|
import * as fromRTLReducer from '../../../store/rtl.reducers';
|
2020-03-16 15:57:57 +00:00
|
|
|
import * as RTLActions from '../../../store/rtl.actions';
|
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 {
|
2019-12-10 16:15:35 +00:00
|
|
|
@Input() direction: string;
|
|
|
|
@Input() totalLiquidity: number;
|
|
|
|
@Input() allChannels: Channel[];
|
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()];
|
|
|
|
|
2020-12-20 23:36:04 +00:00
|
|
|
constructor(private router: Router, private loopService: LoopService, private commonService: CommonService, private store: Store<fromRTLReducer.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();
|
2020-03-16 15:57:57 +00:00
|
|
|
this.store.select('lnd')
|
|
|
|
.pipe(takeUntil(this.unSubs[0]))
|
|
|
|
.subscribe((rtlStore) => {
|
|
|
|
this.showLoop = (rtlStore.nodeSettings.swapServerUrl && rtlStore.nodeSettings.swapServerUrl.trim() !== '') ? true : false;
|
|
|
|
});
|
|
|
|
}
|
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) {
|
|
|
|
this.store.dispatch(new RTLActions.OpenSpinner('Getting Terms and Quotes...'));
|
|
|
|
this.loopService.getLoopOutTermsAndQuotes(this.targetConf)
|
|
|
|
.pipe(takeUntil(this.unSubs[1]))
|
|
|
|
.subscribe(response => {
|
|
|
|
this.store.dispatch(new RTLActions.CloseSpinner());
|
|
|
|
this.store.dispatch(new RTLActions.OpenAlert({ minHeight: '56rem', data: {
|
|
|
|
channel: channel,
|
|
|
|
minQuote: response[0],
|
|
|
|
maxQuote: response[1],
|
|
|
|
direction: SwapTypeEnum.LOOP_OUT,
|
|
|
|
component: LoopModalComponent
|
|
|
|
}}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-10 17:25:52 +00:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.unSubs.forEach(completeSub => {
|
|
|
|
completeSub.next();
|
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-10 16:15:35 +00:00
|
|
|
}
|