You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
5.4 KiB
TypeScript
121 lines
5.4 KiB
TypeScript
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil, filter } from 'rxjs/operators';
|
|
import { Store } from '@ngrx/store';
|
|
import { Actions } from '@ngrx/effects';
|
|
import { faHistory } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { MatTableDataSource, MatSort, MatPaginator, MatPaginatorIntl } from '@angular/material';
|
|
import { Transaction } from '../../../shared/models/lndModels';
|
|
import { PAGE_SIZE, PAGE_SIZE_OPTIONS, getPaginatorLabel, AlertTypeEnum, DataTypeEnum, ScreenSizeEnum } from '../../../shared/services/consts-enums-functions';
|
|
import { LoggerService } from '../../../shared/services/logger.service';
|
|
import { CommonService } from '../../../shared/services/common.service';
|
|
|
|
import * as RTLActions from '../../../store/rtl.actions';
|
|
import * as fromRTLReducer from '../../../store/rtl.reducers';
|
|
|
|
@Component({
|
|
selector: 'rtl-on-chain-transaction-history',
|
|
templateUrl: './on-chain-transaction-history.component.html',
|
|
styleUrls: ['./on-chain-transaction-history.component.scss'],
|
|
providers: [
|
|
{ provide: MatPaginatorIntl, useValue: getPaginatorLabel('Transactions') }
|
|
]
|
|
})
|
|
export class OnChainTransactionHistoryComponent implements OnInit, OnDestroy {
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
@ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
|
|
faHistory = faHistory;
|
|
public displayedColumns = [];
|
|
public listTransactions: any;
|
|
public flgLoading: Array<Boolean | 'error'> = [true];
|
|
public flgSticky = false;
|
|
public pageSize = PAGE_SIZE;
|
|
public pageSizeOptions = PAGE_SIZE_OPTIONS;
|
|
private unsub: Array<Subject<void>> = [new Subject(), new Subject(), new Subject()];
|
|
|
|
constructor(private logger: LoggerService, private commonService: CommonService, private store: Store<fromRTLReducer.RTLState>, private actions$: Actions) {
|
|
let ss = this.commonService.getScreenSize();
|
|
if(ss === ScreenSizeEnum.XS) {
|
|
this.flgSticky = false;
|
|
this.displayedColumns = ['time_stamp_str', 'amount', 'actions'];
|
|
} else if(ss === ScreenSizeEnum.SM || ss === ScreenSizeEnum.MD) {
|
|
this.flgSticky = false;
|
|
this.displayedColumns = ['time_stamp_str', 'amount', 'num_confirmations', 'actions'];
|
|
} else {
|
|
this.flgSticky = true;
|
|
this.displayedColumns = ['time_stamp_str', 'amount', 'num_confirmations', 'actions'];
|
|
}
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.store.dispatch(new RTLActions.FetchTransactions());
|
|
this.actions$.pipe(takeUntil(this.unsub[2]), filter((action) => action.type === RTLActions.RESET_LND_STORE)).subscribe((resetLndStore: RTLActions.ResetLNDStore) => {
|
|
this.store.dispatch(new RTLActions.FetchTransactions());
|
|
});
|
|
|
|
this.store.select('lnd')
|
|
.pipe(takeUntil(this.unsub[0]))
|
|
.subscribe((rtlStore) => {
|
|
rtlStore.effectErrorsLnd.forEach(effectsErr => {
|
|
if (effectsErr.action === 'FetchTransactions') {
|
|
this.flgLoading[0] = 'error';
|
|
}
|
|
});
|
|
if (undefined !== rtlStore.transactions) {
|
|
this.loadTransactionsTable(rtlStore.transactions);
|
|
}
|
|
if (this.flgLoading[0] !== 'error') {
|
|
this.flgLoading[0] = (undefined !== rtlStore.transactions) ? false : true;
|
|
}
|
|
this.logger.info(rtlStore);
|
|
});
|
|
|
|
}
|
|
|
|
applyFilter(selFilter: string) {
|
|
this.listTransactions.filter = selFilter;
|
|
}
|
|
|
|
onTransactionClick(selRow: Transaction, event: any) {
|
|
const flgExpansionClicked = event.target.className.includes('mat-expansion-panel-header') || event.target.className.includes('mat-expansion-indicator');
|
|
if (flgExpansionClicked) {
|
|
return;
|
|
}
|
|
const selTransaction = this.listTransactions.data.filter(transaction => {
|
|
return transaction.tx_hash === selRow.tx_hash;
|
|
})[0];
|
|
const reorderedTransactions = [
|
|
[{key: 'dest_addresses', value: selTransaction.dest_addresses, title: 'Destination Address', width: 100, type: DataTypeEnum.ARRAY}],
|
|
[{key: 'block_hash', value: selTransaction.block_hash, title: 'Block Hash', width: 100}],
|
|
[{key: 'tx_hash', value: selTransaction.tx_hash, title: 'Transaction Hash', width: 100}],
|
|
[{key: 'time_stamp_str', value: selTransaction.time_stamp_str, title: 'Date/Time', width: 50, type: DataTypeEnum.DATE_TIME},
|
|
{key: 'block_height', value: selTransaction.block_height, title: 'Block Height', width: 50, type: DataTypeEnum.NUMBER}],
|
|
[{key: 'num_confirmations', value: selTransaction.num_confirmations, title: 'Number of Confirmations', width: 50, type: DataTypeEnum.NUMBER},
|
|
{key: 'total_fees', value: selTransaction.total_fees, title: 'Total Fees (Sats)', width: 50, type: DataTypeEnum.NUMBER}],
|
|
[{key: 'amount', value: selTransaction.amount, title: 'Amount (Sats)', width: 50, type: DataTypeEnum.NUMBER},
|
|
{key: 'active', value: selTransaction.active, title: 'Active', width: 50, type: DataTypeEnum.BOOLEAN}]
|
|
];
|
|
this.store.dispatch(new RTLActions.OpenAlert({ data: {
|
|
type: AlertTypeEnum.INFORMATION,
|
|
alertTitle: 'Transaction Information',
|
|
message: reorderedTransactions,
|
|
}}));
|
|
}
|
|
|
|
loadTransactionsTable(transactions) {
|
|
this.listTransactions = new MatTableDataSource<Transaction>([...transactions]);
|
|
this.listTransactions.sort = this.sort;
|
|
this.listTransactions.paginator = this.paginator;
|
|
this.logger.info(this.listTransactions);
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.unsub.forEach(completeSub => {
|
|
completeSub.next();
|
|
completeSub.complete();
|
|
});
|
|
}
|
|
|
|
}
|