2021-02-21 19:02:31 +00:00
|
|
|
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { Store } from '@ngrx/store';
|
|
|
|
|
2022-05-17 02:53:13 +00:00
|
|
|
import { UTXO } from '../../../shared/models/clnModels';
|
2021-02-21 19:02:31 +00:00
|
|
|
import { LoggerService } from '../../../shared/services/logger.service';
|
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
import { RTLState } from '../../../store/rtl.state';
|
2022-05-01 17:35:20 +00:00
|
|
|
import { utxos } from '../../store/cln.selector';
|
2021-12-29 23:08:41 +00:00
|
|
|
import { ApiCallStatusPayload } from '../../../shared/models/apiCallsPayload';
|
2021-02-21 19:02:31 +00:00
|
|
|
|
|
|
|
@Component({
|
2022-05-01 17:35:20 +00:00
|
|
|
selector: 'rtl-cln-utxo-tables',
|
2021-02-21 19:02:31 +00:00
|
|
|
templateUrl: './utxo-tables.component.html',
|
|
|
|
styleUrls: ['./utxo-tables.component.scss']
|
|
|
|
})
|
2022-05-01 17:35:20 +00:00
|
|
|
export class CLNUTXOTablesComponent implements OnInit, OnDestroy {
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2021-02-21 19:02:31 +00:00
|
|
|
@Input() selectedTableIndex = 0;
|
2021-08-28 21:03:18 +00:00
|
|
|
@Output() readonly selectedTableIndexChange = new EventEmitter<number>();
|
2021-02-21 19:02:31 +00:00
|
|
|
public numUtxos = 0;
|
|
|
|
public numDustUtxos = 0;
|
2022-11-03 20:03:27 +00:00
|
|
|
public DUST_AMOUNT = 1000;
|
2021-12-29 23:08:41 +00:00
|
|
|
private unSubs: Array<Subject<void>> = [new Subject(), new Subject()];
|
2021-02-21 19:02:31 +00:00
|
|
|
|
2021-12-29 23:08:41 +00:00
|
|
|
constructor(private logger: LoggerService, private store: Store<RTLState>) { }
|
2021-02-21 19:02:31 +00:00
|
|
|
|
|
|
|
ngOnInit() {
|
2021-12-29 23:08:41 +00:00
|
|
|
this.store.select(utxos).pipe(takeUntil(this.unSubs[0])).
|
|
|
|
subscribe((utxosSeletor: { utxos: UTXO[], apiCallStatus: ApiCallStatusPayload }) => {
|
|
|
|
if (utxosSeletor.utxos && utxosSeletor.utxos.length > 0) {
|
2022-10-17 23:58:21 +00:00
|
|
|
this.numUtxos = utxosSeletor.utxos.length || 0;
|
2022-11-03 20:03:27 +00:00
|
|
|
this.numDustUtxos = utxosSeletor.utxos?.filter((utxo) => +(utxo.value || 0) < this.DUST_AMOUNT).length || 0;
|
2021-02-21 19:02:31 +00:00
|
|
|
}
|
2021-12-29 23:08:41 +00:00
|
|
|
this.logger.info(utxosSeletor);
|
2021-02-21 19:02:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectedIndexChanged(event) {
|
|
|
|
this.selectedTableIndexChange.emit(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2021-02-21 19:02:31 +00:00
|
|
|
completeSub.complete();
|
|
|
|
});
|
|
|
|
}
|
2021-08-28 21:03:18 +00:00
|
|
|
|
2021-02-21 19:02:31 +00:00
|
|
|
}
|