Skip to content

Commit 0fad0fb

Browse files
committed
Repost "want" after reconnect.
1 parent 85c4a34 commit 0fad0fb

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

frontend/src/app/about/about.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class AboutComponent implements OnInit {
1313
) { }
1414

1515
ngOnInit() {
16-
this.apiService.sendWebSocket({'action': 'want', data: []});
16+
this.apiService.webSocketWant([]);
1717
}
1818

1919
}

frontend/src/app/blockchain/blockchain.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class BlockchainComponent implements OnInit, OnDestroy {
2626
) {}
2727

2828
ngOnInit() {
29-
this.apiService.sendWebSocket({'action': 'want', data: ['stats', 'blocks', 'projected-blocks']});
29+
this.apiService.webSocketWant(['stats', 'blocks', 'projected-blocks']);
3030

3131
this.txTrackingSubscription = this.memPoolService.txTracking$
3232
.subscribe((response: ITxTracking) => {
@@ -46,14 +46,14 @@ export class BlockchainComponent implements OnInit, OnDestroy {
4646
return;
4747
}
4848
this.txTrackingLoading = true;
49-
this.apiService.sendWebSocket({'action': 'track-tx', 'txId': txId});
49+
this.apiService.webSocketStartTrackTx(txId);
5050
});
5151

5252
this.memPoolService.txIdSearch$
5353
.subscribe((txId) => {
5454
if (txId) {
5555
this.txTrackingLoading = true;
56-
this.apiService.sendWebSocket({'action': 'track-tx', 'txId': txId});
56+
this.apiService.webSocketStartTrackTx(txId);
5757
}
5858
});
5959

frontend/src/app/services/api.service.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const API_BASE_URL = '/api/v1';
1414
})
1515
export class ApiService {
1616
private websocketSubject: Observable<IMempoolDefaultResponse> = webSocket<IMempoolDefaultResponse | any>(WEB_SOCKET_URL);
17+
private lastWant: string[] | null = null;
18+
private goneOffline = false;
1719

1820
constructor(
1921
private httpClient: HttpClient,
@@ -27,7 +29,10 @@ export class ApiService {
2729
.pipe(
2830
retryWhen((errors: any) => errors
2931
.pipe(
30-
tap(() => this.memPoolService.isOffline$.next(true)),
32+
tap(() => {
33+
this.goneOffline = true;
34+
this.memPoolService.isOffline$.next(true);
35+
}),
3136
delay(5000),
3237
)
3338
),
@@ -92,17 +97,31 @@ export class ApiService {
9297
if (response['live-2h-chart']) {
9398
this.memPoolService.live2Chart$.next(response['live-2h-chart']);
9499
}
100+
101+
if (this.goneOffline === true) {
102+
this.goneOffline = false;
103+
if (this.lastWant) {
104+
this.webSocketWant(this.lastWant);
105+
}
106+
}
95107
},
96108
(err: Error) => {
97109
console.log(err);
110+
this.goneOffline = true;
98111
console.log('Error, retrying in 10 sec');
99112
setTimeout(() => this.startSubscription(), 10000);
100113
});
101114
}
102115

103-
sendWebSocket(data: any) {
116+
webSocketStartTrackTx(txId: string) {
117+
// @ts-ignore
118+
this.websocketSubject.next({'action': 'track-tx', 'txId': txId});
119+
}
120+
121+
webSocketWant(data: string[]) {
104122
// @ts-ignore
105-
this.websocketSubject.next(data);
123+
this.websocketSubject.next({'action': 'want', data: data});
124+
this.lastWant = data;
106125
}
107126

108127
listTransactionsForBlock$(height: number): Observable<IBlockTransaction[]> {

frontend/src/app/statistics/statistics.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ export class StatisticsComponent implements OnInit {
154154
switchMap(() => {
155155
this.spinnerLoading = true;
156156
if (this.radioGroupForm.controls['dateSpan'].value === '2h') {
157-
this.apiService.sendWebSocket({'action': 'want', data: ['live-2h-chart']});
157+
this.apiService.webSocketWant(['live-2h-chart']);
158158
return this.apiService.list2HStatistics$();
159159
}
160-
this.apiService.sendWebSocket({'action': 'want', data: ['']});
160+
this.apiService.webSocketWant([]);
161161
if (this.radioGroupForm.controls['dateSpan'].value === '24h') {
162162
return this.apiService.list24HStatistics$();
163163
}

frontend/src/app/television/television.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class TelevisionComponent implements OnInit {
2727
) { }
2828

2929
ngOnInit() {
30-
this.apiService.sendWebSocket({'action': 'want', data: ['projected-blocks', 'live-2h-chart']});
30+
this.apiService.webSocketWant(['projected-blocks', 'live-2h-chart']);
3131

3232
const labelInterpolationFnc = (value: any, index: any) => {
3333
return index % 6 === 0 ? formatDate(value, 'HH:mm', this.locale) : null;

0 commit comments

Comments
 (0)