-
Notifications
You must be signed in to change notification settings - Fork 12
/
pool-blocks.ts
115 lines (98 loc) · 2.63 KB
/
pool-blocks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { ApiClientService } from "../../resources/services/api-client.service";
import { LoaderService } from "../../resources/services/loader.service";
import { HttpResponseMessage } from "aurelia-http-client";
import { bindable, autoinject, observable } from "aurelia-framework";
import { buildQueryString } from "aurelia-path";
import { clearTimeout } from "timers";
@autoinject
export class PoolBlocks {
@bindable
public poolId: string;
public data?: PoolBlockItem[] = [];
public error: boolean = false;
@observable
public currentPageNumber: number = 0;
@observable
public pageSize: number = 5;
public loading: boolean = false;
private timeout;
public get allowNext(): boolean {
if (this.data.length < ((this.currentPageNumber + 1) * this.pageSize)) {
return false;
}
return true;
}
constructor(private apiClientService: ApiClientService, private loadingService: LoaderService) {
}
public nextPage() {
if (this.loading) {
return false;
}
this.currentPageNumber++;
}
public refresh() {
if (this.loading) {
return false;
}
const newPageSize = (this.currentPageNumber + 1) * this.pageSize;
if (newPageSize === this.pageSize) {
this.currentPageNumber = -1;
} else {
this.pageSize = (this.currentPageNumber + 1) * this.pageSize;
}
}
public poolIdChanged() {
this.currentPageNumber = -1;
}
public pageSizeChanged() {
this.currentPageNumber = -1;
}
public currentPageNumberChanged() {
if (this.currentPageNumber < 0) {
this.currentPageNumber = 0;
return;
}
this.bind();
}
public bind() {
this.loading = true;
if (!this.poolId) {
return;
}
if (this.timeout) {
try {
clearTimeout(this.timeout);
} catch{ }
}
this.error = false;
let options = {
pageSize: this.pageSize,
page: this.currentPageNumber
}
this.apiClientService.http.get(`pools/${this.poolId}/blocks?${buildQueryString(options, true)}`).then((value: HttpResponseMessage) => {
if (value.isSuccess) {
if (this.currentPageNumber === 0) {
this.data = [];
}
this.data = [...this.data, ...value.content];
} else {
this.error = true;
}
}).catch(() => {
this.error = true;
}).then(() => {
this.loading = false;
this.timeout = setTimeout(this.refresh.bind(this), 4000);
})
}
}
export interface PoolBlockItem {
blockHeight: number;
status: string;
effort: number;
confirmationProgress: number;
transactionConfirmationData: string;
reward: number;
infoLink: string;
created: string;
}