2021-03-14 09:23:20 +01:00
|
|
|
import {AfterViewInit, ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
|
2021-03-01 09:12:49 +01:00
|
|
|
import {BlockSyncService, TransactionService} from '@app/_services';
|
2020-11-25 08:55:27 +01:00
|
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
|
|
import {MatPaginator} from '@angular/material/paginator';
|
|
|
|
import {MatSort} from '@angular/material/sort';
|
2020-11-04 13:36:30 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-transactions',
|
|
|
|
templateUrl: './transactions.component.html',
|
2021-03-14 09:23:20 +01:00
|
|
|
styleUrls: ['./transactions.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2020-11-04 13:36:30 +01:00
|
|
|
})
|
2020-11-25 08:55:27 +01:00
|
|
|
export class TransactionsComponent implements OnInit, AfterViewInit {
|
2020-12-05 07:30:30 +01:00
|
|
|
transactionDataSource: MatTableDataSource<any>;
|
2021-03-10 10:47:01 +01:00
|
|
|
transactionDisplayedColumns = ['sender', 'recipient', 'value', 'created', 'type'];
|
2021-03-15 12:58:18 +01:00
|
|
|
defaultPageSize = 10;
|
|
|
|
pageSizeOptions = [10, 20, 50, 100];
|
2020-12-05 07:30:30 +01:00
|
|
|
transactions: any[];
|
|
|
|
transaction: any;
|
|
|
|
transactionsType = 'all';
|
2020-11-04 13:36:30 +01:00
|
|
|
|
2020-11-25 08:55:27 +01:00
|
|
|
@ViewChild(MatPaginator) paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
2020-11-04 13:36:30 +01:00
|
|
|
|
2020-11-25 08:55:27 +01:00
|
|
|
constructor(
|
2021-03-01 09:12:49 +01:00
|
|
|
private blockSyncService: BlockSyncService,
|
2020-11-25 08:55:27 +01:00
|
|
|
private transactionService: TransactionService,
|
2021-03-01 09:12:49 +01:00
|
|
|
) {
|
|
|
|
this.blockSyncService.blockSync();
|
|
|
|
}
|
2020-11-04 13:36:30 +01:00
|
|
|
|
2020-11-25 08:55:27 +01:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.transactionService.transactionsSubject.subscribe(transactions => {
|
2020-12-05 07:30:30 +01:00
|
|
|
this.transactionDataSource = new MatTableDataSource<any>(transactions);
|
2020-11-25 08:55:27 +01:00
|
|
|
this.transactionDataSource.paginator = this.paginator;
|
|
|
|
this.transactionDataSource.sort = this.sort;
|
2020-12-05 07:30:30 +01:00
|
|
|
this.transactions = transactions;
|
2020-11-25 08:55:27 +01:00
|
|
|
});
|
2020-11-04 13:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewTransaction(transaction): void {
|
|
|
|
this.transaction = transaction;
|
|
|
|
}
|
2020-11-08 07:31:52 +01:00
|
|
|
|
2020-11-25 08:55:27 +01:00
|
|
|
doFilter(value: string, dataSource): void {
|
|
|
|
dataSource.filter = value.trim().toLocaleLowerCase();
|
|
|
|
}
|
2020-12-05 07:30:30 +01:00
|
|
|
|
|
|
|
filterTransactions(): void {
|
|
|
|
if (this.transactionsType === 'all') {
|
|
|
|
this.transactionService.transactionsSubject.subscribe(transactions => {
|
|
|
|
this.transactionDataSource.data = transactions;
|
|
|
|
this.transactions = transactions;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.transactionDataSource.data = this.transactions.filter(transaction => transaction.type === this.transactionsType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
this.transactionDataSource.paginator = this.paginator;
|
|
|
|
this.transactionDataSource.sort = this.sort;
|
|
|
|
}
|
2020-11-04 13:36:30 +01:00
|
|
|
}
|