2020-11-25 08:55:27 +01:00
|
|
|
import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {BlockSyncService, TransactionService} from '../../_services';
|
2020-11-08 07:31:52 +01:00
|
|
|
import {Conversion, Transaction} from '../../_models';
|
2020-11-25 08:55:27 +01:00
|
|
|
import {MatTableDataSource} from '@angular/material/table';
|
|
|
|
import {SelectionModel} from '@angular/cdk/collections';
|
|
|
|
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',
|
|
|
|
styleUrls: ['./transactions.component.scss']
|
|
|
|
})
|
2020-11-25 08:55:27 +01:00
|
|
|
export class TransactionsComponent implements OnInit, AfterViewInit {
|
|
|
|
transactionDataSource: MatTableDataSource<Transaction>;
|
|
|
|
conversionDataSource: MatTableDataSource<any>;
|
|
|
|
transactionDisplayedColumns = ['sender', 'recipient', 'token', 'value', 'created', 'view', 'select'];
|
|
|
|
conversionDisplayedColumns = ['initialToken', 'initialValue', 'finalToken', 'finalValue', 'trader', 'created', 'view', 'select'];
|
|
|
|
initialSelection = [];
|
|
|
|
allowMultiSelect = true;
|
|
|
|
transactionSelection: SelectionModel<any>;
|
|
|
|
conversionSelection: SelectionModel<any>;
|
2020-11-04 13:36:30 +01:00
|
|
|
transaction: Transaction;
|
2020-11-08 07:31:52 +01:00
|
|
|
conversion: Conversion;
|
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(
|
|
|
|
private transactionService: TransactionService,
|
|
|
|
private blockSyncService: BlockSyncService
|
|
|
|
) {
|
|
|
|
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 => {
|
|
|
|
this.transactionDataSource = new MatTableDataSource<Transaction>(transactions);
|
|
|
|
this.transactionDataSource.paginator = this.paginator;
|
|
|
|
this.transactionDataSource.sort = this.sort;
|
|
|
|
});
|
|
|
|
this.transactionService.conversionsSubject.subscribe(conversions => {
|
|
|
|
this.conversionDataSource = new MatTableDataSource<any>(this.transactionService.conversions);
|
|
|
|
this.conversionDataSource.paginator = this.paginator;
|
|
|
|
this.conversionDataSource.sort = this.sort;
|
|
|
|
});
|
|
|
|
this.transactionSelection = new SelectionModel<any>(this.allowMultiSelect, this.initialSelection);
|
|
|
|
this.conversionSelection = new SelectionModel<any>(this.allowMultiSelect, this.initialSelection);
|
2020-11-04 13:36:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewTransaction(transaction): void {
|
|
|
|
this.transaction = transaction;
|
|
|
|
}
|
2020-11-08 07:31:52 +01:00
|
|
|
|
|
|
|
viewConversion(conversion): void {
|
|
|
|
this.conversion = conversion;
|
|
|
|
}
|
2020-11-25 08:55:27 +01:00
|
|
|
|
|
|
|
ngAfterViewInit(): void {
|
|
|
|
this.transactionDataSource.paginator = this.paginator;
|
|
|
|
this.transactionDataSource.sort = this.sort;
|
|
|
|
this.conversionDataSource.paginator = this.paginator;
|
|
|
|
this.conversionDataSource.sort = this.sort;
|
|
|
|
}
|
|
|
|
|
|
|
|
isAllSelected(selection, dataSource): boolean {
|
|
|
|
const numSelected = selection.selected.length;
|
|
|
|
const numRows = dataSource.data.length;
|
|
|
|
return numSelected === numRows;
|
|
|
|
}
|
|
|
|
|
|
|
|
masterToggle(selection, dataSource): void {
|
|
|
|
this.isAllSelected(selection, dataSource) ? selection.clear() : dataSource.data.forEach(row => selection.select(row));
|
|
|
|
}
|
|
|
|
|
|
|
|
doFilter(value: string, dataSource): void {
|
|
|
|
dataSource.filter = value.trim().toLocaleLowerCase();
|
|
|
|
}
|
2020-11-04 13:36:30 +01:00
|
|
|
}
|