2020-01-06 15:42:42 +00:00
|
|
|
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
|
2020-01-03 20:04:00 +00:00
|
|
|
import { DecimalPipe } from '@angular/common';
|
2020-08-14 20:55:37 +00:00
|
|
|
import { Subject, combineLatest } from 'rxjs';
|
2020-05-03 19:52:38 +00:00
|
|
|
import { takeUntil, filter } from 'rxjs/operators';
|
2020-01-03 20:04:00 +00:00
|
|
|
import { Store } from '@ngrx/store';
|
2020-05-03 19:52:38 +00:00
|
|
|
import { Actions } from '@ngrx/effects';
|
2020-07-07 17:57:15 +00:00
|
|
|
import { MatDialogRef } from '@angular/material/dialog';
|
2020-05-03 19:52:38 +00:00
|
|
|
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
|
2020-01-03 20:04:00 +00:00
|
|
|
|
|
|
|
import { SelNodeChild, GetInfoRoot } from '../../../shared/models/RTLconfig';
|
2020-08-14 20:55:37 +00:00
|
|
|
import { GetInfo, Balance, OnChain, Transaction } from '../../../shared/models/clModels';
|
2020-07-07 17:57:15 +00:00
|
|
|
import { CURRENCY_UNITS, CurrencyUnitEnum, CURRENCY_UNIT_FORMATS, ADDRESS_TYPES, FEE_RATE_TYPES } from '../../../shared/services/consts-enums-functions';
|
2020-01-03 20:04:00 +00:00
|
|
|
import { RTLConfiguration } from '../../../shared/models/RTLconfig';
|
|
|
|
import { CommonService } from '../../../shared/services/common.service';
|
|
|
|
import { LoggerService } from '../../../shared/services/logger.service';
|
|
|
|
|
2020-07-07 17:57:15 +00:00
|
|
|
import * as CLActions from '../../store/cl.actions';
|
2020-01-03 20:04:00 +00:00
|
|
|
import * as RTLActions from '../../../store/rtl.actions';
|
|
|
|
import * as fromRTLReducer from '../../../store/rtl.reducers';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'rtl-cl-on-chain-send',
|
|
|
|
templateUrl: './on-chain-send.component.html',
|
|
|
|
styleUrls: ['./on-chain-send.component.scss']
|
|
|
|
})
|
|
|
|
export class CLOnChainSendComponent implements OnInit, OnDestroy {
|
2020-05-03 19:52:38 +00:00
|
|
|
@ViewChild('form', { static: false }) form: any;
|
|
|
|
public faExclamationTriangle = faExclamationTriangle;
|
2020-01-03 20:04:00 +00:00
|
|
|
public selNode: SelNodeChild = {};
|
|
|
|
public appConfig: RTLConfiguration;
|
|
|
|
public nodeData: GetInfoRoot;
|
|
|
|
public addressTypes = [];
|
2020-08-14 20:55:37 +00:00
|
|
|
public transactions: Transaction[] = [];
|
|
|
|
public selUTXOs = [];
|
2020-08-17 19:58:00 +00:00
|
|
|
public flgUseAllBalance = false;
|
|
|
|
public totalSelectedUTXOAmount = null;
|
2020-01-03 20:04:00 +00:00
|
|
|
public flgLoadingWallet: Boolean | 'error' = true;
|
|
|
|
public selectedAddress = ADDRESS_TYPES[1];
|
2020-07-07 17:57:15 +00:00
|
|
|
public blockchainBalance: Balance = {};
|
|
|
|
public information: GetInfo = {};
|
2020-08-22 22:50:13 +00:00
|
|
|
public isCompatibleVersion = false;
|
2020-01-03 20:04:00 +00:00
|
|
|
public newAddress = '';
|
2020-07-07 17:57:15 +00:00
|
|
|
public transaction: OnChain = {};
|
2020-01-03 20:04:00 +00:00
|
|
|
public feeRateTypes = FEE_RATE_TYPES;
|
|
|
|
public flgMinConf = false;
|
2020-05-03 19:52:38 +00:00
|
|
|
public sendFundError = '';
|
2020-01-10 13:31:38 +00:00
|
|
|
public fiatConversion = false;
|
2020-01-03 20:04:00 +00:00
|
|
|
public amountUnits = CURRENCY_UNITS;
|
|
|
|
public selAmountUnit = CURRENCY_UNITS[0];
|
|
|
|
public currConvertorRate = {};
|
|
|
|
public unitConversionValue = 0;
|
|
|
|
public currencyUnitFormats = CURRENCY_UNIT_FORMATS;
|
2020-08-14 20:55:37 +00:00
|
|
|
public advancedTitle = 'Advanced Options';
|
2020-01-03 20:04:00 +00:00
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject()];
|
|
|
|
|
2020-05-03 19:52:38 +00:00
|
|
|
constructor(public dialogRef: MatDialogRef<CLOnChainSendComponent>, private logger: LoggerService, private store: Store<fromRTLReducer.RTLState>, private commonService: CommonService, private decimalPipe: DecimalPipe, private actions$: Actions) {}
|
2020-01-03 20:04:00 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-08-14 20:55:37 +00:00
|
|
|
combineLatest(
|
|
|
|
this.store.select('root'),
|
|
|
|
this.store.select('cl'))
|
2020-01-03 20:04:00 +00:00
|
|
|
.pipe(takeUntil(this.unSubs[0]))
|
2020-08-14 20:55:37 +00:00
|
|
|
.subscribe(([rootStore, rtlStore]) => {
|
2020-01-10 13:31:38 +00:00
|
|
|
this.fiatConversion = rootStore.selNode.settings.fiatConversion;
|
2020-01-03 20:04:00 +00:00
|
|
|
this.amountUnits = rootStore.selNode.settings.currencyUnits;
|
|
|
|
this.appConfig = rootStore.appConfig;
|
|
|
|
this.nodeData = rootStore.nodeData;
|
2020-08-22 22:50:13 +00:00
|
|
|
this.information = rtlStore.information;
|
|
|
|
this.isCompatibleVersion =
|
|
|
|
this.commonService.isVersionCompatible(this.information.version, '0.9.0')
|
|
|
|
&& this.commonService.isVersionCompatible(this.information.api_version, '0.4.0');
|
2020-08-14 20:55:37 +00:00
|
|
|
this.transactions = this.commonService.sortAscByKey(rtlStore.transactions.filter(tran => tran.status === 'confirmed'), 'value');
|
2020-01-03 20:04:00 +00:00
|
|
|
this.logger.info(rootStore);
|
2020-08-14 20:55:37 +00:00
|
|
|
this.logger.info(rtlStore);
|
2020-01-03 20:04:00 +00:00
|
|
|
});
|
2020-05-03 19:52:38 +00:00
|
|
|
this.actions$.pipe(takeUntil(this.unSubs[1]),
|
2020-07-07 17:57:15 +00:00
|
|
|
filter(action => action.type === CLActions.EFFECT_ERROR_CL || action.type === CLActions.SET_CHANNEL_TRANSACTION_RES_CL))
|
|
|
|
.subscribe((action: CLActions.EffectError | CLActions.SetChannelTransactionRes) => {
|
|
|
|
if (action.type === CLActions.SET_CHANNEL_TRANSACTION_RES_CL) {
|
2020-05-03 19:52:38 +00:00
|
|
|
this.store.dispatch(new RTLActions.OpenSnackBar('Fund Sent Successfully!'));
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2020-07-07 17:57:15 +00:00
|
|
|
if (action.type === CLActions.EFFECT_ERROR_CL && action.payload.action === 'SetChannelTransaction') {
|
2020-05-03 19:52:38 +00:00
|
|
|
this.sendFundError = action.payload.message;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSendFunds() {
|
|
|
|
if(this.invalidValues) { return true; }
|
2020-05-03 19:52:38 +00:00
|
|
|
this.sendFundError = '';
|
2020-08-17 19:58:00 +00:00
|
|
|
if (this.flgUseAllBalance) {
|
|
|
|
this.transaction.satoshis = 'all';
|
|
|
|
}
|
2020-08-14 20:55:37 +00:00
|
|
|
if (this.selUTXOs.length && this.selUTXOs.length > 0) {
|
|
|
|
this.transaction.utxos = [];
|
|
|
|
this.selUTXOs.forEach(utxo => this.transaction.utxos.push(utxo.txid + ':' + utxo.output));
|
|
|
|
}
|
2020-05-03 19:52:38 +00:00
|
|
|
this.store.dispatch(new RTLActions.OpenSpinner('Sending Funds...'));
|
2020-01-03 20:04:00 +00:00
|
|
|
if(this.transaction.satoshis && this.selAmountUnit !== CurrencyUnitEnum.SATS) {
|
2020-08-17 19:58:00 +00:00
|
|
|
this.commonService.convertCurrency(+this.transaction.satoshis, this.selAmountUnit === this.amountUnits[2] ? CurrencyUnitEnum.OTHER : this.selAmountUnit, this.amountUnits[2], this.fiatConversion)
|
2020-05-03 19:52:38 +00:00
|
|
|
.pipe(takeUntil(this.unSubs[2]))
|
2020-01-03 20:04:00 +00:00
|
|
|
.subscribe(data => {
|
2020-08-17 19:58:00 +00:00
|
|
|
this.transaction.satoshis = data[CurrencyUnitEnum.SATS];
|
2020-01-10 03:50:02 +00:00
|
|
|
this.selAmountUnit = CurrencyUnitEnum.SATS;
|
2020-07-07 17:57:15 +00:00
|
|
|
this.store.dispatch(new CLActions.SetChannelTransaction(this.transaction));
|
2020-01-03 20:04:00 +00:00
|
|
|
});
|
|
|
|
} else {
|
2020-07-07 17:57:15 +00:00
|
|
|
this.store.dispatch(new CLActions.SetChannelTransaction(this.transaction));
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get invalidValues(): boolean {
|
2020-03-10 17:25:52 +00:00
|
|
|
return (!this.transaction.address || this.transaction.address === '')
|
2020-08-17 19:58:00 +00:00
|
|
|
|| ((!this.transaction.satoshis || +this.transaction.satoshis <= 0))
|
2020-03-10 17:25:52 +00:00
|
|
|
|| (this.flgMinConf && (!this.transaction.minconf || this.transaction.minconf <= 0));
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resetData() {
|
2020-05-03 19:52:38 +00:00
|
|
|
this.sendFundError = '';
|
2020-01-03 20:04:00 +00:00
|
|
|
this.transaction = {};
|
|
|
|
this.flgMinConf = false;
|
2020-08-17 19:58:00 +00:00
|
|
|
this.totalSelectedUTXOAmount = null;
|
2020-08-14 20:55:37 +00:00
|
|
|
this.selUTXOs = [];
|
2020-08-17 19:58:00 +00:00
|
|
|
this.flgUseAllBalance = false;
|
|
|
|
this.selAmountUnit = CURRENCY_UNITS[0];
|
2020-08-14 20:55:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onUTXOSelectionChange(event: any) {
|
|
|
|
let utxoNew = {value: 0};
|
|
|
|
if (this.selUTXOs.length && this.selUTXOs.length > 0) {
|
|
|
|
this.totalSelectedUTXOAmount = this.selUTXOs.reduce((a, b) => {utxoNew.value = a.value + b.value; return utxoNew;}).value;
|
2020-08-17 19:58:00 +00:00
|
|
|
if (this.flgUseAllBalance) { this.onUTXOAllBalanceChange(); }
|
|
|
|
} else {
|
|
|
|
this.totalSelectedUTXOAmount = null;
|
|
|
|
this.transaction.satoshis = null;
|
|
|
|
this.flgUseAllBalance = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onUTXOAllBalanceChange() {
|
|
|
|
if (this.flgUseAllBalance) {
|
|
|
|
this.transaction.satoshis = this.totalSelectedUTXOAmount;
|
|
|
|
this.selAmountUnit = CURRENCY_UNITS[0];
|
2020-08-14 22:13:55 +00:00
|
|
|
} else {
|
2020-08-17 19:58:00 +00:00
|
|
|
this.transaction.satoshis = null;
|
2020-08-14 20:55:37 +00:00
|
|
|
}
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onAmountUnitChange(event: any) {
|
|
|
|
let self = this;
|
2020-01-04 01:06:36 +00:00
|
|
|
let prevSelectedUnit = (this.selAmountUnit === this.amountUnits[2]) ? CurrencyUnitEnum.OTHER : this.selAmountUnit;
|
|
|
|
let currSelectedUnit = event.value === this.amountUnits[2] ? CurrencyUnitEnum.OTHER : event.value;
|
2020-01-03 20:04:00 +00:00
|
|
|
if(this.transaction.satoshis && this.selAmountUnit !== event.value) {
|
2020-08-17 19:58:00 +00:00
|
|
|
this.commonService.convertCurrency(+this.transaction.satoshis, prevSelectedUnit, this.amountUnits[2], this.fiatConversion)
|
2020-05-03 19:52:38 +00:00
|
|
|
.pipe(takeUntil(this.unSubs[3]))
|
2020-01-03 20:04:00 +00:00
|
|
|
.subscribe(data => {
|
2020-08-17 19:58:00 +00:00
|
|
|
self.transaction.satoshis = self.decimalPipe.transform(data[currSelectedUnit], self.currencyUnitFormats[currSelectedUnit]).replace(/,/g, '');
|
2020-01-03 20:04:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
this.selAmountUnit = event.value;
|
|
|
|
}
|
|
|
|
|
2020-08-14 20:55:37 +00:00
|
|
|
onAdvancedPanelToggle(isClosed: boolean) {
|
|
|
|
if (isClosed) {
|
2020-08-17 19:58:00 +00:00
|
|
|
this.advancedTitle = (this.selUTXOs.length && this.selUTXOs.length > 0) ? 'Advanced Options | Selected UTXOs: ' + this.selUTXOs.length + ' | Selected UTXO Amount: ' + this.decimalPipe.transform(this.totalSelectedUTXOAmount) + ' Sats' : 'Advanced Options';
|
2020-08-14 20:55:37 +00:00
|
|
|
} else {
|
|
|
|
this.advancedTitle = 'Advanced Options';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-03 20:04:00 +00:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.unSubs.forEach(completeSub => {
|
|
|
|
completeSub.next();
|
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|