Restrict accelerator routes to mainnet

This commit is contained in:
Mononaut 2024-07-12 09:29:21 +00:00
parent 871e590305
commit 985b7577e4
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E
2 changed files with 20 additions and 4 deletions

View File

@ -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,
},
{

View File

@ -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 = '';