2020-08-02 19:20:38 +07:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqTransaction, BisqOutput } from '../bisq.interfaces';
|
2020-08-07 13:11:55 +07:00
|
|
|
import { Subject, merge, Observable } from 'rxjs';
|
2020-08-02 19:20:38 +07:00
|
|
|
import { switchMap, map } from 'rxjs/operators';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqApiService } from '../bisq-api.service';
|
2020-07-13 21:46:25 +07:00
|
|
|
import { SeoService } from 'src/app/services/seo.service';
|
2020-07-24 18:41:15 +07:00
|
|
|
import { FormGroup, FormBuilder } from '@angular/forms';
|
2020-08-07 13:11:55 +07:00
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
2020-07-03 23:45:19 +07:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-bisq-transactions',
|
|
|
|
templateUrl: './bisq-transactions.component.html',
|
2020-08-02 19:20:38 +07:00
|
|
|
styleUrls: ['./bisq-transactions.component.scss'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2020-07-03 23:45:19 +07:00
|
|
|
})
|
|
|
|
export class BisqTransactionsComponent implements OnInit {
|
2020-08-02 19:20:38 +07:00
|
|
|
transactions$: Observable<[BisqTransaction[], number]>;
|
2020-07-03 23:45:19 +07:00
|
|
|
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;
|
2020-07-15 13:10:13 +07:00
|
|
|
isLoading = true;
|
|
|
|
loadingItems: number[];
|
2020-07-24 18:41:15 +07:00
|
|
|
radioGroupForm: FormGroup;
|
|
|
|
types: string[] = [];
|
2020-07-03 23:45:19 +07:00
|
|
|
|
2020-07-19 13:46:30 +07:00
|
|
|
// @ts-ignore
|
|
|
|
paginationSize: 'sm' | 'lg' = 'md';
|
|
|
|
paginationMaxSize = 10;
|
|
|
|
|
2020-07-03 23:45:19 +07:00
|
|
|
constructor(
|
2020-07-13 15:16:12 +07:00
|
|
|
private bisqApiService: BisqApiService,
|
2020-07-13 21:46:25 +07:00
|
|
|
private seoService: SeoService,
|
2020-07-24 18:41:15 +07:00
|
|
|
private formBuilder: FormBuilder,
|
2020-08-07 13:11:55 +07:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
2020-07-03 23:45:19 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2020-07-13 21:46:25 +07:00
|
|
|
this.seoService.setTitle('Transactions', true);
|
|
|
|
|
2020-07-24 18:41:15 +07:00
|
|
|
this.radioGroupForm = this.formBuilder.group({
|
|
|
|
UNVERIFIED: false,
|
|
|
|
INVALID: false,
|
|
|
|
GENESIS: false,
|
|
|
|
TRANSFER_BSQ: false,
|
|
|
|
PAY_TRADE_FEE: false,
|
|
|
|
PROPOSAL: false,
|
|
|
|
COMPENSATION_REQUEST: false,
|
|
|
|
REIMBURSEMENT_REQUEST: false,
|
|
|
|
BLIND_VOTE: false,
|
|
|
|
VOTE_REVEAL: false,
|
|
|
|
LOCKUP: false,
|
|
|
|
UNLOCK: false,
|
|
|
|
ASSET_LISTING_FEE: false,
|
|
|
|
PROOF_OF_BURN: false,
|
|
|
|
});
|
|
|
|
|
2020-07-03 23:45:19 +07:00
|
|
|
this.itemsPerPage = Math.max(Math.round(this.contentSpace / this.fiveItemsPxSize) * 5, 10);
|
2020-07-15 13:10:13 +07:00
|
|
|
this.loadingItems = Array(this.itemsPerPage);
|
2020-07-03 23:45:19 +07:00
|
|
|
|
2020-07-19 13:46:30 +07:00
|
|
|
if (document.body.clientWidth < 768) {
|
|
|
|
this.paginationSize = 'sm';
|
|
|
|
this.paginationMaxSize = 3;
|
|
|
|
}
|
|
|
|
|
2020-08-02 19:20:38 +07:00
|
|
|
this.transactions$ = merge(
|
2020-08-07 13:11:55 +07:00
|
|
|
this.route.queryParams
|
|
|
|
.pipe(
|
|
|
|
map((queryParams) => {
|
|
|
|
if (queryParams.page) {
|
|
|
|
this.page = parseInt(queryParams.page, 10);
|
|
|
|
return parseInt(queryParams.page, 10);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
})
|
|
|
|
),
|
2020-07-24 18:41:15 +07:00
|
|
|
this.radioGroupForm.valueChanges
|
|
|
|
.pipe(
|
|
|
|
map((data) => {
|
|
|
|
const types: string[] = [];
|
|
|
|
for (const i in data) {
|
|
|
|
if (data[i]) {
|
|
|
|
types.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.types = types;
|
2020-08-07 13:11:55 +07:00
|
|
|
if (this.page !== 1) {
|
|
|
|
this.pageChange(1);
|
|
|
|
}
|
2020-07-24 18:41:15 +07:00
|
|
|
return 1;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
)
|
2020-07-03 23:45:19 +07:00
|
|
|
.pipe(
|
2020-08-02 19:20:38 +07:00
|
|
|
switchMap((page) => this.bisqApiService.listTransactions$((page - 1) * this.itemsPerPage, this.itemsPerPage, this.types)),
|
|
|
|
map((response) => [response.body, parseInt(response.headers.get('x-total-count'), 10)])
|
|
|
|
);
|
2020-07-03 23:45:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
pageChange(page: number) {
|
2020-08-07 13:11:55 +07:00
|
|
|
this.router.navigate([], {
|
|
|
|
queryParams: { page: page },
|
|
|
|
replaceUrl: true,
|
|
|
|
queryParamsHandling: 'merge',
|
|
|
|
});
|
2020-07-03 23:45:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|