mirror of
https://github.com/mempool/mempool.git
synced 2025-04-08 20:08:32 +02:00
Restrict accelerator routes to mainnet
This commit is contained in:
parent
871e590305
commit
985b7577e4
@ -50,7 +50,7 @@ const routes: Routes = [
|
||||
},
|
||||
{
|
||||
path: 'acceleration',
|
||||
data: { networks: ['bitcoin'] },
|
||||
data: { networks: ['bitcoin'], networkSpecific: true, onlySubnet: [''] },
|
||||
component: StartComponent,
|
||||
children: [
|
||||
{
|
||||
@ -61,7 +61,7 @@ const routes: Routes = [
|
||||
},
|
||||
{
|
||||
path: 'acceleration/list/:page',
|
||||
data: { networks: ['bitcoin'] },
|
||||
data: { networks: ['bitcoin'], networkSpecific: true, onlySubnet: [''] },
|
||||
component: AccelerationsListComponent,
|
||||
},
|
||||
{
|
||||
@ -140,7 +140,7 @@ const routes: Routes = [
|
||||
},
|
||||
{
|
||||
path: 'acceleration/fees',
|
||||
data: { networks: ['bitcoin'] },
|
||||
data: { networks: ['bitcoin'], networkSpecific: true, onlySubnet: [''] },
|
||||
component: AccelerationFeesGraphComponent,
|
||||
},
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ import { Router, NavigationEnd, ActivatedRouteSnapshot } from '@angular/router';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { StateService } from './state.service';
|
||||
import { RelativeUrlPipe } from '../shared/pipes/relative-url/relative-url.pipe';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -30,15 +31,30 @@ export class NavigationService {
|
||||
constructor(
|
||||
private stateService: StateService,
|
||||
private router: Router,
|
||||
private relativeUrlPipe: RelativeUrlPipe,
|
||||
) {
|
||||
this.router.events.pipe(
|
||||
filter(event => event instanceof NavigationEnd),
|
||||
map(() => this.router.routerState.snapshot.root),
|
||||
).subscribe((state) => {
|
||||
this.updateSubnetPaths(state);
|
||||
if (this.enforceSubnetRestrictions(state)) {
|
||||
this.updateSubnetPaths(state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
enforceSubnetRestrictions(root: ActivatedRouteSnapshot): boolean {
|
||||
let route = root;
|
||||
while (route) {
|
||||
if (route.data.onlySubnet && !route.data.onlySubnet.includes(this.stateService.network)) {
|
||||
this.router.navigate([this.relativeUrlPipe.transform('')]);
|
||||
return false;
|
||||
}
|
||||
route = route.firstChild;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// For each network (bitcoin/liquid), find and save the longest url path compatible with the current route
|
||||
updateSubnetPaths(root: ActivatedRouteSnapshot): void {
|
||||
let path = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user