@@ -5,7 +5,7 @@ import { AppError, AppErrors } from '../../types/errors'
55import { EvmTokenType , Layer } from '../../oasis-nexus/api'
66import { Network } from '../../types/network'
77import { SearchScope } from '../../types/searchScope'
8- import { isStableDeploy } from '../../config'
8+ import { isStableDeploy , specialScopePaths } from '../../config'
99import { getSearchTermFromRequest } from '../components/Search/search-utils'
1010import { isLayerHidden } from '../../types/layers'
1111
@@ -37,6 +37,33 @@ export type SpecifiedPerEnabledLayer<T = any, ExcludeLayers = never> = {
3737
3838export type SpecifiedPerEnabledRuntime < T = any > = SpecifiedPerEnabledLayer < T , typeof Layer . consensus >
3939
40+ export const specialScopeRecognition : Partial < Record < string , Partial < Record < string , SearchScope > > > > = { }
41+
42+ function cacheSpecialScopePaths ( ) {
43+ const networks = Object . keys ( specialScopePaths ) as Network [ ]
44+
45+ networks . forEach ( network => {
46+ const networkPaths = specialScopePaths [ network ] !
47+ const layers = Object . keys ( networkPaths ) as Layer [ ]
48+ layers . forEach ( layer => {
49+ const [ word1 , word2 ] = networkPaths [ layer ] !
50+ if ( ! specialScopeRecognition [ word1 ] ) {
51+ specialScopeRecognition [ word1 ] = { }
52+ }
53+ if ( specialScopeRecognition [ word1 ] ! [ word2 ] ) {
54+ const other = specialScopeRecognition [ word1 ] ! [ word2 ] !
55+ console . warn (
56+ `Wrong config: conflicting special scope paths ${ word1 } /${ word2 } definitions used both for ${ other . network } /${ other . layer } and ${ network } /${ layer } ` ,
57+ )
58+ } else {
59+ specialScopeRecognition [ word1 ] ! [ word2 ] = { network, layer }
60+ }
61+ } )
62+ } )
63+ }
64+
65+ cacheSpecialScopePaths ( )
66+
4067export abstract class RouteUtils {
4168 private static ENABLED_LAYERS_FOR_NETWORK = {
4269 [ Network . mainnet ] : {
@@ -60,7 +87,11 @@ export abstract class RouteUtils {
6087 } satisfies Record < Network , Record < Layer , boolean > >
6188
6289 static getScopeRoute = ( { network, layer } : SearchScope ) => {
63- return `/${ encodeURIComponent ( network ) } /${ encodeURIComponent ( layer ) } `
90+ const specialPath = specialScopePaths [ network ] ?. [ layer ]
91+ const result = specialPath
92+ ? `/${ specialPath [ 0 ] } /${ specialPath [ 1 ] } `
93+ : `/${ encodeURIComponent ( network ) } /${ encodeURIComponent ( layer ) } `
94+ return result
6495 }
6596
6697 static getDashboardRoute = ( scope : SearchScope ) => this . getScopeRoute ( scope )
@@ -297,19 +328,25 @@ export const runtimeTransactionParamLoader = async ({ params }: LoaderFunctionAr
297328 return validateRuntimeTxHashParam ( params . hash ! )
298329}
299330
300- export const assertEnabledScope = ( {
301- network,
302- layer,
303- } : {
331+ export const assertEnabledScope = ( params : {
304332 network : string | undefined
305333 layer : string | undefined
306334} ) : SearchScope => {
307- if ( ! network || ! RouteUtils . getEnabledNetworks ( ) . includes ( network as Network ) ) {
335+ const { network : networkLike , layer : layerLike } = params
336+ if ( ! networkLike || ! layerLike ) {
337+ throw new AppError ( AppErrors . InvalidUrl )
338+ }
339+
340+ const { network, layer } = specialScopeRecognition [ networkLike ] ?. [ layerLike ] ?? {
341+ network : networkLike as Network ,
342+ layer : layerLike as Layer ,
343+ }
344+
345+ if ( ! RouteUtils . getEnabledNetworks ( ) . includes ( network as Network ) ) {
308346 throw new AppError ( AppErrors . InvalidUrl )
309347 }
310348
311349 if (
312- ! layer || // missing param
313350 ! RouteUtils . getAllLayersForNetwork ( network as Network ) . enabled . includes ( layer as Layer ) // unsupported on network
314351 ) {
315352 throw new AppError ( AppErrors . UnsupportedLayer )
0 commit comments