From 985b7577e40c1eea3a7816bfb188807b47bbff82 Mon Sep 17 00:00:00 2001 From: Mononaut Date: Fri, 12 Jul 2024 09:29:21 +0000 Subject: [PATCH] Restrict accelerator routes to mainnet --- .../src/app/graphs/graphs.routing.module.ts | 6 +++--- .../src/app/services/navigation.service.ts | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/graphs/graphs.routing.module.ts b/frontend/src/app/graphs/graphs.routing.module.ts index dd3535f65..40bf64144 100644 --- a/frontend/src/app/graphs/graphs.routing.module.ts +++ b/frontend/src/app/graphs/graphs.routing.module.ts @@ -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, }, { diff --git a/frontend/src/app/services/navigation.service.ts b/frontend/src/app/services/navigation.service.ts index aed114c75..57f7f84dd 100644 --- a/frontend/src/app/services/navigation.service.ts +++ b/frontend/src/app/services/navigation.service.ts @@ -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 = '';