Improved network switching.
This commit is contained in:
@@ -38,30 +38,36 @@ export class StateService {
|
||||
constructor(
|
||||
private router: Router,
|
||||
) {
|
||||
this.setNetworkBasedonUrl(window.location.pathname);
|
||||
|
||||
this.router.events.subscribe((event) => {
|
||||
if (event instanceof NavigationStart) {
|
||||
switch (event.url.split('/')[1]) {
|
||||
case 'liquid':
|
||||
case 'liquid-tv':
|
||||
if (this.network !== 'liquid') {
|
||||
this.network = 'liquid';
|
||||
this.networkChanged$.next('liquid');
|
||||
}
|
||||
return;
|
||||
case 'testnet':
|
||||
case 'testnet-tv':
|
||||
if (this.network !== 'testnet') {
|
||||
this.network = 'testnet';
|
||||
this.networkChanged$.next('testnet');
|
||||
}
|
||||
return;
|
||||
default:
|
||||
if (this.network !== '') {
|
||||
this.network = '';
|
||||
this.networkChanged$.next('');
|
||||
}
|
||||
}
|
||||
this.setNetworkBasedonUrl(event.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setNetworkBasedonUrl(url: string) {
|
||||
switch (url.split('/')[1]) {
|
||||
case 'liquid':
|
||||
case 'liquid-tv':
|
||||
if (this.network !== 'liquid') {
|
||||
this.network = 'liquid';
|
||||
this.networkChanged$.next('liquid');
|
||||
}
|
||||
return;
|
||||
case 'testnet':
|
||||
case 'testnet-tv':
|
||||
if (this.network !== 'testnet') {
|
||||
this.network = 'testnet';
|
||||
this.networkChanged$.next('testnet');
|
||||
}
|
||||
return;
|
||||
default:
|
||||
if (this.network !== '') {
|
||||
this.network = '';
|
||||
this.networkChanged$.next('');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,20 @@ export class WebsocketService {
|
||||
private onlineCheckTimeout: number;
|
||||
private onlineCheckTimeoutTwo: number;
|
||||
private subscription: Subscription;
|
||||
private network = '';
|
||||
|
||||
constructor(
|
||||
private stateService: StateService,
|
||||
) {
|
||||
this.websocketSubject = webSocket<WebsocketResponse | any>(WEB_SOCKET_URL + '/' + this.stateService.network);
|
||||
this.network = this.stateService.network;
|
||||
this.websocketSubject = webSocket<WebsocketResponse | any>(WEB_SOCKET_URL + '/' + this.network);
|
||||
this.startSubscription();
|
||||
|
||||
this.stateService.networkChanged$.subscribe((network) => {
|
||||
if (network === this.network) {
|
||||
return;
|
||||
}
|
||||
this.network = network;
|
||||
clearTimeout(this.onlineCheckTimeout);
|
||||
clearTimeout(this.onlineCheckTimeoutTwo);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user