2020-08-10 23:47:44 +07:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
|
2020-07-13 15:16:12 +07:00
|
|
|
import { BisqTransaction, BisqOutput } from '../bisq.interfaces';
|
2020-08-10 23:47:44 +07:00
|
|
|
|
2020-08-13 02:35:10 +07:00
|
|
|
import { merge, Observable } from 'rxjs';
|
2020-08-10 23:47:44 +07:00
|
|
|
import { switchMap, map, tap, filter } 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-08-08 22:48:18 +07:00
|
|
|
import { IMultiSelectOption, IMultiSelectSettings, IMultiSelectTexts } from 'ngx-bootrap-multiselect';
|
2021-03-05 15:38:46 +07:00
|
|
|
import { WebsocketService } from 'src/app/services/websocket.service';
|
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;
|
2020-08-10 23:47:44 +07:00
|
|
|
itemsPerPage = 50;
|
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-08-08 22:48:18 +07:00
|
|
|
txTypeOptions: IMultiSelectOption[] = [
|
2021-04-26 06:35:56 +09:00
|
|
|
{ id: 1, name: $localize`Asset listing fee` },
|
|
|
|
{ id: 2, name: $localize`Blind vote` },
|
|
|
|
{ id: 3, name: $localize`Compensation request` },
|
|
|
|
{ id: 4, name: $localize`Genesis` },
|
|
|
|
{ id: 13, name: $localize`Irregular` },
|
|
|
|
{ id: 5, name: $localize`Lockup` },
|
|
|
|
{ id: 6, name: $localize`Pay trade fee` },
|
|
|
|
{ id: 7, name: $localize`Proof of burn` },
|
|
|
|
{ id: 8, name: $localize`Proposal` },
|
|
|
|
{ id: 9, name: $localize`Reimbursement request` },
|
|
|
|
{ id: 10, name: $localize`Transfer BSQ` },
|
|
|
|
{ id: 11, name: $localize`Unlock` },
|
|
|
|
{ id: 12, name: $localize`Vote reveal` },
|
2020-08-08 22:48:18 +07:00
|
|
|
];
|
2020-10-04 17:51:21 +07:00
|
|
|
txTypesDefaultChecked = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
|
2020-08-08 22:48:18 +07:00
|
|
|
|
|
|
|
txTypeDropdownSettings: IMultiSelectSettings = {
|
|
|
|
buttonClasses: 'btn btn-primary btn-sm',
|
|
|
|
displayAllSelectedText: true,
|
|
|
|
showCheckAll: true,
|
|
|
|
showUncheckAll: true,
|
|
|
|
maxHeight: '500px',
|
|
|
|
fixedTitle: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
txTypeDropdownTexts: IMultiSelectTexts = {
|
2020-12-03 18:34:19 +07:00
|
|
|
defaultTitle: $localize`:@@bisq-transactions.filter:Filter`,
|
|
|
|
checkAll: $localize`:@@bisq-transactions.selectall:Select all`,
|
|
|
|
uncheckAll: $localize`:@@bisq-transactions.unselectall:Unselect all`,
|
2020-08-08 22:48:18 +07:00
|
|
|
};
|
|
|
|
|
2020-07-19 13:46:30 +07:00
|
|
|
// @ts-ignore
|
|
|
|
paginationSize: 'sm' | 'lg' = 'md';
|
2021-05-03 10:11:30 -03:00
|
|
|
paginationMaxSize = 4;
|
2020-07-19 13:46:30 +07:00
|
|
|
|
2020-08-08 22:48:18 +07:00
|
|
|
txTypes = ['ASSET_LISTING_FEE', 'BLIND_VOTE', 'COMPENSATION_REQUEST', 'GENESIS', 'LOCKUP', 'PAY_TRADE_FEE',
|
2020-10-04 17:51:21 +07:00
|
|
|
'PROOF_OF_BURN', 'PROPOSAL', 'REIMBURSEMENT_REQUEST', 'TRANSFER_BSQ', 'UNLOCK', 'VOTE_REVEAL', 'IRREGULAR'];
|
2020-08-08 22:48:18 +07:00
|
|
|
|
2020-07-03 23:45:19 +07:00
|
|
|
constructor(
|
2021-03-05 15:38:46 +07:00
|
|
|
private websocketService: WebsocketService,
|
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-08-10 23:47:44 +07:00
|
|
|
private cd: ChangeDetectorRef,
|
2020-07-03 23:45:19 +07:00
|
|
|
) { }
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-03-05 15:38:46 +07:00
|
|
|
this.websocketService.want(['blocks']);
|
2020-12-03 18:34:19 +07:00
|
|
|
this.seoService.setTitle($localize`:@@add4cd82e3e38a3110fe67b3c7df56e9602644ee:Transactions`);
|
2020-07-13 21:46:25 +07:00
|
|
|
|
2020-07-24 18:41:15 +07:00
|
|
|
this.radioGroupForm = this.formBuilder.group({
|
2020-08-11 00:01:22 +07:00
|
|
|
txTypes: [this.txTypesDefaultChecked],
|
2020-07-24 18:41:15 +07:00
|
|
|
});
|
|
|
|
|
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(
|
2020-08-10 23:47:44 +07:00
|
|
|
filter((queryParams) => {
|
|
|
|
const newPage = parseInt(queryParams.page, 10);
|
|
|
|
const types = queryParams.types;
|
|
|
|
if (newPage !== this.page || types !== this.types.map((type) => this.txTypes.indexOf(type) + 1).join(',')) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}),
|
|
|
|
tap((queryParams) => {
|
2020-08-07 13:11:55 +07:00
|
|
|
if (queryParams.page) {
|
2020-08-10 23:47:44 +07:00
|
|
|
const newPage = parseInt(queryParams.page, 10);
|
|
|
|
this.page = newPage;
|
2020-08-11 00:01:22 +07:00
|
|
|
} else {
|
|
|
|
this.page = 1;
|
2020-08-10 23:47:44 +07:00
|
|
|
}
|
|
|
|
if (queryParams.types) {
|
|
|
|
const types = queryParams.types.split(',').map((str: string) => parseInt(str, 10));
|
|
|
|
this.types = types.map((id: number) => this.txTypes[id - 1]);
|
|
|
|
this.radioGroupForm.get('txTypes').setValue(types, { emitEvent: false });
|
2020-08-11 00:01:22 +07:00
|
|
|
} else {
|
|
|
|
this.types = [];
|
|
|
|
this.radioGroupForm.get('txTypes').setValue(this.txTypesDefaultChecked, { emitEvent: false });
|
2020-08-07 13:11:55 +07:00
|
|
|
}
|
2020-08-11 00:01:22 +07:00
|
|
|
this.cd.markForCheck();
|
2020-08-07 13:11:55 +07:00
|
|
|
})
|
|
|
|
),
|
2020-07-24 18:41:15 +07:00
|
|
|
this.radioGroupForm.valueChanges
|
|
|
|
.pipe(
|
2020-08-10 23:47:44 +07:00
|
|
|
tap((data) => {
|
2020-08-08 22:48:18 +07:00
|
|
|
this.types = data.txTypes.map((id: number) => this.txTypes[id - 1]);
|
|
|
|
if (this.types.length === this.txTypes.length) {
|
|
|
|
this.types = [];
|
2020-07-24 18:41:15 +07:00
|
|
|
}
|
2020-08-10 23:47:44 +07:00
|
|
|
this.page = 1;
|
|
|
|
this.typesChanged(data.txTypes);
|
|
|
|
this.cd.markForCheck();
|
2020-07-24 18:41:15 +07:00
|
|
|
})
|
2020-08-10 23:47:44 +07:00
|
|
|
),
|
2020-07-24 18:41:15 +07:00
|
|
|
)
|
2020-07-03 23:45:19 +07:00
|
|
|
.pipe(
|
2020-08-08 22:48:18 +07:00
|
|
|
switchMap(() => this.bisqApiService.listTransactions$((this.page - 1) * this.itemsPerPage, this.itemsPerPage, this.types)),
|
2020-08-02 19:20:38 +07:00
|
|
|
map((response) => [response.body, parseInt(response.headers.get('x-total-count'), 10)])
|
|
|
|
);
|
2020-07-03 23:45:19 +07:00
|
|
|
}
|
|
|
|
|
2020-08-13 00:46:44 +07:00
|
|
|
pageChange(page: number) {
|
2020-08-07 13:11:55 +07:00
|
|
|
this.router.navigate([], {
|
2020-08-10 23:47:44 +07:00
|
|
|
relativeTo: this.route,
|
2020-08-07 13:11:55 +07:00
|
|
|
queryParams: { page: page },
|
2020-08-10 23:47:44 +07:00
|
|
|
queryParamsHandling: 'merge',
|
|
|
|
});
|
2020-08-13 00:46:44 +07:00
|
|
|
// trigger queryParams change
|
|
|
|
this.page = -1;
|
2020-08-10 23:47:44 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
typesChanged(types: number[]) {
|
|
|
|
this.router.navigate([], {
|
|
|
|
relativeTo: this.route,
|
|
|
|
queryParams: { types: types.join(','), page: 1 },
|
2020-08-07 13:11:55 +07:00
|
|
|
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-08-11 00:43:24 +07:00
|
|
|
|
2021-06-09 14:09:25 -05:00
|
|
|
getStringByTxType(id: string) {
|
|
|
|
return this.txTypeOptions.find((type) => type.id).name;
|
|
|
|
}
|
|
|
|
|
2020-08-11 00:43:24 +07:00
|
|
|
trackByFn(index: number) {
|
|
|
|
return index;
|
|
|
|
}
|
2020-07-03 23:45:19 +07:00
|
|
|
}
|