2020-07-03 23:45:19 +07:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqTransaction, BisqOutput } from '../bisq.interfaces';
|
2020-07-03 23:45:19 +07:00
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { switchMap } from 'rxjs/operators';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqApiService } from '../bisq-api.service';
|
2020-07-03 23:45:19 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bisq-transactions',
|
|
|
|
templateUrl: './bisq-transactions.component.html',
|
|
|
|
styleUrls: ['./bisq-transactions.component.scss']
|
|
|
|
})
|
|
|
|
export class BisqTransactionsComponent implements OnInit {
|
|
|
|
transactions: BisqTransaction[];
|
|
|
|
totalCount: number;
|
|
|
|
page = 1;
|
|
|
|
itemsPerPage: number;
|
2020-07-13 15:16:12 +07:00
|
|
|
contentSpace = window.innerHeight - (165 + 75);
|
2020-07-03 23:45:19 +07:00
|
|
|
fiveItemsPxSize = 250;
|
|
|
|
|
|
|
|
pageSubject$ = new Subject<number>();
|
|
|
|
|
|
|
|
constructor(
|
2020-07-13 15:16:12 +07:00
|
|
|
private bisqApiService: BisqApiService,
|
2020-07-03 23:45:19 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
this.itemsPerPage = Math.max(Math.round(this.contentSpace / this.fiveItemsPxSize) * 5, 10);
|
|
|
|
|
|
|
|
this.pageSubject$
|
|
|
|
.pipe(
|
2020-07-13 15:16:12 +07:00
|
|
|
switchMap((page) => this.bisqApiService.listTransactions$((page - 1) * 10, this.itemsPerPage))
|
2020-07-03 23:45:19 +07:00
|
|
|
)
|
|
|
|
.subscribe((response) => {
|
|
|
|
this.transactions = response.body;
|
|
|
|
this.totalCount = parseInt(response.headers.get('x-total-count'), 10);
|
|
|
|
}, (error) => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.pageSubject$.next(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pageChange(page: number) {
|
|
|
|
this.pageSubject$.next(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateTotalOutput(outputs: BisqOutput[]): number {
|
|
|
|
return outputs.reduce((acc: number, output: BisqOutput) => acc + output.bsqAmount, 0);
|
|
|
|
}
|
2020-07-13 15:16:12 +07:00
|
|
|
|
|
|
|
trackByFn(index: number) {
|
|
|
|
return index;
|
|
|
|
}
|
2020-07-03 23:45:19 +07:00
|
|
|
}
|