2020-10-12 22:43:16 +00:00
|
|
|
import { Component, OnInit, OnDestroy, ViewChild, Inject } from '@angular/core';
|
2022-11-24 02:20:23 +00:00
|
|
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
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-10-12 22:43:16 +00:00
|
|
|
import { takeUntil, filter, take } 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-10-12 22:43:16 +00:00
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
2021-08-28 21:03:18 +00:00
|
|
|
import { MatStepper } from '@angular/material/stepper';
|
2020-05-03 19:52:38 +00:00
|
|
|
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
|
2021-12-29 23:08:41 +00:00
|
|
|
import * as sha256 from 'sha256';
|
2020-01-03 20:04:00 +00:00
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
import { SelNodeChild, RTLConfiguration } from '../../../shared/models/RTLconfig';
|
2022-05-01 17:35:20 +00:00
|
|
|
import { CLNOnChainSendFunds } from '../../../shared/models/alertData';
|
2023-12-06 04:32:05 +00:00
|
|
|
import { GetInfo, Balance, OnChain, UTXO, LocalRemoteBalance } from '../../../shared/models/clnModels';
|
2022-05-01 17:35:20 +00:00
|
|
|
import { CURRENCY_UNITS, CurrencyUnitEnum, CURRENCY_UNIT_FORMATS, ADDRESS_TYPES, FEE_RATE_TYPES, APICallStatusEnum, CLNActions, ScreenSizeEnum } from '../../../shared/services/consts-enums-functions';
|
2020-01-03 20:04:00 +00:00
|
|
|
import { CommonService } from '../../../shared/services/common.service';
|
|
|
|
import { LoggerService } from '../../../shared/services/logger.service';
|
|
|
|
|
2020-10-12 22:43:16 +00:00
|
|
|
import { RTLEffects } from '../../../store/rtl.effects';
|
2021-12-29 23:08:41 +00:00
|
|
|
import { RTLState } from '../../../store/rtl.state';
|
|
|
|
import { isAuthorized, openSnackBar } from '../../../store/rtl.actions';
|
2022-05-01 17:35:20 +00:00
|
|
|
import { setChannelTransaction } from '../../store/cln.actions';
|
2021-12-29 23:08:41 +00:00
|
|
|
import { rootAppConfig, rootSelectedNode } from '../../../store/rtl.selector';
|
2023-12-06 04:32:05 +00:00
|
|
|
import { clnNodeInformation, utxoBalances } from '../../store/cln.selector';
|
2021-12-29 23:08:41 +00:00
|
|
|
import { ApiCallStatusPayload } from '../../../shared/models/apiCallsPayload';
|
2020-01-03 20:04:00 +00:00
|
|
|
|
|
|
|
@Component({
|
2022-05-01 17:35:20 +00:00
|
|
|
selector: 'rtl-cln-on-chain-send-modal',
|
2020-12-20 23:36:04 +00:00
|
|
|
templateUrl: './on-chain-send-modal.component.html',
|
|
|
|
styleUrls: ['./on-chain-send-modal.component.scss']
|
2020-01-03 20:04:00 +00:00
|
|
|
})
|
2022-05-01 17:35:20 +00:00
|
|
|
export class CLNOnChainSendModalComponent implements OnInit, OnDestroy {
|
2021-08-28 21:03:18 +00:00
|
|
|
|
|
|
|
@ViewChild('form', { static: true }) form: any;
|
|
|
|
@ViewChild('formSweepAll', { static: false }) formSweepAll: any;
|
|
|
|
@ViewChild('stepper', { static: false }) stepper: MatStepper;
|
2020-05-03 19:52:38 +00:00
|
|
|
public faExclamationTriangle = faExclamationTriangle;
|
2020-10-12 22:43:16 +00:00
|
|
|
public sweepAll = false;
|
2022-08-19 04:41:59 +00:00
|
|
|
public selNode: SelNodeChild | null = {};
|
2020-01-03 20:04:00 +00:00
|
|
|
public appConfig: RTLConfiguration;
|
|
|
|
public addressTypes = [];
|
2021-02-21 19:02:31 +00:00
|
|
|
public utxos: UTXO[] = [];
|
2022-08-19 04:41:59 +00:00
|
|
|
public selUTXOs: UTXO[] = [];
|
2020-08-17 19:58:00 +00:00
|
|
|
public flgUseAllBalance = false;
|
2022-08-19 04:41:59 +00:00
|
|
|
public totalSelectedUTXOAmount: number | null = null;
|
2020-01-03 20:04:00 +00:00
|
|
|
public selectedAddress = ADDRESS_TYPES[1];
|
2020-07-07 17:57:15 +00:00
|
|
|
public blockchainBalance: Balance = {};
|
|
|
|
public information: GetInfo = {};
|
2020-01-03 20:04:00 +00:00
|
|
|
public newAddress = '';
|
2022-08-19 04:41:59 +00:00
|
|
|
public transaction: OnChain | any = {};
|
2020-01-03 20:04:00 +00:00
|
|
|
public feeRateTypes = FEE_RATE_TYPES;
|
2021-12-29 23:08:41 +00:00
|
|
|
public selFeeRate = '';
|
|
|
|
public customFeeRate = null;
|
2020-01-03 20:04:00 +00:00
|
|
|
public flgMinConf = false;
|
2021-12-29 23:08:41 +00:00
|
|
|
public minConfValue = null;
|
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-10-12 22:43:16 +00:00
|
|
|
public flgValidated = false;
|
|
|
|
public flgEditable = true;
|
|
|
|
public passwordFormLabel = 'Authenticate with your RTL password';
|
|
|
|
public sendFundFormLabel = 'Sweep funds';
|
|
|
|
public confirmFormLabel = 'Confirm sweep';
|
2021-08-28 21:03:18 +00:00
|
|
|
public amountError = 'Amount is Required.';
|
2022-11-24 02:20:23 +00:00
|
|
|
passwordFormGroup: UntypedFormGroup;
|
|
|
|
sendFundFormGroup: UntypedFormGroup;
|
|
|
|
confirmFormGroup: UntypedFormGroup;
|
2021-12-29 23:08:41 +00:00
|
|
|
public screenSize = '';
|
|
|
|
public screenSizeEnum = ScreenSizeEnum;
|
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject(), new Subject()];
|
2020-01-03 20:04:00 +00:00
|
|
|
|
2022-10-31 21:24:41 +00:00
|
|
|
constructor(
|
|
|
|
public dialogRef: MatDialogRef<CLNOnChainSendModalComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: CLNOnChainSendFunds,
|
|
|
|
private logger: LoggerService,
|
|
|
|
private store: Store<RTLState>,
|
|
|
|
private commonService: CommonService,
|
|
|
|
private decimalPipe: DecimalPipe,
|
|
|
|
private actions: Actions,
|
2022-11-24 02:20:23 +00:00
|
|
|
private formBuilder: UntypedFormBuilder,
|
2022-10-31 21:24:41 +00:00
|
|
|
private rtlEffects: RTLEffects,
|
|
|
|
private snackBar: MatSnackBar) {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.screenSize = this.commonService.getScreenSize();
|
|
|
|
}
|
2020-01-03 20:04:00 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-10-12 22:43:16 +00:00
|
|
|
this.sweepAll = this.data.sweepAll;
|
|
|
|
this.passwordFormGroup = this.formBuilder.group({
|
|
|
|
hiddenPassword: ['', [Validators.required]],
|
|
|
|
password: ['', [Validators.required]]
|
|
|
|
});
|
|
|
|
this.sendFundFormGroup = this.formBuilder.group({
|
|
|
|
transactionAddress: ['', Validators.required],
|
2021-12-29 23:08:41 +00:00
|
|
|
selFeeRate: [null],
|
|
|
|
customFeeRate: [null],
|
2020-10-12 22:43:16 +00:00
|
|
|
flgMinConf: [false],
|
2021-12-29 23:08:41 +00:00
|
|
|
minConfValue: [{ value: null, disabled: true }]
|
2020-10-12 22:43:16 +00:00
|
|
|
});
|
2021-08-28 21:03:18 +00:00
|
|
|
this.confirmFormGroup = this.formBuilder.group({});
|
2021-12-29 23:08:41 +00:00
|
|
|
this.sendFundFormGroup.controls.flgMinConf.valueChanges.pipe(takeUntil(this.unSubs[0])).subscribe((flg) => {
|
2020-10-12 22:43:16 +00:00
|
|
|
if (flg) {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.sendFundFormGroup.controls.selFeeRate.disable();
|
|
|
|
this.sendFundFormGroup.controls.selFeeRate.setValue(null);
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.reset();
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.enable();
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.setValidators([Validators.required]);
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.setValue(null);
|
2020-10-12 22:43:16 +00:00
|
|
|
} else {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.sendFundFormGroup.controls.selFeeRate.enable();
|
|
|
|
this.sendFundFormGroup.controls.selFeeRate.setValue(null);
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.setValue(null);
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.disable();
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.setValidators(null);
|
|
|
|
this.sendFundFormGroup.controls.minConfValue.setErrors(null);
|
2020-10-12 22:43:16 +00:00
|
|
|
}
|
|
|
|
});
|
2021-12-29 23:08:41 +00:00
|
|
|
this.sendFundFormGroup.controls.selFeeRate.valueChanges.pipe(takeUntil(this.unSubs[1])).subscribe((feeRate) => {
|
|
|
|
this.sendFundFormGroup.controls.customFeeRate.setValue(null);
|
|
|
|
this.sendFundFormGroup.controls.customFeeRate.reset();
|
|
|
|
if (feeRate === 'customperkb' && !this.sendFundFormGroup.controls.flgMinConf.value) {
|
|
|
|
this.sendFundFormGroup.controls.customFeeRate.setValidators([Validators.required]);
|
|
|
|
} else {
|
|
|
|
this.sendFundFormGroup.controls.customFeeRate.setValidators(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
combineLatest([this.store.select(rootSelectedNode), this.store.select(rootAppConfig)]).pipe(takeUntil(this.unSubs[1])).
|
|
|
|
subscribe(([selNode, appConfig]) => {
|
|
|
|
this.fiatConversion = selNode.settings.fiatConversion;
|
|
|
|
this.amountUnits = selNode.settings.currencyUnits;
|
|
|
|
this.appConfig = appConfig;
|
|
|
|
});
|
2022-05-01 17:35:20 +00:00
|
|
|
this.store.select(clnNodeInformation).pipe(takeUntil(this.unSubs[2])).
|
2021-12-29 23:08:41 +00:00
|
|
|
subscribe((nodeInfo: GetInfo) => {
|
|
|
|
this.information = nodeInfo;
|
|
|
|
});
|
2023-12-06 04:32:05 +00:00
|
|
|
this.store.select(utxoBalances).pipe(takeUntil(this.unSubs[3])).
|
|
|
|
subscribe((utxoBalancesSeletor: { utxos: UTXO[], balance: Balance, localRemoteBalance: LocalRemoteBalance, apiCallStatus: ApiCallStatusPayload }) => {
|
|
|
|
this.utxos = this.commonService.sortAscByKey(utxoBalancesSeletor.utxos?.filter((utxo) => utxo.status === 'confirmed'), 'value');
|
|
|
|
this.logger.info(utxoBalancesSeletor);
|
2021-08-28 21:03:18 +00:00
|
|
|
});
|
|
|
|
this.actions.pipe(
|
2021-12-29 23:08:41 +00:00
|
|
|
takeUntil(this.unSubs[4]),
|
2022-05-01 17:35:20 +00:00
|
|
|
filter((action) => action.type === CLNActions.UPDATE_API_CALL_STATUS_CLN || action.type === CLNActions.SET_CHANNEL_TRANSACTION_RES_CLN)).
|
2021-12-29 23:08:41 +00:00
|
|
|
subscribe((action: any) => {
|
2022-05-01 17:35:20 +00:00
|
|
|
if (action.type === CLNActions.SET_CHANNEL_TRANSACTION_RES_CLN) {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(openSnackBar({ payload: 'Fund Sent Successfully!' }));
|
2021-08-28 21:03:18 +00:00
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2022-05-01 17:35:20 +00:00
|
|
|
if (action.type === CLNActions.UPDATE_API_CALL_STATUS_CLN && action.payload.status === APICallStatusEnum.ERROR && action.payload.action === 'SetChannelTransaction') {
|
2021-08-28 21:03:18 +00:00
|
|
|
this.sendFundError = action.payload.message;
|
|
|
|
}
|
|
|
|
});
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 21:03:18 +00:00
|
|
|
onAuthenticate(): boolean | void {
|
|
|
|
if (!this.passwordFormGroup.controls.password.value) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-12 22:43:16 +00:00
|
|
|
this.flgValidated = false;
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(isAuthorized({ payload: sha256(this.passwordFormGroup.controls.password.value).toString() }));
|
2021-08-28 21:03:18 +00:00
|
|
|
this.rtlEffects.isAuthorizedRes.
|
|
|
|
pipe(take(1)).
|
|
|
|
subscribe((authRes) => {
|
|
|
|
if (authRes !== 'ERROR') {
|
|
|
|
this.passwordFormGroup.controls.hiddenPassword.setValue(this.passwordFormGroup.controls.password.value);
|
|
|
|
this.stepper.next();
|
|
|
|
} else {
|
|
|
|
this.dialogRef.close();
|
|
|
|
this.snackBar.open('Unauthorized User. Logging out from RTL.');
|
|
|
|
}
|
|
|
|
});
|
2020-10-12 22:43:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 21:03:18 +00:00
|
|
|
onSendFunds(): boolean | void {
|
2020-05-03 19:52:38 +00:00
|
|
|
this.sendFundError = '';
|
2020-08-17 19:58:00 +00:00
|
|
|
if (this.flgUseAllBalance) {
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = 'all';
|
2020-08-17 19:58:00 +00:00
|
|
|
}
|
2020-08-14 20:55:37 +00:00
|
|
|
if (this.selUTXOs.length && this.selUTXOs.length > 0) {
|
|
|
|
this.transaction.utxos = [];
|
2022-08-19 04:41:59 +00:00
|
|
|
this.selUTXOs.forEach((utxo: UTXO) => this.transaction.utxos?.push(utxo.txid + ':' + utxo.output));
|
2020-08-14 20:55:37 +00:00
|
|
|
}
|
2020-10-12 22:43:16 +00:00
|
|
|
if (this.sweepAll) {
|
2021-12-29 23:08:41 +00:00
|
|
|
if (
|
|
|
|
(!this.sendFundFormGroup.controls.transactionAddress.value || this.sendFundFormGroup.controls.transactionAddress.value === '') ||
|
|
|
|
(this.sendFundFormGroup.controls.flgMinConf.value && (!this.sendFundFormGroup.controls.minConfValue.value || this.sendFundFormGroup.controls.minConfValue.value <= 0)) ||
|
|
|
|
(this.selFeeRate === 'customperkb' && !this.flgMinConf && !this.customFeeRate)
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = 'all';
|
|
|
|
this.transaction.destination = this.sendFundFormGroup.controls.transactionAddress.value;
|
2020-10-12 22:43:16 +00:00
|
|
|
if (this.sendFundFormGroup.controls.flgMinConf.value) {
|
2023-12-06 04:32:05 +00:00
|
|
|
delete this.transaction.feerate;
|
2021-12-29 23:08:41 +00:00
|
|
|
this.transaction.minconf = this.sendFundFormGroup.controls.flgMinConf.value ? this.sendFundFormGroup.controls.minConfValue.value : null;
|
2020-10-12 22:43:16 +00:00
|
|
|
} else {
|
|
|
|
delete this.transaction.minconf;
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.feerate = (this.sendFundFormGroup.controls.selFeeRate.value === 'customperkb' &&
|
2022-10-31 21:24:41 +00:00
|
|
|
!this.sendFundFormGroup.controls.flgMinConf.value && this.sendFundFormGroup.controls.customFeeRate.value) ?
|
|
|
|
((this.sendFundFormGroup.controls.customFeeRate.value * 1000) + 'perkb') : this.sendFundFormGroup.controls.selFeeRate.value;
|
2020-10-12 22:43:16 +00:00
|
|
|
}
|
|
|
|
delete this.transaction.utxos;
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(setChannelTransaction({ payload: this.transaction }));
|
2020-10-12 22:43:16 +00:00
|
|
|
} else {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.transaction.minconf = this.flgMinConf ? this.minConfValue : null;
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction['feerate'] = (this.selFeeRate === 'customperkb' && !this.flgMinConf && this.customFeeRate) ? (this.customFeeRate * 1000) + 'perkb' : this.selFeeRate !== '' ? this.selFeeRate : null;
|
|
|
|
if ((!this.transaction.destination || this.transaction.destination === '') ||
|
|
|
|
((!this.transaction.satoshi || +this.transaction.satoshi <= 0)) ||
|
2021-12-29 23:08:41 +00:00
|
|
|
(this.flgMinConf && (!this.transaction.minconf || this.transaction.minconf <= 0)) ||
|
|
|
|
(this.selFeeRate === 'customperkb' && !this.flgMinConf && !this.customFeeRate)) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-12-06 04:32:05 +00:00
|
|
|
if (this.transaction.satoshi && this.transaction.satoshi !== 'all' && this.selAmountUnit !== CurrencyUnitEnum.SATS) {
|
|
|
|
this.commonService.convertCurrency(+this.transaction.satoshi, this.selAmountUnit === this.amountUnits[2] ? CurrencyUnitEnum.OTHER : this.selAmountUnit, CurrencyUnitEnum.SATS, this.amountUnits[2], this.fiatConversion).
|
2021-12-29 23:08:41 +00:00
|
|
|
pipe(takeUntil(this.unSubs[5])).
|
2021-08-28 21:03:18 +00:00
|
|
|
subscribe({
|
|
|
|
next: (data) => {
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = data[CurrencyUnitEnum.SATS];
|
2021-08-28 21:03:18 +00:00
|
|
|
this.selAmountUnit = CurrencyUnitEnum.SATS;
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(setChannelTransaction({ payload: this.transaction }));
|
2021-08-28 21:03:18 +00:00
|
|
|
}, error: (err) => {
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = null;
|
2021-08-28 21:03:18 +00:00
|
|
|
this.selAmountUnit = CurrencyUnitEnum.SATS;
|
|
|
|
this.amountError = 'Conversion Error: ' + err;
|
|
|
|
}
|
|
|
|
});
|
2020-10-12 22:43:16 +00:00
|
|
|
} else {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.dispatch(setChannelTransaction({ payload: this.transaction }));
|
2020-10-12 22:43:16 +00:00
|
|
|
}
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetData() {
|
2021-08-28 21:03:18 +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
|
|
|
}
|
|
|
|
|
2020-10-12 22:43:16 +00:00
|
|
|
stepSelectionChanged(event: any) {
|
|
|
|
this.sendFundError = '';
|
|
|
|
switch (event.selectedIndex) {
|
|
|
|
case 0:
|
|
|
|
this.passwordFormLabel = 'Authenticate with your RTL password';
|
2021-08-28 21:03:18 +00:00
|
|
|
this.sendFundFormLabel = 'Sweep funds';
|
2020-10-12 22:43:16 +00:00
|
|
|
break;
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2020-10-12 22:43:16 +00:00
|
|
|
case 1:
|
|
|
|
this.passwordFormLabel = 'User authenticated successfully';
|
2021-08-28 21:03:18 +00:00
|
|
|
this.sendFundFormLabel = 'Sweep funds';
|
2020-10-12 22:43:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
this.passwordFormLabel = 'User authenticated successfully';
|
2021-08-28 21:03:18 +00:00
|
|
|
this.sendFundFormLabel = 'Sweep funds | Address: ' + this.sendFundFormGroup.controls.transactionAddress.value +
|
2021-12-29 23:08:41 +00:00
|
|
|
(this.sendFundFormGroup.controls.flgMinConf.value ? (' | Min Confirmation Blocks: ' + this.sendFundFormGroup.controls.minConfValue.value) : (this.sendFundFormGroup.controls.selFeeRate.value ? (' | Fee Rate: ' +
|
2022-08-19 04:41:59 +00:00
|
|
|
this.feeRateTypes.find((frType) => frType.feeRateId === this.sendFundFormGroup.controls.selFeeRate.value)?.feeRateType) : ''));
|
2020-10-12 22:43:16 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
this.passwordFormLabel = 'Authenticate with your RTL password';
|
2021-08-28 21:03:18 +00:00
|
|
|
this.sendFundFormLabel = 'Sweep funds';
|
2020-10-12 22:43:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (event.selectedIndex < event.previouslySelectedIndex) {
|
|
|
|
if (event.selectedIndex === 0) {
|
|
|
|
this.passwordFormGroup.controls.hiddenPassword.setValue('');
|
|
|
|
}
|
2021-08-28 21:03:18 +00:00
|
|
|
}
|
2020-10-12 22:43:16 +00:00
|
|
|
}
|
|
|
|
|
2020-08-14 20:55:37 +00:00
|
|
|
onUTXOSelectionChange(event: any) {
|
|
|
|
if (this.selUTXOs.length && this.selUTXOs.length > 0) {
|
2023-05-17 02:41:50 +00:00
|
|
|
this.totalSelectedUTXOAmount = this.selUTXOs?.reduce((total, curr) => (total + ((curr.amount_msat || 0) / 1000)), 0);
|
2021-08-28 21:03:18 +00:00
|
|
|
if (this.flgUseAllBalance) {
|
|
|
|
this.onUTXOAllBalanceChange();
|
|
|
|
}
|
2020-08-17 19:58:00 +00:00
|
|
|
} else {
|
|
|
|
this.totalSelectedUTXOAmount = null;
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = null;
|
2020-08-17 19:58:00 +00:00
|
|
|
this.flgUseAllBalance = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onUTXOAllBalanceChange() {
|
|
|
|
if (this.flgUseAllBalance) {
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = this.totalSelectedUTXOAmount;
|
2020-08-17 19:58:00 +00:00
|
|
|
this.selAmountUnit = CURRENCY_UNITS[0];
|
2020-08-14 22:13:55 +00:00
|
|
|
} else {
|
2023-12-06 04:32:05 +00:00
|
|
|
this.transaction.satoshi = null;
|
2020-08-14 20:55:37 +00:00
|
|
|
}
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onAmountUnitChange(event: any) {
|
2021-08-28 21:03:18 +00:00
|
|
|
const self = this;
|
|
|
|
const prevSelectedUnit = (this.selAmountUnit === this.amountUnits[2]) ? CurrencyUnitEnum.OTHER : this.selAmountUnit;
|
2020-01-04 01:06:36 +00:00
|
|
|
let currSelectedUnit = event.value === this.amountUnits[2] ? CurrencyUnitEnum.OTHER : event.value;
|
2023-12-06 04:32:05 +00:00
|
|
|
if (this.transaction.satoshi && this.selAmountUnit !== event.value) {
|
|
|
|
this.commonService.convertCurrency(+this.transaction.satoshi, prevSelectedUnit, currSelectedUnit, this.amountUnits[2], this.fiatConversion).
|
2021-12-29 23:08:41 +00:00
|
|
|
pipe(takeUntil(this.unSubs[6])).
|
2021-08-28 21:03:18 +00:00
|
|
|
subscribe({
|
|
|
|
next: (data) => {
|
|
|
|
this.selAmountUnit = event.value;
|
2023-12-06 04:32:05 +00:00
|
|
|
self.transaction.satoshi = self.decimalPipe.transform(data[currSelectedUnit], self.currencyUnitFormats[currSelectedUnit])?.replace(/,/g, '');
|
2021-08-28 21:03:18 +00:00
|
|
|
}, error: (err) => {
|
2023-12-06 04:32:05 +00:00
|
|
|
self.transaction.satoshi = null;
|
2021-08-28 21:03:18 +00:00
|
|
|
this.amountError = 'Conversion Error: ' + err;
|
|
|
|
this.selAmountUnit = prevSelectedUnit;
|
|
|
|
currSelectedUnit = prevSelectedUnit;
|
|
|
|
}
|
|
|
|
});
|
2020-01-03 20:04:00 +00:00
|
|
|
}
|
2021-08-28 21:03:18 +00:00
|
|
|
}
|
2020-01-03 20:04:00 +00:00
|
|
|
|
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() {
|
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-01-03 20:04:00 +00:00
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|